home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch19 / filter / FilterManager.java < prev    next >
Encoding:
Java Source  |  1997-02-16  |  1.2 KB  |  59 lines

  1. // Simple Multiuser Server
  2. // (c) Copyright Justin Couch   justin@vlc.com.au
  3. // The Virtual Light Company 1996
  4. //
  5. // From Chapter 20: Late Night VRML 2.0 and java
  6. //
  7. // This is the Filter manager class. Maintains the list of active connections.
  8. // New connections are added with the add() method. Once every five seconds
  9. // it loops through the list of connections and looks for the inactive sessions
  10. // indicated by the isActive() method for each connection. Dead ones are
  11. // removed.
  12.  
  13. package filter;
  14.  
  15. import java.util.*;
  16.  
  17. class FilterManager extends Thread
  18. {
  19.     Vector connection_list = null;
  20.  
  21.     public FilterManager()
  22.     {
  23.         connection_list = new Vector(5, 2);
  24.     }
  25.  
  26.     public void run()
  27.     {
  28.         int    i;
  29.         FilterMessage msg;
  30.  
  31.         while(true)
  32.         {
  33.             // lock the vector so that we don't get clashes when trying to
  34.             // add a new connection
  35.             synchronized(connection_list)
  36.             {
  37.                 for(i = 0; i < connection_list.size(); i++)
  38.                 {
  39.                     msg = (FilterMessage)connection_list.elementAt(i);
  40.                     if(!msg.isAlive())
  41.                     {
  42.                         connection_list.removeElementAt(i);
  43.                         i--;
  44.                     }
  45.                 }
  46.             }
  47.             Thread.yield();
  48.         }
  49.     }
  50.  
  51.     public void add(FilterMessage msg)
  52.     {
  53.         synchronized(connection_list)
  54.         {
  55.             connection_list.addElement(msg);
  56.         }
  57.     }
  58. }
  59.