home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-16 | 3.6 KB | 166 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 main file. In here the program starts. It creates the four
- // different servers and looks after any cleanup that needs to be done of
- // shutdown.
- //
- // This program sits in an endless loop every 30 seconds it wakes up and
- // tests the ports to see if they are alive. This will probably do
- // something more later on.
-
- import registry.*;
- import filter.Filter;
- import filter.UserServer;
- import chat.Chat;
- import update.Update;
-
- public class muserver extends Thread
- {
- int base_port;
- RegistryServer rserver;
- Registry registry;
- UserServer userver;
- Filter filter;
- Chat chat;
- Update update;
-
- ThreadGroup serverThreadGroup = new ThreadGroup("Internal Server ThreadGroup");
- ThreadGroup filterThreadGroup = new ThreadGroup("Filter Server ThreadGroup");
- ThreadGroup updateThreadGroup = new ThreadGroup("Update Server ThreadGroup");
- ThreadGroup registryThreadGroup = new ThreadGroup("Registry Server ThreadGroup");
- ThreadGroup chatThreadGroup = new ThreadGroup("Chat Server ThreadGroup");
-
- // construct the basic system of the four servers
- public muserver(int base_pt, boolean debug)
- {
- System.out.println("Starting Multi User Environment server");
-
- setPriority(2);
- if(debug)
- System.out.println("Debugging is ON");
-
- base_port = base_pt;
-
- rserver = new RegistryServer(serverThreadGroup);
- userver = new UserServer(serverThreadGroup, debug);
- filter = new Filter(base_port, filterThreadGroup, userver);
- registry = new Registry(base_port, registryThreadGroup, rserver, debug);
- update = new Update(base_port + 2, updateThreadGroup, userver);
- chat = new Chat(base_port + 4, chatThreadGroup, userver);
-
- userver.start();
- rserver.start();
- filter.start();
- registry.start();
- update.start();
- chat.start();
-
- this.start();
- }
-
- public void run()
- {
- String input;
-
- while(true)
- {
- try
- {
- sleep(30000);
- }
- catch(InterruptedException e)
- {
- }
-
- if(!chat.isAlive())
- {
- System.err.println("Restarting chat server");
- chat = new Chat(base_port + 4, chatThreadGroup, userver);
- chat.start();
- }
-
- if(!update.isAlive())
- {
- System.err.println("Restarting update server");
- update = new Update(base_port + 2, updateThreadGroup, userver);
- update.start();
- }
-
- if(!filter.isAlive())
- {
- System.err.println("Restarting filter server");
- filter = new Filter(base_port, filterThreadGroup, userver);
- filter.start();
- }
-
- if(!registry.isAlive())
- {
- System.err.println("Restarting registry server");
- registry = new Registry(base_port, registryThreadGroup, rserver);
- registry.start();
- }
-
- if(!rserver.isAlive())
- {
- System.err.println("Registry server has died, exiting.");
- System.exit(2);
- }
-
- if(!userver.isAlive())
- {
- System.err.println("User server has dies, exiting");
- System.exit(3);
- }
-
- Thread.yield();
- }
- }
-
- public static void main(String[] args)
- {
- int i;
- int port = 3000;
- boolean _debug = false;
-
- if(args.length > 0)
- {
- for(i = 0; i < args.length; i++)
- {
- if(args[i].charAt(0) == '-')
- {
- if(args[i].equals("-d"))
- _debug = true;
- else
- {
- System.out.println("Usage: muserver [-d] [port]");
- System.exit(1);
- }
- }
- else
- {
- try
- {
- port = Integer.parseInt(args[i]);
- }
- catch (NumberFormatException e)
- {
- System.out.println("Invalid number for port");
- System.out.println("using default port 3000");
-
- // paranoia setting
- port = 3000;
- }
- break;
- }
- }
- }
-
- new muserver(port, _debug);
- }
- }
-
-