home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-16 | 1.3 KB | 60 lines |
- // Simple Multiuser Server
- // (c) Copyright Justin Couch justin@vlc.com.au
- // The Virtual Light Company 1996
- //
- // From Chapter 20: Late Night VRML 2.0 and java
- //
- // This is the Registry manager class. Maintains the list of active connections.
- // New connections are added with the add() method. Once every five seconds
- // it loops through the list of connections and looks for the inactive sessions
- // indicated by the isActive() method for each connection. Dead ones are
- // removed.
-
- package registry;
-
- import java.util.*;
- import registry.RegistryMessage;
-
- class RegistryManager extends Thread
- {
- Vector connection_list = null;
-
- public RegistryManager()
- {
- connection_list = new Vector(5, 2);
- }
-
- public void run()
- {
- int i;
- RegistryMessage msg;
-
- while(true)
- {
- // lock the vector so that we don't get clashes when trying to
- // add a new connection
- synchronized(connection_list)
- {
- for(i = 0; i < connection_list.size(); i++)
- {
- msg = (RegistryMessage)connection_list.elementAt(i);
- if(!msg.isAlive())
- {
- connection_list.removeElementAt(i);
- i--; // adjust for the removed element
- }
- }
- }
- Thread.yield();
- }
- }
-
- public void add(RegistryMessage msg)
- {
- synchronized(connection_list)
- {
- connection_list.addElement(msg);
- }
- }
- }
-