diff options
Diffstat (limited to 'java/JACE/netsvcs')
40 files changed, 0 insertions, 6083 deletions
diff --git a/java/JACE/netsvcs/Handler.java b/java/JACE/netsvcs/Handler.java deleted file mode 100644 index 7bf73f01206..00000000000 --- a/java/JACE/netsvcs/Handler.java +++ /dev/null @@ -1,185 +0,0 @@ -package JACE.netsvcs; - -import java.io.*; -import java.net.*; -import JACE.OS.*; -import JACE.Connection.*; - -/** - * Abstract class representing a handler for a Server. Provides - * default implementations and template methods. - * - *@see Server - *@author Everett Anderson - */ -public abstract class Handler extends SvcHandler -{ - /** - * Initialize this Handler. The default implementation sets the - * done flag to false. - * - *@return -1 on failure, 0 on success - */ - public int open (Object obj) - { - done_ = false; - return 0; - } - - /** - * Shut down this handler. Default implementation calls close (). - */ - public int close (long flags) - { - return close (); - } - - /** - * Shut down this handler, setting the done flag, and removing it - * from the parent Server's handler list. - */ - public synchronized int close () - { - if (!done ()) { - try { - done_ = true; - parent_.removeHandler (this); - peer ().close (); - } catch (IOException e) { - return -1; - } - } - - return 0; - } - - /** - * Returns the name of the host that is connected to this handler, - * or null if not connected. - */ - public String hostName () - { - if (done ()) - return null; - else - return this.peer().socket().getInetAddress().getHostName(); - } - - /** - * Process a single request and handle any errors. The default - * implementation calls handleRequest with an Object from - * newRequest (). - */ - public void handleRequest () - { - handleRequest (newRequest ()); - } - - /** - * Process a single request and handle any errors. The default - * implementation calls processRequest with the given request - * Object, and then handles exceptions appropriately. Subclasses - * normally just implement processRequest rather than override - * this method. - * - *@param request request to process - */ - public void handleRequest (Object request) - { - try { - - processRequest (request); - - } catch (NullPointerException e) { - if (!done ()) { - ACE.ERROR("Failure: " + e); - close (); - } - } catch (SocketException e) { - if (!done ()) { - ACE.DEBUG (hostName () + " disconnected"); - close (); - } - } catch (EOFException e) { - if (!done ()) { - ACE.DEBUG (hostName () + " disconnected"); - close (); - } - } catch (IOException e) { - if (!done ()) { - ACE.ERROR ("Lost connection: " + e); - close (); - } - } - } - - /** - * Process a single request (including reading it from the wire) - * without handling errors. Subclasses must define the behavior. - * - *@param requestObject request to process - *@exception SocketException problem with the socket - *@exception EOFException end of connection, - * usually means client disconnected - *@exception IOException error during transmission - */ - protected abstract void processRequest (Object requestObject) - throws SocketException, EOFException, IOException; - - /** - * Returns a new instance of a request object. Subclasses must - * define the behavior. - */ - public abstract Object newRequest (); - - /** - * Called by the JVM when a Handler is run in its own Thread. The - * default implementation creates a single request object which is - * reused during multiple handleRequest calls. The loop exits - * when the Handler's done() method returns true. - */ - public void run() - { - Object request = newRequest (); - - while (!done ()) - handleRequest (request); - - close (); - } - - /** - * Set the Server parent of this Handler. - */ - public void parent (Server parent) - { - parent_ = parent; - } - - /** - * Return the Server parent of this Handler. - */ - public Server parent () - { - return parent_; - } - - /** - * Check to see if this Handler should shut down. - */ - protected synchronized boolean done () - { - return done_; - } - - /** - * Closes the handler, freeing resources. - */ - protected void finalize () throws Throwable - { - close (); - } - - private boolean done_ = true; - private Server parent_; -} diff --git a/java/JACE/netsvcs/Logger/LogRecord.java b/java/JACE/netsvcs/Logger/LogRecord.java deleted file mode 100644 index 972cf45af74..00000000000 --- a/java/JACE/netsvcs/Logger/LogRecord.java +++ /dev/null @@ -1,290 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.netsvcs.Logger - * - * = FILENAME - * LogRecord.java - * - *@author Chris Cleeland, Everett Anderson - * - *************************************************/ -package JACE.netsvcs.Logger; - -import java.util.*; -import java.io.*; -import JACE.OS.*; - -/** - * Communicates logging information. Compatible with the C++ ACE - * ACE_Log_Record class. - */ -public class LogRecord -{ - /** - * Maximum size of a LogRecord - */ - final public int MAXLOGMSGLEN = 4 * 1024; - - private int type_; - private int length_; - private long msec_; - private int pid_; - private byte[] msgData_; - private final static int numIntMembers = 5; - private final static int sizeofIntInBytes = 4; - - /** - * Create a default instance. - */ - public LogRecord() - { - type(0); - timeStamp((int)new Date().getTime()); - length(0); - pid(0); - } - - /** - * Create a LogRecord. This is the designated initializer. - * @param priority a numeric specification of the priority (ascending) - * @param milliseconds time attached to the log entry in Unix <pre>time_t</pre> format - * @param pid the process ID - */ - public LogRecord(int priority, - long milliseconds, - int pid) - { - type(priority); - timeStamp(milliseconds); - length(0); - pid(pid); - } - - /** - * Create a LogRecord with the current time and the given message. - * - *@param message message to log - */ - public LogRecord (String message) - { - this (); - - msgData (message); - } - - /** - * Conversion to string. Only includes the <pre>msgData_</pre> member. - */ - public String toString() - { - String result = null; - try { - result = new String (msgData_, - "US-ASCII"); - } catch (UnsupportedEncodingException e) { - result = new String (msgData_); - } - - return result; - } - - /** - * Place a textual representation of the record on a PrintStream. - * When verbose is specified to be true, the output takes the form - * <PRE>(Date)@(host name)@(PID)@(type)@(message)</PRE> - * Otherwise it just prints the message. - * @param hostname name of the host generating this record - * @param verbose specify how much information to print (see above) - * @param ps A PrintStream instance to which the output should go. - */ - public void print(String hostname, - boolean verbose, - PrintStream ps) - { - String toprint; - if (verbose) - { - Date now = new Date(this.timeStamp()); - - /* 01234567890123456789012345 */ - /* Wed Oct 18 14:25:36 1989n0 */ - toprint = now.toString().substring(4) + "@" - + hostname + "@" + pid_ + "@" + type_ + "@" - + this.toString(); - } - else - { - toprint = this.toString(); - } - ps.println(toprint); - } - - /** - * Read in the data for this LogRecord from the given InputStream. - * - *@param is InputStream to read from - *@exception IOException error during transmission - */ - public void streamInFrom (InputStream is) throws IOException - { - BufferedInputStream bis = new BufferedInputStream (is); - - DataInputStream dis = new DataInputStream (bis); - - streamInFrom (dis); - } - - /** - * Read in the data for this LogRecord from the given DataInputStream. - * - *@param dis DataInputStream to read from - *@exception IOException error during transmission - */ - public void streamInFrom(DataInputStream dis) throws IOException - { - // Order here must match layout order in the C++ class. - length(dis.readInt()); - type(dis.readInt()); - this.timeStamp((long)dis.readInt() * 1000); - - // Skip smaller time resolution info since we're lucky if Java's - // timer can handle more than millisecond precision, anyway - dis.skipBytes(4); - - pid(dis.readInt()); - - int dataLength = (int) (length_ - numIntMembers * sizeofIntInBytes); - - msgData_ = new byte[dataLength]; - - dis.readFully(msgData_, 0, dataLength); - } - - /** - * Write this LogRecord out to the given OutputStream. - * - *@param os OutputStream to write to - *@exception IOException error during transmission - */ - public void streamOutTo (OutputStream os) throws IOException - { - BufferedOutputStream bos = new BufferedOutputStream (os); - - DataOutputStream dos = new DataOutputStream (bos); - - streamOutTo (dos); - } - - /** - * Write this LogRecord out to the given DataOutputStream. - * - *@param dos OutputStream to write to - *@exception IOException error during transmission - */ - public void streamOutTo(DataOutputStream dos) throws IOException - { - dos.writeInt(length()); - dos.writeInt(type()); - dos.writeInt((int)(this.msec_ / 1000)); - dos.writeInt(0); - dos.writeInt(pid()); - - dos.write(msgData_); - - dos.flush (); - } - - /** - * Return the LogRecord type. - */ - public int type() { return type_; } - - /** - * Set the LogRecord type. - */ - public void type(int t) { type_ = t; } - - /** - * Return the length of this LogRecord. - */ - public int length() { return length_; } - - /** - * Set the length of this LogRecord. - */ - public void length(int l) { length_ = l; } - - /** - * Calculate the length of this LogRecord from the size of - * the message and the header. - */ - private void setLen(int msgLen) - { length(msgLen + numIntMembers * sizeofIntInBytes); } - - /** - * Return the millisec time stamp of this LogRecord. - */ - public long timeStamp() { return this.msec_; } - - /** - * Set the millisec time stamp of this LogRecord. - */ - public void timeStamp(long msec){ this.msec_ = msec; } - - /** - * Return the PID of this LogRecord. - */ - public int pid() { return pid_; } - - /** - * Set the PID of this LogRecord. - */ - public void pid(int p) { pid_ = p; } - - /** - * Return the message of this LogRecord as a byte array. - */ - public byte[] msgData() { return msgData_; } - - /** - * Set the message of this LogRecord to a given byte array. - */ - public void msgData(byte[] m) - { - int size = m.length; - - if (size > MAXLOGMSGLEN) - size = MAXLOGMSGLEN; - - this.msgData_ = new byte[size]; - - System.arraycopy(m, 0, msgData_, 0, size); - - setLen(size); - } - - /** - * Set the message of this LogRecord to a given byte array. First - * tries to use US-ASCII encoding, then uses the default encoding - * if that fails. The toString method is essentially the opposite - * version. - */ - public void msgData(String m) - { - byte temp[] = null; - try { - temp = m.getBytes("US-ASCII"); - } catch (UnsupportedEncodingException e) { - temp = m.getBytes (); - } - if (temp.length > MAXLOGMSGLEN) { - this.msgData_ = new byte[MAXLOGMSGLEN]; - - System.arraycopy(temp, 0, msgData_, 0, MAXLOGMSGLEN); - } else - this.msgData_ = temp; - - setLen(msgData_.length); - } -} diff --git a/java/JACE/netsvcs/Logger/LoggingStrategy.java b/java/JACE/netsvcs/Logger/LoggingStrategy.java deleted file mode 100644 index b7912499385..00000000000 --- a/java/JACE/netsvcs/Logger/LoggingStrategy.java +++ /dev/null @@ -1,35 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Logger - * - * = FILENAME - * LogMessageReceiver.java - * - *@author Everett Anderson - * - *************************************************/ -package JACE.netsvcs.Logger; - -import java.io.*; - -/** - * Encapsulates the handling of a LogRecord from a given host, allowing - * easy swapping of behavior in the logging service. Strategies could - * be developed to save to a file, print on a certain stream, forward - * to another service, etc. - * - *@see StderrStrategy - *@see LogRecord - */ -public interface LoggingStrategy -{ - /** - * Process the given LogRecord. - * - *@param hostname host from which this LogRecord originated - *@param record LogRecord instance to process - */ - public void logRecord (String hostname, - LogRecord record); -} diff --git a/java/JACE/netsvcs/Logger/ServerLoggingAcceptor.java b/java/JACE/netsvcs/Logger/ServerLoggingAcceptor.java deleted file mode 100644 index c0ef8831fc6..00000000000 --- a/java/JACE/netsvcs/Logger/ServerLoggingAcceptor.java +++ /dev/null @@ -1,147 +0,0 @@ -package JACE.netsvcs.Logger; - -import java.util.*; -import java.io.*; -import java.net.*; -import JACE.SOCK_SAP.*; -import JACE.Connection.*; -import JACE.OS.*; -import JACE.Misc.*; -import JACE.netsvcs.Server; - -/** - * Server for the logging service. Sets the default logging strategy - * to StderrStrategy so that logging requests are printed on the - * System.err stream. Other strategies can be specified on the - * command line. - * <P> - * <B>Valid command line arguments:</B> - * <PRE> - * -r (class name) Specify a LoggingStrategy - * (Default is StdErrStrategy) - * -p (port) Port to listen on for clients - * -d Enable debugging messages - * -a (class name) Specify ActivateStrategy - * (Default is thread per connection) - * </PRE> - * - *@see LoggingStrategy - *@see StderrStrategy - */ -public class ServerLoggingAcceptor extends Server -{ - /** - * Default constructor. Sets the default LoggingStrategy to - * StderrStrategy. - */ - public ServerLoggingAcceptor () - { - name ("Logging Service"); - logStrategy_ = new StderrStrategy (); - } - - /** - * Simple main program for running the logging service without the - * service configurator. - * - *@param args command line arguments - */ - public static void main (String [] args) - { - ServerLoggingAcceptor sla = new ServerLoggingAcceptor(); - - sla.init(args); - } - - /** - * Accessor for the LoggingStrategy - */ - public LoggingStrategy loggingStrategy () - { - return this.logStrategy_; - } - - /** - * Creates a new ServerLoggingHandler instance. - */ - protected SvcHandler makeSvcHandler () - { - return new ServerLoggingHandler (); - } - - /** - * 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 ("-r <class name> Specify a LoggingStrategy"); - ACE.ERROR (" (Default is StdErrStrategy"); - ACE.ERROR ("-p <port> Port to listen on for clients"); - ACE.ERROR ("-d Enable debugging messages"); - ACE.ERROR ("-a <class name> Specify ActivateStrategy"); - ACE.ERROR (" (Default is single threaded"); - } - - /** - * Parses the command line arguments. See the class description - * for more information. - * - *@param args command line arguments - *@return -1 on failure, 0 on success - */ - protected int parseArgs (String args[]) - { - String s; - Object strategy; - GetOpt opt = new GetOpt (args, "p:r:da:", true); - int c = 0; - - try { - - while ((c = opt.next ()) != -1) - { - switch (c) - { - case 'd': - ACE.enableDebugging (); - ACE.DEBUG ("Debugging is enabled"); - break; - case 'p': - if (!port (opt.optarg ())) - return -1; - break; - case 'a': - strategy = newStrategyInstance (opt.optarg (), - "ActivateStrategy"); - if (strategy == null) - return -1; - - activateStrategy ((ActivateStrategy) strategy); - break; - case 'r': - // Load the Strategy with the given name - strategy = newStrategyInstance (opt.optarg (), - "LoggingStrategy"); - if (strategy == null) - return -1; - - logStrategy_ = (LoggingStrategy)strategy; - break; - default: - ACE.ERROR ("Unknown argument: " + c); - return -1; - } - } - } catch (ArrayIndexOutOfBoundsException e) { - ACE.ERROR ("Option -" + (char)c + " requires an argument"); - return -1; - } - - return 0; - } - - private LoggingStrategy logStrategy_; -} diff --git a/java/JACE/netsvcs/Logger/ServerLoggingHandler.java b/java/JACE/netsvcs/Logger/ServerLoggingHandler.java deleted file mode 100644 index 88a564c2c34..00000000000 --- a/java/JACE/netsvcs/Logger/ServerLoggingHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Logger - * - * = FILENAME - * ServerLoggingHandler.java - * - *@author Everett Anderson - * - *************************************************/ -package JACE.netsvcs.Logger; - -import java.io.*; -import java.util.*; -import java.net.*; -import JACE.SOCK_SAP.*; -import JACE.Connection.*; -import JACE.OS.*; -import JACE.netsvcs.Handler; - -/** - * - * Created by ServerLoggingAcceptor to handle logging requests. This - * simply reads the record and hands it to the registered LoggingStrategy. - * - * @see JACE.netsvcs.Logger.ServerLoggingAcceptor - */ -public class ServerLoggingHandler extends Handler -{ - /** - * Reads in the given LogRecord request and hands it to the - * LoggingStrategy registered with the ServerLoggingAcceptor parent. - * - *@param request LogRecord instance to use - */ - public void processRequest (Object request) - throws SocketException, EOFException, IOException - { - LogRecord rec = (LogRecord)request; - - rec.streamInFrom (this.peer ().dataInputStream ()); - - ServerLoggingAcceptor parent = (ServerLoggingAcceptor)parent (); - - parent.loggingStrategy ().logRecord (this.hostName (), rec); - } - - /** - * Creates a new instance of LogRecord. - */ - public Object newRequest () - { - return new LogRecord (); - } -} - - - - diff --git a/java/JACE/netsvcs/Logger/StderrStrategy.java b/java/JACE/netsvcs/Logger/StderrStrategy.java deleted file mode 100644 index ee927e19062..00000000000 --- a/java/JACE/netsvcs/Logger/StderrStrategy.java +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Logger - * - * = FILENAME - * DefaultLMR.java - * - * - *@author Everett Anderson - * - *************************************************/ -package JACE.netsvcs.Logger; - -import java.io.*; - -/** - * Default LoggingStrategy for the logging service. This prints out the - * LogRecord on the System.err stream. - * - * @see JACE.netsvcs.Logger.LogRecord - */ -public class StderrStrategy implements LoggingStrategy -{ - /** - * Process the given LogRecord by printing it on the System.err stream. - * - *@param hostname host from which this LogRecord originated - *@param record LogRecord instance to process - */ - public void logRecord (String hostname, - LogRecord record) - { - record.print(hostname, true, System.err); - } -} diff --git a/java/JACE/netsvcs/Logger/c.bat b/java/JACE/netsvcs/Logger/c.bat deleted file mode 100644 index 6600766df1d..00000000000 --- a/java/JACE/netsvcs/Logger/c.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -javac -d C:\Everett\JACE\classes *.java diff --git a/java/JACE/netsvcs/Logger/package.html b/java/JACE/netsvcs/Logger/package.html deleted file mode 100644 index 84bffb246d9..00000000000 --- a/java/JACE/netsvcs/Logger/package.html +++ /dev/null @@ -1,17 +0,0 @@ -<!-- $Id$ --> -<HTML> -<BODY> -Logging Service for processing logging records received from remote hosts. -<P> -The strategy for how to process the records can be easily changed via the -command line. -<P> -A simple test client is available in the tests directory under netsvcs\Logger. -The service itself can either be run on the command line (by running -ServerLoggingAcceptor) or by loading it with a ServiceConfig file (see -the tests for the service configurator). - -@see JACE.netsvcs.Logger.LoggingStrategy -@see <a href="http://www.cs.wustl.edu/~schmidt/ACE-netsvcs.html">ACE Network Services</a> -</BODY> -</HTML> diff --git a/java/JACE/netsvcs/Naming/NameAcceptor.java b/java/JACE/netsvcs/Naming/NameAcceptor.java deleted file mode 100644 index 7e7be457d70..00000000000 --- a/java/JACE/netsvcs/Naming/NameAcceptor.java +++ /dev/null @@ -1,313 +0,0 @@ -/************************************************* - * - * = 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. - * <P> - * 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). - * <P> - * <B>Valid command line arguments:</B> - * <PRE> - * -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) - * </PRE> - * - *@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 <file name> File name of the database"); - ACE.ERROR (" (Default is namedata.dat)"); - ACE.ERROR ("-p <port number> Port to listen on for clients"); - ACE.ERROR ("-d Enable debugging"); - ACE.ERROR ("-t <time sec> How often to save the database"); - ACE.ERROR (" (Default is 60 seconds)"); - ACE.ERROR ("-a <class name> Specify ActivateStrategy"); - ACE.ERROR (" (Default is multi-threaded"); - } - - /** - * Parses the command line arguments. See the class description - * for more information. - * - *@param args command line arguments - *@return -1 on failure, 0 on success - */ - protected int parseArgs (String [] args) - { - int c = 0; - String s; - GetOpt opt = new GetOpt (args, "p:f:t:da:", true); - - try { - - while ((c = opt.next ()) != -1) { - switch (c) - { - case 'f': - this.filename_ = opt.optarg (); - break; - case 't': - try { - this.updateInterval_ = Integer.parseInt (opt.optarg ()); - } catch (NumberFormatException e) { - ACE.ERROR ("Invalid interval specified: " + e.getMessage ()); - return -1; - } - break; - case 'd': - ACE.enableDebugging (); - ACE.DEBUG ("Debugging is enabled"); - break; - case 'p': - if (!port (opt.optarg ())) - return -1; - break; - case 'a': - Object strategy = newStrategyInstance (opt.optarg (), - "ActivateStrategy"); - if (strategy == null) - return -1; - - activateStrategy ((ActivateStrategy) strategy); - break; - default: - ACE.ERROR ("Unknown argument: " + (char)c); - return -1; - } - } - } catch (ArrayIndexOutOfBoundsException e) { - ACE.ERROR ("Option -" + (char)c + " requires an argument"); - return -1; - } - - return 0; - } - - /** - * Loads the hash table into memory from the specified - * file. Uses ObjectInputStream. - */ - protected void loadTable () - { - File file = new File(this.filename_); - FileInputStream fis; - ObjectInputStream ois; - - Hashtable ht = null; - - try { - - if ((file.exists()) && (file.canRead())) { - - fis = new FileInputStream (file); - - ois = new ObjectInputStream(fis); - - ht = (Hashtable)ois.readObject(); - } else - return; - } catch (ClassNotFoundException e) { - ACE.ERROR(e); - } catch (StreamCorruptedException e) { - ACE.ERROR(e); - } catch (SecurityException e) { - ACE.ERROR(e); - } catch (IOException e) { - ACE.ERROR(e); - } - - if (ht != null) - this.mapping_ = ht; - - } - - /** - * Writes the table out to the specified file if it has been modified. - */ - protected void saveTable () - { - if (!modifiedMapping ()) - return; - - FileOutputStream fos; - ObjectOutputStream oos; - - try { - - fos = new FileOutputStream(this.filename_); - oos = new ObjectOutputStream(fos); - - synchronized (this.mapping_) { - oos.writeObject(this.mapping_); - - modifiedMapping (false); - } - - oos.flush(); - - oos.close(); - - } catch (OptionalDataException e) { - ACE.ERROR(e); - } catch (NotSerializableException e) { - ACE.ERROR(e); - } catch (IOException e) { - ACE.ERROR(e); - } - } - - /** - * Call back for the TimerQueue. This calls the method to save the - * hash table. The default time out is 60 seconds. - */ - public int handleTimeout (TimeValue tv, Object obj) - { - this.saveTable(); - - return 0; - } - - // Mapping data structure - Hashtable mapping_ = null; - - // Default file name - String filename_ = "namedata.dat"; - - // How often to save the table (seconds) - int updateInterval_ = 60; - - // Calls handleTimeout at updateInterval_ intervals - TimerQueue tq_ = null; - - boolean mappingWasModified_ = false; -} - diff --git a/java/JACE/netsvcs/Naming/NameHandler.java b/java/JACE/netsvcs/Naming/NameHandler.java deleted file mode 100644 index 9989e925543..00000000000 --- a/java/JACE/netsvcs/Naming/NameHandler.java +++ /dev/null @@ -1,473 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Naming - * - * = FILENAME - * NameHandler.java - * - *************************************************/ -package JACE.netsvcs.Naming; - -import java.net.SocketException; -import java.io.*; -import java.util.*; -import JACE.OS.*; -import JACE.Connection.*; -import JACE.Reactor.*; -import JACE.SOCK_SAP.*; -import JACE.netsvcs.Handler; - -/** - * Handlers interaction between a client (NameProxy) and the naming - * service database. Created by NameAcceptor to handle requests. - * <P> - * In general, the user binds a name to a (value, type) pair. The type is just - * treated as just another String (in the C++ version the name and value are - * arrays of 16 bit data types and the type is an array of 8 bit chars). - * <P> - * For this to work in the hash table scheme, the type and value are wrapped in - * a ValueType class defined as a nested top level class within the - * NameHandler. - * <P> - * This is compatible with the C++ ACE remote name service. - * - *@see JACE.netsvcs.Naming.NameAcceptor - *@see JACE.netsvcs.Naming.NameRequest - *@see JACE.netsvcs.Naming.NameReply - * - *@author Everett Anderson - */ -public class NameHandler extends Handler -{ - /** - * Constructor - * - * @param mapping Hash table created in NameAcceptor - */ - public NameHandler (Hashtable mapping) - { - this.mapping_ = mapping; - } - - /** - * Read in the given NameRequest and calls dispatch. - */ - public void processRequest (Object request) - throws SocketException, EOFException, IOException - { - NameRequest nameRequest = (NameRequest)request; - - nameRequest.streamInFrom (peer ().dataInputStream ()); - - this.dispatch (nameRequest); - } - - /** - * Create a new instance of NameRequest. - */ - public Object newRequest () - { - return new NameRequest (); - } - - /** - * This is the point at which a request is sent to the various methods - * that fulfill it. It switches on the request type -- bind, - * rebind, resolve, etc. - * - *@param nameRequest The request to respond to - */ - void dispatch (NameRequest nameRequest) throws IOException - { - NameAcceptor parent = (NameAcceptor)parent (); - - // Call the various other member functions based on the - // message type of the request -- bind, rebind, etc. - switch (nameRequest.requestType()) - { - case NameRequest.BIND: - this.bind(nameRequest, false); - parent.modifiedMapping (true); - break; - case NameRequest.REBIND: - this.bind(nameRequest, true); - parent.modifiedMapping (true); - break; - case NameRequest.RESOLVE: - this.resolve(nameRequest); - break; - case NameRequest.UNBIND: - this.unbind(nameRequest); - parent.modifiedMapping (true); - break; - case NameRequest.LIST_NAMES: - this.listByName(nameRequest.name(), false); - break; - case NameRequest.LIST_VALUES: - this.listByValue(nameRequest.name(), false); - break; - case NameRequest.LIST_TYPES: - this.listByType(nameRequest.name(), false); - break; - case NameRequest.LIST_NAME_ENTRIES: - this.listByName(nameRequest.name(), true); - break; - case NameRequest.LIST_VALUE_ENTRIES: - this.listByValue(nameRequest.name(), true); - break; - case NameRequest.LIST_TYPE_ENTRIES: - this.listByType(nameRequest.name(), true); - break; - default: - ACE.ERROR("Unknown type: " + nameRequest.requestType()); - - // Send a failure message. This will only work if the other - // side is expecting something like a NameReply rather than - // a NameRequest. It would've been better to have everything - // use NameRequests to avoid this kind of thing. - NameReply reply = new NameReply (NameReply.FAILURE, 0); - reply.streamOutTo(peer ().dataOutputStream ()); - break; - } - - } - - /** - * - * Bind a name and a (value, type) pair. All this data is given in the - * NameRequest from the client. Returns a NameReply back to the client - * with either Reply.SUCCESS or Reply.FAILURE as the type. - * - *@param request NameRequest given by the client - *@param rebind Is this a rebind or not? - */ - void bind (NameRequest request, - boolean rebind) throws IOException - { - // The hash table entries consists of (String name, ValueType data) - // pairs, so create the appropriate ValueType - ValueType vt = new ValueType(request.type(), - request.value()); - - // Reply to tell sender of success or failure - NameReply reply = new NameReply(); - - // If it's a rebind request, overwrite the old entry. If the key doesn't - // exist, add it. If it does exist and it's not a bind request, return - // a failure code via a NameReply. - if ((rebind) || (!this.mapping_.containsKey(request.name()))) { - - ACE.DEBUG ("Binding: " + request.name() + " and " + vt.value_); - - // Add/Update the entry in the hash table - this.mapping_.put(request.name(), vt); - - // Set the reply code to success - reply.type(NameReply.SUCCESS); - - } else { - - ACE.DEBUG ("Key " + request.name() + " already exists"); - - // Set reply code to failure - reply.type(NameReply.FAILURE); - - // reply error code unused as far as I know - } - - reply.streamOutTo(peer ().dataOutputStream ()); - } - - /** - * Given a name, this looks up and returns the type and value. This is - * done by sending back a full NameRequest with the correct info. If - * there is a problem, an "empty" NameRequest is returned -- it has no - * name, type, or value fields. - * - *@param request NameRequest sent by the client (has the name to lookup) - */ - void resolve (NameRequest request) throws IOException - { - // A NameRequest is also used in response - NameRequest result; - - // If the requested name is in the hash table, return the data - if (this.mapping_.containsKey(request.name())) { - - // Get the data pair based on the name - ValueType vt = (ValueType)this.mapping_.get(request.name()); - - ACE.DEBUG("Good resolve: " + vt.value_); - - // Fill the reply structure - result = new NameRequest(NameRequest.RESOLVE, - null, - vt.value_, - vt.type_, - null); - - } else { - - // Otherwise return a null response - result = new NameRequest(NameRequest.RESOLVE, - null, - null, - null, - null); - - } - - result.streamOutTo (peer ().dataOutputStream ()); - } - - /** - * - * Given a name, remove its entry in the mapping. Returns a NameReply - * to the client with NameReply.SUCCESS or NameReply.FAILURE. - * - *@param request NameRequest from the client (has the name to remove) - */ - void unbind (NameRequest request) throws IOException - { - NameReply reply = new NameReply(); - - // If the given key isn't in the table, return an error - // Otherwise remove it. Uses a NameReply to respond. - if (!this.mapping_.containsKey(request.name())) - reply.type(NameReply.FAILURE); - else { - this.mapping_.remove(request.name()); - reply.type(NameReply.SUCCESS); - } - - // Send the reply out to the socket - reply.streamOutTo (peer ().dataOutputStream ()); - } - - /** - * - * Given a pattern string (given in NameRequest's name field), this - * finds all the entries in the mapping which have a name that begins with - * the string. Each one is sent back separately via a NameRequest, and this - * sequence is followed by a blank NameRequest. - * - *@param pattern Pattern to find (what result names should - * begin with) - *@param completeLookup Should the value and type be returned as well? - */ - void listByName (String pattern, - boolean completeLookup) throws IOException - { - // Get a listing of all the keys in the hash table - Enumeration enum = this.mapping_.keys(); - - // References used in the loop - String name; - ValueType vt; - - // A NameRequest is used to return each item corresponding to the pattern. - NameRequest result = - new NameRequest((completeLookup ? NameRequest.LIST_NAMES : - NameRequest.LIST_NAME_ENTRIES), - null, - null, - null, - null); - - // Keep ourselves safe from null pointer exceptions - if (pattern == null) - pattern = new String(""); - - // Scan through all the elements - while (enum.hasMoreElements()) { - - // Get a key - name = (String)enum.nextElement(); - - // Does it fit the pattern? - if (name.startsWith(pattern)) { - - // Set the result name - result.name(name); - - // Only make another hash table request if the user - // wants all the data - if (completeLookup) { - - // Get data from the hash table - vt = (ValueType)mapping_.get(name); - - // Set the rest of the data - result.type(vt.type_); - result.value(vt.value_); - } - - // Send it to the socket - result.streamOutTo (peer ().dataOutputStream ()); - } - } - - // Send final null message - result.name(null); - result.type(null); - result.value(null); - result.requestType(NameRequest.MAX_ENUM); - result.streamOutTo (peer ().dataOutputStream ()); - } - - /** - * - * Given a pattern string (given in NameRequest's name field), this - * finds all the entries in the mapping which have a type that begins with - * the string. Each one is sent back separately via a NameRequest, and this - * sequence is followed by a blank NameRequest. - * - *@param pattern Pattern to find (what result types should - * begin with) - *@param completeLookup Should the value be returned as well? This is - * only used to decide between LIST_TYPES and - * LIST_TYPE_ENTRIES since we might as well send - * back both if we look them up together. - */ - void listByType (String pattern, - boolean completeLookup) throws IOException - { - // Get a listing of all the keys in the hash table - Enumeration enum = this.mapping_.keys(); - - // References used in the loop - String name; - ValueType vt; - - // A NameRequest is used to return each item corresponding to the pattern. - NameRequest result = - new NameRequest((completeLookup ? NameRequest.LIST_TYPES : - NameRequest.LIST_TYPE_ENTRIES), - null, - null, - null, - null); - // Keep ourselves safe from null pointer exceptions - if (pattern == null) - pattern = new String(""); - - // Scan through all the elements - while (enum.hasMoreElements()) { - - // Get a key - name = (String)enum.nextElement(); - - // Have to get all the data for this entry to compare - vt = (ValueType)mapping_.get(name); - - // Does it fit the pattern? - if (vt.type_ != null) - if (vt.type_.startsWith(pattern)) { - - // Set the result values - result.name(name); - result.type(vt.type_); - result.value(vt.value_); - - // Send it out to the socket - result.streamOutTo (peer ().dataOutputStream ()); - } - } - - // Send final null message - result.name(null); - result.type(null); - result.value(null); - result.requestType(NameRequest.MAX_ENUM); - result.streamOutTo (peer ().dataOutputStream ()); - } - /** - * - * Given a pattern string (given in NameRequest's name field), this - * finds all the entries in the mapping which have a value that begins with - * the string. Each one is sent back separately via a NameRequest, and this - * sequence is followed by a blank NameRequest. - * - *@param pattern Pattern to find (what result values should - * begin with) - *@param completeLookup Should the value be returned as well? This is - * only used to decide between LIST_TYPES and - * LIST_TYPE_ENTRIES since we might as well send - * back both if we look them up together. - */ - void listByValue (String pattern, - boolean completeLookup) throws IOException - { - // Get a listing of all the keys in the hash table - Enumeration enum = this.mapping_.keys(); - - // References used in the loop - String name; - ValueType vt; - - // A NameRequest is used to return each item corresponding to the pattern. - NameRequest result = - new NameRequest((completeLookup ? NameRequest.LIST_VALUES : - NameRequest.LIST_VALUE_ENTRIES), - null, - null, - null, - null); - // Keep ourselves safe from null pointer exceptions - if (pattern == null) - pattern = new String(""); - - // Scan through all the elements - while (enum.hasMoreElements()) { - - // Get a key - name = (String)enum.nextElement(); - - // Have to get all the data for this entry to compare - vt = (ValueType)mapping_.get(name); - - // Does it fit the pattern? - if (vt.value_ != null) - if (vt.value_.startsWith(pattern)) { - - // Set the result values - result.name(name); - result.type(vt.type_); - result.value(vt.value_); - - // Send it out to the socket - result.streamOutTo (peer ().dataOutputStream ()); - } - } - - // Send final null message - result.name(null); - result.type(null); - result.value(null); - result.requestType(NameRequest.MAX_ENUM); - result.streamOutTo (peer ().dataOutputStream ()); - } - - // References to the hash table and the timer queue - private Hashtable mapping_; - - /** - * A simple wrapper to keep the type and value together in - * the hash table. - */ - static class ValueType implements Serializable - { - /** - * Constructor - * - *@param type Type string to include - *@param value Value string to include - */ - ValueType(String type, String value) - { this.type_ = type; this.value_ = value; } - - public String type_; - public String value_; - } -} diff --git a/java/JACE/netsvcs/Naming/NameProxy.java b/java/JACE/netsvcs/Naming/NameProxy.java deleted file mode 100644 index 9b1b3102f1d..00000000000 --- a/java/JACE/netsvcs/Naming/NameProxy.java +++ /dev/null @@ -1,405 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Naming - * - * = FILENAME - * NameProxy.java - * - *************************************************/ -package JACE.netsvcs.Naming; - -import java.io.*; -import java.net.*; -import java.util.*; -import JACE.OS.*; -import JACE.SOCK_SAP.*; -import JACE.Connection.*; - -/** - * Proxy which clients can use to interact with the naming service. - * Can be used with the Connector. - * - *@see JACE.Connection.Connector - *@see NameAcceptor - *@see NameHandler - * - *@author Everett Anderson - */ -public class NameProxy extends SvcHandler -{ - /** - * Constructor, connects itself using a Connector. - * - *@param host name of the host of the naming service - *@param port port to connect to on the host - */ - public NameProxy (String host, int port) - throws UnknownHostException, - SocketException, - InstantiationException, - IllegalAccessException, - IOException - { - Connector c = new Connector (); - c.open (host, port); - c.connect (this); - } - - /** - * Default constructor. Proxies created with this constructor must - * be connected to use. - */ - public NameProxy () - { - } - - /** - * Constructor taking a SOCKStream to use. - * - *@param sock SOCKStream already open to the naming service - */ - public NameProxy (SOCKStream sock) - { - this.stream_ = sock; - } - - /** - * Initialize this proxy. (Called by Connector) - */ - public int open (Object obj) - { - connected_ = true; - return 0; - } - - /** - * Close the proxy, shutting down the connection to the service. - */ - public int close () - { - if (!connected_) - return 0; - - try { - this.peer ().close (); - } catch (IOException e) { - return -1; - } finally { - connected_ = false; - } - - return 0; - } - - /** - * Attempt to bind the given data pair - * @param name Name/key - * @param value Value to bind - * - * @return True iff bind is successful - */ - public boolean bind(String name, String value) throws IOException - { - return this.bind(name, value, null, false); - } - - /** - * Attempt to bind the given data triplet - * @param name Name/key - * @param value Value to bind - * @param type Type to bind (another string) - * - * @return True iff the bind was successful - */ - public boolean bind(String name, String value, String type) - throws IOException - { - return this.bind(name, value, type, false); - } - - /** - * The most generic of the bind methods. Allows factoring out of - * common code. Not public. - */ - boolean bind (String name, String value, String type, boolean rebind) - throws IOException - { - // Create a new NameRequest with the desired info - NameRequest request = - new NameRequest(rebind ? NameRequest.REBIND : NameRequest.BIND, - name, - value, - type, - null); - - // Send it to the naming service - request.streamOutTo(this.stream_); - - // Create a reply - NameReply reply = new NameReply(); - - // Get the status of the bind from the naming service - reply.streamInFrom(this.stream_); - - // Return true on success - return (reply.type() == NameReply.SUCCESS ? true : false); - } - - /** - * Rebind a name and a value - * @param name Name/key - * @param value Bound value - * - * @return True if the rebind was successful - */ - public boolean rebind (String name, String value) throws IOException - { - return this.bind(name, value, null, true); - } - - /** - * Rebind a name, value, and type - * @param name Name/key - * @param value Bound value - * @param type Bound type - * - * @return True if rebind was successful - */ - public boolean rebind (String name, String value, String type) - throws IOException - { - return this.bind(name, value, type, true); - } - /** - * Look up information bound to the given key/name. - * - * @param name Name/key - * - * @return Vector with three elements: - * 0 Name/key - * 1 Value - * 2 Type - */ - public Vector resolve (String name) throws IOException - { - // Create a new NameRequest with the name & request type - NameRequest request = new NameRequest(NameRequest.RESOLVE, - name, - null, - null, - null); - - // Send it to the naming service - request.streamOutTo(this.stream_); - - // Get a response (hopefully with the value and type) - request.streamInFrom(this.stream_); - - // Dump the result into a vector - Vector result = new Vector(); - - result.addElement(request.name()); - result.addElement(request.value()); - result.addElement(request.type()); - - // Cut it down to the size we need - result.trimToSize(); - - return result; - } - - /** - * Remove the entry in the mapping corresponding to the given name/key. - * - * @param name Name/key - * - * @return True if the unbind was successful - */ - public boolean unbind (String name) throws IOException - { - NameRequest request = new NameRequest(NameRequest.UNBIND, - name, - null, - null, - null); - // Send the request to the naming service - request.streamOutTo(this.stream_); - - NameReply reply = new NameReply(); - - // Get reply - reply.streamInFrom(this.stream_); - - return (reply.type() == NameReply.SUCCESS ? true : false); - } - - /** - * Return a vector that's a list of names (Strings) that begin with - * the given pattern - * @param pattern Search pattern - * @return Vector List of names - */ - public Vector listNames (String pattern) throws IOException - { - return this.requestSimpleList(pattern, NameRequest.LIST_NAMES); - } - - /** - * Return a vector that's a list of types (Strings) that begin with - * the given pattern - * @param pattern Search pattern - * @return Vector List of types - */ - public Vector listTypes (String pattern) throws IOException - { - return this.requestSimpleList(pattern, NameRequest.LIST_TYPES); - } - - /** - * Return a vector that's a list of values (Strings) that begin with - * the given pattern - * @param pattern Search pattern - * @return Vector List of values - */ - public Vector listValues (String pattern) throws IOException - { - return this.requestSimpleList(pattern, NameRequest.LIST_VALUES); - } - - /** - * Non-public generic list gathering method - */ - Vector requestSimpleList (String pattern, int type) throws IOException - { - // Make request for a list of the given type - NameRequest request = new NameRequest(type, - pattern, - null, - null, - null); - request.streamOutTo(this.stream_); - - // Allocate and reuse the DIS here rather than each time we call - // streamInFrom - DataInputStream dis = new DataInputStream(this.stream_.inputStream()); - - request.streamInFrom(dis); - Vector result = new Vector(); - - // Add elements until there's a null message with the MAX_ENUM - // request type - while (request.requestType() != NameRequest.MAX_ENUM) { - if (type == NameRequest.LIST_NAMES) - result.addElement(new String(request.name())); - else - if (type == NameRequest.LIST_VALUES) - result.addElement(new String(request.value())); - else - result.addElement(new String(request.type())); - - request.streamInFrom(dis); - } - - // Adjust the vector to the minimal size - result.trimToSize(); - - return result; - } - - /** - * Get a vector with the entire data set for entries whose name begins with - * the given pattern. Each element in the vector is another vector - * with the following layout: - * 0 Name/key - * 1 Value - * 2 Type - * - * @param pattern Search pattern - * @return Vector of vectors - */ - public Vector listNameEntries (String pattern) throws IOException - { - return this.requestComplexList(pattern, NameRequest.LIST_NAME_ENTRIES); - } - - /** - * Get a vector with the entire data set for entries whose value begins with - * the given pattern. Each element in the vector is another vector - * with the following layout: - * 0 Name/key - * 1 Value - * 2 Type - * - * @param pattern Search pattern - * @return Vector of vectors - */ - public Vector listValueEntries (String pattern) throws IOException - { - return this.requestComplexList(pattern, NameRequest.LIST_VALUE_ENTRIES); - } - - /** - * Get a vector with the entire data set for entries whose type begins with - * the given pattern. Each element in the vector is another vector - * with the following layout: - * 0 Name/key - * 1 Value - * 2 Type - * - * @param pattern Search pattern - * @return Vector of vectors - */ - - public Vector listTypeEntries (String pattern) throws IOException - { - return this.requestComplexList(pattern, NameRequest.LIST_TYPE_ENTRIES); - } - - /** - * Non-public generic method for getting a a vector of vectors with the - * entire data set for entries fitting the given pattern. - */ - Vector requestComplexList (String pattern, int type) throws IOException - { - // Create request with desired type - NameRequest request = new NameRequest(type, - pattern, - null, - null, - null); - // Send it to the naming service - request.streamOutTo(this.stream_); - - // Allocate the DIS here and reuse - DataInputStream dis = new DataInputStream(this.stream_.inputStream()); - - // Get the first response - request.streamInFrom(dis); - Vector result = new Vector(); - - // Loop while we don't see a null response with the MAX_ENUM - //request type - while (request.requestType() != NameRequest.MAX_ENUM) { - Vector entry = new Vector(); - - // Create an element in the main vector - entry.addElement(request.name()); - entry.addElement(request.value()); - entry.addElement(request.type()); - entry.trimToSize(); - - // Add it to the result - result.addElement(entry); - - // Get another NameRequest - request.streamInFrom(dis); - } - - result.trimToSize(); - - return result; - } - - private boolean connected_ = false; -} diff --git a/java/JACE/netsvcs/Naming/NameReply.java b/java/JACE/netsvcs/Naming/NameReply.java deleted file mode 100644 index d20c9ed05f0..00000000000 --- a/java/JACE/netsvcs/Naming/NameReply.java +++ /dev/null @@ -1,169 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Naming - * - * = FILENAME - * NameReply.java - * - *************************************************/ -package JACE.netsvcs.Naming; - -import java.io.*; -import java.util.*; -import JACE.OS.*; -import JACE.Connection.*; -import JACE.Reactor.*; -import JACE.ASX.*; -import JACE.SOCK_SAP.*; - -/** - * Used by the naming server to give quick status messages - * to the client. This is only used to signal the success or - * failure of bind and unbind requests. The error number seems - * to be unused in the C++ version. - * - *@see NameHandler - *@author Everett Anderson - * - */ -public class NameReply -{ - /** Successful operation indicator */ - public final static int SUCCESS = 0; - - /** Failed operation indicator */ - public final static int FAILURE = -1; - - /** - * Default Constructor (success, errno 0) - */ - public NameReply () - { - this.type_ = this.SUCCESS; - this.errno_ = 0; - } - - /** - * Constructor - * - *@param type Success or failure - *@param err Error number (unused) - */ - public NameReply (int type, int err) - { - this.type_ = type; - this.errno_ = err; - } - - /** - * Length accessor - */ - int length() - { return this.length_; } - - /** - * Type accessor -- success or failure - */ - int type() - { return this.type_; } - - /** - * Error number accessor - */ - int errno() - { return this.errno_; } - - /** - * Set type - * @param type New type - */ - void type(int type) - { this.type_ = type; } - - /** - * Set error number - * @param errno New error number - */ - void errno(int errno) - { this.errno_ = errno; } - - /** - * Send this data to the given SOCKStream. - * - *@param sock SOCKStream to send to - */ - public void streamOutTo (JACE.SOCK_SAP.SOCKStream sock) throws IOException - { - streamOutTo (sock.dataOutputStream ()); - } - - /** - * Send this instance to the given DataOutputStream. - */ - public void streamOutTo (DataOutputStream dos) throws IOException - { - dos.writeInt(this.length_); - dos.writeInt(this.type_); - dos.writeInt(this.errno_); - - dos.flush(); - } - - /** - * Send this instance to the given OutputStream. - */ - public void streamOutTo (OutputStream os) throws IOException - { - BufferedOutputStream bos = new BufferedOutputStream (os); - DataOutputStream dos = new DataOutputStream (bos); - - streamOutTo (dos); - } - - /** - * Fill the fields of this instance from data in the socket - * - *@param sock SOCKStream to read from - */ - public void streamInFrom (JACE.SOCK_SAP.SOCKStream sock) throws IOException - { - this.streamInFrom(sock.dataInputStream ()); - } - - /** - * Fill this instance from the DataInputStream (which should be buffered). - * - *@param dis DataInputStream to use - */ - public void streamInFrom (DataInputStream dis) throws IOException - { - int length = dis.readInt(); - - if (length != this.length_) - throw new IOException("Incorrect NameReply length"); - - type_ = dis.readInt(); - errno_ = dis.readInt(); - } - - /** - * Fill this instance from the given InputStream. - */ - public void streamInFrom (InputStream is) throws IOException - { - BufferedInputStream bis = new BufferedInputStream (is); - DataInputStream dis = new DataInputStream (bis); - - streamInFrom (dis); - } - - final static int length_ = 12; - - int type_; - int errno_; -} - - - - diff --git a/java/JACE/netsvcs/Naming/NameRequest.java b/java/JACE/netsvcs/Naming/NameRequest.java deleted file mode 100644 index 706b14728c5..00000000000 --- a/java/JACE/netsvcs/Naming/NameRequest.java +++ /dev/null @@ -1,373 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Naming - * - * = FILENAME - * NameRequest.java - * - *@see netsvcs.Naming.NameHandler - * - *@author Everett Anderson - * - *************************************************/ -package JACE.netsvcs.Naming; - -import java.io.*; -import java.util.*; -import JACE.OS.*; -import JACE.Connection.*; -import JACE.Reactor.*; -import JACE.ASX.*; -import JACE.SOCK_SAP.*; - -/** - * Holds information including name, value, type, and request - * type. Used by both client and naming server as detailed in - * NameHandler. Compatible with the C++ ACE_Name_Request. - * - *@see NameHandler - */ -public class NameRequest -{ - /** Bind request type */ - public static final int BIND = 1; - - /** Rebind request type */ - public static final int REBIND = 2; - - /** Resolve request type */ - public static final int RESOLVE = 3; - - /** Unbind request type */ - public static final int UNBIND = 4; - - /** List Names request type */ - public static final int LIST_NAMES = 5; - - /** List Values request type */ - public static final int LIST_VALUES = 13; - - /** List Types request type */ - public static final int LIST_TYPES = 21; - - /** List Name Entries request type */ - public static final int LIST_NAME_ENTRIES = 6; - - /** List Value Entries request type */ - public static final int LIST_VALUE_ENTRIES = 14; - - /** List Type Entries request type */ - public static final int LIST_TYPE_ENTRIES = 22; - - /** Type used to send a final "null" request when returning - * a list of items */ - public static final int MAX_ENUM = 11; - /** - * Maximum length of a NameRequest instance. - * See C++ ACE Name_Request_Reply.h for the details of the - * value of this constant. - */ - public static final int MAX_LEN = 6182; - - /** - * Default constructor. - */ - public NameRequest () - { - this.name_ = this.value_ = this.type_ = null; - this.length_ = 32; - } - - /** - * Constructor - * - * @param requestType Type of request this is (BIND, REBIND, etc) - * @param name Key to bind - * @param value Value to bind - * @param type Type to couple with the value - * @param timeout Timer information (not really used in JACE yet) - */ - public NameRequest(int requestType, - String name, - String value, - String type, - TimeValue timeout) - { - this.requestType_ = requestType; - - if (timeout == null) { - - this.blockForever_ = 1; - this.secTimeout_ = 0; - this.usecTimeout_ = 0; - } else { - - this.blockForever_ = 0; - this.secTimeout_ = (int)timeout.sec(); - this.usecTimeout_ = (int)timeout.getMilliTime() * 1000; - } - - // This is necessary to make sure null pointer exceptions are - // avoided. It makes it more consistent later on - if (name == null) - this.name_ = new String(""); - else - this.name_ = new String(name); - if (value == null) - this.value_ = new String(""); - else - this.value_ = new String(value); - if (type == null) - this.type_ = new String(""); - else - this.type_ = new String(type); - - // Set the length - this.calculateLength(); - } - - /** - * Calculate the transmission length (bytes) of this structure - */ - private void calculateLength() - { - // The type is sent as an 8 bit data type (chars in the C++ version), - // but the name and value are sent as 16 bit chars (ACE_USHORT16's in C++) - - this.length_ = 34 + this.type_.length() + 2 * (this.name_.length() + - this.value_.length()); - } - - /** - * Return the transmission length - */ - public int length() - { return this.length_; } - - /** - * Return the name/key - */ - public String name() - { return new String(this.name_); } - - /** - * Set the name/key - * @param name Name to set to - */ - public void name(String name) - { - if (name == null) - this.name_ = new String(""); - else - this.name_ = new String(name); - - this.calculateLength(); - } - - /** - * Return the value - */ - public String value() - { return new String(this.value_); } - - /** - * Set the value - * @param value New value - */ - public void value(String value) - { - if (value == null) - this.value_ = new String(""); - else - this.value_ = new String(value); - - this.calculateLength(); - } - - /** - * Return the type - */ - public String type() - { return new String(this.type_); } - - /** - * Set the type - * @param type New type - */ - public void type(String type) - { - if (type == null) - this.type_ = new String(""); - else - this.type_ = new String(type); - - this.calculateLength(); - } - - /** - * Fill the fields of this instance with data from the InputStream. - */ - public void streamInFrom (InputStream is) throws IOException - { - BufferedInputStream bis = new BufferedInputStream (is); - - DataInputStream dis = new DataInputStream (bis); - - this.streamInFrom(dis); - } - - /** - * Fill the fields of this instance with data from the SOCKStream. - */ - public void streamInFrom (SOCKStream sock) throws IOException - { - streamInFrom (sock.dataInputStream ()); - } - - /** - * Fill the fields of this instance from the given DataInputStream - * - *@param dis DataInputStream to read from - */ - public void streamInFrom (DataInputStream dis) throws IOException - { - // Read the length (32 bits) - length_ = dis.readInt(); - - if (length_ > MAX_LEN) - throw new IOException ("Invalid NameRequest length " + length_); - - // Read the request type - requestType_ = dis.readInt(); - - // Can we block forever to fulfill this request? (unused) - blockForever_ = dis.readInt(); - - // How long until we should time out this request? (unused) - secTimeout_ = dis.readInt(); - usecTimeout_ = dis.readInt(); - - // The sizes are in bytes, and there are two bytes per char - // (ACE_USHORT16 in C++ land) - int nameLen = dis.readInt() / 2; - int valueLen = dis.readInt() / 2; - - int typeLen = dis.readInt(); - - // Read the name -- just read chars since they're 16 bits. - // Hopefully the SOCKStream has buffered the data - char buf[] = new char[nameLen]; - for (int i = 0; i < nameLen; i++) { - buf[i] = dis.readChar(); - } - this.name_ = new String(buf); - - // Read the value - buf = new char[valueLen]; - for (int i = 0; i < valueLen; i++) - buf[i] = dis.readChar(); - this.value_ = new String(buf); - - // Read the type -- now we can use readFully since - // the type was sent as 8 bit chars - byte tbuf[] = new byte[typeLen]; - dis.readFully(tbuf); - this.type_ = new String(tbuf); - - // Skip the null char at the end - dis.skipBytes(2); - } - - /** - * Write the data of this instance to the given SOCKStream. - */ - public void streamOutTo (SOCKStream sock) throws IOException - { - streamOutTo (sock.dataOutputStream ()); - } - - /** - * Write the data of this instance to the given OutputStream. - */ - public void streamOutTo (OutputStream os) throws IOException - { - BufferedOutputStream bos = new BufferedOutputStream (os); - DataOutputStream dos = new DataOutputStream (bos); - - streamOutTo (dos); - } - - /** - * Send this NameRequest out to the given DataOutputStream - */ - public void streamOutTo (DataOutputStream dos) throws IOException - { - dos.writeInt(length_); - dos.writeInt(requestType_); - dos.writeInt(blockForever_); - dos.writeInt(secTimeout_); - dos.writeInt(usecTimeout_); - - // Byte sizes are sent, and the name and value are stored as - // 16 bit char arrays (ACE_USHORT16 arrays in C++ version) - dos.writeInt(this.name_.length() * 2); - dos.writeInt(this.value_.length() * 2); - dos.writeInt(this.type_.length()); - - // Making sure the name_ wasn't null comes in handy - // in situations like this - dos.writeChars(this.name_); - dos.writeChars(this.value_); - dos.writeBytes(this.type_); - - // Null termination - dos.writeChar(0); - - // Send it for real - dos.flush(); - } - - /** - * Set the requestType - *@param type Type to set to - */ - public void requestType(int type) - { - this.requestType_ = type; - } - - /** - * Get requestType - */ - public int requestType() - { - return this.requestType_; - } - - /** - * Can we block forever to fulfill the request? (unused) - */ - public boolean blockForever() - { - return (this.blockForever_ != 0) ? true : false; - } - - /** - * Allowed timeout (unused) - */ - public int secTimeout() - { - return this.secTimeout_; - } - - int length_; - int requestType_; - int blockForever_; - int secTimeout_; - int usecTimeout_; - - String name_; - String value_; - String type_; -}; diff --git a/java/JACE/netsvcs/Naming/c.bat b/java/JACE/netsvcs/Naming/c.bat deleted file mode 100644 index 2b540b1b051..00000000000 --- a/java/JACE/netsvcs/Naming/c.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -javac -d c:\Everett\JACE\classes *.java diff --git a/java/JACE/netsvcs/Naming/package.html b/java/JACE/netsvcs/Naming/package.html deleted file mode 100644 index b7ee951fc2e..00000000000 --- a/java/JACE/netsvcs/Naming/package.html +++ /dev/null @@ -1,11 +0,0 @@ -<!-- $Id$ --> -<HTML> -<BODY> -Naming Service for associating names and values in a distributed system. -<P> -A simple test program for NameProxy and the naming service is in -the tests directory under netsvcs\Naming. - -@see <a href="http://www.cs.wustl.edu/~schmidt/ACE-netsvcs.html">ACE Network Services</a> -</BODY> -</HTML> diff --git a/java/JACE/netsvcs/Server.java b/java/JACE/netsvcs/Server.java deleted file mode 100644 index 199a830d0c5..00000000000 --- a/java/JACE/netsvcs/Server.java +++ /dev/null @@ -1,356 +0,0 @@ -package JACE.netsvcs; - -import java.io.*; -import java.net.*; -import java.util.*; -import JACE.OS.*; -import JACE.Connection.*; -import JACE.Misc.GetOpt; -import JACE.ServiceConfigurator.Service; - -/** - * Abstract class providing default implementations for several - * Service methods. Currently, all the network services - * descend from this class. The real work for a service is done - * by a Handler. - * <P> - * Inner classes are provided for thread per connection - * and single threaded server activation strategies. Currently, - * specifying a single threaded strategy means that the server will - * disconnect the client after handling one request. Acceptor and - * EventHandler may be changed later to incorporate handleInput to - * address this. Thus, the default activation strategy is thread - * per connection. - * - *@see Handler - *@see JACE.Connection.ActivateStrategy - *@author Everett Anderson - */ -public abstract class Server extends Acceptor implements Runnable -{ - /** - * Safely shuts down all the handlers as well as the accepting socket. - * - *@return -1 on failure, 0 on success - */ - public synchronized int fini () - { - if (!done ()) { - ACE.DEBUG ("Shutting down " + name ()); - try { - this.done_ = true; - for (int i = handlers_.size () - 1; i >= 0; i--) - ((Handler)handlers_.elementAt (i)).close (); - - this.sockAcceptor_.close(); - } catch (IOException e) { - ACE.ERROR(e); - return -1; - } - } - - return 0; - } - - /** - * Returns information about the state of the service such as - * suspended, not running, or running. - */ - public String info () - { - if (suspended ()) - return "suspended"; - else - if (done ()) - return "not running"; - else - return "running on port " + port_; - } - - /** - * Provided for extra initialization in subclasses after the - * command line arguments have been parsed but before starting the - * service. This is a good place to set the default ActivateStrategy - * since you can make sure it wasn't set in parseArgs. The default - * implementation sets the strategy to Server.ThreadPerConnection. - * - *@return -1 on error, 0 on success - */ - protected int initialize () - { - if (activateStrategy_ == null) - activateStrategy (new Server.ThreadPerConnection ()); - - return 0; - } - - /** - * Template method for initialization. Calls parseArgs, initialize, - * sets the done() state to false, and starts this Server in its own - * thread. If parseArgs fails, this calls printUsage. - * - *@param args command line arguments - *@return -1 on failure, 0 on success - */ - public int init (String [] args) - { - // Parse arguments - if (this.parseArgs (args) == -1) { - printUsage (); - return -1; - } - - if (initialize () < 0) { - ACE.ERROR (name () + " failed initializing"); - return -1; - } - - ACE.DEBUG ("Using " + activateStrategy_.getClass().getName ()); - ACE.DEBUG ("Starting " + name () + " on port: " + this.port_); - - done_ = false; - - // Run in own thread of control so that we don't block the caller - new Thread (this).start(); - return 0; - } - - /** - * Called by the JVM when this Server starts running in its own - * thread. - */ - public void run () - { - try { - this.open (this.port_); - while (!this.done ()) { - this.accept (); - } - } catch (InstantiationException e) { - ACE.ERROR (e); - } catch (IllegalAccessException e) { - ACE.ERROR (e); - } catch (IOException e) { - if (!done ()) - ACE.ERROR (e); - } finally { - fini (); - } - } - - /** - * Calls the appropriate activation strategy with the given - * service handler. This assumes the SvcHandler is an instance - * of type Handler, and sets its parent accordingly. - * - *@param sh SvcHandler (assumed to be a Handler) to activate - *@return -1 on failure, 0 on success - */ - protected int activateSvcHandler (SvcHandler sh) - { - if (done ()) - return -1; - - addHandler (sh); - ((Handler)sh).parent (this); - - while (suspended () && !done ()) - Thread.yield (); - - if (activateStrategy_.activateSvcHandler (sh) != 0) { - removeHandler (sh); - return -1; - } - - return 0; - } - - /** - * Add the given SvcHandler to this Servers list of handlers. - * @param sh service handler to add (assumed to be a Handler) - */ - protected void addHandler (SvcHandler sh) - { - handlers_.addElement (sh); - } - - /** - * Called by Handler instances during their close () method. - *@param sh service handler to remove - */ - public void removeHandler (SvcHandler sh) - { - handlers_.removeElement (sh); - } - - /** - * Parses the command line arguments. Subclasses must override - * this. - * - *@param args command line arguments - *@return -1 on failure, 0 on success - */ - protected abstract int parseArgs (String [] args); - - /** - * Create the appropriate Handler. Subclasses must override this, - * returning a new instance of the proper subclass of Handler. - * - *@return new Handler instance - */ - protected abstract SvcHandler makeSvcHandler (); - - /** - * Print out the correct syntax and meaning of the command line - * arguments. - */ - protected abstract void printUsage (); - - /** - * Set the ActivateStrategy for handlers. - * - *@param strategy new ActivateStrategy to use - *@see JACE.Connection.ActivateStrategy - */ - protected void activateStrategy (ActivateStrategy strategy) - { - activateStrategy_ = strategy; - } - - /** - * Return the current ActivateStrategy for handlers. - * - *@return current ActivateStrategy instance - */ - protected ActivateStrategy activateStrategy () - { - return activateStrategy_; - } - - /** - * Check to see if this Server has been shut down. - */ - protected synchronized boolean done () - { - return done_; - } - - /** - * Useful method for subclasses when parsing the port command - * line option. - * - *@param port String gathered from the command line representing the port - *@return false if there was an error, true if successful - */ - protected boolean port (String port) - { - try { - - this.port_ = Integer.parseInt (port); - - } catch (NumberFormatException e) { - ACE.ERROR("Invalid port specified: " + e.getMessage ()); - return false; - } catch (ArrayIndexOutOfBoundsException e) { - ACE.ERROR("Port option requires an argument"); - return false; - } - - return true; - } - - /** - * Useful method for subclasses when trying to load and instantiate - * a certain class from a command line argument. This can be used - * when a possible command line argument is what kind of activation - * strategy is used for handlers. - * - *@param classname name of the class to load and create an instance of - *@param descrption descrption of what type of class it is - *@return null if failed loading, a new instance of the class on success - */ - protected Object newStrategyInstance (String classname, - String description) - { - try { - Class factory = Class.forName (classname); - - return factory.newInstance (); - - } catch (ClassNotFoundException e) { - ACE.ERROR("Unable to find " + description + ": " - + e.getMessage ()); - } catch (InstantiationException e) { - ACE.ERROR ("Instantiating " + description + ": " - + e.getMessage ()); - } catch (IllegalAccessException e) { - ACE.ERROR ("Illegal access on " + description + ": " - + e.getMessage ()); - } - - return null; - } - - /** - * Shuts down the Server if it wasn't already done - */ - protected void finalize () throws Throwable - { - fini (); - } - - private boolean done_ = true; - - /** - * List of currently active Handlers - */ - protected Vector handlers_ = new Vector (); - private ActivateStrategy activateStrategy_ = null; - - /** - * Activation strategy in which each Handler is run in its own - * Thread. - */ - public static class ThreadPerConnection extends ActivateStrategy - { - /** - * Opens the given service handler, and runs it in its own - * Thread. - *@param sh service handler to activate - *@return -1 on failure, 0 on success - */ - public int activateSvcHandler (SvcHandler sh) - { - if (sh.open (null) < 0) - return -1; - - new Thread (sh).start (); - return 0; - } - } - - /** - * Activation strategy in which all Handlers are run in the - * Server Thread in sequence. This assumes that the given - * SvcHandler is a Handler instance. - */ - public static class SingleThreaded extends ActivateStrategy - { - /** - * Opens the given service handler, calls Handler.handleRequest, and - * then Handler.close before returning. - *@param sh service handler to activate (assumed to be a Handler) - *@return -1 on failure, 0 on success - */ - public int activateSvcHandler (SvcHandler sh) - { - if (sh.open (null) < 0) - return -1; - - ((Handler)sh).handleRequest (); - ((Handler)sh).close (); - - return 0; - } - } -} diff --git a/java/JACE/netsvcs/Time/TSClerkHandler.java b/java/JACE/netsvcs/Time/TSClerkHandler.java deleted file mode 100644 index e0a2290d81b..00000000000 --- a/java/JACE/netsvcs/Time/TSClerkHandler.java +++ /dev/null @@ -1,195 +0,0 @@ -package JACE.netsvcs.Time; - -import java.io.*; -import java.net.*; - -import JACE.OS.*; -import JACE.Connection.*; -import JACE.ASX.*; - -/** - * Requests a time update from a time server. This is used by the - * TSClerkProcessor to query a server. - */ -public class TSClerkHandler extends SvcHandler -{ - /** - * Constructor. - * - *@param parent TSClerkProcessor which is creating this instance - *@param host name of the machine this handler is connected to - *@param port port on the time server to connect to - */ - public TSClerkHandler (TSClerkProcessor parent, - String host, - int port) - { - parent_ = parent; - host_ = host; - port_ = port; - } - - /** - * Initialize this handler. Called automatically by Connector when a - * successful connection is made. - * - *@return -1 on failure, 0 on success - */ - public int open (Object obj) - { - ACE.DEBUG ("Successful connection to " + host ()); - connected (true); - return 0; - } - - /** - * Safely shut down this handler, closing the socket. - * - *@return -1 on failure, 0 on success - */ - public synchronized int close () - { - if (!connected ()) - return 0; - - ACE.DEBUG ("Shutting down connection to " + host ()); - try { - peer ().close (); - } catch (IOException e) { - return -1; - } finally { - connected (false); - } - - return 0; - } - - /** - * Accessor for the port number of the server. - */ - public int port () - { - return port_; - } - - /** - * Accessor for the host name of the server. - */ - public String host () - { - return host_; - } - - /** - * Check to see if this handler is currently connected to a server. - */ - public synchronized boolean connected () - { - return connected_; - } - - /** - * Set the connected state. - * - *@param state true if connected, false if not - */ - protected synchronized void connected (boolean state) - { - connected_ = state; - } - - /** - * (Isn't used, just fulfills the interface. Returns -1 by - * default) - */ - public int handleTimeout (TimeValue tv, Object obj) - { - return -1; - } - - /** - * (Isn't used, just fulfills the interface.) - */ - public void run () - { - ACE.ERROR ("TSClerkHandler is not setup to run in its own thread"); - } - - /** - * Sends a request to the server and waits for a reply. This is called - * by TSClerkProcessor. - * - *@return -1 on failure, 0 on success - */ - public int sendRequest () - { - // Ask the clerk processor to connect this handler if it isn't - // already. Thus, it tries to reconnect if the server has gone - // down. - if (!connected ()) - parent_.connectHandler (this, host_, port_); - - TimeRequest request = new TimeRequest (); - - long start, stop; - try { - - start = System.currentTimeMillis (); - request.streamOutTo (peer().outputStream ()); - - request.streamInFrom (peer().inputStream ()); - stop = System.currentTimeMillis (); - - } catch (NullPointerException e) { - close (); - return -1; - } catch (IOException e) { - close (); - return -1; - } - - // Compute the difference in the local time and the server time - // (in seconds) - long difference = request.time () - (stop / 1000); - - // Calculate the transmission time (in seconds) - long oneWayTime = (stop - start) / 2000; - - difference += oneWayTime; - - /* - ACE.DEBUG (host() + " reports:"); - ACE.DEBUG (" time difference: " + difference); - ACE.DEBUG (" trans. delay: " + oneWayTime); - */ - - // Set the time difference for this handler - delta (difference); - - return 0; - } - - /** - * Returns the current time difference between local time and - * the server (in seconds). - */ - public synchronized long delta () - { - return delta_; - } - - /** - * Sets the current time difference between local time and the - * server (in seconds). - */ - protected synchronized void delta (long delta) - { - delta_ = delta; - } - - private long delta_; - private TSClerkProcessor parent_; - private boolean connected_ = false; - private String host_; - private int port_; -} diff --git a/java/JACE/netsvcs/Time/TSClerkProcessor.java b/java/JACE/netsvcs/Time/TSClerkProcessor.java deleted file mode 100644 index bec3bd417df..00000000000 --- a/java/JACE/netsvcs/Time/TSClerkProcessor.java +++ /dev/null @@ -1,307 +0,0 @@ -package JACE.netsvcs.Time; - -import java.net.*; -import java.io.*; -import java.util.*; - -import JACE.ASX.TimeValue; -import JACE.Connection.*; -import JACE.OS.*; -import JACE.Reactor.*; -import JACE.Misc.*; - -/** - * Clerk used to query a number of time servers, compute the average - * of the time differences, and report it with a sequence number. This - * can be used to adjust the current local time accordingly. - * <P> - * <B>Valid command line arguments:</B> - * <PRE> - * -h (host name:port) Specify a time server to contact - * -t (time in seconds) Specify how often to query the servers - * (Defaults to five minutes) - * -d Enable debugging messages - * </PRE> - */ -public class TSClerkProcessor implements EventHandler, Runnable -{ - /** - * Prints out the valid command line arguments. See the class - * description for more information. - */ - public void printUsage () - { - ACE.ERROR ("Valid options:"); - ACE.ERROR ("-h <host name>:<port> Specify a time server to contact"); - ACE.ERROR ("-t <time in seconds> How often to query the servers"); - ACE.ERROR ("-d Enable debugging messages"); - } - - /** - * Parses the command line arguments. See the class description - * for more information. - */ - protected int parseArgs (String args[]) - { - GetOpt opt = new GetOpt (args, "h:t:d", true); - for (int c; (c = opt.next ()) != -1; ) - { - switch (c) - { - // Specify a hostname:port pair to query - case 'h': - if (newHandler (opt.optarg ()) == -1) { - printUsage (); - return -1; - } - break; - // Specify time interval to query servers - case 't': - int sec = Integer.parseInt (opt.optarg ()); - updateInterval_ = new TimeValue (sec); - break; - case 'd': - ACE.enableDebugging (); - ACE.DEBUG ("Debugging is enabled"); - break; - default: - ACE.ERROR ("Unknown argument: " + (char)c); - printUsage (); - return -1; - } - } - return 0; - } - - /** - * Safely shut down the clerk and all its handlers. - */ - public synchronized void close () - { - if (!done_) { - done_ = true; - tq_.cancelTimer (this); - - for (int i = 0; i < handlerSet_.size (); i++) { - TSClerkHandler h = (TSClerkHandler)handlerSet_.elementAt (i); - - h.close (); - } - } - } - - /** - * Called by the JVM when the clerk is run in its own thread. If the - * TimerQueue provided to (or created by) this TSClerkProcessor isn't - * running its event loop, it will be run in this thread (by calling - * handleEvents ()). - * - *@see JACE.Reactor.TimerQueue - */ - public void run () - { - if (handlerSet_.size () == 0) { - ACE.DEBUG ("No servers are registered. Call init first."); - return; - } - - if (!tq_.eventLoopRunning ()) - tq_.handleEvents (); - } - - /** - * Initialize this TSClerkProcessor with command line arguments. See - * the class description for more information. This also schedules - * a timeout with the timer queue for when to query the servers. - * - *@return -1 on failure, 0 on success - */ - public int init (String args[]) - { - if (args.length < 2) { - printUsage (); - return -1; - } - - if (parseArgs (args) == -1) - return -1; - - if (handlerSet_.size () == 0) { - ACE.ERROR ("No servers are registered."); - done_ = true; - return -1; - } - - if (tq_ == null) - tq_ = new TimerQueue (true); - - tq_.scheduleTimer (this, - "Time Service Processor", - TimeValue.zero, - updateInterval_); - - return 0; - } - - /** - * Called by TSClerkHandler instances when they need to connect - * (or reconnect) to a server. This uses Connector to make the - * connection. - * - *@param handler TSClerkHandler to connect to the server - *@param host name of the service - *@param port port to connect to on the server - */ - void connectHandler (TSClerkHandler handler, - String host, - int port) - { - // Don't let handlers reconnect if we are in the process of closing - if (done_) - return; - - ACE.DEBUG ("Connecting handler to " + host + " on port " + port); - try { - - Connector c = new Connector (); - c.open (host, port); - c.connect (handler); - - } catch (UnknownHostException e) { - synchronized (this) { - handlerSet_.removeElement (handler); - } - ACE.ERROR (e); - } catch (SocketException e) { - ACE.ERROR (e); - } catch (InstantiationException e) { - ACE.ERROR (e); - } catch (IllegalAccessException e) { - ACE.ERROR (e); - } catch (IOException e) { - ACE.ERROR (e); - } - } - - /** - * Create a new TSClerkHandler for the given (host name):(port) - * combination. See the class description for more information about - * providing a host names and ports on the command line. - * - *@param hostAndPort String with the host name and port separated by - * a colon. - *@return -1 on failure, 0 on success - */ - protected int newHandler (String hostAndPort) - { - int colon = hostAndPort.lastIndexOf (':'); - - if (colon < 1) { - ACE.ERROR ("Invalid -h <host>:<port> parameter: " + hostAndPort); - return -1; - } - - int port = Integer.parseInt (hostAndPort.substring (colon + 1)); - String host = hostAndPort.substring (0, colon); - - ACE.DEBUG ("New handler for server " + host + " on port " + port); - - TSClerkHandler handler = new TSClerkHandler (this, host, port); - handlerSet_.addElement (handler); - - return 0; - } - - /** - * Have each TSClerkHandler query its time server, average the results, - * and set the timeStatus accordingly. This is called by the - * TimerQueue when appropriate. The interval can be specified on the - * command line. - */ - public synchronized int handleTimeout (TimeValue tv, Object obj) - { - if (done_) - return -1; - - // Increment the sequence number - int sequenceNumber = status_.sequenceNumber () + 1; - Enumeration handlers = handlerSet_.elements (); - - long total = 0; - int count = 0; - - // Use each handler to query its server, collecting the time - // difference information. - while (handlers.hasMoreElements ()) { - TSClerkHandler h = (TSClerkHandler)handlers.nextElement (); - - if (h.sendRequest () < 0) - continue; - - total += h.delta (); - count++; - } - - if (count == 0) { - ACE.ERROR ("Could not reach any time servers, will keep trying."); - return 0; - } - - timeStatus (new TimeInfo (sequenceNumber, total / count)); - - ACE.DEBUG ("Status: " + timeStatus ()); - - return 0; - } - - /** - * Return the current sequence number and time difference pair. - */ - public synchronized TimeInfo timeStatus () - { - return status_; - } - - /** - * Set the current sequence number and time difference pair. - */ - protected synchronized void timeStatus (TimeInfo status) - { - status_ = status; - } - - /** - * Default constructor. Results in this TSClerkProcessor creating - * a new timer queue which runs in its own thread. Thus, this - * TSClerkProcessor runs in its own thread. - */ - public TSClerkProcessor () - { - // Effectively runs in its own thread because of the timer queue - } - - /** - * Constructor allowing the timer queue to be specified. If the timer - * queue isn't already running, the caller is responsible for calling - * handleEvents to start the clerk. Be careful since the querying - * process for the servers may take a while. - * - *@param queue TimerQueue to register with - */ - public TSClerkProcessor (TimerQueue queue) - { - tq_ = queue; - } - - private boolean done_ = false; - - // List of the TSClerkHandlers this uses to maintain its - // server connections. - private Vector handlerSet_ = new Vector (); - private TimerQueue tq_ = null; - - // Default is every five minutes - private TimeValue updateInterval_ = new TimeValue (300, 0); - - TimeInfo status_ = new TimeInfo (); -} diff --git a/java/JACE/netsvcs/Time/TSServerAcceptor.java b/java/JACE/netsvcs/Time/TSServerAcceptor.java deleted file mode 100644 index 7e8b9476c19..00000000000 --- a/java/JACE/netsvcs/Time/TSServerAcceptor.java +++ /dev/null @@ -1,116 +0,0 @@ -package JACE.netsvcs.Time; - -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.Concurrency.ThreadManager; -import JACE.netsvcs.Server; - -/** - * Server for the time service. Creates TSServerHandlers as necessary - * to handle the requests. - * <P> - * <B>Valid command line arguments:</B> - * <PRE> - * -p (port) Port to listen on for clients"); - * -d Enable debugging messages"); - * -a (class name) Specify ActivateStrategy"); - * (Default is multi-threaded"); - * </PRE> - * - */ -public class TSServerAcceptor extends Server -{ - public TSServerAcceptor () - { - // Set the name in case we're not using the service configurator - name ("Time Service"); - } - - /** - * Simple main program for running the logging service without the - * service configurator. - * - *@param args command line arguments - */ - public static void main (String [] args) - { - // Simple main program to get things rolling - TSServerAcceptor ta = new TSServerAcceptor(); - - ta.init (args); - } - - /** - * Creates a new TSServerHandler instance. - */ - protected SvcHandler makeSvcHandler () - { - return new TSServerHandler (); - } - - /** - * 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 ("-p <port> Port to listen on for clients"); - ACE.ERROR ("-d Enable debugging messages"); - ACE.ERROR ("-a <class name> Specify ActivateStrategy"); - ACE.ERROR (" (Default is multi-threaded"); - } - - /** - * Parses the command line arguments. See the class description - * for more information. - * - *@param args command line arguments - *@return -1 on failure, 0 on success - */ - protected int parseArgs (String [] args) - { - int c = 0; - GetOpt opt = new GetOpt(args, "p:da:", true); - - try { - - while ((c = opt.next ()) != -1) { - switch (c) - { - case 'd': - ACE.enableDebugging (); - ACE.DEBUG ("Debugging is enabled"); - break; - case 'p': - if (!port (opt.optarg ())) - return -1; - break; - case 'a': - Object strategy = newStrategyInstance (opt.optarg (), - "ActivateStrategy"); - if (strategy == null) - return -1; - - activateStrategy ((ActivateStrategy) strategy); - break; - default: - ACE.ERROR("Unknown argument: " + (char)c); - return -1; - } - } - } catch (ArrayIndexOutOfBoundsException e) { - ACE.ERROR ("Option -" + (char)c + " requires an argument"); - return -1; - } - - return 0; - } -} diff --git a/java/JACE/netsvcs/Time/TSServerHandler.java b/java/JACE/netsvcs/Time/TSServerHandler.java deleted file mode 100644 index 69bf4239280..00000000000 --- a/java/JACE/netsvcs/Time/TSServerHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -package JACE.netsvcs.Time; - -import java.io.*; -import java.util.*; -import java.net.*; -import JACE.OS.*; -import JACE.Connection.*; -import JACE.Reactor.*; -import JACE.SOCK_SAP.*; -import JACE.netsvcs.Handler; - -/** - * Created by TSServerAcceptor to handle time update requests. Currently, - * this simply sends back the current time (in seconds). - * - * @see JACE.netsvcs.Logger.ServerLoggingAcceptor - */ -public class TSServerHandler extends Handler -{ - /** - * Reads in the given TimeRequest request and calls dispatch. - * - *@param request TimeRequest instance to use - */ - public void processRequest (Object requestObject) - throws SocketException, EOFException, IOException - { - TimeRequest request = (TimeRequest)requestObject; - - request.streamInFrom (peer ().dataInputStream ()); - - this.dispatch (request); - } - - /** - * Sets the time value of the request to be the local time (in sec) - * and sends it back to the client. - */ - void dispatch(TimeRequest request) throws IOException - { - request.time ((int)(System.currentTimeMillis () / 1000)); - - request.streamOutTo (peer().outputStream ()); - } - - /** - * Creates a new instance of TimeRequest. - */ - public Object newRequest () - { - return new TimeRequest (); - } -} diff --git a/java/JACE/netsvcs/Time/TimeInfo.java b/java/JACE/netsvcs/Time/TimeInfo.java deleted file mode 100644 index 4ebfc793adb..00000000000 --- a/java/JACE/netsvcs/Time/TimeInfo.java +++ /dev/null @@ -1,90 +0,0 @@ -package JACE.netsvcs.Time; - -/** - * Wrapper for use with the clerk, containing a sequence number and - * time offset pair. - */ -public class TimeInfo -{ - /** - * Default constructor. - */ - public TimeInfo () - { - this (0, 0); - } - - /** - * Constructor. - * - *@param seqNum sequence number - *@param delta time offset in seconds - */ - public TimeInfo (int seqNum, long delta) - { - sequenceNumber_ = seqNum; - delta_ = delta; - } - - /** - * Returns this TimeInfo's sequence number. - */ - public int sequenceNumber () - { - return sequenceNumber_; - } - - /** - * Sets this TimeInfo's sequence number. - */ - public void sequenceNumber (int num) - { - sequenceNumber_ = num; - } - - /** - * Returns the time offset represented by this TimeInfo instance. - * (in sec) - */ - public long delta () - { - return delta_; - } - - /** - * Sets the time offset (in sec). - */ - public void delta (long num) - { - delta_ = num; - } - - /** - * Returns an informative String about the time difference represented - * by this TimeInfo instance. The sequence number is included in - * brackets. - * <P> - * Example: - * <PRE> - * Local time is 3 sec slower [57] - * </PRE> - */ - public String toString () - { - String result = "Local time is "; - if (delta_ > 0) { - result += (delta_ + " sec slower"); - } else - if (delta_ < 0) { - result += (delta_ + " sec faster"); - } else - result += "the same as the average"; - - result += " [" + sequenceNumber_ + "]"; - - return result; - } - - private long delta_; - private int sequenceNumber_; -} diff --git a/java/JACE/netsvcs/Time/TimeRequest.java b/java/JACE/netsvcs/Time/TimeRequest.java deleted file mode 100644 index 1b0e691398a..00000000000 --- a/java/JACE/netsvcs/Time/TimeRequest.java +++ /dev/null @@ -1,121 +0,0 @@ -package JACE.netsvcs.Time; - -import java.io.*; -import java.net.*; - -/** - * Request for a time update (and its reply). This is compatible with - * C++ ACE_Time_Request. Currently, the Java version always specifies to - * block forever for requests. - */ -public class TimeRequest -{ - /** - * Type for requesting updates. - */ - public static int TIME_UPDATE = 01; - - /** - * Default constructor, specifies block forever for an update. - */ - public TimeRequest () - { - messageType_ = TIME_UPDATE; - blockForever_ = 1; - } - - /** - * Constructor specifying the type of request, the current - * time, and to block forever. - */ - public TimeRequest (int messageType, - int timeSec) - { - time_ = timeSec; - messageType_ = messageType; - blockForever_ = 1; - } - - /** - * Dump all class information to a String. - */ - public String toString () - { - return "TimeRequest (" + messageType_ + - ", " + blockForever_ + ", " + secTimeout_ + ", " + - usecTimeout_ + ", " + time_ + ")"; - } - - /** - * Read the TimeRequest in from a given InputStream. - */ - public void streamInFrom (InputStream is) - throws IOException, EOFException - { - BufferedInputStream bis = new BufferedInputStream (is, 25); - DataInputStream dis = new DataInputStream (bis); - - streamInFrom (dis); - } - - /** - * Read the TimeRequest in from a given DataInputStream. - */ - public void streamInFrom (DataInputStream dis) - throws IOException, EOFException - { - messageType_ = dis.readInt (); - blockForever_ = dis.readInt (); - secTimeout_ = dis.readInt (); - usecTimeout_ = dis.readInt (); - time_ = dis.readInt (); - } - - /** - * Write this TimeRequest out to a given OutputStream. - */ - public void streamOutTo (OutputStream os) - throws IOException - { - BufferedOutputStream bos = new BufferedOutputStream (os, 25); - DataOutputStream dos = new DataOutputStream (bos); - - streamOutTo (dos); - } - - /** - * Write this TimeRequest out to a given DataOutputStream. - */ - public void streamOutTo (DataOutputStream dos) throws IOException - { - dos.writeInt (messageType_); - dos.writeInt (blockForever_); - dos.writeInt (secTimeout_); - dos.writeInt (usecTimeout_); - dos.writeInt (time_); - - dos.flush (); - } - - /** - * Return the time value in seconds. - */ - public int time () - { - return time_; - } - - /** - * Set the time value in seconds. - */ - public void time (int value) - { - time_ = value; - } - - private int messageType_; - private int blockForever_; - private int secTimeout_; - private int usecTimeout_; - private int time_; -} diff --git a/java/JACE/netsvcs/Time/c.bat b/java/JACE/netsvcs/Time/c.bat deleted file mode 100644 index 5e9e99f5807..00000000000 --- a/java/JACE/netsvcs/Time/c.bat +++ /dev/null @@ -1 +0,0 @@ -javac -d C:\Everett\JACE\classes *.java diff --git a/java/JACE/netsvcs/Time/package.html b/java/JACE/netsvcs/Time/package.html deleted file mode 100644 index 96fff45b643..00000000000 --- a/java/JACE/netsvcs/Time/package.html +++ /dev/null @@ -1,10 +0,0 @@ -<!-- $Id$ --> -<HTML> -<BODY> -Time Service for synchronizing clocks of collaborating network computers. -<P> -A simple test client is available under the tests directory in netsvcs\Time. - -@see <a href="http://www.cs.wustl.edu/~schmidt/ACE-netsvcs.html">ACE Network Services</a> -</BODY> -</HTML> diff --git a/java/JACE/netsvcs/Time/r.bat b/java/JACE/netsvcs/Time/r.bat deleted file mode 100644 index 7c89fbddd77..00000000000 --- a/java/JACE/netsvcs/Time/r.bat +++ /dev/null @@ -1 +0,0 @@ -java JACE.netsvcs.Time.%1 %2 %3 %4 %5 %6 %7 %8 %9 diff --git a/java/JACE/netsvcs/Token/LockHandler.java b/java/JACE/netsvcs/Token/LockHandler.java deleted file mode 100644 index 8e3612efb42..00000000000 --- a/java/JACE/netsvcs/Token/LockHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -package JACE.netsvcs.Token; - -/** - * Defines a handler for a certain type of lock. This allows new types - * of synchronization mechanisms to be added to the Token service without - * any modification of existing code. Implementing class instances that - * are registered (via the command line or another way) - * with the token service can be created as requests for that type of - * lock come into the service. - * - *@see LockHandlerAdapter - *@see MutexHandler - *@author Everett Anderson - */ -public interface LockHandler -{ - /** - * Process a given TokenRequest and construct the appropriate - * reply. The request has already been read from the connection, - * and the reply will be sent without the LockHandler having to - * worry about the details. - * - *@param caller TokenRequestHandler which is accessing this LockHandler - *@param request request read from the connection - *@return appropriate TokenReply (success, failure, etc) - */ - TokenReply handleRequest(TokenRequestHandler caller, - TokenRequest request); - - /** - * Release any claim the client represented with the given ID - * has on this handler's lock. This is used when a client - * disconnects. - * - *@param clientID ID of the client whose claims to abandon - */ - void abandonLock (String clientID); -} diff --git a/java/JACE/netsvcs/Token/LockHandlerAdapter.java b/java/JACE/netsvcs/Token/LockHandlerAdapter.java deleted file mode 100644 index e240000161c..00000000000 --- a/java/JACE/netsvcs/Token/LockHandlerAdapter.java +++ /dev/null @@ -1,380 +0,0 @@ -package JACE.netsvcs.Token; - -import java.util.*; -import JACE.ASX.*; -import JACE.OS.*; -import JACE.Concurrency.*; - -/** - * LockHandler implementation for any AbstractLock. - * <P> - * Provides the dispatching to appropriate methods on an AbstractLock - * as requests come in. - */ -public class LockHandlerAdapter implements LockHandler -{ - /** - * Constructor taking an AbstractLock to use as the locking - * mechanism the requests work on. - */ - public LockHandlerAdapter (AbstractLock lock) - { - lock_ = lock; - } - - /** - * Default constructor. - */ - public LockHandlerAdapter () - { - lock_ = null; - } - - /** - * Dispatch the request according to its type, calling the - * appropriate methods on the AbstractLock member. - * - *@param caller TokenRequestHandler which called handleRequest (unused) - *@param request request to process - *@return appropriate reply to send to the client - */ - public TokenReply handleRequest (TokenRequestHandler caller, - TokenRequest request) - { - String client = request.clientID (); - String token = request.tokenName (); - TokenReply result = null; - - // Dispatch according to operation type - switch (request.operationType ()) - { - case LockOperations.ACQUIRE: - ACE.DEBUG (client + " begins ACQUIRE for " + token); - result = acquireDispatcher (request); - break; - case LockOperations.RELEASE: - ACE.DEBUG (client + " begins RELEASE for " + token); - result = release (request); - break; - case LockOperations.RENEW: - ACE.DEBUG (client + " begins RENEW for " + token); - result = renew (request); - break; - case LockOperations.REMOVE: - ACE.DEBUG (client + " begins REMOVE for " + token); - result = remove (request); - break; - case LockOperations.TRY_ACQUIRE: - ACE.DEBUG (client + " begins TRY_ACQUIRE for " + token); - result = tryAcquireDispatcher (request); - break; - default: - ACE.ERROR ("Unknown operation: " + request.operationType ()); - break; - } - - ACE.DEBUG (client + " result: " + result); - - return result; - } - - /** - * Create a TimeValue from the given request's timeout information. Note - * that the time in the request is an absolute time timeout. - * - *@param request request to obtain the timeout info from - *@return null if useTimeout is false, otherwise a TimeValue - * representing the appropriate time period - */ - protected TimeValue getTimeout (TokenRequest request) - { - if (request.useTimeout ()) - return new TimeValue (request.sec (), - request.usec () * 1000); - else - return null; - } - - /** - * Call acquireWrite on the lock, returning its return value. - * - *@see AbstractLock#acquireWrite - *@return value from the lock's operation - */ - protected int acquireWrite (TokenRequest request, TimeValue timeout) - throws LockException, TimeoutException, InterruptedException - { - int result; - - if (timeout != null) - result = lock_.acquireWrite (timeout); - else - result = lock_.acquireWrite (); - - return result; - } - - /** - * Call acquireRead on the lock, returning its return value. - * - *@see AbstractLock#acquireRead - *@return value from the lock's operation - */ - protected int acquireRead (TokenRequest request, TimeValue timeout) - throws LockException, TimeoutException, InterruptedException - { - int result; - - if (timeout != null) - result = lock_.acquireRead (timeout); - else - result = lock_.acquireRead (); - - return result; - } - - /** - * Call acquire on the lock, returning its return value. - * - *@see AbstractLock#acquire - *@return value from the lock's operation - */ - protected int acquire (TokenRequest request, TimeValue timeout) - throws LockException, TimeoutException, InterruptedException - { - int result; - - if (timeout != null) - result = lock_.acquire (timeout); - else - result = lock_.acquire (); - - return result; - } - - /** - * Dispatch to the appropriate acquire method. In C++ ACE, when - * the type is LockTypes.RWLOCK and the proxy type is - * LockTypes.WRITE_LOCK_PROXY, then this calls acquireWrite. - * If it's RWLOCK and the proxy is READ_LOCK_PROXY, it calls - * acquireRead. In the normal case, it just calls acquire. - * - *@return reply to be sent back to the client (values for errno - * include constants in TokenReply such as EFAULT, ETIME, - * EINTR, or NO_ERRORS) - */ - protected TokenReply acquireDispatcher (TokenRequest request) - { - int result; - TimeValue timeout = getTimeout (request); - - try { - - /* - ACE specifies that when requesting a reader lock, the - token type will be RWLOCK and the proxy type is 0. - When it's a writer lock, the proxy type is 1. - */ - if (request.tokenType () == LockTypes.RWLOCK) { - if (request.proxyType () == LockTypes.READ_LOCK_PROXY) - result = acquireRead (request, timeout); - else - result = acquireWrite (request, timeout); - } else - result = acquire (request, timeout); - - } catch (LockException e) { - return new TokenReply (TokenReply.EFAULT, - request.arg ()); - } catch (TimeoutException e) { - return new TokenReply (TokenReply.ETIME, - request.arg ()); - } catch (InterruptedException e) { - return new TokenReply (TokenReply.EINTR, - request.arg ()); - } - - if (result == AbstractLock.FAILURE) { - return new TokenReply (TokenReply.EFAULT, - request.arg ()); - } else { - return new TokenReply (TokenReply.NO_ERRORS, - request.arg ()); - } - } - - /** - * Process a release request and construct a reply. The values - * for errno include TokenReply constants EFAULT, EACCES, or - * NO_ERRORS. - */ - protected TokenReply release (TokenRequest request) - { - int result; - - try { - result = lock_.release (); - } catch (LockException e) { - return new TokenReply (TokenReply.EFAULT, - request.arg ()); - } - - if (result == AbstractLock.FAILURE) { - return new TokenReply (TokenReply.EACCES, - request.arg ()); - } else { - return new TokenReply (TokenReply.NO_ERRORS, - request.arg ()); - } - } - - /** - * Process a renew request and construct a reply. The values for - * errno include TokenReply constants EFAULT, ETIME, EINTR, EACCES, - * or NO_ERRORS. - */ - protected TokenReply renew (TokenRequest request) - { - int result = AbstractLock.FAILURE; - TimeValue timeout = getTimeout (request); - - try { - - if (timeout != null) { - result = lock_.renew (request.requeuePosition (), - timeout); - } else { - result = lock_.renew (request.requeuePosition ()); - } - - } catch (LockException e) { - return new TokenReply (TokenReply.EFAULT, - request.arg ()); - } catch (TimeoutException e) { - return new TokenReply (TokenReply.ETIME, - request.arg ()); - } catch (InterruptedException e) { - return new TokenReply (TokenReply.EINTR, - request.arg ()); - } - - if (result == AbstractLock.FAILURE) { - return new TokenReply (TokenReply.EACCES, - request.arg ()); - } else { - return new TokenReply (TokenReply.NO_ERRORS, - request.arg ()); - } - } - - /** - * Process a remove request and construct a reply. This currently - * is not supported in the normal AbstractLock interface, so the - * default implementation returns a reply with errno set to - * TokenReply.ENOTSUP. - */ - protected TokenReply remove (TokenRequest request) - { - ACE.ERROR ("Remove is unimplemented"); - return new TokenReply (TokenReply.ENOTSUP, - request.arg ()); - } - - /** - * Call tryAcquireWrite on the lock, returning the result. - */ - protected int tryAcquireWrite (TokenRequest request) - throws LockException - { - return lock_.tryAcquireWrite (); - } - - /** - * Call tryAcquireRead on the lock, returning the result. - */ - protected int tryAcquireRead (TokenRequest request) - throws LockException - { - return lock_.tryAcquireRead (); - } - - /** - * Call tryAcquire on the lock, returning the result. - */ - protected int tryAcquire (TokenRequest request) throws LockException - { - return lock_.tryAcquire (); - } - - /** - * Dispatch to the appropriate tryAcquire method. In C++ ACE, when - * the type is LockTypes.RWLOCK and the proxy type is - * LockTypes.WRITE_LOCK_PROXY, then this calls acquireWrite. - * If it's RWLOCK and the proxy is READ_LOCK_PROXY, it calls - * acquireRead. In the normal case, it just calls acquire. - * - *@return reply to be sent back to the client (values for errno - * include constants in TokenReply such as EFAULT, - * EWOULDBLOCK, or NO_ERRORS). - */ - protected TokenReply tryAcquireDispatcher (TokenRequest request) - { - int result; - - try { - - /* - ACE specifies that when requesting a reader lock, the - token type will be RWLOCK and the proxy type is 0. - When it's a writer lock, the proxy type is 1. - */ - if (request.tokenType () == LockTypes.RWLOCK) { - if (request.proxyType () == LockTypes.READ_LOCK_PROXY) - result = tryAcquireRead (request); - else - result = tryAcquireWrite (request); - } else - result = tryAcquire (request); - - } catch (LockException e) { - return new TokenReply (TokenReply.EFAULT, - request.arg ()); - } - - if (result == AbstractLock.FAILURE) { - return new TokenReply (TokenReply.EWOULDBLOCK, - request.arg ()); - } else { - return new TokenReply (TokenReply.NO_ERRORS, - request.arg ()); - } - } - - /** - * Abandon any claim the specified client has on the lock. - * - *@param clientID identification of the client - */ - public void abandonLock (String clientID) - { - ACE.DEBUG (clientID + " abandoning lock"); - try { - int nesting_level = 0; - while (lock_.release () != AbstractLock.FAILURE) - { - nesting_level++; - // Loop until not the owner in case the lock - // supports nested acquires - } - if (nesting_level == 0) - ACE.DEBUG (clientID + " was not the owner"); - else - ACE.DEBUG (clientID + " had " + nesting_level + " locks"); - } catch (LockException e) { - ACE.ERROR ("While abandoning lock: " + e.getMessage ()); - // Don't need to send a reply to the client - } - } - - protected AbstractLock lock_; -} diff --git a/java/JACE/netsvcs/Token/LockOperations.java b/java/JACE/netsvcs/Token/LockOperations.java deleted file mode 100644 index f5dfa5bc486..00000000000 --- a/java/JACE/netsvcs/Token/LockOperations.java +++ /dev/null @@ -1,16 +0,0 @@ -package JACE.netsvcs.Token; - -/** - * Constants defining the operation types available on a lock. - * For information on specifying a read/write style lock, see LockTypes. - * - *@see LockTypes - */ -public interface LockOperations -{ - int ACQUIRE = 0; - int RELEASE = 1; - int RENEW = 2; - int REMOVE = 3; - int TRY_ACQUIRE = 4; -} diff --git a/java/JACE/netsvcs/Token/LockTypes.java b/java/JACE/netsvcs/Token/LockTypes.java deleted file mode 100644 index f377529367a..00000000000 --- a/java/JACE/netsvcs/Token/LockTypes.java +++ /dev/null @@ -1,19 +0,0 @@ -package JACE.netsvcs.Token; - -/** - * Constants related to the default lock and proxy types. New types - * of LockHandlers and lock types can be created and registered with - * the token service on the command line without modifying this. - * <P> - * C++ ACE handles RWLOCK in this way: - * When a request comes through for a RWLOCK, the proxy type is - * 0 for a read lock request and 1 for a write lock request. - */ -public interface LockTypes -{ - int MUTEX = 0; - int RWLOCK = 1; - - int READ_LOCK_PROXY = 0; - int WRITE_LOCK_PROXY = 1; -} diff --git a/java/JACE/netsvcs/Token/MutexHandler.java b/java/JACE/netsvcs/Token/MutexHandler.java deleted file mode 100644 index 82f79fe5a76..00000000000 --- a/java/JACE/netsvcs/Token/MutexHandler.java +++ /dev/null @@ -1,51 +0,0 @@ -package JACE.netsvcs.Token; - -import JACE.Concurrency.*; - -/** - * LockHandler implementation for a mutex lock. - * <P> - * Currently, this uses JACE.Concurrency.Token as the actual lock since - * it supports nested acquires. - * - *@see LockHandler - */ -public class MutexHandler extends LockHandlerAdapter -{ - // Uses token since it supports nested acquires. - static class ExtendedMutex extends Token - { - // This is so that we don't make any assumptions about previous - // implementations of LockAdapter, and enable owner checking with - // the client ID from TokenRequest. The thread name is set in - // handleRequest. - protected Object accessorID () - { - return Thread.currentThread().getName(); - } - } - - /** - * Default constructor. - */ - public MutexHandler () - { - super (new ExtendedMutex ()); - } - - public TokenReply handleRequest (TokenRequestHandler caller, - TokenRequest request) - { - Thread.currentThread().setName (request.clientID ()); - - return super.handleRequest (caller, request); - } - - public void abandonLock (String clientID) - { - Thread.currentThread().setName (clientID); - - super.abandonLock (clientID); - } -} - diff --git a/java/JACE/netsvcs/Token/RWMutexHandler.java b/java/JACE/netsvcs/Token/RWMutexHandler.java deleted file mode 100644 index 89dc679dd8d..00000000000 --- a/java/JACE/netsvcs/Token/RWMutexHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -package JACE.netsvcs.Token; - -import JACE.Concurrency.*; - -/** - * LockHandler implementation for a reader/writer mutex lock. - * <P> - * Since it uses RWMutex as the actual lock, it doesn't support - * nested acquires. - * - *@see LockHandler - */ -public class RWMutexHandler extends LockHandlerAdapter -{ - static class ExtendedRWMutex extends RWMutex - { - // This is so that we don't make any assumptions about previous - // implementations of LockAdapter, and enable owner checking with - // the client ID from TokenRequest. The thread name is set in - // handleRequest. - protected Object accessorID () - { - return Thread.currentThread().getName(); - } - } - - /** - * Default constructor. - */ - public RWMutexHandler () - { - super (new ExtendedRWMutex ()); - } - - public TokenReply handleRequest (TokenRequestHandler caller, - TokenRequest request) - { - // Set the name of this thread to the client ID to perform - // proper owner checking. - Thread.currentThread().setName (request.clientID ()); - - // process the request - return super.handleRequest (caller, request); - } - - public void abandonLock (String clientID) - { - // Set the name of this thread to the client ID to perform - // proper owner checking. - Thread.currentThread().setName (clientID); - - super.abandonLock (clientID); - } -} diff --git a/java/JACE/netsvcs/Token/RemoteLock.java b/java/JACE/netsvcs/Token/RemoteLock.java deleted file mode 100644 index 824e05a31f0..00000000000 --- a/java/JACE/netsvcs/Token/RemoteLock.java +++ /dev/null @@ -1,543 +0,0 @@ -package JACE.netsvcs.Token; - -import java.io.*; -import JACE.Concurrency.*; -import JACE.ASX.*; -import JACE.Connection.*; -import JACE.OS.*; - -/** - * Proxy used by clients to connect to the token service. This - * implements the AbstractLock interface, so can be used like any - * other synchronization mechanism. The user can either use this - * class directly, or use a proxy which already inputs its type. - * <P> - * Currently, a separate instance (and thus a separate socket connection) - * must be used for each thread which accesses the service. The token - * service itself could handle multiple client IDs and token names per - * connection with the following requirement -- since the service blocks - * in its operations, a shadow mutex would have to be used in the proxy. - * <P> - * It would be best if the user called the close () method after finishing - * up with a RemoteLock, but that is not absolutely necessary. The socket - * will be closed when the JVM exits or finalize is called. (That will also - * free the actual token in the token service in case release was never - * called.) - * <P> - * The SLEEPHOOK result is never returned, only SUCCESS or FAILURE. (C++ - * version doesn't seem to indicate the sleep hook result.) - * - *@see MutexHandler - *@see RWMutexHandler - *@see JACE.Concurrency.AbstractLock - * - *@author Everett Anderson - */ -public class RemoteLock extends SvcHandler implements AbstractLock -{ - /** - * Accessor for the token name. - * - *@return name of the token - */ - public String tokenName () - { - return request_.tokenName (); - } - - /** - * Set the name of the token. - */ - public void tokenName (String name) - { - request_.tokenName (name); - } - - /** - * Accessor for the client ID. - */ - public String clientID () - { - return request_.clientID (); - } - - /** - * Set the client ID. - */ - public void clientID (String clientID) - { - request_.clientID (clientID); - } - - /** - * Constructor. - * - *@see LockTypes - *@param tokenType type of token to create in the token service - *@param proxyType type of proxy to define this RemoteLock as - *@param tokenName name of the token to connect to in the token service - *@param clientID clientID to use to refer to this client - *@param host host name of the token service - *@param port port to connect to for the token service - */ - public RemoteLock (int tokenType, - int proxyType, - String tokenName, - String clientID, - String host, - int port) - { - host_ = host; - port_ = port; - - // Only allocates one reply and one request - reply_ = new TokenReply (); - - request_ = new TokenRequest (tokenType, - proxyType, - 0, - tokenName, - clientID); - } - - /** - * Reconnect this proxy to the token service. - * - *@exception LockException problem occured in reconnecting - */ - protected void reconnect () throws LockException - { - Connector c = new Connector (); - c.open (host_, port_); - - try { - c.connect (this); - } catch (InstantiationException e) { - throw new LockException (e.getMessage()); - } catch (IllegalAccessException e) { - throw new LockException (e.getMessage()); - } catch (IOException e) { - throw new LockException (e.getMessage()); - } - } - - /** - * Check to see if this RemoteLock is connected. - */ - public boolean connected () - { - return connected_; - } - - /** - * Initialize this RemoteLock. Called by Connector. - */ - public int open (Object obj) - { - connected_ = true; - return 0; - } - - /** - * Shut down the connection to the server. Current implementation - * calls close (). - */ - public int close (long flags) - { - return close (); - } - - /** - * Shut down the connection to the server and mark this lock - * as disconnected. - */ - public int close () - { - if (connected ()) { - try { - connected_ = false; - peer ().close (); - } catch (IOException e) { - return -1; - } - } - - return 0; - } - - /** - * Send the given request to the token service, throwing a - * LockException on error. - */ - protected void sendRequest (TokenRequest request) throws LockException - { - try { - if (!connected ()) - reconnect (); - - request.streamOutTo (peer ().dataOutputStream ()); - - } catch (IOException e) { - close (); - throw new LockException (e.getMessage ()); - } - } - - /** - * Receive a reply from the token service, throwing a LockException - * on error. - */ - protected void receiveReply (TokenReply reply) throws LockException - { - if (!connected ()) - throw new LockException ("Proxy wasn't connected, any replies lost"); - - try { - - reply.streamInFrom (peer ().dataInputStream ()); - - } catch (IOException e) { - close (); - throw new LockException (e.getMessage ()); - } - } - - /** - * For errors that shouldn't generate exceptions, return the - * appropriate result code as defined in AbstractLock. - * - *@return AbstractLock.SUCCESS or AbstractLock.FAILURE - */ - protected int processErrno (TokenReply reply) - { - switch (reply.errno ()) - { - case TokenReply.NO_ERRORS: - return AbstractLock.SUCCESS; - case TokenReply.EIO: - close (); - return AbstractLock.FAILURE; - default: - return AbstractLock.FAILURE; - } - } - - /** - * Make a request to the token service with the given operation - * type and arguments. - * - *@see LockOperations - *@see LockTypes - *@param operationType type of operation to perform - *@param proxyType type of proxy this is - *@param requeuePosition put this owner at this position in the - * waiting queue (only makes sense if the - * operation is renew) - *@return AbstractLock.SUCCESS or AbstractLock.FAILURE - *@exception LockException remote access error occured - */ - protected int makeRequest (int operationType, - int proxyType, - int requeuePosition) - throws LockException - { - request_.operationType (operationType); - request_.proxyType (proxyType); - request_.requeuePosition (requeuePosition); - request_.useTimeout (false); - - sendRequest (request_); - receiveReply (reply_); - - // make sure that if someone does send a magic cookie arg back, - // to keep it going - request_.arg (reply_.arg ()); - - return processErrno (reply_); - } - - /** - * Make a request to the token service with the given arguments - * that must be performed by the given absolute time timeout. - * Currently, the timeout is managed by the remote service. - * - *@see LockOperations - *@see LockTypes - *@param operationType type of operation to perform - *@param proxyType type of proxy this is - *@param requeuePosition put this owner at this position in the - * waiting queue (only makes sense if the - * operation is renew) - *@param timeout absolute time timeout to accomplish the operation by - *@return AbstractLock.SUCCESS or AbstractLock.FAILURE - *@exception LockException remote access error occured - */ - protected int makeRequest (int operationType, - int proxyType, - int requeuePosition, - TimeValue timeout) - throws LockException, TimeoutException - { - request_.operationType (operationType); - request_.proxyType (proxyType); - request_.requeuePosition (requeuePosition); - request_.useTimeout (timeout); - - sendRequest (request_); - receiveReply (reply_); - - request_.arg (reply_.arg ()); - - if (reply_.errno () == TokenReply.ETIME) - throw new TimeoutException (timeout, "Remote Lock"); - - return processErrno (reply_); - } - - /** - * Acquire ownership of the lock, blocking indefinitely if necessary. - * <P> - *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception LockException a remote error occured - */ - public int acquire () throws LockException - { - return makeRequest (LockOperations.ACQUIRE, 0, 0); - } - - /** - * Acquire ownership of the lock by the given absolute time time-out. - * A value of null for the timeout parameter results in a blocking - * acquire. - * A value of TimeValue.zero throws a TimeoutException if the - * acquire would block. - * <P> - *@param timeout absolute time by which the lock must be acquired - *@return appropriate Lock return value (AbstractLock.FAILURE, - * AbstractLock.SUCCESS or AbstractLock.SLEEPHOOK) - *@exception LockException a remote error occured - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - *@see #tryAcquire - */ - public int acquire (TimeValue timeout) - throws LockException, TimeoutException - { - return makeRequest (LockOperations.ACQUIRE, 0, 0, timeout); - } - - /** - * Acquire a read lock, blocking indefinitely if necessary. - * - *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception LockException a remote error occured - */ - public int acquireRead () throws LockException - { - return makeRequest (LockOperations.ACQUIRE, - LockTypes.READ_LOCK_PROXY, - 0); - } - - /** - * Acquire a read lock by the given absolute time time-out. - * - *@param timeout absolute time by which the lock must be acquired - *@return appropriate lock return value (AbstractLock.FAILURE, - * AbstractLock.SUCCESS or AbstractLock.SLEEPHOOK) - *@exception LockException a remote error occured - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - *@see #tryAcquireRead - */ - public int acquireRead (TimeValue timeout) - throws LockException, TimeoutException - { - return makeRequest (LockOperations.ACQUIRE, - LockTypes.READ_LOCK_PROXY, - 0, - timeout); - } - - /** - * Acquire a write lock, blocking indefinitely if necessary. - * - *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception LockException a remote error occured - */ - public int acquireWrite () - throws LockException - { - return makeRequest (LockOperations.ACQUIRE, - LockTypes.WRITE_LOCK_PROXY, - 0); - } - - /** - * Acquire a write lock by the given absolute time time-out. - * - *@param timeout absolute time by which the lock must be acquired - *@return appropriate lock return value (AbstractLock.FAILURE, - * AbstractLock.SUCCESS or AbstractLock.SLEEPHOOK) - *@exception LockException a remote error occured - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - *@see #tryAcquireWrite - */ - public int acquireWrite (TimeValue timeout) - throws LockException, TimeoutException - { - return makeRequest (LockOperations.ACQUIRE, - LockTypes.WRITE_LOCK_PROXY, - 0, - timeout); - } - - - /** - * Give up the lock to some number of waiting threads (if any), then - * reacquire, blocking indefinitely if necessary. - * <P> - * An optimized method that efficiently reacquires the token if no - * other threads are waiting. This is useful for situations where - * you don't want to degrade the quality of service if there are - * other threads waiting to get the token. - * <P> - *@param requeuePosition position in the waiters queue to insert - * this thread. If this value is -1 and there are other - * threads waiting to obtain the token, this thread is queued - * at the end. If this value is greater than -1, then it - * indicates how many entries to skip over before inserting - * our thread into the queue. (For example, if it is 0, - * this thread is put at the front of the queue.) If this - * value is greater than the number of waiters, this thread is - * simply put at the end of the current waiters queue. - *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception LockException a remote error occured - */ - public int renew (int requeuePosition) - throws LockException - { - return makeRequest (LockOperations.RENEW, - 0, - requeuePosition); - } - - /** - * Give up the lock to some waiting threads (if any), then reacquire - * by the given absolute time time-out. - * <P> - * An optimized method that efficiently reacquires the token if no - * other threads are waiting. This is useful for situations where - * you don't want to degrade the quality of service if there are - * other threads waiting to get the token. - * <P> - * A value of null for the timeout indicates a blocking renew. - * <P> - *@param requeuePosition position in the waiters queue to insert - * this thread. If this value is -1 and there are other - * threads waiting to obtain the token, this thread is queued - * at the end. If this value is greater than -1, then it - * indicates how many entries to skip over before inserting - * our thread into the queue. (For example, if it is 0, - * this thread is put at the front of the queue.) If this - * value is greater than the number of waiters, this thread is - * simply put at the end of the current waiters queue. - * - *@param timeout absolute time by which the lock must be reacquired - * - *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException a remote error occured - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - */ - public int renew (int requeuePosition, TimeValue timeout) - throws LockException, TimeoutException - { - return makeRequest (LockOperations.RENEW, - 0, - requeuePosition, - timeout); - } - - /** - * Try to acquire the lock without blocking. - * <P> - *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException a remote error occured - */ - public int tryAcquire () throws LockException - { - return makeRequest (LockOperations.TRY_ACQUIRE, 0, 0); - } - - /** - * Try to acquire a read lock without blocking. - * <P> - *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException a remote error occured - */ - public int tryAcquireRead () throws LockException - { - return makeRequest (LockOperations.TRY_ACQUIRE, - LockTypes.READ_LOCK_PROXY, - 0); - } - - /** - * Try to acquire a write lock without blocking. - * - *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException a remote error occured - */ - public int tryAcquireWrite () throws LockException - { - return makeRequest (LockOperations.TRY_ACQUIRE, - LockTypes.WRITE_LOCK_PROXY, - 0); - } - - /** - * Release ownership of this lock. - * - *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException a remote error occured - */ - public int release () throws LockException - { - return makeRequest (LockOperations.RELEASE, 0, 0); - } - - /** - * Closes the connection to the server (if it is still open). - */ - protected void finalize () throws Throwable - { - close (); - } - - /** - * No-op implementation for the sleep hook (unused). - */ - public void sleepHook () {} - - /** Status of whether this RemoteLock is connected to the server or not */ - protected boolean connected_ = false; - - /** Request object for transmissions to the server */ - protected TokenRequest request_; - - /** Reply object for receiving transmissions from the server */ - protected TokenReply reply_; - - /** Host name of the token service */ - protected String host_; - - /** Port number of the token service */ - protected int port_; -} diff --git a/java/JACE/netsvcs/Token/RemoteMutex.java b/java/JACE/netsvcs/Token/RemoteMutex.java deleted file mode 100644 index 7f2a4311116..00000000000 --- a/java/JACE/netsvcs/Token/RemoteMutex.java +++ /dev/null @@ -1,28 +0,0 @@ -package JACE.netsvcs.Token; - -/** - * Proxy used by clients for accessing a mutex at the token service. - */ -public class RemoteMutex extends RemoteLock -{ - /** - * Constructor. - * - *@param tokenName name of the mutex to access - *@param clientID identification of this client - *@param host host of the token service - *@param port port number of the token service - */ - public RemoteMutex (String tokenName, - String clientID, - String host, - int port) - { - super (LockTypes.MUTEX, - 0, - tokenName, - clientID, - host, - port); - } -} diff --git a/java/JACE/netsvcs/Token/RemoteRWMutex.java b/java/JACE/netsvcs/Token/RemoteRWMutex.java deleted file mode 100644 index cc666bfd70f..00000000000 --- a/java/JACE/netsvcs/Token/RemoteRWMutex.java +++ /dev/null @@ -1,29 +0,0 @@ -package JACE.netsvcs.Token; - -/** - * Proxy used by clients for accessing a reader/writer mutex - * at the token service. - */ -public class RemoteRWMutex extends RemoteLock -{ - /** - * Constructor. - * - *@param tokenName name of the reader/writer lock to access - *@param clientID identification of this client - *@param host host of the token service - *@param port port number of the token service - */ - public RemoteRWMutex (String tokenName, - String clientID, - String host, - int port) - { - super (LockTypes.RWLOCK, - 0, - tokenName, - clientID, - host, - port); - } -} diff --git a/java/JACE/netsvcs/Token/TokenAcceptor.java b/java/JACE/netsvcs/Token/TokenAcceptor.java deleted file mode 100644 index 53adf08753b..00000000000 --- a/java/JACE/netsvcs/Token/TokenAcceptor.java +++ /dev/null @@ -1,353 +0,0 @@ -package JACE.netsvcs.Token; - -import java.io.*; -import java.net.*; -import java.util.*; -import JACE.OS.*; -import JACE.Misc.*; -import JACE.Connection.*; -import JACE.netsvcs.Server; - -/** - * Server for the token service. Launches TokenRequestHandlers as - * connections are made. Currently, the activation strategy must be - * thread per connection since the operations are allowed to block - * during acquires, etc. - * <P> - * Two types of locks are supported by default -- Mutex and RWMutex. - * New lock types can be added from the command line without changing - * any code in the service. To do this, just create a class which - * implements the LockHandler interface. - * <P> - * When a request for a new lock comes in, a LockHandler of the corresponding - * type is created and a mapping is created between the lock name and the - * handler. Later requests reuse that mapping. - * <P> - * <B>Valid command line arguments:</B> - * <PRE> - * -f (class name):(type) Specify a LockHandler for a type of lock"); - * -p (port number) Port to listen on for clients"); - * -d Enable debugging messages"); - * </PRE> - * - *@see JACE.netsvcs.Server - *@see TokenRequestHandler - *@see LockHandler - *@see LockTypes - */ -public class TokenAcceptor extends Server -{ - protected void addDefaultFactories() throws ClassNotFoundException { - addHandlerFactory(LockTypes.MUTEX, - Class.forName("JACE.netsvcs.Token.MutexHandler")); - addHandlerFactory(LockTypes.RWLOCK, - Class.forName("JACE.netsvcs.Token.RWMutexHandler")); - } - - /** - * Default constructor. - */ - public TokenAcceptor() { - - // Set the name in case we aren't using the service configurator. - name ("Token Service"); - - lockHandlerMap_ = new Hashtable(); - handlerFactoryMap_ = new Hashtable(); - clientHandlerMap_ = new Hashtable (); - } - - /** - * Add a map between a type of lock and the factory which - * creates LockHandler instances that handle it. - * - *@see LockTypes - *@param type number representing the type of lock - *@param factory Class object for a LockHandler class - */ - public void addHandlerFactory(Integer type, Class factory) { - handlerFactoryMap_.put(type, factory); - } - - /** - * Add a map between a type of lock and the factory which - * creates LockHandler instances that handle it. - * - *@see LockTypes - *@param type number representing the type of lock - *@param factory Class object for a LockHandler class - */ - public void addHandlerFactory(int type, Class factory) { - addHandlerFactory(new Integer(type), factory); - } - - /** - * Remove the LockHandler factory which handles locks - * of the specified type. - * - *@param type type of LockHandler to cease supporting - *@return the LockHandler instance (or null if not found) - */ - public Object removeHandlerFactory(Integer type) { - return handlerFactoryMap_.remove(type); - } - - /** - * Remove the LockHandler factory which handles locks - * of the specified type. - * - *@param type type of LockHandler to cease supporting - *@return the LockHandler instance (or null if not found) - */ - public Object removeHandlerFactory(int type) { - return handlerFactoryMap_.remove(new Integer(type)); - } - - /** - * Retrieve the LockHandler corresponding to the given name - * or create a new one if it doesn't exist. This is called by - * TokenRequestHandlers. - * - *@param lockName name of the lock to retrieve or create a LockHandler for - *@param lockType type of the lock - *@return LockHandler which handles the lock with that name - */ - public LockHandler getLockHandler (String lockName, - int lockType) { - synchronized (lockHandlerMap_) { - - Object obj = lockHandlerMap_.get(lockName); - - if (obj != null) - return (LockHandler)obj; - else { - LockHandler handler = newHandler (lockType); - lockHandlerMap_.put (lockName, handler); - return handler; - } - } - } - - /** - * Create a new LockHandler of the specified type. - * - *@param type type of LockHandler to create - *@return a new LockHandler instance - */ - protected LockHandler newHandler (int type) { - ACE.DEBUG ("Creating new handler of type " + type); - Object factoryObj = handlerFactoryMap_.get(new Integer(type)); - if (factoryObj == null) - return null; - - Class factory = (Class)factoryObj; - LockHandler handler = null; - - try { - handler = (LockHandler)factory.newInstance(); - } catch (InstantiationException e) { - ACE.ERROR("Can't create a handler of type " + type); - } catch (IllegalAccessException e) { - ACE.ERROR("Handler of type " + type + - " must have a default constructor"); - } - return handler; - } - - /** - * Simple main program. See the class description for more - * information about command line arguments. - */ - public static void main(String args[]) { - TokenAcceptor ta = new TokenAcceptor(); - - ta.init(args); - } - - /** - * Create a new TokenRequestHandler instance. - */ - protected SvcHandler makeSvcHandler() - { - return new TokenRequestHandler(); - } - - /** - * Sets up the default factories so the user can override them on - * the command line, then delegates back to Server.init (String[]). - * - *@see JACE.netsvcs.Server#init - *@param args command line arguments - *@return -1 on failure, 0 on success - */ - public int init(String [] args) { - try { - addDefaultFactories (); - } catch (ClassNotFoundException e) { - ACE.ERROR ("Can't find default factory " + e.getMessage ()); - return -1; - } - - return super.init (args); - } - - /** - * 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 <class name>:<type> Specify a handler for a type of lock"); - ACE.ERROR ("-p <port number> Port to listen on for clients"); - ACE.ERROR ("-d Enable debugging messages"); - } - - /** - * Parses the command line arguments. See the class description - * for more information. - * - *@param args command line arguments - *@return -1 on failure, 0 on success - */ - protected int parseArgs(String [] args) - { - int c = 0; - GetOpt opt = new GetOpt(args, "p:f:d", true); - - try { - - while ((c = opt.next ()) != -1) { - switch (c) - { - case 'd': - ACE.enableDebugging (); - ACE.DEBUG ("Debugging is enabled"); - break; - case 'p': - if (!port (opt.optarg ())) - return -1; - break; - case 'f': - if (newHandlerFactory (opt.optarg ()) < 0) - return -1; - break; - default: - ACE.ERROR("Unknown argument: " + (char)c); - return -1; - } - } - } catch (ArrayIndexOutOfBoundsException e) { - ACE.ERROR ("Option -" + (char)c + " requires an argument"); - return -1; - } - - return 0; - } - - /** - * Load the Class for the specified LockHandler and create a mapping - * from its type to the Class instance. Used to parse the command - * line pair of (class name):(type). - * - *@param nameAndType (class name):(type) pair from the command line - *@return -1 on failure, 0 on success - */ - protected int newHandlerFactory (String nameAndType) - { - int colon = nameAndType.lastIndexOf (':'); - - if (colon < 1) { - ACE.ERROR ("Invalid -f <class name>:<type num> for handler: " + - nameAndType); - return -1; - } - - int type = 0; - try { - type = Integer.parseInt (nameAndType.substring (colon + 1)); - } catch (NumberFormatException e) { - ACE.ERROR ("Invalid token type: " + e.getMessage ()); - return -1; - } - - String name = nameAndType.substring (0, colon); - - Class factory; - try { - factory = Class.forName (name); - } catch (ClassNotFoundException e) { - ACE.ERROR (e.getMessage ()); - return -1; - } - - addHandlerFactory (type, factory); - ACE.DEBUG ("New handler " + name + " with type " + type); - - return 0; - } - - /** - * Create a mapping between a client ID and a LockHandler. This is - * only used by TokenRequestHandlers in order to keep track of which - * locks a client touches. That way, if/when a client disconnects, - * all its locks can be abandoned successfully. - * - *@param clientID client identification (key in the mapping) - *@param handler LockHandler to map to (value in the mapping) - * - */ - void addClientLockHandler (String clientID, - LockHandler handler) - { - Object obj = clientHandlerMap_.get (clientID); - if (obj == null) { - // Probably won't have more than 10 locks per client ID, and the Vector - // should resize automatically even if someone does. - Vector handlerList = new Vector (10); - handlerList.addElement (handler); - clientHandlerMap_.put (clientID, handlerList); - } else { - Vector handlerList = (Vector)obj; - int alreadyThereIndex = handlerList.indexOf (handler); - if (alreadyThereIndex == -1) - handlerList.addElement (handler); - } - } - - /** - * Called by TokenRequestHandlers to remove a specified client ID - * from the client ID to LockHandler mapping. - */ - void removeClient (String clientID) - { - clientHandlerMap_.remove (clientID); - } - - /** - * Called by TokenRequestHandlers to obtain a list of all LockHandlers - * accessed by a particular client. Useful for abandoning the locks. - */ - Enumeration getClientLockHandlers (String clientID) - { - Object obj = clientHandlerMap_.get (clientID); - if (obj == null) - return null; - else - return ((Vector)obj).elements (); - } - - // These should be replaced by weak hash maps when available - - // Map consisting of (token name) to (LockHandler instance) pairs - private Hashtable lockHandlerMap_; - - // Map consisting of (Integer token type) to (Class instance for - // corresponding LockHandler class) - private Hashtable handlerFactoryMap_; - - // Map consisting of (client ID) to (Vector of LockHandler) pairs - private Hashtable clientHandlerMap_; -} - diff --git a/java/JACE/netsvcs/Token/TokenReply.java b/java/JACE/netsvcs/Token/TokenReply.java deleted file mode 100644 index 35f50901610..00000000000 --- a/java/JACE/netsvcs/Token/TokenReply.java +++ /dev/null @@ -1,171 +0,0 @@ -package JACE.netsvcs.Token; - -import java.io.*; -import JACE.ASX.*; -import JACE.OS.*; - -/** - * Reply from a lock operation, and constants involved in it. - * This is compatible with the C++ ACE version. The user probably - * never deals directly with the constant errno values in Java ACE since - * the proxy (RemoteLock) should hide those details. - */ -public class TokenReply -{ - - /** indicates success */ - public static final int NO_ERRORS = 0; - - /** indicates a timeout */ - public static final int ETIME = 62; - - /** indicates the operation was interrupted */ - public static final int EINTR = 4; - - /** deadlock indication errno (JACE currently doesn't implement a - * deadlock detection system, but C++ ACE does and JACE proxies - * act appropriately). - */ - public static final int EDEADLK = 45; - - /** indicates the operation would block, used in tryAcquire */ - public static final int EWOULDBLOCK = 11; - - /** indicates a token name or client ID was too long */ - public static final int ENAMETOOLONG = 78; - - /** indicates an operation type was not supported */ - public static final int ENOTSUP = 48; - - /** indicates that this client was not the owner of the lock, - * so couldn't perform the desired operation */ - public static final int EACCES = 13; - - /** indicates an IO error occured during transmission of the request */ - public static final int EIO = 5; - - /** indicates a generic failure to complete the request */ - public static final int EFAULT = 14; - - /** indicates an operation was requested on an unknown type of token */ - public static final int EINVAL = 22; - - /** constant length of a valid token reply */ - private final static int LENGTH = 12; - - /** error code */ - private int errno_; - - /** argument (unused in JACE) */ - private int arg_; - - /** Dump the state of this TokenReply to a String */ - public String toString () - { - return "TokenReply(" + this.length() + ", " + this.errno_ - + ", " + this.arg_ + ")"; - } - - /** Default constructor (NO_ERRORS) */ - public TokenReply () - { - errno_ = NO_ERRORS; - arg_ = 0; - } - - /** Constructor which takes the error code and argument */ - public TokenReply (int errno, int arg) - { - errno_ = errno; - arg_ = arg; - } - - /** - * Accessor for the length of this TokenReply. - */ - public int length () - { - return LENGTH; - } - - /** Accessor for the error code of this TokenReply. */ - public int errno () - { - return errno_; - } - - /** - * Set the error code of this TokenReply. - */ - public void errno (int value) - { - errno_ = value; - } - - /** - * Accessor of the argument of this TokenReply. (Unused in JACE) - */ - public int arg () - { - return arg_; - } - - /** - * Set the argument of this TokenReply. (Unused in JACE) - */ - public void arg (int value) - { - arg_ = value; - } - - /** - * Read this TokenReply in from the given InputStream. - */ - public void streamInFrom (InputStream is) - throws IOException, EOFException - { - BufferedInputStream bis = new BufferedInputStream (is, LENGTH); - DataInputStream dis = new DataInputStream (bis); - - streamInFrom (dis); - } - - /** - * Read this TokenReply in from the given DataInputStream. - */ - public void streamInFrom (DataInputStream dis) - throws IOException, EOFException - { - int length = dis.readInt (); - if (length != LENGTH) - throw new IOException ("Invalid TokenReply length " + length); - - this.errno_ = dis.readInt (); - this.arg_ = dis.readInt (); - } - - /** - * Write this TokenReply out to the given OutputStream. - */ - public void streamOutTo (OutputStream os) - throws IOException - { - BufferedOutputStream bos = new BufferedOutputStream (os, LENGTH); - DataOutputStream dos = new DataOutputStream (bos); - - streamOutTo (dos); - } - - /** - * Write this TokenReply out to the given DataOutputStream. - */ - public void streamOutTo (DataOutputStream dos) - throws IOException - { - dos.writeInt (LENGTH); - dos.writeInt (this.errno_); - dos.writeInt (this.arg_); - - dos.flush (); - } -} diff --git a/java/JACE/netsvcs/Token/TokenRequest.java b/java/JACE/netsvcs/Token/TokenRequest.java deleted file mode 100644 index eb1113428c5..00000000000 --- a/java/JACE/netsvcs/Token/TokenRequest.java +++ /dev/null @@ -1,426 +0,0 @@ -package JACE.netsvcs.Token; - -import java.io.*; -import JACE.ASX.*; -import JACE.OS.*; - -/** - * Request for an operation on a lock. This is compatible with the - * C++ ACE version. The US-ASCII character encoding is used for - * String to byte conversions (and vice versa). If - * that encoding isn't supported, it attempts to use the default - * encoding (but prints a message). Users probably never need to - * deal with this class directly. The notify field isn't used - * in JACE (or in C++ ACE as far as I can tell). - * - *@author Everett Anderson - */ -public class TokenRequest -{ - /** Maximum length for a token name */ - public final static int MAX_TOKEN_NAME_LEN = 40; - - /** Maximum length for a client ID */ - public final static int MAX_CLIENT_ID_LEN = 276; - - /** Length of the fixed size header */ - protected final static int HEADER_LEN = 40; - - /** Maximum length of any TokenRequest (total) */ - protected final static int MAX_LEN = 359; - - /** - * Dump this TokenRequest's state out to a String. - */ - public String toString() - { - return "TokenRequest(" + this.length() + ", " + - this.tokenType_ + ", " + - this.proxyType_ + ", " + - this.operationType_ + ", " + - this.requeuePosition_ + ", " + - this.notify_ + ", " + - this.useTimeout_ + ", " + - this.sec_ + ", " + - this.usec_ + ", " + - this.arg_ + ", " + - this.tokenName_ + ", " + - this.clientID_ + ")"; - } - - /** Default constructor. */ - public TokenRequest() - { - // Remember that the length is transmitted first - tokenType_ = 0; - proxyType_ = 0; - operationType_ = 0; - requeuePosition_ = 0; - notify_ = 0; - useTimeout_ = 0; - sec_ = 0; - usec_ = 0; - arg_ = 0; - tokenName_ = ""; - clientID_ = ""; - // Transmission is "<10 ints><token name>(null):<clientID>(null)" - - charEncoding_ = "US-ASCII"; - - buffer_ = new byte[MAX_LEN]; - } - - /** - * Create a request which doesn't use timeouts. - * - *@param tokenType type of token (usually a constant in LockTypes) - *@param proxyType type of proxy (usually a constant in LockTypes) - *@param operationType type of operation (usually a constant in - * LockOperations) - *@param tokenName name of the token to operate on - *@param clientID name of the client requesting an operation - * - *@see LockTypes - *@see LockOperations - */ - public TokenRequest(int tokenType, - int proxyType, - int operationType, - String tokenName, - String clientID) - { - this(); - - this.tokenType_ = tokenType; - this.proxyType_ = proxyType; - this.operationType_ = operationType; - this.tokenName_ = tokenName; - this.clientID_ = clientID; - } - - /** - * Create a request which uses the given absolute time timeout. - * - *@param tokenType type of token (usually a constant in LockTypes) - *@param proxyType type of proxy (usually a constant in LockTypes) - *@param operationType type of operation (usually a constant in - * LockOperations) - *@param tokenName name of the token to operate on - *@param clientID name of the client requesting an operation - *@param tv absolute time timeout to process the request by - * - *@see LockTypes - *@see LockOperations - */ - public TokenRequest(int tokenType, - int proxyType, - int operationType, - String tokenName, - String clientID, - TimeValue tv) - { - this(tokenType, - proxyType, - operationType, - tokenName, - clientID); - - this.useTimeout_ = 1; - this.sec_ = (int)tv.sec(); - this.usec_ = tv.nanos() / 1000; - } - - /** - * Return the length of this TokenRequest. - * <P> - * Details: - * <PRE> - * Fixed size header of length HEADER_LEN - * token name - * null - * : - * client ID - * null - * </PRE> - */ - public int length() - { - return (HEADER_LEN + - this.tokenName_.length() + - this.clientID_.length() + 3); - } - - /** Accessor for the token type. */ - public int tokenType() - { - return this.tokenType_; - } - /** Set the token type. */ - public void tokenType(int type) - { - this.tokenType_ = type; - } - /** Accessor for the proxy type. */ - public int proxyType() - { - return this.proxyType_; - } - /** Set the proxy type. */ - public void proxyType(int type) - { - this.proxyType_ = type; - } - /** Accessor for the operation type. */ - public int operationType() - { - return this.operationType_; - } - /** Set the operation type. */ - public void operationType(int type) - { - this.operationType_ = type; - } - /** Accessor for the requeue position. This only makes - * sense for a renew operation. */ - public int requeuePosition() - { - return this.requeuePosition_; - } - /** Set the requeue position. This only makes sense for - * a renew operation. */ - public void requeuePosition(int position) - { - this.requeuePosition_ = position; - } - /** Accessor for the flag to determine if a timeout should be used. */ - public boolean useTimeout() - { - return (this.useTimeout_ == 1 ? true : false); - } - /** Set the flag to enable or disable use of timeouts. - */ - public void useTimeout(boolean useIt) - { - this.useTimeout_ = (useIt == true ? 1 : 0); - } - - /** - * Set the absolute time timeout to the given TimeValue's value, and - * enable the useTimeout flag. - */ - public void useTimeout (TimeValue timeout) - { - this.useTimeout_ = 1; - this.sec_ = (int)timeout.sec (); - this.usec_ = timeout.nanos () / 1000; - } - - /** - * Accessor for the seconds component of the absolute time timeout. - */ - public int sec() - { - return this.sec_; - } - /** Set the seconds component of the timeout. */ - public void sec(int sec) - { - this.sec_ = sec; - } - /** Accessor for the usec component of the timeout. */ - public int usec() - { - return this.usec_; - } - /** Set the usec component of the timeout. */ - public void usec(int usec) - { - this.usec_ = usec; - } - /** Accessor for the arg value. (unused in JACE) */ - public int arg() - { - return this.arg_; - } - /** Set the arg value. (unused in JACE) */ - public void arg(int arg) - { - this.arg_ = arg; - } - - /** Accessor for the name of the token. */ - public String tokenName() - { - return this.tokenName_; - } - - /** Set the name of the token. */ - public void tokenName(String name) - { - this.tokenName_ = name; - } - - /** Accessor for the client identification string. */ - public String clientID() - { - return this.clientID_; - } - - /** Set the client identification string. */ - public void clientID(String ID) - { - this.clientID_ = ID; - } - - /** - * Construct a String from a specific subset of the byte array. - * The string begins at the start index and ends at either the - * end of the buffer or the first byte with value 0 (null). - * Tries to use the specified encoding, but uses the default - * platform encoding if it isn't available. - * - *@param start beginning index in the buffer - *@param bufferLength total length of the buffer - */ - protected String stringFromBuffer(int start, int bufferLength) - { - int end = start; - String result = null; - - while (end < bufferLength && this.buffer_[end] != 0) - end++; - - try { - result = new String(this.buffer_, - start, - end - start, - this.charEncoding_); - } catch (UnsupportedEncodingException e) { - ACE.ERROR(this.charEncoding_ + " is not supported!"); - result = new String (this.buffer_, start, end - start); - } - - return result; - } - - /** - * Read the request in from the given InputStream. - */ - public void streamInFrom(InputStream is) - throws IOException, EOFException - { - BufferedInputStream bis = new BufferedInputStream(is, - MAX_LEN); - DataInputStream dis = new DataInputStream(bis); - - streamInFrom (dis); - } - - /** - * Read the request in from the given DataInputStream. - */ - public void streamInFrom (DataInputStream dis) - throws IOException, EOFException - { - int length = dis.readInt(); - if (length > MAX_LEN || length < HEADER_LEN + 5) - throw new IOException ("Invalid TokenRequest length: " + length); - - this.tokenType_ = dis.readInt(); - this.proxyType_ = dis.readInt(); - this.operationType_ = dis.readInt(); - this.requeuePosition_ = dis.readInt(); - this.notify_ = dis.readInt(); - this.useTimeout_ = dis.readInt(); - this.sec_ = dis.readInt(); - this.usec_ = dis.readInt(); - this.arg_ = dis.readInt(); - - int total = dis.read(this.buffer_, 0, length - HEADER_LEN); - - this.tokenName_ = this.stringFromBuffer(0, total); - - this.clientID_ = this.stringFromBuffer(this.tokenName_.length() + 2, - total); - - if (this.tokenName_.length() > MAX_TOKEN_NAME_LEN || - this.clientID_.length() > MAX_CLIENT_ID_LEN) - throw new IOException("Exceeds maximum token name or client ID"); - } - - /** - * Write the request out to the given OutputStream. - */ - public void streamOutTo (OutputStream os) - throws IOException - { - BufferedOutputStream bos = new BufferedOutputStream(os); - DataOutputStream dos = new DataOutputStream(bos); - - streamOutTo (dos); - } - - /** - * Write the request out to the given DataOutputStream. Tries to use - * the specified encoding to the convert the token name and client ID - * to bytes, but uses the platform default encoding if necessary. - */ - public void streamOutTo (DataOutputStream dos) - throws IOException - { - dos.writeInt(this.length()); - dos.writeInt(this.tokenType_); - dos.writeInt(this.proxyType_); - dos.writeInt(this.operationType_); - dos.writeInt(this.requeuePosition_); - - dos.writeInt(this.notify_); - dos.writeInt(this.useTimeout_); - dos.writeInt(this.sec_); - dos.writeInt(this.usec_); - dos.writeInt(this.arg_); - - StringBuffer data = new StringBuffer(this.tokenName_.length() + - this.clientID_.length() + - 3); - - data.append(this.tokenName_); - data.append('\0'); - data.append(':'); - data.append(this.clientID_); - data.append('\0'); - - byte buf [] = null; - String dataString = data.toString (); - try { - buf = dataString.getBytes (this.charEncoding_); - } catch (UnsupportedEncodingException e) { - ACE.ERROR (charEncoding_ + " is unsupported, trying to use default"); - buf = dataString.getBytes (); - } - - dos.write(buf, 0, buf.length); - dos.flush(); - } - - private int tokenType_; - private int proxyType_; - private int operationType_; - private int requeuePosition_; - private int notify_; - private int useTimeout_; - private int sec_; - private int usec_; - private int arg_; - - private String tokenName_; - private String clientID_; - - private byte buffer_[]; - - /** - * Character encoding to use for converting the token name and - * client ID to/from bytes. - */ - protected String charEncoding_; -} diff --git a/java/JACE/netsvcs/Token/TokenRequestHandler.java b/java/JACE/netsvcs/Token/TokenRequestHandler.java deleted file mode 100644 index cb6d729f3bd..00000000000 --- a/java/JACE/netsvcs/Token/TokenRequestHandler.java +++ /dev/null @@ -1,180 +0,0 @@ -package JACE.netsvcs.Token; - -import java.io.*; -import java.net.SocketException; -import java.util.*; -import JACE.Connection.*; -import JACE.OS.*; -import JACE.netsvcs.Handler; - -/** - * Created by TokenAcceptor to handle token requests. Delegates to - * the appropriate LockHandler. This is fairly robust, and can handle - * multiple clients and locks (meaning requests can come in to this - * handle with varying client IDs and token names and still be processed - * and released appropriately.) Compatible with the C++ ACE token service. - * - *@author Everett Anderson - */ -class TokenRequestHandler extends Handler -{ - /** - * Default constructor. - */ - public TokenRequestHandler() { - this.clients_ = new Vector (10); - } - - /** - * Creates a new TokenRequest instance. - */ - public Object newRequest () - { - return new TokenRequest (); - } - - /** - * Sends an error message to a client with the TokenReply.EIO - * errno before abandoning the connection. This is used when an IO - * error occured while receiving the request. - * - *@param lastRequest request object to get the arg from - */ - protected void sendAbortMessage (TokenRequest lastRequest) - { - TokenReply reply = new TokenReply (TokenReply.EIO, - lastRequest.arg ()); - try { - reply.streamOutTo (this.peer ().dataOutputStream ()); - } catch (Exception e) { - // Doesn't matter if there is an error here, we've abandoned - // the connection. - } - } - - /** - * Safely shuts down this handler, making sure to release any locks - * that were touched by clients from this TokenRequestHandler. - * - *@return -1 on failure, 0 on success - */ - public synchronized int close () - { - // For every client X that has used this handler - // for every LockHandler that X has used - // release the lock until it fails because X isn't the owner - // remove the client entries - // Call Handler.close () - if (!done ()) { - - TokenAcceptor parent = (TokenAcceptor) parent (); - Enumeration clientEnum = clients_.elements (); - - while (clientEnum.hasMoreElements ()) { - String clientID = (String)clientEnum.nextElement (); - - Enumeration handlers = parent.getClientLockHandlers (clientID); - if (handlers == null) - continue; - - int num = 0; - - while (handlers.hasMoreElements ()) { - LockHandler handler = (LockHandler)handlers.nextElement (); - - handler.abandonLock (clientID); - - num++; - } - - parent.removeClient (clientID); - } - - return super.close (); - } - - return 0; - } - - /** - * Read in the given TokenRequest and delegates to the appropriate - * LockHandler. - * - *@see JACE.netsvcs.Handler - *@param requestObject TokenRequest object to use - */ - public void processRequest (Object requestObject) - throws SocketException, EOFException, IOException - { - TokenRequest request = (TokenRequest)requestObject; - TokenAcceptor parent = (TokenAcceptor) parent (); - - try { - request.streamInFrom (this.peer ().dataInputStream ()); - - if (!request.tokenName ().equals (lastTokenName_)) { - // Switched tokens: - // - // Either find a handler that's already been made (which would - // mean this token has been accessed before), or create a new - // one with a new token - handler_ = parent.getLockHandler(request.tokenName(), - request.tokenType()); - - if (handler_ == null) { - // The client asked for an operation on a type of token - // that we don't know about. - ACE.ERROR ("Unknown lock type: " + request.tokenType ()); - TokenReply error = new TokenReply (TokenReply.EINVAL, - request.arg ()); - error.streamOutTo(this.peer ().dataOutputStream ()); - return; - } - - // Add this LockHandler to the list of those accessed by - // this clientID - parent.addClientLockHandler (request.clientID (), - handler_); - } - - if (!request.clientID ().equals (lastClientID_)) { - // Switched clients - - if (!clients_.contains (request.clientID ())) - clients_.addElement (request.clientID ()); - - parent.addClientLockHandler (request.clientID (), - handler_); - } - - lastClientID_ = request.clientID (); - lastTokenName_ = request.tokenName (); - - TokenReply reply = handler_.handleRequest(this, request); - - reply.streamOutTo(this.peer ().dataOutputStream ()); - - } catch (NullPointerException e) { - sendAbortMessage (request); - throw e; - } catch (IOException e) { - sendAbortMessage (request); - throw e; - } - } - - // List of clientIDs that have been processed by this instance - // of TokenRequestHandler. This is useful when abandoning the - // locks of any clients that have been using this socket. - private Vector clients_; - - // Name of the last token accessed - private String lastTokenName_ = null; - - // Last client ID which accessed a token from this handler - private String lastClientID_ = null; - - // Current LockHandler - private LockHandler handler_ = null; -} - diff --git a/java/JACE/netsvcs/Token/package.html b/java/JACE/netsvcs/Token/package.html deleted file mode 100644 index 80777aecc0a..00000000000 --- a/java/JACE/netsvcs/Token/package.html +++ /dev/null @@ -1,16 +0,0 @@ -<!-- $Id$ --> -<HTML> -<BODY> -Token Service for remote mutexes and reader/writer locks. -<P> -New types of lock can be easily added on the command line to the service -without changing existing code by implementing a LockHandler for the new -type. -<P> -A simple test client is available in the tests directory under -netsvcs\Token. - -@see JACE.netsvcs.Token.LockHandler -@see <a href="http://www.cs.wustl.edu/~schmidt/ACE-netsvcs.html">ACE Network Services</a> -</BODY> -</HTML> diff --git a/java/JACE/netsvcs/package.html b/java/JACE/netsvcs/package.html deleted file mode 100644 index a806080aece..00000000000 --- a/java/JACE/netsvcs/package.html +++ /dev/null @@ -1,11 +0,0 @@ -<!-- $Id$ --> -<HTML> -<BODY> -Bases classes for the network services and two activation strategies. -<P> -Services can be loaded and managed via the Service Configurator. - -@see JACE.ServiceConfigurator -@see <a href="http://www.cs.wustl.edu/~schmidt/ACE-netsvcs.html">ACE Network Services</a> -</BODY> -</HTML> |