/************************************************* * * = PACKAGE * netsvcs.Naming * * = FILENAME * NameAcceptor.java * *************************************************/ package JACE.netsvcs.Naming; import java.io.*; import java.net.*; import java.util.*; import JACE.OS.*; import JACE.Misc.*; import JACE.Connection.*; import JACE.Reactor.*; import JACE.ASX.TimeValue; import JACE.netsvcs.Server; /** * Server for the naming service. * Listens on the specified port (command line option) and launches * NameHandlers when connections are made. *
* The hash table for the mapping and a timer queue are created here. * Periodically, if it has been changed, the mapping is saved to a file. * If the data file exists at load time, it is read from disk. Currently, * the service stores the entire mapping in one Hashtable (which is probably * kept in memory at all times). *
* Valid command line arguments: *
* -f (file name) File name of the database * (Default is namedata.dat) * -p (port number) Port to listen on for clients * -d Enable debugging * -t (time sec) How often to save the database (default 60 sec) * -a (class name) Specify ActivateStrategy * (Default is multi-threaded) ** *@see NameHandler * *@author Everett Anderson * */ public class NameAcceptor extends Server { /** * Constructor */ public NameAcceptor () { // Set the name in case we are not using the service // configurator name ("Naming Service"); // Create the hash table and timer queue this.mapping_ = new Hashtable (); this.tq_ = new TimerQueue (true); } /** * Simple main program. See the class description for more * information about command line arguments. */ public static void main (String [] args) { // Simple main program to get things rolling NameAcceptor na = new NameAcceptor(); na.init(args); } /** * Check to see if the mapping has been modified since the last * save. */ synchronized boolean modifiedMapping () { return mappingWasModified_; } /** * Set the modified state of the mapping. */ synchronized void modifiedMapping (boolean value) { mappingWasModified_ = value; } /** * Cancels the timer which was used to save the mapping, then delegates * to Server.fini (). * *@return -1 on failure, 0 on success */ public int fini () { if (!done () && tq_ != null) tq_.cancelTimer (this); return super.fini (); } /** * Read the data file (if it exists) and schedule a periodic timer * to save it at intervals. At the end, this delegates to * Server.initialize () (which currently sets the default * activation scheme if it wasn't defined on the command line). * *@see Server#initialize *@return -1 on failure, 0 on success */ protected int initialize () { this.loadTable (); this.tq_.scheduleTimer (this, null, new TimeValue (this.updateInterval_), new TimeValue (this.updateInterval_)); // Use whatever default ActivateStrategy is defined in the // Server class (unless specified in parseArgs) return super.initialize (); } /** * Create a new NameHandler instance. */ protected SvcHandler makeSvcHandler () { return new NameHandler (mapping_); } /** * Prints out the valid command line arguments. See the class * description for more information. Called by Server.init when * parseArgs returns -1. */ protected void printUsage () { ACE.ERROR ("Valid options:\n"); ACE.ERROR ("-f