diff options
Diffstat (limited to 'java/src')
60 files changed, 0 insertions, 9130 deletions
diff --git a/java/src/ACE.java b/java/src/ACE.java deleted file mode 100644 index 8fa6e1823fa..00000000000 --- a/java/src/ACE.java +++ /dev/null @@ -1,164 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.OS - * - * = FILENAME - * JACE.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.OS; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - * <blockquote>Constants, utility "functions", etc.</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * Defines default constants for ACE. Many of these are used for the - * ACE tests and applications. You may want to change some of these to - * correspond to your environment. Also, routines for error handling, - * debugging and bit manipulation are included. - *</blockquote> - * - * <h2>NOTES</h2> - *<blockquote> - * This class is non-instantiable, and intended only to provide a constrained - * namespace. - *</blockquote> - */ -public abstract class ACE -{ - /** - * Default port on which a server listens for connections. - */ - public static final int DEFAULT_SERVER_PORT = 10002; - - /** - * Default name to use for a thread group. - */ - public static final String DEFAULT_THREAD_GROUP_NAME = "ace_thread_group"; - - /** - * Disable debugging. Once debugging is disabled, all ACE.DEBUG - * statements would be ignored. - */ - public static final void disableDebugging () - { - ACE.debug_ = false; - } - - /** - * Enable debugging. Once debugging is enabled, all ACE.DEBUG - * statements get printed. - */ - public static final void enableDebugging () - { - ACE.debug_ = true; - } - - /** - * Print the string representation of Java Exception. - *@param e Java exception - */ - public static final void ERROR (Exception e) - { - System.err.println (e); - } - - /** - * Print the string being passed in. - *@param s a Java String - */ - public static final void ERROR (String s) - { - System.err.println (s); - } - - /** - * Print the string being passed in. - *@param s A Java String - *@return Error value passed in - */ - public static final int ERROR_RETURN (String s, int errorVal) - { - System.err.println (s); - return errorVal; - } - - /** - * Print the string being passed in. Note the behavior will vary - * depending upon whether debugging is enabled or disabled. - *@param s a Java String - */ - public static final void DEBUG (String s) - { - if (ACE.debug_) - System.out.println (s); - } - - /** - * Flush out any data that may be buffered. - */ - public static final void FLUSH () - { - System.out.flush (); - } - - /** - * Set the bits of WORD using BITS as the mask. - *@param WORD the bits to be set. - *@param BITS the mask to use. - *@return The value obtained after setting the bits. - */ - public static final long SET_BITS (long WORD, long BITS) - { - return WORD | BITS; - } - - /** - * Clear the bits of WORD using BITS as the mask. - *@param WORD the bits to clear. - *@param BITS the mask to use. - *@return The value obtained after clearing the bits. - */ - public static final long CLR_BITS (long WORD, long BITS) - { - return WORD & ~BITS; - } - - /** - * Check if bits are enabled in WORD. - *@param WORD the bits to check. - *@param BIT the bit to check to see if it is enabled or not. - *@return true if bit is enabled, false otherwise. - */ - public static final boolean BIT_ENABLED (long WORD, long BIT) - { - return (WORD & BIT) != 0; - } - - /** - * Check if bits are disabled in WORD. - *@param WORD the bits to check. - *@param BIT the bit to check to see if it is disabled or not. - *@return true if bit is disabled, false otherwise. - */ - public static final boolean BIT_DISABLED (long WORD, long BIT) - { - return (WORD & BIT) == 0; - } - - // Debug flag (turn debugging on/off) - private static boolean debug_ = true; - - // Default private constructor to avoid instantiation - private ACE () - { - } -} - - diff --git a/java/src/AcceptStrategy.java b/java/src/AcceptStrategy.java deleted file mode 100644 index e5af43f07f5..00000000000 --- a/java/src/AcceptStrategy.java +++ /dev/null @@ -1,89 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * AcceptStrategy.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.SOCK_SAP.*; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Interface for specifying a passive connection - * acceptance strategy for a - * <a href="ACE.Connection.SvcHandler.html"><tt>SvcHandler</tt></a> - * . - *</blockquote> - * - * <h2>DESCRIPTION</h2> - * - *<blockquote> - * This class provides a strategy that manages passive - * connection setup for an application, and can be extended - * to define new strategies. - *</blockquote> - * - * @see SvcHandler - * @see Acceptor - */ - -public class AcceptStrategy -{ - /** - * Create an instance of Accept Strategy. - *@param port port number where the server will listen for connections - *@exception IOException couldn't open port - */ - AcceptStrategy (int port) throws IOException - { - this.open (port); - } - - /** - * Initialize AcceptStrategy. - *@param port port number where the server will listen for connections - *@exception IOException couldn't open port - */ - public void open (int port) throws IOException - { - // Create a new SOCK_Acceptor to accept client connections - this.sockAcceptor_ = new SOCKAcceptor (port); - } - - /** - * Accept connections into the SvcHandler. Note that subclasses - * should overwrite this method to provide a different accept - * strategy. - *@param sh Svc Handler in which to accept the connection - *@exception SocketException Socket error - *@exception IOException Socket error - *@return 0 - */ - public int acceptSvcHandler (SvcHandler sh) throws - SocketException, IOException - { - // Create a new stream - SOCKStream sockStream = new SOCKStream (); - - // Block in accept. Returns when a connection shows up - this.sockAcceptor_.accept (sockStream); - - // Set the streams for the new handler - sh.setHandle (sockStream); - return 0; - } - - // Our connection acceptance factory - private SOCKAcceptor sockAcceptor_; - -} diff --git a/java/src/Acceptor.java b/java/src/Acceptor.java deleted file mode 100644 index 562b5a85d07..00000000000 --- a/java/src/Acceptor.java +++ /dev/null @@ -1,216 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * Acceptor.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.OS.*; -import JACE.SOCK_SAP.*; -import JACE.ServiceConfigurator.*; - -/** - * <hr> - * <p><h2>SYNOPSIS</h2> - * - * <blockquote>Abstract factory for creating a service handler - * (<a href="ACE.Connection.SvcHandler.html"><tt>SvcHandler</tt></a>), - * accepting into the - * <a href="ACE.Connection.SvcHandler.html"><tt>SvcHandler</tt></a>, and activating the - * <a href="ACE.Connection.SvcHandler.html"><tt>SvcHandler</tt></a>.</blockquote> - * - * <p><h2>DESCRIPTION</h2> - * - * <blockquote>Implements the basic strategy for passively establishing - * connections with applications. The <tt>Acceptor</tt> - * is a factory for <tt>SvcHandler</tt> instances, and, by default - * generates a new <tt>SvcHandler</tt> instance for each connection - * esablished.</blockquote> - * - * <p> - * - * <blockquote> The user of this class <em>must</em> provide a - * reference to a handler factory prior to calling <a - * href="#accept()"><tt>accept</tt></a>, or an exception will be - * thrown. The handler factory is identified by the meta-class for - * the <tt>SvcHandler</tt>, and is typically obtained by calling <a - * href="java.lang.Class#classForName(java.lang.String)"><tt>Class.classForName("SvcHandler")</tt></a>. - * </blockquote> - * - * <p> - * - * <blockquote> TCP is the transport mechanism used, via - * <a href="ACE.SOCK_SAP.SOCKAcceptor.html#_top_"><tt>SOCKAcceptor</tt></a>, - * <em>et.al.</em> The SvcHandler is instantiated with a concrete type - * that performs the application-specific service. </blockquote> - * - * <h2>NOTES</h2> - * - * <blockquote> This class is not directly related to the - * <tt>AcceptorStrategy</tt> class.</blockquote> - * - * - * @see java.lang.Class - * @see JACE.Connection.SvcHandler - * @see JACE.SOCK_SAP.SOCKAcceptor - */ -public class Acceptor extends ServiceObject -{ - /** - * Create an instance of Acceptor. Default constructor. Note that if - * an instance is created via this method, <tt>setHandlerFactory</tt> - * must be called prior to using <tt>accept</tt>. - * - * @see JACE.Connection.Acceptor.setHandlerFactory - */ - public Acceptor () - { - } - - /** - * Create an instance of Acceptor. - *@param handlerFactory meta-class reference used to create - * an instance of a SvcHandler when a connection is accepted - * (typically obtained by calling <tt>Class.classForName</tt>). - * - *@see java.lang.Class.forName - */ - public Acceptor (Class handlerFactory) - { - this.handlerFactory_ = handlerFactory; - } - - /** - * Set the handler factory. This is provided to aid the default - * no-arg constructor. - *@param handlerFactory meta-class reference used to create - * an instance of a SvcHandler when a connection is accepted - * (typically obtained by calling <tt>Class.forName</tt>). - * - *@see java.lang.Class.forName - */ - public void setHandlerFactory (Class handlerFactory) - { - this.handlerFactory_ = handlerFactory; - } - - /** - * Initialize the Acceptor. - *@param port TCP port number where the Acceptor will listen for connections - *@exception IOException socket level exception - */ - public void open (int port) throws IOException - { - this.sockAcceptor_ = new SOCKAcceptor (port); - } - - /** - * Template method for accepting connections. Delegates operational - * activities to the following bridge methods: - * <ul> - * <li><tt>makeSvcHandler</tt></li> - * <li><tt>acceptSvcHandler</tt></li> - * <li><tt>activateSvcHandler</tt></li> - * </ul> - * - * <p> - * - * The method first obtains a <tt>SvcHandler</tt> via - * <tt>makeSvcHandler</tt>, accepts the connection <q>into</q> the - * handler using <tt>acceptSvcHandler</tt>, and finally turns over - * control to the handler with <tt>activateSvcHandler</tt>. - * - *@exception SocketException socket level error - *@exception InstantiationException <tt>makeSvcHandler</tt> failure - *@exception IllegalAccessException <tt>makeSvcHandler</tt> failure - *@exception IOException socket level error - */ - public void accept () throws SocketException, - InstantiationException, - IllegalAccessException, - IOException - { - - // Create a Svc_Handler using the appropriate Creation_Strategy - SvcHandler sh = this.makeSvcHandler (); - - // Accept a connection into the SvcHandler using the appropriate - // Accept_Strategy - this.acceptSvcHandler (sh); - - // Activate the SvcHandler using the appropriate ActivationStrategy - this.activateSvcHandler (sh); - } - - /** - * Bridge method for creating a <tt>SvcHandler</tt>. The default is to - * create a new <SvcHandler>. However, subclasses can override this - * policy to perform <SvcHandler> creation in any way that they like - * (such as creating subclass instances of <SvcHandler>, using a - * singleton, etc.) - *@return a new instance of the SvcHandler - *@exception InstantiationException could not create new SvcHandler - *@exception IllegalAccessException no SvcHandler factory provided - */ - protected SvcHandler makeSvcHandler () - throws InstantiationException, IllegalAccessException - { - // Create a new handler for the connection - return (SvcHandler) handlerFactory_.newInstance (); - } - - /** - * Bridge method for accepting the new connection into the - * <tt>SvcHandler</tt>. The default behavior delegates the work to - * <tt>SOCKAcceptor.accept</tt>. However, subclasses can override this - * strategy. - *@param sh SvcHandler in which to accept the connection - *@return 0 - *@exception SocketException socket level error - *@exception IOException socket level error - */ - protected int acceptSvcHandler (SvcHandler sh) - throws SocketException, IOException - { - // Create a new stream - SOCKStream sockStream = new SOCKStream (); - - // Block in accept. Returns when a connection shows up - this.sockAcceptor_.accept (sockStream); - - // Set the streams for the new handler - sh.setHandle (sockStream); - return 0; - } - - /** - * Bridge method for activating a <tt>SvcHandler</tt>. The default - * behavior of this method is to activate the <tt>SvcHandler</tt> by - * calling its open() method (which allows the <tt>SvcHandler</tt> to - * define its own concurrency strategy). However, subclasses can - * override this strategy to do more sophisticated concurrency - * activations. - *@param sh SvcHandler to activate - *@return 0 - */ - protected int activateSvcHandler (SvcHandler sh) - { - sh.open (null); - return 0; - } - - // Handler class that should be instantiated when a connection is - // made with a client - private Class handlerFactory_; - - // Our connection acceptance factory - protected SOCKAcceptor sockAcceptor_; -} diff --git a/java/src/ActivateStrategy.java b/java/src/ActivateStrategy.java deleted file mode 100644 index 882203ad552..00000000000 --- a/java/src/ActivateStrategy.java +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * ActivateStrategy.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - - -/** - * <hr> - *<h2>SYNOPSIS</h2> - * Bridge supporting activation strategy used by - * <a href="ACE.Connection.StrategyAcceptor.html#_top_"><tt>StrategyAcceptor</tt></a> - * - *<h2>DESCRIPTION</h2> - * Subclass and overload - * <a href="#activateSvcHandler(ACE.Connection.SvcHandler)"><tt>activateSvcHandler</tt></a> - * in order change the activation strategy. Then, submit this subclass to - * <a href="ACE.Connection.StrategyAcceptor.html#_top_"><tt>StrategyAcceptor</tt></a> - * as the activation strategy. - * - *@see StrategyAcceptor - */ -public class ActivateStrategy -{ - /** - * Activate the Svc Handler. Note that subclasses should overwrite - * this method to provide a different Activate strategy. - *@param sh Svc Handler to activate - *@return zero if success, non-zero for failure - */ - public int activateSvcHandler (SvcHandler sh) - { - sh.open (null); - return 0; - } -} diff --git a/java/src/AddServiceObjectNode.java b/java/src/AddServiceObjectNode.java deleted file mode 100644 index aa99c51ebc3..00000000000 --- a/java/src/AddServiceObjectNode.java +++ /dev/null @@ -1,54 +0,0 @@ -package JACE.ServiceConfigurator; - -import java.io.*; -import JACE.OS.*; - -class AddServiceObjectNode extends ParseNode -{ - - public AddServiceObjectNode () - { - this.locator_ = new String(); - this.params_ = new String(); - } - - /* This should be the class name, fully qualified or in the class path */ - public String locator () - { - return this.locator_; - } - - public String params () - { - return this.params_; - } - - public void params (String params) - { - this.params_ = params; - } - - public boolean suspended () - { - return this.suspended_; - } - - public void init(String name, String locator, boolean suspended) - { - super.name_ = name; - this.locator_ = locator; - this.suspended_ = suspended; - } - - public void apply () - { - ACE.DEBUG("AddServiceObjectNode apply"); - - if (JACE.ServiceConfigurator.ServiceConfig.initialize(this) == -1) - ACE.ERROR("Error adding " + this.name_); - } - - String params_; - String locator_; - boolean suspended_; -}; diff --git a/java/src/Blob.java b/java/src/Blob.java deleted file mode 100644 index 69feef248b3..00000000000 --- a/java/src/Blob.java +++ /dev/null @@ -1,94 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * Blob.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.SOCK_SAP.*; -import JACE.ASX.*; -import JACE.OS.*; - -public class Blob -{ - public int open (String filename, String hostname , int port) - { - this.filename_ = filename; - this.hostname_ = hostname; - this.port_ = port; - return 0; - } - - public MessageBlock read (int length, int offset) - { - // Check if we have a valid length and a valid offset - if (length < 0 || offset < 0) - { - ACE.ERROR ("Blob::read(): Negative length or offset"); - return null; - } - - // Create a Blob Reader - BlobReader blobReader = new BlobReader (length, offset, this.filename_, this.hostname_, this.port_); - - // Receive data - MessageBlock mb = blobReader.receiveData (); - if (blobReader.bytesRead () != length) - return null; - else - return mb; - } - - public int write (MessageBlock mb, int length, int offset) - { - // Check if we have a valid length and a valid offset - if (length < 0 || offset < 0) - ACE.ERROR ("Blob::write(): Negative length or offset"); - - // Create a Blob Writer - BlobWriter blobWriter = new BlobWriter (mb, length, offset, this.filename_); - - try - { - // Connect to the server - this.connector_.open (this.hostname_, this.port_); - this.connector_.connect (blobWriter); - } - catch (UnknownHostException e) - { - ACE.ERROR (e); - } - catch (InstantiationException e) - { - ACE.ERROR (e); - } - catch (IllegalAccessException e) - { - ACE.ERROR (e); - } - catch (IOException e) - { - ACE.ERROR (e); - } - - return blobWriter.bytesWritten (); - } - - public int close () - { - return 0; - } - - String filename_; - String hostname_; - int port_; - Connector connector_ = new Connector (); -} diff --git a/java/src/BlobHandler.java b/java/src/BlobHandler.java deleted file mode 100644 index ec282bdeaa9..00000000000 --- a/java/src/BlobHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * BlobHandler.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.SOCK_SAP.*; -import JACE.ASX.*; -import JACE.OS.*; - -public abstract class BlobHandler extends SvcHandler -{ - public BlobHandler (int length, int offset, String filename) - { - this.length_ = length; - this.offset_ = offset; - this.filename_ = filename; - } - - public abstract int open (Object obj); - - protected int length_ = 0; - protected int offset_ = 0; - protected String filename_ = null; -} - diff --git a/java/src/BlobReader.java b/java/src/BlobReader.java deleted file mode 100644 index 7209f3c721f..00000000000 --- a/java/src/BlobReader.java +++ /dev/null @@ -1,104 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * BlobReader.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.SOCK_SAP.*; -import JACE.ASX.*; -import JACE.OS.*; - -// Reader ************************************************** - -public class BlobReader -{ - public BlobReader (int length, - int offset, - String filename, - String hostname, - int port) - { - this.length_ = length; - this.offset_= offset; - this.filename_ = filename; - this.hostname_ = hostname; - this.port_ = port; - } - - - public MessageBlock receiveData () - { - String hostname = this.hostname_; - String filename = this.filename_; - - // Check if the filename begins with a "/" and if so, remove it - // since we are concatenating a "/" to the hostname. - if (this.filename_.startsWith ("/")) - filename = this.filename_.substring (1); - - hostname = hostname + ":" + this.port_ + "/"; - // System.out.println (hostname + filename); - - // Allocate a buffer to hold the offset worth of data - byte tempBuf [] = new byte [this.offset_]; - // Allocate a buffer to hold the actual data - byte dataBuf [] = new byte [this.length_]; - - try - { - // Create a URL to fetch the file - URL url = new URL (this.protocol_ + hostname + filename); - - // Get the input stream and pipe it to a DataInputStream - DataInputStream iStream = new DataInputStream (url.openStream ()); - - // Read the offset worth of bytes - iStream.readFully (tempBuf, 0, this.offset_); - - // Read length worth of bytes - iStream.readFully (dataBuf, 0, this.length_); - } - catch (MalformedURLException e) - { - ACE.ERROR (e); - } - catch (IOException e) - { - ACE.ERROR (e); - } - // Cache number of bytes read - this.bytesRead_ = this.length_; - return new MessageBlock (new String (dataBuf, 0, this.length_)); - } - - public int close (long flags) - { - return 0; - } - - public int bytesRead () - { - return this.bytesRead_; - } - - private String protocol_ = "http://"; - - int length_ = 0; - int offset_= 0; - String filename_ = null; - String hostname_ = "localhost"; - int port_ = 80; - - int bytesRead_ = 0; -} - - diff --git a/java/src/BlobWriter.java b/java/src/BlobWriter.java deleted file mode 100644 index 09cc88a1f9e..00000000000 --- a/java/src/BlobWriter.java +++ /dev/null @@ -1,220 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * BlobWriter.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.SOCK_SAP.*; -import JACE.ASX.*; -import JACE.OS.*; - -// Writer ************************************************** - -public class BlobWriter extends BlobHandler -{ - public BlobWriter (MessageBlock mb, - int length, - int offset, - String filename) - { - super (length, offset, filename); - this.mb_ = mb; - this.returnCode_ = -1; - - } - - /******************************* - * This constructor should be used when using the basic HTTP 1.1 - * authentication scheme - *******************************/ - public BlobWriter (MessageBlock mb, - int length, - int offset, - String filename, - String authentication) - { - super (length, offset, filename); - this.mb_ = mb; - this.returnCode_ = -1; - this.authentication_ = authentication; - } - - - public int open (Object obj) - { - if (this.sendRequest () != 0) - { - ACE.ERROR ("BlobWriter::open():sendRequest failed"); - return -1; - } - else if (this.receiveReply () != 0) - { - ACE.ERROR ("BlobWriter::open():receiveReply failed"); - return -1; - } - return 0; - } - - public int close (long flags) - { - return 0; - } - - public int bytesWritten () - { - return this.bytesWritten_;; - } - - protected int sendRequest () - { - // Check for sanity -- check if we have any data to send. - if (this.offset_+ this.length_ > this.mb_.length ()) - { - ACE.ERROR ("BlobWriter::sendRequest():Invalid offset/length"); - return -1; - } - - if (this.sendHeader () == -1) - { - ACE.ERROR ("BlobWriter::sendHeader failed."); - return -1; - } - else - if (this.sendData () == -1) - { - ACE.ERROR ("BlobWriter::sendData failed."); - return -1; - } - return 0; - } - - // Send the header - protected int sendHeader () - { - String filename = this.filename_; - // Check if the filename begins with a "/" and if it doesn't, add it - if (!this.filename_.startsWith ("/")) - filename = "/" + this.filename_; - - // Create the header, store the actual length in mesglen - String mesg = this.requestPrefix_ + " " + filename + " " + this.requestSuffix_; - - if (this.authentication_ != null) - mesg += "Authorization: Basic " + JACE.Connection.HTTPHelper.EncodeBase64(this.authentication_) + '\n'; - - mesg += "Content-length: " + this.length_ + "\n"; - - try - { - if (this.peer ().send (mesg) < 0) - { - ACE.ERROR ("Error sending request"); - return -1; - } - } - catch (IOException e) - { - ACE.ERROR (e); - return -1; - } - return 0; - } - - // Send the data - protected int sendData () - { - // Get the actual data to send - String data = this.mb_.base ().substring (this.offset_, - this.offset_ + this.length_); - - - try - { - // System.out.println (data); - // Now send the data - if (this.peer ().send (data) != this.length_) - { - ACE.ERROR ("Error sending file"); - return -1; - } - } - catch (IOException e) - { - ACE.ERROR (e); - return -1; - } - this.bytesWritten_ = this.length_; - return 0; - } - - - protected int receiveReply () - { - System.out.println("Waiting for reply"); - - // Receive the reply from the server - StringBuffer reply = new StringBuffer (1024); - - try - { - if (this.peer ().recv (reply) < 0) - { - ACE.ERROR ("Error receiving reply from server"); - return -1; - } - } - catch (IOException e) - { - ACE.ERROR (e); - } - - String s = reply.toString (); - - int index = -1; - // Now parse the reply to see if it was a success or a failure - if ((index = s.indexOf (replyPrefix_)) == -1) - { - ACE.ERROR ("Error receiving reply from server"); - return -1; - } - - int codeIndex = index + replyPrefix_.length () + 1; - - // Assume code is a 3 digit number - String codeString = s.substring (codeIndex, codeIndex + 3); - - returnCode_ = (new Integer (codeString)).intValue (); - // System.out.println (code); - - if (returnCode_ >= 200 && returnCode_ < 300) { // Check if everything went smoothly - System.out.println("We got the goodies!"); - return 0; - } else - return -1; - } - - public int returnCode () - { - return this.returnCode_; - } - - protected String authentication_ = null; - protected String protocol_ = "http://"; - protected int bytesWritten_ = 0; - protected MessageBlock mb_ = null; - protected String requestPrefix_ = "PUT"; - protected String requestSuffix_ = "HTTP/1.0\n"; - protected String replyPrefix_ = "HTTP/1.0"; - protected int returnCode_; -} - - diff --git a/java/src/ClassNameGenerator.java b/java/src/ClassNameGenerator.java deleted file mode 100644 index 0be175c5275..00000000000 --- a/java/src/ClassNameGenerator.java +++ /dev/null @@ -1,181 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ClassNameGenerator.java - * - * Given a locator string which may specify a class name, this generates as many possible locations for that - * class file as possible. This is needed when trying to infer a class name from a C++ DLL line in the - * svc.conf file. Implements the Enumeration interface. A variety of questionable tactics are - * used. - * - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import java.util.*; -import JACE.OS.*; - -public class ClassNameGenerator implements Enumeration -{ - /** - * Constructor - * @param locator Locator string -- approximate class name - */ - public ClassNameGenerator (String locator) - { - this.locator_ = locator; - this.current_ = 0; - this.suggestions_ = new Vector(); - - this.makeSuggestions(); - } - - /** - * More unseen possibilities? - */ - public boolean hasMoreElements() - { - return this.current_ < this.suggestions_.size(); - } - - /** - * Get the next string - */ - public Object nextElement() - { - return this.suggestions_.elementAt(this.current_++); - } - - /** - * Take away things underscores, adjust capitalization. This - * makes a name more like a Java class name - */ - String makeJavaName(String oldName) - { - StringTokenizer tok = new StringTokenizer(oldName, "_"); - String result = new String(); - - while (tok.hasMoreTokens()) { - String token = tok.nextToken(); - - if (token.length() > 0) { - - result += (Character.toUpperCase(token.charAt(0)) + token.substring(1)); - } - } - - return result; - } - - - /** - * Generate the suggestions - */ - void makeSuggestions() - { - String slash = new String(System.getProperty("file.separator")); - - // Discard things like .shobj - if ((this.locator_.charAt(0) == '.') && (this.locator_.charAt(1) != '.')) { - int firstslash = this.locator_.indexOf(slash); - if (firstslash > 0) - this.locator_ = this.locator_.substring(firstslash + 1); - } - - // Find the last directory separator and the colon (inbetween - // these two is the last directory name, and by our convention - // this should be the class name) - int lastSlash = this.locator_.lastIndexOf(slash); - int colon = this.locator_.lastIndexOf(":"); - - ACE.DEBUG("Working with " + this.locator_ + " " + - lastSlash + " " + colon); - - // Best bet first: - // Locator string is a path, and the last directory name is the class - // name - String lastDir = new String(this.locator_.substring(lastSlash + 1, - colon)); - - // Save any other path info for later tries - String path = null; - if (lastSlash >= 0) - path = this.locator_.substring(0, lastSlash + 1); - - int tryNum = 0; - - if (lastDir.length() > 0) { - - // Add this try - this.suggestions_.addElement(lastDir); - - if (path != null) - this.suggestions_.addElement(path + lastDir); - - // Second try: - // Same as the first, but changed to the Java convention for class names: - // Begins with a capital letter, capital letters for new words rather - // than underscores. - - String try2 = this.makeJavaName(lastDir); - - this.suggestions_.addElement(try2); - if (path != null) - this.suggestions_.addElement(path + try2); - } - - // Third try: - // After the colon, the name of the method that created instances of the - // class in C++ may contain the class name. Maybe in the format of - // make_classname, etc. - - String lastWord = new String(this.locator_.substring(colon + 1)); - - if (lastWord.length() > 0) { - - // Try the word after the colon, too - this.suggestions_.addElement(lastWord); - if (path != null) - this.suggestions_.addElement(path + lastWord); - - String try2 = this.makeJavaName(lastWord); - - this.suggestions_.addElement(try2); - if (path != null) - this.suggestions_.addElement(path + try2); - - int make = lastWord.indexOf("make"); - if (make >= 0) { - - make += 4; - String makeTry = new String(lastWord.substring(make)); - - if (makeTry.length() > 0) { - - this.suggestions_.addElement(makeTry); - if (path != null) - this.suggestions_.addElement(path + makeTry); - - String try3 = this.makeJavaName(makeTry); - - this.suggestions_.addElement(try3); - if (path != null) - this.suggestions_.addElement(path + try3); - } - } - } - - } - - String locator_; - Vector suggestions_; - - int current_; -}; - - diff --git a/java/src/ClassReader.java b/java/src/ClassReader.java deleted file mode 100644 index c10c00b061c..00000000000 --- a/java/src/ClassReader.java +++ /dev/null @@ -1,146 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ClassReader.java - * - *@author Everett Anderson - * - *@see JACE.ServiceConfigurator - *@see JACE.ServiceConfigurator.ServiceLoader - * - *************************************************/ -package JACE.ServiceConfigurator; - -import JACE.OS.*; -import java.io.*; -import java.util.*; - -/** - * <hr> - * <p><b>TITLE</b><br> - * Given a classfile name, this determines the qualified class name - * of what's inside (pacakage and class name together). It is necessary - * when users want to dynamically load classes, but don't provide the - * full name in svc.conf. - */ - -public class ClassReader -{ - // Types found in classfiles - public static final byte CONSTANT_Class = 7; - public static final byte CONSTANT_Fieldref = 9; - public static final byte CONSTANT_Methodref = 10; - public static final byte CONSTANT_InterfaceMethodref = 11; - public static final byte CONSTANT_String = 8; - public static final byte CONSTANT_Integer = 3; - public static final byte CONSTANT_Float = 4; - public static final byte CONSTANT_Long = 5; - public static final byte CONSTANT_Double = 6; - public static final byte CONSTANT_NameAndType = 12; - public static final byte CONSTANT_Utf8 = 1; - - /** Returns a string that is the qualified class name of the - * given file. It returns null if there are any problems. - * - *@param fileName File to examine - * - *@return String that's the qualified class name of the - * given file (null on error) - */ - public static String getClassName(String fileName) - { - try { - - // Open the .class file - FileInputStream fis = new FileInputStream(fileName); - - DataInputStream dis = new DataInputStream(fis); - - // Skip magic number and version numbers - dis.skipBytes(8); - - // Find out how many entries are in the constant pool table - int count = dis.readUnsignedShort(); - - // Hash table to hold the text entries (possibilities for - // the class name) - Hashtable ht = new Hashtable(); - - // Vector that holds the index of the class name for each - // class record (the vector is indexed by placement in the - // table) - Vector vt = new Vector(count); - Integer noValue = new Integer(-1); - int type; - - // Scan through all the entries - for (int i = 1; i < count; i++) { - - // Read what type of entry this is - type = dis.readUnsignedByte(); - - switch (type) { - - case CONSTANT_Class: - // Save the index of the class name - vt.addElement(new Integer(dis.readUnsignedShort())); - break; - case CONSTANT_Fieldref: - case CONSTANT_Methodref: - case CONSTANT_InterfaceMethodref: - case CONSTANT_Integer: - case CONSTANT_Float: - case CONSTANT_NameAndType: - // Skip the data - vt.addElement(noValue); - dis.skipBytes(4); - break; - case CONSTANT_String: - // Skip the data - vt.addElement(noValue); - dis.skipBytes(2); - break; - case CONSTANT_Long: - case CONSTANT_Double: - // Skip the data - vt.addElement(noValue); - dis.skipBytes(8); - // These take up two spots in the table - i++; - break; - case CONSTANT_Utf8: - vt.addElement(noValue); - // Save the text in the hash table - ht.put(new Integer(i), new String(dis.readUTF())); - break; - default: - ACE.DEBUG("Unknown type: " + type); - break; - - } - - } - - // Skip the access flags - dis.skipBytes(2); - - // Get index in table of this class - int classIdx = dis.readUnsignedShort(); - - // Get index in the table of the name of this class - Integer idx = (Integer)vt.elementAt(classIdx - 1); - - // Put the result in period separated notation - String result = new String(((String)ht.get(idx)).replace('/', '.')); - - return result; - - } catch (IOException e) { - ACE.ERROR("" + e); - return null; - } - } -} diff --git a/java/src/Condition.java b/java/src/Condition.java deleted file mode 100644 index 59a97c9a1a7..00000000000 --- a/java/src/Condition.java +++ /dev/null @@ -1,124 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * Condition.java - * - *@author Irfan Pyarali - * - *************************************************/ -package JACE.Concurrency; - -import JACE.ASX.TimeoutException; -import JACE.ASX.TimeValue; - -/** - * <hr> - * <h2>TITLE</h2> - *<blockquote> - * Abstraction for <em>traditional</em> - * condition variable - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * This condition variable allows the use of one - * mutex between multiple conditions. - * This implementation is based on the C++ version of ACE. - *</blockquote> - */ -public class Condition -{ - /** - * Default constructor - *@param Mutex for synchronization - */ - public Condition (Mutex mutex) - { - mutex_ = mutex; - } - - /** - * Wait for condition to become signaled. - *@exception InterruptedException exception during wait - */ - public void Wait () - throws InterruptedException - { - waiters_++; - - try - { - mutex_.release(); - semaphore_.acquire (); - mutex_.acquire (); - } - finally - { - waiters_--; - } - } - - /** - * TimedWait for condition to become signaled. - *@exception TimeoutException wait timed out exception - *@exception InterruptedException exception during wait - */ - public void Wait (TimeValue tv) - throws TimeoutException, InterruptedException - { - waiters_++; - - try - { - mutex_.release(); - - TimeValue start = TimeValue.getTimeOfDay (); - - semaphore_.acquire (tv); - - TimeValue now = TimeValue.getTimeOfDay (); - tv.minusEquals (TimeValue.minus (now, start)); - - mutex_.acquire (tv); - } - finally - { - waiters_--; - } - } - - /** - * Signal condition. Wake one waiter (if any). - */ - public void signal () - { - if (waiters_ > 0) - semaphore_.release (); - } - - /** - * Signal condition. Wake up all waiters (if any). - */ - public void broadcast () - { - for (int i = waiters_; i > 0; i--) - semaphore_.release (); - } - - /** - * Accessor to lock - *@return Mutex - */ - public Mutex mutex () - { - return mutex_; - } - - private int waiters_; - private Semaphore semaphore_ = new Semaphore (0); - private Mutex mutex_; - -} diff --git a/java/src/Connector.java b/java/src/Connector.java deleted file mode 100644 index 7393ea486e0..00000000000 --- a/java/src/Connector.java +++ /dev/null @@ -1,157 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * Connector.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.OS.*; -import JACE.SOCK_SAP.*; -import JACE.ServiceConfigurator.*; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Abstract factory for connecting a - * (<a href="JACE.Connection.SvcHandler.html"><tt>SvcHandler</tt></a>), - * to an application. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * Implements the basic strategy for actively establishing connections - * with applications. The <tt>Connector</tt> establishes the connection, - * passing it on to a <tt>SvcHandler</tt> instance, and handing over - * control to that instance. - *<p> - * TCP is the transport mechanism used, via - * <a href="JACE.SOCK_SAP.SOCKConnector.html#_top_"><tt>SOCKConnector</tt></a>. - *</blockquote> - * - *<h2>NOTES</h2> - *<blockquote> - * This class, as currently implemented, does not work like its C++ counterpart. - * Future versions are expected to rectify this discrepancy. - *</blockquote> - * - *@see SOCKConnector - *@see SvcHandler - */ -public class Connector extends ServiceObject -{ - /** - * Create a Connector. Do nothing constructor. Allows user to - * call <a href="#open(java.lang.String)">open</a>() later. - */ - public Connector () - { - } - - /** - * Create a Connector passing in server hostname and port - * number, effectively shorthand for calling - * <a href="#open(java.lang.String)">open</a>(). - *@param hostname server hostname - *@param port server port number - */ - public Connector (String hostname, int port) - { - this.open (hostname, port); - } - - /** - * Initialize the Connector passing in server hostname and port - * number. Note that no connection attempt is made. - *@param hostname server hostname - *@param port server port number - */ - public void open (String hostname, int port) - { - this.hostname_ = hostname; - this.port_ = port; - } - - /** - * Connect to the server. - *@param sh Svc Handler to use to handle the connection - *@exception UnknownHostException Bad host - *@exception SocketException Socket error - *@exception InstantiationException Couldn't create new SOCKConnector - *@exception IllegalAccessException No strategy available - *@exception IOException Socket error - */ - public void connect (SvcHandler sh) throws UnknownHostException, - SocketException, - InstantiationException, - IllegalAccessException, - IOException - { - // Make a connection using the appropriate Connection_Strategy - this.connectSvcHandler (sh); - - // Activate the Svc_Handler using the appropriate Activation_Strategy - this.activateSvcHandler (sh); - } - - /** - * Bridge method for making a new connection. The default behavior - * creates a new SOCKConnector and then calls setHandle() on the - * <SvcHandler> that was passed in. Subclasses can override this - * strategy, if needed. - *@param sh Svc Handler to use to handle the connection - *@return 0 - *@exception SocketException Socket error - *@exception IOException Socket error - */ - protected int connectSvcHandler (SvcHandler sh) throws - SocketException, IOException - { - // Create a new stream - SOCKStream sockStream = new SOCKStream (); - - // Create a SOCK_Connector (note the constructor does the connect for us) - this.sockConnector_ = new SOCKConnector (sockStream, - this.hostname_, - this.port_); - ACE.DEBUG ("Connected to " + - sockStream.socket ().getInetAddress ()); - - // Set the streams for the new handler - sh.setHandle (sockStream); - return 0; - } - - /** - * Bridge method for activating a <SvcHandler>. The default - * behavior of this method is to activate the <SvcHandler> by - * calling its open() method (which allows the SVC_HANDLER to define - * its own concurrency strategy). However, subclasses can override - * this strategy to do more sophisticated concurrency activations. - *@param sh Svc Handler to activate - *@return 0 - */ - protected int activateSvcHandler (SvcHandler sh) - { - sh.open (null); - return 0; - } - - - // Port server is listening on - private int port_; - - // Server hostname - private String hostname_; - - // Our connection factory - private SOCKConnector sockConnector_; -} diff --git a/java/src/CreationStrategy.java b/java/src/CreationStrategy.java deleted file mode 100644 index f929ef86204..00000000000 --- a/java/src/CreationStrategy.java +++ /dev/null @@ -1,64 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * CreationStrategy.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Defines the interface for specifying a creation strategy for a - * <a href="ACE.Connection.SvcHandler.html#_top_"><tt>SvcHandler</tt></a> to the - * <a href="ACE.Connection.StrategyAcceptor.html#_top_"><tt>StrategyAcceptor</tt></a>. - *</blockquote> - * - * <p><b>DESCRIPTION</b><br> - *<blockquote> - * The default behavior is to make a new SvcHandler. However, - * subclasses can override this strategy to perform SvcHandler - * creation in any way that they like (such as creating subclass - * instances of SvcHandler, using a singleton, dynamically - * linking the handler, etc.). - *</blockquote> - * - *@see SvcHandler - *@see StrategyAcceptor - *@see AcceptStrategy - *@see ActivateStrategy - */ -public class CreationStrategy -{ - /** - * Create an instance of Creation Strategy. - *@param handlerFactory Svc Handler factory that is used to create - * an instance of a Svc Handler - */ - public CreationStrategy (Class handlerFactory) - { - this.handlerFactory_ = handlerFactory; - } - - /** - * Create a new SvcHandler. Note that subclasses should override - * this method to provide a new creation strategy. - *@return reference to a new instance of the SvcHandler (or subclass) - *@exception InstantiationException Unable to instantiate. - *@exception IllegalAccessException No handler factory available. - */ - public SvcHandler makeSvcHandler () throws InstantiationException, - IllegalAccessException - { - // Create a new Svc_Handler - return (SvcHandler) handlerFactory_.newInstance (); - } - - private Class handlerFactory_; -} diff --git a/java/src/EventHandler.java b/java/src/EventHandler.java deleted file mode 100644 index 25057a459c8..00000000000 --- a/java/src/EventHandler.java +++ /dev/null @@ -1,53 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Reactor - * - * = FILENAME - * EventHandler.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Reactor; - -import JACE.ASX.TimeValue; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Provides an abstract interface for handling timer events. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * Classes implementing this interface handle a timer's - * expiration. - *</blockquote> - * - * <h2>NOTES</h2> - *<blockquote> - * Users of C++ ACE will notice that this defines a substantially - * smaller interface than the C++ counterpart. Signal events are - * absent due to the complete absence of this feature from Java itself. - * Moreover, at this point - * there is still some question regarding whether or not the I/O - * portion will make any sense or fit into the Java model for I/O. - *</blockquote> - * - *@see TimerQueue - *@see Reactor - */ -public interface EventHandler -{ - /** - * Called when timer expires. - *@param tv Time Value for which timer was set - *@param obj An arbitrary object that was passed to the Timer Queue - * (Asynchronous Completion Token) - */ - public int handleTimeout (TimeValue tv, Object obj); -} - -// Note that more methods will be added as needed diff --git a/java/src/GetOpt.java b/java/src/GetOpt.java deleted file mode 100644 index 2bf5d27c406..00000000000 --- a/java/src/GetOpt.java +++ /dev/null @@ -1,150 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Misc - * - * = FILENAME - * GetOpt.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Misc; - -import java.io.*; -import java.util.Hashtable; -import java.util.StringTokenizer; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Iterator for parsing command-line arguments. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * This version of `get_opt' appears to the caller like standard - * Unix `get_opt' but it behaves differently for the user, since - * it allows the user to intersperse the options with the other - * arguments. - * - * <p> As `get_opt' works, it permutes the elements of `argv' so that, - * when it is done, all the options precede everything else. Thus - * all application programs are extended to handle flexible argument - * order. - *</blockquote> - * - */ -public class GetOpt -{ - /** - * Constructor - *@param args command line arguments - *@param optstring string containing the legitimate option - * characters. A colon in optstring means that the previous character - * is an option that wants an argument which is then taken from the - * rest of the current args-element. Here is an example of what - * optstring might look like: "c:dP:p". - */ - public GetOpt (String[] args, String optstring) - { - // Cache the arguments - this.args_ = args; - this.hasArg_ = false; - - // Build the arg hashtable - this.buildArgTable (optstring); - } - - /** - * Scan elements specified in optstring for next option flag. - *@return The character corresponding to the next flag. - */ - public int next () - { - if (this.args_ == null) - return -1; - - if (this.index_ < this.args_.length) - { - String arg = this.args_[this.index_++]; - - // Make sure flag starts with "-" - if (!arg.startsWith ("-")) - return -1; - - // Check if there is more than one character specified as flag - if (arg.length () > 2) - return -1; - - // So far so good - // Check if the flag is in the arg_table and if it is get the - // associated binding. - Character c = (Character) this.argTable_.get (new Character (arg.charAt (1))); - if (c == null) - return -1; - - if (c.charValue () == '#') - { - this.hasArg_ = false; - return arg.charAt (1); - } - else if (c.charValue () == ':') - { - this.hasArg_ = true; - return arg.charAt (1); - } - else // This should not happen - return -1; - } - return -1; - } - - /** - * Get the argument (if any) associated with the flag. - *@return the argument associated with the flag. - */ - public String optarg () - { - if (this.hasArg_) - return this.args_[this.index_++]; - else - return null; - } - - // Build the argument table - private void buildArgTable (String s) - { - this.argTable_ = new Hashtable (); - StringTokenizer tokens = new StringTokenizer (s, ":"); - while (tokens.hasMoreTokens ()) - { - // Get the next token - String t = tokens.nextToken (); - - // First add all flags except the one with ":" after it - // Note "#" is an arbitrary character we use to distinguish - // the two cases - for (int i = 0; i < t.length () - 1; i++) - this.argTable_.put (new Character (t.charAt (i)), - new Character ('#')); - - // Now Add the flag just before ":" to the arg_table - this.argTable_.put (new Character (t.charAt (t.length () - 1)), - new Character (':')); - } - } - - private String [] args_; - // Copy of the args passed in - - private boolean hasArg_; - // Indicator that the flag has an argument following it - - private int index_; - // Index into the array of arguments - - private Hashtable argTable_; - // Table of flags that take arguments after them -} diff --git a/java/src/HTTPHelper.java b/java/src/HTTPHelper.java deleted file mode 100644 index d946913693c..00000000000 --- a/java/src/HTTPHelper.java +++ /dev/null @@ -1,84 +0,0 @@ -package JACE.Connection; - -import JACE.OS.*; -// Collection of various methods that have to do with HTTP - -public class HTTPHelper -{ - // Encoding and decoding yadda - public static String Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - // Basic encoding used in the HTTP 1.1 RFC. This doesn't - // put the string "Basic " at the beginning of the return - // string. Adapted from James' JAWS HTTP_Helpers code. - // Returns null on error. - public static String EncodeBase64 (String secret) - { - StringBuffer output = new StringBuffer(); - - // Index of the input string - int inidx = 0; - - // character value - int c; - - int char_count = 0; - int bits = 0; - boolean error = false; - - while (inidx < secret.length()) - { - c = secret.charAt(inidx++); - - // This will mess up internationalization. I wonder if it is really - // necessary for HTTP? - if (c > 255) - { - ACE.DEBUG ("encountered char > 255 (decimal %d): " + c); - error = true; - break; - } - - bits += c; - char_count++; - - if (char_count == 3) - { - output.append(HTTPHelper.Alphabet.charAt(bits >> 18)); - output.append(HTTPHelper.Alphabet.charAt((bits >> 12) & 0x3f)); - output.append(HTTPHelper.Alphabet.charAt((bits >> 6) & 0x3f)); - output.append(HTTPHelper.Alphabet.charAt(bits & 0x3f)); - - bits = 0; - char_count = 0; - } - else - bits <<= 8; - } - - if (!error) - { - if (char_count != 0) - { - bits <<= 16 - (8 * char_count); - output.append(HTTPHelper.Alphabet.charAt(bits >> 18)); - output.append(HTTPHelper.Alphabet.charAt((bits >> 12) & 0x3f)); - - if (char_count == 1) - { - output.append("=="); - } - else - { - output.append(HTTPHelper.Alphabet.charAt((bits >> 6) & 0x3f)); - output.append('='); - } - } - - return output.toString(); - } - - // Returns null on error - return null; - } -}; diff --git a/java/src/INETAddr.java b/java/src/INETAddr.java deleted file mode 100644 index 8d16c46c6b3..00000000000 --- a/java/src/INETAddr.java +++ /dev/null @@ -1,99 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.SOCK_SAP - * - * = FILENAME - * INETAddr.java - * - *@author Chris Cleeland - * - *************************************************/ -package JACE.SOCK_SAP; - -import java.io.*; -import java.net.*; -import JACE.OS.*; - -/** - * <hr> - * <p><b>TITLE</b><br> - * Defines an endpoint of a connection, encapsulating host and port. - * This is only a part-way implementation of C++ ACE's ACE_INET_Addr. - * - * <p><b>LIMITATIONS</b><br> - * Currently the class is very limited in its capabilities; it will - * be expanded in future revisions of ACE. - */ -public class INETAddr // extends Addr -{ - private InetAddress addr_; - private int port_ = 0; - /** - */ - public INETAddr () - { - // Do nothing constructor - } - - /** - * Create an INETAddr from a port/hostname - *@param port port number to connect with server at - *@param hostname hostname of the server - */ - public INETAddr (int port, String hostname) throws UnknownHostException - { - super(); - port_ = port; - addr_ = InetAddress.getByName(hostname); - // Should really use getAllByName(), - // but I don't think we do that in - // C++ ACE, even. - } - - /** - * Create an INETAddr from an address. - * @param address an address in the form "ip-number:port-number", <em>e.g.</em> <pre>tango.cs.wustl.edu:1234</pre> or <pre>128.252.166.57:1234</pre>; if no ':' is present address is assumed to be <b>INADDR_ANY</b> and address contains only the port number - * @throws UnknownHostException - */ - public INETAddr (String address) throws UnknownHostException - { - int colon = address.indexOf(':'); - if (colon != 0) - { - addr_ = InetAddress.getByName(address.substring(0, colon)); - address = address.substring(colon+1); - } - - port_ = Integer.parseInt(address); - } - - /** - * Return the name of the host. - */ - public String getHostName() - { - return addr_.getHostName(); - } - - /** - * Return the dotted Internet address. - */ - public String getHostAddr() - { - return addr_.toString(); - } - - /** - * Return the port number. - */ - public int getPortNumber() - { - return port_; - } - - public String toString() - { - return getHostAddr() + Integer.toString(port_); - } -} diff --git a/java/src/IOCntlCmds.java b/java/src/IOCntlCmds.java deleted file mode 100644 index 2469428a3a6..00000000000 --- a/java/src/IOCntlCmds.java +++ /dev/null @@ -1,34 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * TaskFlags.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -public abstract class IOCntlCmds -{ - /** Set the low water mark. */ - public static final int SET_LWM = 1; - - /** Get the low water mark. */ - public static final int GET_LWM = 2; - - /** Set the high water mark. */ - public static final int SET_HWM = 3; - - /** Get the high water mark. */ - public static final int GET_HWM = 4; - - /** Link modules */ - public static final int MOD_LINK = 5; - - /** Unlink modules */ - public static final int MOD_UNLINK = 6; - -} diff --git a/java/src/IOCntlMsg.java b/java/src/IOCntlMsg.java deleted file mode 100644 index 8b69310c4f7..00000000000 --- a/java/src/IOCntlMsg.java +++ /dev/null @@ -1,128 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * IOCntlMsg.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Data format for IOCTL messages - *</blockquote> - */ -public class IOCntlMsg -{ - - // = Initialization method. - - /* - * Initialize the control message. - *@param c IOCntlCmd for the control message. Note that this should - * be of type IOCntlCmds - */ - public IOCntlMsg (int c) - { - this.cmd_ = c; - } - - // = Get/set methods - - /* - * Get the command. - *@return the command. - */ - public int cmd () - { - return this.cmd_; - } - - /* - * Set the command. - *@param c the command. - */ - public void cmd (int c) - { - this.cmd_ = c; - } - - /* - * Get the count. - *@return the count. - */ - public int count () - { - return this.count_; - } - - /* - * Set the count. - *@param c the count. - */ - public void count (int c) - { - this.count_ = c; - } - - /* - * Get the error. - *@return the error. - */ - public int error () - { - return this.error_; - } - - /* - * Set the error. - *@param e the error. - */ - public void error (int e) - { - this.error_ = e; - } - - /* - * Get the return value. - *@return the return value. - */ - public int rval () - { - return this.rval_; - } - - /* - * Set the return value. - *@param r the return value. - */ - public void rval (int r) - { - this.rval_ = r; - } - - public String toString () - { - return (new Integer (this.cmd_)).toString (); - } - - private int cmd_; - // Command. - - private int count_; - // Count. - - private int error_; - // Error. - - private int rval_; - // Return value -} diff --git a/java/src/JACE.DSP b/java/src/JACE.DSP deleted file mode 100644 index 8c564995235..00000000000 --- a/java/src/JACE.DSP +++ /dev/null @@ -1,292 +0,0 @@ -# Microsoft Developer Studio Project File - Name="JACE" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 5.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Java Virtual Machine Java Project" 0x0809
-
-CFG=JACE - Java Virtual Machine Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "JACE.MAK".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "JACE.MAK" CFG="JACE - Java Virtual Machine Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "JACE - Java Virtual Machine Release" (based on\
- "Java Virtual Machine Java Project")
-!MESSAGE "JACE - Java Virtual Machine Debug" (based on\
- "Java Virtual Machine Java Project")
-!MESSAGE
-
-# Begin Project
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-JAVA=jvc.exe
-
-!IF "$(CFG)" == "JACE - Java Virtual Machine Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir ""
-# PROP BASE Intermediate_Dir ""
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\classes-r\"
-# PROP Intermediate_Dir ""
-# PROP Target_Dir ""
-# ADD BASE JAVA /O
-# ADD JAVA /O
-
-!ELSEIF "$(CFG)" == "JACE - Java Virtual Machine Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir ""
-# PROP BASE Intermediate_Dir ""
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\classes\"
-# PROP Intermediate_Dir ""
-# PROP Target_Dir ""
-# ADD BASE JAVA /g
-# ADD JAVA /g
-
-!ENDIF
-
-# Begin Target
-
-# Name "JACE - Java Virtual Machine Release"
-# Name "JACE - Java Virtual Machine Debug"
-# Begin Source File
-
-SOURCE=.\Acceptor.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\AcceptStrategy.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ACE.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ActivateStrategy.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\AddServiceObjectNode.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\Blob.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\BlobHandler.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\BlobReader.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\BlobWriter.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ClassNameGenerator.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ClassReader.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\Condition.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\Connector.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\CreationStrategy.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\EventHandler.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\GetOpt.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\HTTPHelper.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\INETAddr.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\IOCntlCmds.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\IOCntlMsg.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\MessageBlock.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\MessageQueue.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\MessageType.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\Module.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\Mutex.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\OS.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ParseNode.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ProfileTimer.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\RemoveNode.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ResumeNode.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\RWMutex.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\Semaphore.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ServiceConfig.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ServiceLoader.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ServiceObject.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ServiceObjectRecord.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ServiceRecord.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ServiceRepository.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\SOCKAcceptor.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\SOCKConnector.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\SOCKStream.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\StrategyAcceptor.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\Stream.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\StreamHead.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\StreamTail.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\SuspendNode.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\SvcHandler.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\Task.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\TaskFlags.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ThreadManager.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\ThruTask.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\TimedWait.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\TimeoutException.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\TimerQueue.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\TimeValue.java
-# End Source File
-# Begin Source File
-
-SOURCE=.\Token.java
-# End Source File
-# End Target
-# End Project
diff --git a/java/src/JACE.DSW b/java/src/JACE.DSW deleted file mode 100644 index 1adb106b259..00000000000 --- a/java/src/JACE.DSW +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 5.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "JACE"=.\JACE.DSP - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/java/src/Makefile b/java/src/Makefile deleted file mode 100644 index ebdf2329861..00000000000 --- a/java/src/Makefile +++ /dev/null @@ -1,153 +0,0 @@ -# Makefile -# $Id$ - -.SUFFIXES: .java .class - -JACE_WRAPPER = .. -CLASSDIR = $(JACE_WRAPPER)/classes -DOCDIR = $(JACE_WRAPPER)/doc - -JC = javac -JCOPTS = -g -d $(CLASSDIR) -JD = javadoc -JDOPTS = -d $(DOCDIR) - -COMPILE.java = $(JC) $(JCOPTS) $(filter %.java,$?) - -CLASSPATH := $(CLASSDIR):$(CLASSPATH) - -all: asx os concurrency connection timers misc reactor svcconfig socksap - -pkg_all = $(pkg_asx_timestuff) $(pkg_asx) $(pkg_os) $(pkg_concurrency) \ - $(pkg_connection) $(pkg_timers) $(pkg_misc) $(pkg_reactor) \ - $(pkg_socksap) $(pkg_svcconfig) - -doc: - $(JD) $(JDOPTS) $(addsuffix .java,$(pkg_all)) $(packages) - -clean: - find ${JACE_WRAPPER}/classes/JACE -name '*.class' -print | xargs ${RM} - -docclean: - find ${JACE_WRAPPER}/doc -name '*.html' -print | xargs ${RM} - -realclean: clean docclean - - -pkg_asx_timestuff = \ - TimeValue \ - TimeoutException \ - TimedWait - -asx_timestuff: $(addsuffix .java,$(pkg_asx_timestuff)) - $(COMPILE.java) - -pkg_asx = \ - IOCntlCmds \ - IOCntlMsg \ - Task \ - TaskFlags \ - ThruTask \ - Module \ - MessageType \ - MessageBlock \ - MessageQueue \ - StreamHead \ - StreamTail \ - Stream - -asx: os asx_timestuff reactor concurrency $(addsuffix .java,$(pkg_asx)) - $(COMPILE.java) - -pkg_os = \ - OS \ - ACE - -os: $(addsuffix .java,$(pkg_os)) - $(COMPILE.java) - -pkg_concurrency = \ - Condition \ - Mutex \ - RWMutex \ - Semaphore \ - ThreadManager \ - Token - -concurrency: $(addsuffix .java,$(pkg_concurrency)) asx_timestuff os - $(COMPILE.java) - -pkg_connection = \ - SvcHandler \ - Acceptor \ - Connector \ - AcceptStrategy \ - ActivateStrategy \ - CreationStrategy \ - StrategyAcceptor \ - Blob \ - BlobHandler \ - BlobReader \ - BlobWriter \ - HTTPHelper - -connection: os socksap svcconfig $(addsuffix .java,$(pkg_connection)) - $(COMPILE.java) - -pkg_timers = \ - ProfileTimer - -timers: $(addsuffix .java,$(pkg_timers)) - $(COMPILE.java) - -pkg_misc = \ - GetOpt - -misc: $(addsuffix .java,$(pkg_misc)) - $(COMPILE.java) - -pkg_reactor = \ - EventHandler \ - TimerQueue - -reactor: asx_timestuff $(addsuffix .java,$(pkg_reactor)) - $(COMPILE.java) - -pkg_socksap = \ - INETAddr \ - SOCKStream \ - SOCKAcceptor \ - SOCKConnector - -socksap: os $(addsuffix .java,$(pkg_socksap)) - $(COMPILE.java) - -pkg_svcconfig = \ - ServiceLoader \ - ClassReader \ - ParseNode \ - SuspendNode \ - ResumeNode \ - RemoveNode \ - ServiceRecord \ - ServiceObjectRecord \ - AddServiceObjectNode \ - ServiceObject \ - ServiceConfig \ - ServiceRepository - -svcconfig: os reactor misc $(addsuffix .java,$(pkg_svcconfig)) - $(COMPILE.java) - -packages = JACE \ - JACE.ASX \ - JACE.Connection \ - JACE.Concurrency \ - JACE.Misc \ - JACE.OS \ - JACE.Reactor \ - JACE.SOCK_SAP \ - JACE.ServiceConfigurator \ - JACE.Timers - - diff --git a/java/src/MessageBlock.java b/java/src/MessageBlock.java deleted file mode 100644 index 1741f9bef80..00000000000 --- a/java/src/MessageBlock.java +++ /dev/null @@ -1,453 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * MessageBlock.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Object used to store messages in the ASX framework. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * <tt>MessageBlock</tt> is modeled after the message data structures - * used in System V STREAMS. A <tt>MessageBlock</tt> is composed of - * one or more <tt>MessageBlock</tt>s that are linked together by <em>PREV</em> - * and <em>NEXT</em> pointers. In addition, a <tt>MessageBlock</tt> may also be - * linked to a chain of other <tt>MessageBlock</tt>s. This structure - * enables efficient manipulation of arbitrarily-large messages - * <em>without</em> incurring memory copying overhead. - *</blockquote> - * - *@see MessageQueue - */ -public class MessageBlock -{ - /** - * Create an empty Message Block - */ - public MessageBlock () - { - this (0); - } - - /** - * Create an empty Message Block. - * Note that this assumes that type of MessageBlock is MB_DATA. - *@param size size of the Message Block to create. - */ - public MessageBlock (int size) - { - // Note the explicit cast toString() is needed. For some strange - // reason, it fails otherwise if size == 0. - this ((new StringBuffer (size)).toString ()); - } - - /** - * Create a Message Block. Note that this assumes that type of - * MessageBlock is MB_DATA. - *@param data initial data to create a Message Block with. - */ - public MessageBlock (String data) - { - this (MessageType.MB_DATA, - null, - data); - } - - /** - * Create a Message Block. - *@param type type of the Message Block (must be one of those - * specified in class Message Type) - *@param cont next block of data - *@param data initial data to create Message Block with - */ - public MessageBlock (int type, - MessageBlock cont, - String data) - { - this.flags_ = 0; - this.priority_ = 0; - this.next_ = null; - this.prev_ = null; - - this.init (type, cont, data); - } - - /** - * Create a Message Block. Note that this assumes that type of - * MessageBlock is MB_OBJECT. - *@param obj initial object to create a Message Block with. - */ - public MessageBlock (Object obj) - { - this (MessageType.MB_OBJECT, - null, - obj); - } - - /** - * Create a Message Block. - *@param type type of the Message Block (must be one of those - * specified in class Message Type) - *@param cont next block of data - *@param obj initial object to create Message Block with - */ - public MessageBlock (int type, - MessageBlock cont, - Object obj) - { - this.init (type, cont, obj); - } - - /* Initialize the Message Block - *@param data data to initialize Message Block with - */ - public void init (String data) - { - this.base_ = new StringBuffer (data); - } - - /** - * Initialize a Message Block. - *@param type type of the Message Block (must be one of those - * specified in class Message Type) - *@param cont next block of data - *@param data data to initialize Message Block with - */ - public void init (int msgType, - MessageBlock msgCont, - String data) - { - if (data.length () == 0) - this.base_ = new StringBuffer (0); - else - this.base_ = new StringBuffer (data); - this.type_ = msgType; - this.cont_ = msgCont; - } - - /** - * Initialize a Message Block. Note that this assumes that type of - * MessageBlock is MB_OBJECT. - *@param obj initial object to initialize a Message Block with. - */ - public void init (Object obj) - { - this.init (MessageType.MB_OBJECT, null, obj); - } - - /** - * Initialize a Message Block. - *@param type type of the Message Block (must be one of those - * specified in class Message Type) - *@param cont next block of data - *@param obj object to initialize Message Block with - */ - public void init (int msgType, - MessageBlock msgCont, - Object obj) - { - this.obj_ = obj; - this.type_ = msgType; - this.cont_ = msgCont; - this.flags_ = 0; - this.priority_ = 0; - this.next_ = null; - this.prev_ = null; - } - - /** - * Set message flags. Note that the flags will be set on top of - * already set flags. - *@param moreFlags flags to set for the Message Block. - */ - public long setFlags (long moreFlags) - { - // Later we might mask more_flags so that user can't change - // internal ones: more_flags &= ~(USER_FLAGS -1). - this.flags_ = ACE.SET_BITS (this.flags_, moreFlags); - return this.flags_; - } - - /** - * Unset message flags. - *@param lessFlags flags to unset for the Message Block. - */ - public long clrFlags (long lessFlags) - { - // Later we might mask more_flags so that user can't change - // internal ones: less_flags &= ~(USER_FLAGS -1). - this.flags_ = ACE.CLR_BITS (this.flags_, lessFlags); - return this.flags_; - } - - /** - * Get the message flags. - *@return Message flags - */ - public long flags () - { - return this.flags_; - } - - /** - * Get the type of the message. - *@return message type - */ - public int msgType () - { - return this.type_; - } - - /** - * Set the type of the message. - *@param t type of the message - */ - public void msgType (int t) - { - this.type_ = t; - } - - /** - * Get the class of the message. Note there are two classes, - * <normal> messages and <high-priority> messages. - *@return message class - */ - public int msgClass () - { - return this.msgType () >= MessageType.MB_PRIORITY - ? MessageType.MB_PRIORITY : MessageType.MB_NORMAL; - } - - /** - * Find out if the message is a data message. - *@return true if message is a data message, false otherwise - */ - public boolean isDataMsg () - { - int mt = this.msgType (); - return mt == MessageType.MB_DATA - || mt == MessageType.MB_PROTO - || mt == MessageType.MB_PCPROTO; - } - - /** - * Find out if the message is an object message. - *@return true if message is an object message, false otherwise - */ - public boolean isObjMsg () - { - int mt = this.msgType (); - return mt == MessageType.MB_OBJECT - || mt == MessageType.MB_PROTO - || mt == MessageType.MB_PCPROTO; - } - - /** - * Get the priority of the message. - *@return message priority - */ - public long msgPriority () - { - return this.priority_; - } - - /** - * Set the priority of the message. - *@param pri priority of the message - */ - public void msgPriority (long pri) - { - this.priority_ = pri; - } - - /** - * Get message data. This assumes that msgType is MB_DATA. - *@return message data - */ - public String base () - { - // Create a String object to return - char temp[] = new char [this.base_.length ()]; - this.base_.getChars (0, this.base_.length (), temp, 0); - return new String (temp); - } - - /** - * Set the message data. This assumes that msgType is MB_DATA. - *@param data message data - *@param msgFlags message flags - */ - public void base (String data, - long msgFlags) - { - this.base_ = new StringBuffer (data); - this.flags_ = msgFlags; - } - - /** - * Get message object. This assumes that msgType is MB_OBJECT. - *@return message object - */ - public Object obj () - { - return this.obj_; - } - - /** - * Set the message object. This assumes that msgType is MB_OBJECT. - *@param object message object - *@param msgFlags message flags - */ - public void obj (Object obj, - long msgFlags) - { - this.obj_ = obj; - this.flags_ = msgFlags; - } - - // = The following four methods only make sense if the Message_Block - // is of type MB_DATA and not MB_OBJECT. - - /** - * Get length of the message. This method only makes sense if the - * MessageBlock is of type MB_DATA and not MB_OBJECT. - *@return length of the message. - */ - public int length () - { - return this.base_.length (); - } - - /** - * Set the length of the message. This method only makes sense if the - * MessageBlock is of type MB_DATA and not MB_OBJECT. - *@param n message length - */ - public void length (int n) - { - this.base_.setLength (n); - } - - /** - * Get size of the allocated buffer for the message. This method - * only makes sense if the MessageBlock is of type MB_DATA and not - * MB_OBJECT. - *@return size of the message buffer - */ - public int size () - { - return this.base_.capacity (); - } - - /** - * Set the total size of the buffer. This method will grow the - * buffer if need be. Also, this method only makes sense if the - * MessageBlock is of type MB_DATA and not MB_OBJECT. - *@param n size of message buffer - */ - public void size (int n) - { - this.base_.ensureCapacity (n); - } - - - /** - * Get the continuation field. The coninuation field is used to - * chain together composite messages. - *@return the continuation field - */ - public MessageBlock cont () - { - return this.cont_; - } - - /** - * Set the continuation field. The coninuation field is used to - * chain together composite messages. - *@param msgCont continuation field - */ - void cont (MessageBlock msgCont) - { - this.cont_ = msgCont; - } - - /** - * Get link to next message. The next message points to the - * <MessageBlock> directly ahead in the MessageQueue. - *@return next message block - */ - MessageBlock next () - { - return this.next_; - } - - /** - * Set link to next message. The next message points to the - * <MessageBlock> directly ahead in the MessageQueue. - *@param msgBlock next message block - */ - void next (MessageBlock msgBlock) - { - this.next_ = msgBlock; - } - - /** - * Get link to previous message. The previous message points to the - * <MessageBlock> directly before in the MessageQueue. - *@return previous message block - */ - MessageBlock prev () - { - return this.prev_; - } - - /** - * Set link to previous message. The previous message points to the - * <MessageBlock> directly before in the MessageQueue. - *@param msgBlock previous message block - */ - void prev (MessageBlock msgBlock) - { - this.prev_ = msgBlock; - } - - private int type_; - // Type of message. - - private long flags_; - // Misc flags. - - private long priority_; - // Priority of message. - - private StringBuffer base_; - // String data of message block (initialized to null). - - private Object obj_; - // Object data of message block (initialized to null). - - private MessageBlock cont_; - // Next message block in the chain. - - private MessageBlock next_; - // Next message in the list. - - private MessageBlock prev_; - // Previous message in the list. - -} - diff --git a/java/src/MessageQueue.java b/java/src/MessageQueue.java deleted file mode 100644 index e25fdc65238..00000000000 --- a/java/src/MessageQueue.java +++ /dev/null @@ -1,636 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * MessageQueue.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import java.util.Date; -import JACE.OS.*; -import JACE.Reactor.*; - -class NotFullCondition extends TimedWait -{ - public NotFullCondition (MessageQueue mq) - { - super (mq); - this.mq_ = mq; - } - - public boolean condition () { - // Delegate to the appropriate conditional - // check on the MessageQueue. - return !this.mq_.isFull (); - } - private MessageQueue mq_; -} - -class NotEmptyCondition extends TimedWait -{ - public NotEmptyCondition (MessageQueue mq) - { - super (mq); - this.mq_ = mq; - } - - public boolean condition () { - // Delegate to the appropriate conditional - // check on the MessageQueue. - return !this.mq_.isEmpty (); - } - private MessageQueue mq_; -} - - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * A thread-safe message queueing facility, modeled after the - * queueing facilities in System V StreamS. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *</blockquote> - * <tt>MessageQueue</tt> is the central queueing facility for messages - * in the ASX framework. All operations are thread-safe, as it is intended - * to be used for inter-thread communication (<em>e.g.</em>, a producer and - * consumer thread joined by a <tt>MessageQueue</tt>). The queue - * consiste of <tt>MessageBlock</tt>s. - *</blockquote> - * - *@see MessageBlock - *@see TimeValue - */ -public class MessageQueue -{ - /** - * Default constructor - */ - public MessageQueue () - { - this (DEFAULT_HWM, DEFAULT_LWM); - } - - /** - * Create a Message Queue with high and low water marks. - *@param hwm High water mark (max number of bytes allowed in the - * queue) - *@param lwm Low water mark (min number of bytes in the queue) - */ - public MessageQueue (int hwm, int lwm) - { - if (this.open (hwm, lwm) == -1) - ACE.ERROR ("open"); - } - - /** - * Initialize a Message Queue with high and low water marks. - *@param hwm High water mark (max number of bytes allowed in the - * queue) - *@param lwm Low water mark (min number of bytes in the queue) - */ - public synchronized int open (int hwm, int lwm) - { - this.highWaterMark_ = hwm; - this.lowWaterMark_ = lwm; - this.deactivated_ = false; - this.currentBytes_ = 0; - this.currentCount_ = 0; - this.tail_ = null; - this.head_ = null; - return 0; - } - - // = For enqueue, enqueueHead, enqueueTail, and dequeueHead if - // timeout is specified, the caller will wait for amount of time in - // tv. Calls will return, however, when queue is closed, - // deactivated, or if the time specified in tv elapses. - - /** - * Enqueue a <MessageBlock> into the <MessageQueue> in accordance - * with its <msgPriority> (0 is lowest priority). Note that the - * call will block (unless the queue has been deactivated). - * - *@exception java.lang.InterruptedException Interrupted while accessing queue - *@param newItem item to enqueue onto the Message Queue - *@return -1 on failure, else the number of items still on the queue. - */ - public synchronized int enqueue (MessageBlock newItem) throws InterruptedException - { - return this.enqueue (newItem, null); - } - - /** - * Enqueue a <MessageBlock> into the <MessageQueue> in accordance - * with its <msgPriority> (0 is lowest priority). Note that the - * call will return if <timeout> amount of time expires or if the - * queue has been deactivated. - *@param newItem item to enqueue onto the Message Queue - *@param tv amount of time (TimeValue) to wait before returning - * (unless operation completes before) - *@return -1 on failure, else the number of items still on the - * queue. - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - public synchronized int enqueue (MessageBlock newItem, - TimeValue tv) throws InterruptedException - { - int result = -1; - if (this.deactivated_) - return -1; - try - { - if (tv == null) // Need to do a blocking wait - notFullCondition_.timedWait (); - else // Need to do a timed wait - notFullCondition_.timedWait (tv); - } - catch (TimeoutException e) - { - return -1; - } - - // Check again if queue is still active - if (this.deactivated_) - return -1; - else - result = this.enqueueInternal (newItem); - - // Tell any blocked threads that the queue has a new item! - this.notEmptyCondition_.broadcast (); - return result; - } - - /** - * Enqueue a <MessageBlock> at the end of the <MessageQueue>. Note - * that the call will block (unless the queue has been deactivated). - *@param newItem item to enqueue onto the Message Queue - *@return -1 on failure, else the number of items still on the queue. - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - public synchronized int enqueueTail (MessageBlock newItem) throws InterruptedException - { - return this.enqueueTail (newItem, null); - } - - /** - * Enqueue a <MessageBlock> at the end of the <MessageQueue>. Note - * that the call will return if <timeout> amount of time expires or - * if the queue has been deactivated. - *@param newItem item to enqueue onto the Message Queue - *@param tv amount of time (TimeValue) to wait before returning - * (unless operation completes before) - *@return -1 on failure, else the number of items still on the queue. - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - public synchronized int enqueueTail (MessageBlock newItem, - TimeValue tv) throws InterruptedException - { - int result = -1; - if (this.deactivated_) - return -1; - try - { - if (tv == null) // Need to do a blocking wait - notFullCondition_.timedWait (); - else // Need to do a timed wait - notFullCondition_.timedWait (tv); - } - catch (TimeoutException e) - { - return -1; - } - - // Check again if queue is still active - if (this.deactivated_) - return -1; - else - result = this.enqueueTailInternal (newItem); - - // Tell any blocked threads that the queue has a new item! - this.notEmptyCondition_.broadcast (); - return result; - } - - /** - * Enqueue a <MessageBlock> at the head of the <MessageQueue>. Note - * that the call will block (unless the queue has been deactivated). - *@param newItem item to enqueue onto the Message Queue - *@return -1 on failure, else the number of items still on the queue. - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - public synchronized int enqueueHead (MessageBlock newItem) throws InterruptedException - { - return this.enqueueHead (newItem, null); - } - - /** - * Enqueue a <MessageBlock> at the head of the <MessageQueue>. Note - * that the call will return if <timeout> amount of time expires or - * if the queue has been deactivated. - *@param newItem item to enqueue onto the Message Queue - *@param tv amount of time (TimeValue) to wait before returning - * (unless operation completes before) - *@return -1 on failure, else the number of items still on the queue. - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - public synchronized int enqueueHead (MessageBlock newItem, - TimeValue tv) throws InterruptedException - { - int result = -1; - if (this.deactivated_) - return -1; - try - { - if (tv == null) // Need to do a blocking wait - notFullCondition_.timedWait (); - else // Need to do a timed wait - notFullCondition_.timedWait (tv); - } - catch (TimeoutException e) - { - return -1; - } - - // Check again if queue is still active - if (this.deactivated_) - return -1; - else - result = this.enqueueHeadInternal (newItem); - - // Tell any blocked threads that the queue has a new item! - this.notEmptyCondition_.broadcast (); - return result; - } - - /** - * Dequeue and return the <MessageBlock> at the head of the - * <MessageQueue>. Note that the call will block (unless the queue - * has been deactivated). - *@return null on failure, else the <MessageBlock> at the head of queue. - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - public synchronized MessageBlock dequeueHead () throws InterruptedException - { - return this.dequeueHead (null); - } - - /** - * Dequeue and return the <MessageBlock> at the head of the - * <MessageQueue>. Note that the call will return if <timeout> - * amount of time expires or if the queue has been deactivated. - *@return null on failure, else the <MessageBlock> at the head of queue. - *@exception InterruptedException Interrupted while accessing queue - */ - public synchronized MessageBlock dequeueHead (TimeValue tv) throws InterruptedException - { - MessageBlock result = null; - if (this.deactivated_) - return null; - try - { - if (tv == null) // Need to do a blocking wait - notEmptyCondition_.timedWait (); - else // Need to do a timed wait - notEmptyCondition_.timedWait (tv); - } - catch (TimeoutException e) - { - return null; - } - - // Check again if queue is still active - if (this.deactivated_) - return null; - else - result = this.dequeueHeadInternal (); - - // Tell any blocked threads that the queue has room for an item! - this.notFullCondition_.broadcast (); - return result; - } - - /** - * Check if queue is full. - *@return true if queue is full, else false. - */ - public synchronized boolean isFull () - { - return this.isFullInternal (); - } - - /** - * Check if queue is empty. - *@return true if queue is empty, else false. - */ - public synchronized boolean isEmpty () - { - return this.isEmptyInternal (); - } - - /** - * Get total number of bytes on the queue. - *@return total number number of bytes on the queue - */ - public int messageBytes () - { - return this.currentBytes_; - } - - /** - * Get total number of messages on the queue. - *@return total number number of messages on the queue - */ - public int messageCount () - { - return this.currentCount_; - } - - // = Flow control routines - - /** - * Get high watermark. - *@return high watermark - */ - public int highWaterMark () - { - return this.highWaterMark_; - } - - /** - * Set high watermark. - *@param hwm high watermark - */ - public void highWaterMark (int hwm) - { - this.highWaterMark_ = hwm; - } - - /** - * Get low watermark. - *@return low watermark - */ - public int lowWaterMark () - { - return this.lowWaterMark_; - } - - /** - * Set low watermark. - *@param lwm low watermark - */ - public void lowWaterMark (int lwm) - { - this.lowWaterMark_ = lwm; - } - - // = Activation control methods. - - /** - * Deactivate the queue and wakeup all threads waiting on the queue - * so they can continue. No messages are removed from the queue, - * however. Any other operations called until the queue is - * activated again will immediately return -1. - *@return WAS_INACTIVE if queue was inactive before the call and - * WAS_ACTIVE if queue was active before the call. - */ - public synchronized int deactivate () - { - return this.deactivateInternal (); - } - - - /** - * Reactivate the queue so that threads can enqueue and dequeue - * messages again. - *@return WAS_INACTIVE if queue was inactive before the call and - * WAS_ACTIVE if queue was active before the call. - */ - public synchronized int activate () - { - return this.activateInternal (); - } - - protected boolean isEmptyInternal () - { - // Not sure about this one!!!! - return this.currentBytes_ <= this.lowWaterMark_ && this.currentCount_ <= 0; - } - - protected boolean isFullInternal () - { - return this.currentBytes_ > this.highWaterMark_; - } - - protected int deactivateInternal () - { - int currentStatus = - this.deactivated_ ? WAS_INACTIVE : WAS_ACTIVE; - - this.notFullCondition_.broadcast (); - this.notEmptyCondition_.broadcast (); - - this.deactivated_ = true; - return currentStatus; - } - - protected int activateInternal () - { - int currentStatus = - this.deactivated_ ? WAS_INACTIVE : WAS_ACTIVE; - this.deactivated_ = false; - - return currentStatus; - } - - protected int enqueueTailInternal (MessageBlock newItem) - { - if (newItem == null) - return -1; - - // List was empty, so build a new one. - if (this.tail_ == null) - { - this.head_ = newItem; - this.tail_ = newItem; - newItem.next (null); - newItem.prev (null); - } - // Link at the end. - else - { - newItem.next (null); - this.tail_.next (newItem); - newItem.prev (this.tail_); - this.tail_ = newItem; - } - - if (newItem.msgType() != MessageType.MB_OBJECT) - { - // Make sure to count *all* the bytes in a composite message!!! - for (MessageBlock temp = newItem; - temp != null; - temp = temp.cont ()) - this.currentBytes_ += temp.size (); - } - - this.currentCount_++; - return this.currentCount_; - } - - protected int enqueueHeadInternal (MessageBlock newItem) - { - if (newItem == null) - return -1; - - newItem.prev (null); - newItem.next (this.head_); - - if (this.head_ != null) - this.head_.prev (newItem); - else - this.tail_ = newItem; - - this.head_ = newItem; - - if (newItem.msgType() != MessageType.MB_OBJECT) - { - // Make sure to count *all* the bytes in a composite message!!! - for (MessageBlock temp = newItem; - temp != null; - temp = temp.cont ()) - this.currentBytes_ += temp.size (); - } - - this.currentCount_++; - - return this.currentCount_; - } - - protected int enqueueInternal (MessageBlock newItem) - { - if (newItem == null) - return -1; - - if (this.head_ == null) - // Check for simple case of an empty queue, where all we need to - // do is insert <newItem> into the head. - return this.enqueueHeadInternal (newItem); - else - { - MessageBlock temp; - - // Figure out where the new item goes relative to its priority. - - for (temp = this.head_; - temp != null; - temp = temp.next ()) - { - if (temp.msgPriority () <= newItem.msgPriority ()) - // Break out when we've located an item that has lower - // priority that <newItem>. - break; - } - - if (temp == null) - // Check for simple case of inserting at the end of the queue, - // where all we need to do is insert <newItem> after the - // current tail. - return this.enqueueTailInternal (newItem); - else if (temp.prev () == null) - // Check for simple case of inserting at the beginning of the - // queue, where all we need to do is insert <newItem> before - // the current head. - return this.enqueueHeadInternal (newItem); - else - { - // Insert the message right before the item of equal or lower - // priority. - newItem.next (temp); - newItem.prev (temp.prev ()); - temp.prev ().next (newItem); - temp.prev (newItem); - } - } - - if (newItem.msgType() != MessageType.MB_OBJECT) - { - // Make sure to count *all* the bytes in a composite message!!! - for (MessageBlock temp = newItem; - temp != null; - temp = temp.cont ()) - this.currentBytes_ += temp.size (); - } - - this.currentCount_++; - return this.currentCount_; - } - - protected MessageBlock dequeueHeadInternal () - { - MessageBlock firstItem = this.head_; - this.head_ = this.head_.next (); - - if (this.head_ == null) - this.tail_ = null; - - if (firstItem.msgType() != MessageType.MB_OBJECT) - { - // Make sure to subtract off all of the bytes associated with this - // message. - for (MessageBlock temp = firstItem; - temp != null; - temp = temp.cont ()) - this.currentBytes_ -= temp.size (); - } - - this.currentCount_--; - return firstItem; - } - - - /** Default high watermark (16 K). */ - public final static int DEFAULT_HWM = 16 * 1024; - - /** Default low watermark. */ - public final static int DEFAULT_LWM = 0; - - /** Message queue was active before activate() or deactivate(). */ - public final static int WAS_ACTIVE = 1; - - /** Message queue was inactive before activate() or deactivate(). */ - public final static int WAS_INACTIVE = 2; - - private int highWaterMark_; - // Greatest number of bytes before blocking. - - private int lowWaterMark_; - // Lowest number of bytes before unblocking occurs. - - private boolean deactivated_; - // Indicates that the queue is inactive. - - private int currentBytes_; - // Current number of bytes in the queue. - - private int currentCount_; - // Current number of messages in the queue. - - private MessageBlock head_; - // Head of Message_Block list. - - private MessageBlock tail_; - // Tail of Message_Block list. - - // The Delegated Notification mechanisms. - private NotFullCondition notFullCondition_ = new NotFullCondition (this); - private NotEmptyCondition notEmptyCondition_ = new NotEmptyCondition (this); - -} diff --git a/java/src/MessageType.java b/java/src/MessageType.java deleted file mode 100644 index 62c34455854..00000000000 --- a/java/src/MessageType.java +++ /dev/null @@ -1,110 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * MessageType.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Message types used by ACE.MessageBlock. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * Defines bit masks used to identify various types of messages. - *</blockquote> - * - *<h2>NOTES</h2> - *<blockquote> - * This class is not intended to be instantiable. - *</blockquote> - */ -public class MessageType -{ - // = Data and protocol messages (regular and priority) - /** regular data */ - public static final int MB_DATA = 0x01; - - /** protocol control */ - public static final int MB_PROTO = 0x02; - - /** regular data */ - public static final int MB_OBJECT = 0x09; - - - // = Control messages (regular and priority) - /** line break */ - public static final int MB_BREAK = 0x03; - - /** pass file pointer */ - public static final int MB_PASSFP = 0x04; - - /** post an event to an event queue */ - public static final int MB_EVENT = 0x05; - - /** generate process signal */ - public static final int MB_SIG = 0x06; - - /** ioctl; set/get params */ - public static final int MB_IOCTL = 0x07; - - /** set various stream head options */ - public static final int MB_SETOPTS = 0x08; - - - // = Control messages (high priority; go to head of queue) - /** acknowledge ioctl */ - public static final int MB_IOCACK = 0x81; - - /** negative ioctl acknowledge */ - public static final int MB_IOCNAK = 0x82; - - /** priority proto message */ - public static final int MB_PCPROTO = 0x83; - - /** generate process signal */ - public static final int MB_PCSIG = 0x84; - - /** generate read notification */ - public static final int MB_READ = 0x85; - - /** flush your queues */ - public static final int MB_FLUSH = 0x86; - - /** stop transmission immediately */ - public static final int MB_STOP = 0x87; - - /** restart transmission after stop */ - public static final int MB_START = 0x88; - - /** line disconnect */ - public static final int MB_HANGUP = 0x89; - - /** fatal error used to set u.u_error */ - public static final int MB_ERROR = 0x8a; - - /** post an event to an event queue */ - public static final int MB_PCEVENT = 0x8b; - - - /** Normal priority messages */ - public static final int MB_NORMAL = 0x00; - - /** High priority control messages */ - public static final int MB_PRIORITY = 0x80; - - // Default private constructor to avoid instantiation - private MessageType () - { - } -} - diff --git a/java/src/Module.java b/java/src/Module.java deleted file mode 100644 index 6eb56bcbf43..00000000000 --- a/java/src/Module.java +++ /dev/null @@ -1,253 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * Module.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Provides an abstraction for managing a bi-directional flow of - * messages. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * This is based on the Module concept in System V Streams, - * which contains a pair of Tasks, one for handling upstream - * processing, one for handling downstream processing. - *</blockquote> - */ -public class Module -{ - // = Initialization and termination methods. - - /** - * Create an empty Module. - */ - public Module () - { - // Do nothing... - this.name ("<unknown>"); - } - - /* - * Create an initialized module. - *@param modName identity of the module. - *@param writerQ writer task of the module. - *@param readerQ reader task of the module. - *@param flags Module flags - */ - public Module (String modName, - Task writerQ, - Task readerQ, - Object flags) - { - this.open (modName, writerQ, readerQ, flags); - } - - /* - * Create an initialized module. - *@param modName identity of the module. - *@param writerQ writer task of the module. - *@param readerQ reader task of the module. - *@param flags Module flags - */ - public void open (String modName, - Task writerQ, - Task readerQ, - Object arg) - { - this.name (modName); - this.arg_ = arg; - - if (writerQ == null) - writerQ = new ThruTask (); - if (readerQ == null) - readerQ = new ThruTask (); - - this.reader (readerQ); - this.writer (writerQ); - - // Setup back pointers. - readerQ.module (this); - writerQ.module (this); - } - - - /* - * Set the writer task. - *@param q the writer task - */ - public void writer (Task q) - { - this.qPair_[1] = q; - if (q != null) - q.flags (ACE.CLR_BITS (q.flags (), TaskFlags.ACE_READER)); - } - - /* - * Set the reader task. - *@param q the reader task - */ - public void reader (Task q) - { - this.qPair_[0] = q; - if (q != null) - q.flags (ACE.SET_BITS (q.flags (), TaskFlags.ACE_READER)); - } - - /* - * Link this Module on top of Module. - *@param m the module to link this on top of. - */ - public void link (Module m) - { - this.next (m); - this.writer ().next (m.writer ()); - m.reader ().next (this.reader ()); - } - - /* - * Set and get pointer to sibling Task in Module. - *@param orig the task to get the sibling for - *@return the sibling of the task - */ - public Task sibling (Task orig) - { - if (this.qPair_[0] == orig) - return this.qPair_[1]; - else if (this.qPair_[1] == orig) - return this.qPair_[0]; - else - return null; - } - - /* - * Close down the module and its tasks. - *@param flags Module flags - *@return 0 on success, -1 on failure - */ - public int close (long flags) - { - Task readerQ = this.reader (); - Task writerQ = this.writer (); - int result = 0; - - if (readerQ != null) - { - if (readerQ.close (flags) == -1) - result = -1; - readerQ.flush (flags); - readerQ.next (null); - } - - if (writerQ != null) - { - if (writerQ.close (flags) == -1) - result = -1; - writerQ.flush (flags); - writerQ.next (null); - } - - return result; - } - - /* - * Get the argument passed to tasks. - *@return the argument passed to tasks. - */ - public Object arg () - { - return this.arg_; - } - - /* - * Set the argument to be passed to tasks. - *@param a the argument to be passed to tasks. - */ - public void arg (Object a) - { - this.arg_ = a; - } - - /* - * Get the name of the module. - *@return the name of the module. - */ - public String name () - { - return this.name_; - } - - /* - * Set the name of the module. - *@param n the name of the module. - */ - public void name (String n) - { - this.name_ = n; - } - - /* - * Get the writer task of the module. - *@return the writer task of the module. - */ - public Task writer () - { - return this.qPair_[1]; - } - - /* - * Get the reader task of the module. - *@return the reader task of the module. - */ - public Task reader () - { - return this.qPair_[0]; - } - - /* - * Get the next pointer to the module above in the stream. - *@return the next pointer to the module above in the stream. - */ - public Module next () - { - return this.next_; - } - - /* - * Set the next pointer to the module above in the stream. - *@param m the next pointer to the module above in the stream. - */ - public void next (Module m) - { - this.next_ = m; - } - - private Task qPair_[] = new Task[2]; - // Pair of Tasks that form the "read-side" and "write-side" of the - // ACE_Module partitioning. - - private String name_ = null; - // Name of the ACE_Module. - - private Module next_; - // Next ACE_Module in the stack. - - private Object arg_; - // Argument passed through to the reader and writer task when they - // are opened. - -} - diff --git a/java/src/Mutex.java b/java/src/Mutex.java deleted file mode 100644 index 8daab4ff9eb..00000000000 --- a/java/src/Mutex.java +++ /dev/null @@ -1,92 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * Mutex.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Concurrency; - -import java.util.*; -import JACE.ASX.*; - -class TimedWaitMAdapter extends TimedWait -{ - TimedWaitMAdapter (Object obj) - { - super (obj); - } - - // Check to see if the lock is currently held or not. - public boolean condition () - { - return !this.inUse_; - } - - // Acquire/Release the lock - public void inUse (boolean c) - { - this.inUse_ = c; - } - - private boolean inUse_ = false; - // The actual lock -} - - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Value added abstraction for mutex variable creation. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * A timed mutex, <em>i.e.</em> a mutex whose operations do not - * block forever and can <q>time out</q>. - *</blockquote> - */ -public class Mutex -{ - /** - * Acquire the mutex. Note that this will block. - *@exception InterruptedException exception during wait - */ - public synchronized void acquire () throws InterruptedException - { - this.monitor_.timedWait (); - this.monitor_.inUse (true); - } - - /** - * Acquire the mutex. Note that the call will return if <timeout> - * amount of time expires. - *@param tv amount of time (TimeValue) to wait before returning - * (unless operation completes before) - *@exception TimeoutException wait timed out exception - *@exception InterruptedException exception during wait - */ - public synchronized void acquire (TimeValue tv) throws - TimeoutException, InterruptedException - { - this.monitor_.timedWait (tv); - this.monitor_.inUse (true); - } - - /** - * Release the mutex. - */ - public synchronized void release () - { - this.monitor_.inUse (false); - this.monitor_.signal (); - } - - private TimedWaitMAdapter monitor_ = new TimedWaitMAdapter (this); - // The monitor (adapter) to wait on -} diff --git a/java/src/OS.java b/java/src/OS.java deleted file mode 100644 index c17fd6d07f2..00000000000 --- a/java/src/OS.java +++ /dev/null @@ -1,72 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.OS - * - * = FILENAME - * OS.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.OS; - -import java.util.StringTokenizer; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Methods to extend the capabilities of the Java runtime system. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * This non-instantiable class contains little <q>utility functions</q> - * that should have been in Java to begin with :-) - *</blockquote> - */ -public class OS -{ - /** - * Create an array of Strings from a single String using <delim> as - * the delimiter. - *@param args the String to break up to make an array of Strings - *@param delim the delimeter to use to break the String up - *@return an array containing the original String broken up - */ - public static String [] createStringArray (String args, String delim) - { - // First determine the number of arguments - int count = 0; - StringTokenizer tokens = new StringTokenizer (args, delim); - while (tokens.hasMoreTokens ()) - { - tokens.nextToken (); - count++; - } - if (count == 0) - return null; - - // Create argument array - String [] argArray = new String [count]; - int index = 0; - tokens = new StringTokenizer (args, " "); - while (tokens.hasMoreTokens ()) - { - argArray [index] = tokens.nextToken (); - index++; - } - - // Assert index == count - if (index != count) - return null; - else - return argArray; - } - - // Default private constructor to avoid instantiation - private OS () - { - } -} diff --git a/java/src/ParseNode.java b/java/src/ParseNode.java deleted file mode 100644 index cdf8bb57955..00000000000 --- a/java/src/ParseNode.java +++ /dev/null @@ -1,69 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ParseNode.java - * - * Base class for the data types used in the parse tree for adjusting - * services. Things like SuspendNode extend this. - * - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import JACE.OS.*; - -public class ParseNode -{ - /** - * Constructor - * - */ - public ParseNode () - { - this.name_ = new String("Uninitialized"); - } - - /** - * Initialize the service (subclasses - * may do more than set the name) - */ - public void init (String name) - { - this.name_ = name; - } - - /** - * Subclasses override to do real work, usually - * initiating a service or modifying one - */ - public void apply () - { - // Empty - } - - /** - * Retrive the service name - */ - public String name() - { - return this.name_; - } - - /** - * Set the name of the service - */ - public void name(String newName) - { - this.name_ = newName; - } - - String name_; -}; - - - diff --git a/java/src/ProfileTimer.java b/java/src/ProfileTimer.java deleted file mode 100644 index b7e9c908a13..00000000000 --- a/java/src/ProfileTimer.java +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Timers - * - * = FILENAME - * ProfileTimer.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Timers; - -/** - * <hr> - * <p><b>TITLE</b><br> - * A Java wrapper for interval timers. - */ -public class ProfileTimer -{ - /** - * Start the timer. - */ - public void start () - { - this.startTime_ = java.lang.System.currentTimeMillis (); - } - - /** - * Stop the timer. - */ - public void stop () - { - this.stopTime_ = java.lang.System.currentTimeMillis (); - } - - /** - * Determine elapsed time between start and stop. - *@return Total elapsed time (stop - start). - */ - public long elapsedTime () - { - return this.stopTime_ - this.startTime_; - } - - private long startTime_; - private long stopTime_; -} diff --git a/java/src/README b/java/src/README deleted file mode 100644 index 1882de26380..00000000000 --- a/java/src/README +++ /dev/null @@ -1,19 +0,0 @@ -$Id$ - -Make sure to update the environment variable CLASSPATH to include the -path to where java/classes/ is located. The Java compiler uses this to -find classes when resolving dependencies. - -As with the C++ version of ACE, the Makefile requires GNU Make. - -Suggestions are welcome to: - -Douglas C. Schmidt (schmidt@cs.wustl.edu) -Everett Anderson (eea1@cs.wustl.edu) -Darrell Brunsch (brunsch@cs.wustl.edu) -Prashant Jain (pjain@cs.wustl.edu) - -The documentation for Java ACE has not been included in the release -but can be automatically generated by typing "make doc" in the src -directory. Note that the gif images needed by the documentation ARE -included in the release. diff --git a/java/src/RWMutex.java b/java/src/RWMutex.java deleted file mode 100644 index 1161d9a8618..00000000000 --- a/java/src/RWMutex.java +++ /dev/null @@ -1,174 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * RWMutex.java - * - *@author Ross Dargahi (rossd@krinfo.com), Prashant Jain, and Irfan Pyarali - * - *************************************************/ - -package JACE.Concurrency; - -import JACE.OS.*; - -/******************************************************************************* -* <HR> -* <B> Description </B> -* <BR> -* This class increments a read/write lock. A read/write lock allows multiple -* readers or a single writer to access the guarded element. -* This implementation is based on the C++ version of ACE. -* </PRE><P><HR> -* <B> Notes </B> -* <UL> -* <LI> This class does not support recursive semantics -* </UL> -*******************************************************************************/ -public class RWMutex -{ - /** - * Acquires the write lock - * @exception InterruptedException Lock acquisition interrupted - **/ - public void acquire() - throws InterruptedException - { - acquireWrite(); - } - - /** - * Acquires the read lock - * @exception InterruptedException Lock acquisition interrupted - **/ - public void acquireRead() - throws InterruptedException - { - // make sure we start with no exception - InterruptedException exception_ = null; - - // grab lock - lock_.acquire (); - - // Give preference to writers who are waiting. - while (referenceCount_ < 0 || numberOfWaitingWriters_ > 0) - { - numberOfWaitingReaders_++; - try - { - waitingReaders_.Wait (); - } - catch (InterruptedException exception) - { - // cache exception - exception_ = exception; - } - numberOfWaitingReaders_--; - } - - if (exception_ == null) - // No errors - referenceCount_++; - - // make sure this is released in all cases - lock_.release (); - - if (exception_ != null) - // error: propogate - throw exception_; - } - - /** - * Acquires the write lock - * @exception InterruptedException Lock acquisition interrupted - **/ - public void acquireWrite() - throws InterruptedException - { - // make sure we start with no exception - InterruptedException exception_ = null; - - // grab lock - lock_.acquire (); - - // Give preference to writers who are waiting. - while (referenceCount_ != 0) - { - numberOfWaitingWriters_++; - try - { - waitingWriters_.Wait (); - } - catch (InterruptedException exception) - { - // cache exception - exception_ = exception; - } - numberOfWaitingWriters_--; - } - - if (exception_ == null) - // No errors - referenceCount_ = -1; - - // make sure this is released in all cases - lock_.release (); - - if (exception_ != null) - // error: propogate - throw exception_; - } - - /** - * Release held lock - * @exception InterruptedException Lock acquisition interrupted - **/ - public void release() - throws InterruptedException - { - lock_.acquire (); - - // Releasing a reader. - if (referenceCount_ > 0) - referenceCount_--; - else - // Releasing a writer. - if (referenceCount_ == -1) - referenceCount_ = 0; - - // Give preference to writers over readers... - if (numberOfWaitingWriters_ > 0) - { - waitingWriters_.signal (); - } - else if (numberOfWaitingReaders_ > 0) - { - waitingReaders_.broadcast (); - } - - - lock_.release (); - } - - private Mutex lock_ = new Mutex (); - // Serialize access to internal state. - - private Condition waitingReaders_ = new Condition (lock_); - // Reader threads waiting to acquire the lock. - - private int numberOfWaitingReaders_; - // Number of waiting readers. - - private Condition waitingWriters_ = new Condition (lock_); - // Writer threads waiting to acquire the lock. - - private int numberOfWaitingWriters_ = 0; - // Number of waiting writers. - - private int referenceCount_ = 0; - // Value is -1 if writer has the lock, else this keeps track of the - // number of readers holding the lock. -} - diff --git a/java/src/RemoveNode.java b/java/src/RemoveNode.java deleted file mode 100644 index b613d981ee5..00000000000 --- a/java/src/RemoveNode.java +++ /dev/null @@ -1,35 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * RemoveNode.java - * - * Used when a service is specified to be removed based on a line - * in a service configurator file. Note: Make sure to call the - * prepareToReload method in ServiceConfig before reloading the - * service that is being removed. - * - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import JACE.OS.*; - -class RemoveNode extends ParseNode -{ - public RemoveNode () - { - } - - public void apply () - { - ACE.DEBUG("RemoveNode apply"); - - if (JACE.ServiceConfigurator.ServiceConfig.remove(this.name_) == -1) - ACE.ERROR("Error removing " + this.name_); - } -}; diff --git a/java/src/ResumeNode.java b/java/src/ResumeNode.java deleted file mode 100644 index 055c19da408..00000000000 --- a/java/src/ResumeNode.java +++ /dev/null @@ -1,34 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ResumeNode.java - * - * Used when a service is specified to be resumed based on a line - * in a service configurator file. The actual implementation of the - * service being resumed does the work. - * - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import JACE.OS.*; - -class ResumeNode extends ParseNode -{ - public ResumeNode () - { - } - - public void apply () - { - ACE.DEBUG("ResumeNode apply: " + this.name_); - - if (JACE.ServiceConfigurator.ServiceConfig.resume(this.name_) == -1) - ACE.ERROR("Error resuming " + this.name_); - } -}; diff --git a/java/src/SOCKAcceptor.java b/java/src/SOCKAcceptor.java deleted file mode 100644 index f94d037d462..00000000000 --- a/java/src/SOCKAcceptor.java +++ /dev/null @@ -1,115 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.SOCK_SAP - * - * = FILENAME - * SOCKAcceptor.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.SOCK_SAP; - -import java.io.*; -import java.net.*; -import JACE.OS.*; - -/** - * <hr> - * <p><b>TITLE</b><br> - * Defines the format and interface for an ACE.SOCKAcceptor. - */ -public class SOCKAcceptor -{ - // = Initialization - - /** - * Create a SOCKAcceptor. Do nothing constructor. Allows user to - * call open() later and pass in the port number. - */ - public SOCKAcceptor () - { - } - - /** - * Create a SOCKAcceptor. - *@param port port number where the server will listen for connections - */ - public SOCKAcceptor (int port) throws IOException - { - this.open (port); - } - - /** - * Create socket to listen for connections on. - *@param port port number where the server will listen for connections - */ - public void open(int port) throws IOException - { - // Close old socket (if there is one) - this.close (); - - // Create a new server socket - this.listenSocket_ = new ServerSocket (port); - // ACE.DEBUG ("Server listening on port " + port); - } - - /** - * Close the socket and do any necessary cleanup. - */ - public void close () throws IOException - { - if (this.listenSocket_ != null) - { - this.listenSocket_.close (); - this.listenSocket_ = null; - } - } - - /** - * Accept a connection. The streams are set when the method returns. - *@param sockStream SOCK Stream to use for the connection - */ - public void accept (SOCKStream sockStream) throws SocketException, IOException - { - // Block in accept. Returns when a connection shows up and sets - // the streams - sockStream.socket (this.listenSocket_.accept ()); - ACE.DEBUG ("Accepted connection from " + - sockStream.socket ().getInetAddress ()); - } - - /** - * Get the underlying listen socket. - *@return the underlying listen socket - */ - public ServerSocket listenSocket () - { - return this.listenSocket_; - } - - /** - * Set the underlying listen socket. - *@param s the underlying listen socket - */ - public void listenSocket (ServerSocket s) - { - this.listenSocket_ = s; - } - - /** - * Clean up when the garbage collector gets run (if at all). Note - * that there is no guarantee that finalize () will get called. - *@exception Throwable (Probably IOException from the socket level) - */ - protected void finalize () throws Throwable - { - super.finalize (); - this.close (); - } - - // Socket on which listen for connections (by default initialized to - // null) - private ServerSocket listenSocket_; -} diff --git a/java/src/SOCKConnector.java b/java/src/SOCKConnector.java deleted file mode 100644 index 98dfcaf6b3d..00000000000 --- a/java/src/SOCKConnector.java +++ /dev/null @@ -1,75 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.SOCK_SAP - * - * = FILENAME - * SOCKConnector.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.SOCK_SAP; - -import java.io.*; -import java.net.*; -import JACE.OS.*; - -/** - * <hr> - * <p><b>TITLE</b><br> - * Defines an active connection factory for the socket wrappers. - */ -public class SOCKConnector -{ - // = Initialization - - /** - * Create a SOCKConnector. Do nothing constructor. Allows user to - * call connect() later. - */ - public SOCKConnector () - { - // Do nothing constructor - } - - /** - * Create a SOCKConnector and connect to the server. - *@param sockStream SOCK Stream to use for the connection - *@param hostname hostname of the server - *@param port port number to connect with server at - */ - public SOCKConnector (SOCKStream sockStream, - String hostname, - int port) throws SocketException, IOException - { - this.connect (sockStream, - hostname, - port); - } - - /** - * Connect to the server. - *@param sockStream SOCK Stream to use for the connection - *@param hostname hostname of the server - *@param port port number to connect with server at - */ - public void connect (SOCKStream sockStream, - String hostname, - int port) throws SocketException, IOException - { - sockStream.socket (new Socket (hostname, port)); - } - - /** - * Connect to the server. - *@param sockStream SOCK Stream to use for the connection - *@param addr INETAddr instance specifying host/port - */ - public void connect (SOCKStream sockStream, - INETAddr addr) throws SocketException, IOException - { - sockStream.socket (new Socket (addr.getHostName(), - addr.getPortNumber())); - } -} diff --git a/java/src/SOCKStream.java b/java/src/SOCKStream.java deleted file mode 100644 index f255b7bc44a..00000000000 --- a/java/src/SOCKStream.java +++ /dev/null @@ -1,218 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.SOCK_SAP - * - * = FILENAME - * SOCKStream.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.SOCK_SAP; - -import java.io.*; -import java.net.*; -import JACE.OS.*; - -/** - * <hr> - * <p><b>TITLE</b><br> - * Defines the methods in the ACE.SOCKStream abstraction. - * - * <p><b>DESCRIPTION</b><br> - * This adds additional wrapper methods atop the java Socket class. - */ -public class SOCKStream -{ - /** - * Create a default SOCK Stream. Do nothing constructor. - */ - public SOCKStream () - { - } - - /** - * Create a SOCK Stream. - *@param s Socket to initialize SOCK Stream with. - */ - public SOCKStream (Socket s) throws IOException - { - this.socket (s); - } - - /** - * Set the socket and the underlying streams. - *@param s Socket associated with the SOCK Stream. - */ - public void socket (Socket s) throws IOException - { - this.socket_ = s; - // Note that if s is not a valid socket or is null, the - // following calls will throw exceptions - - // Create buffered, platform independent byte streams. This hasn't been switched - // to the newer character streams since the change would break cross talk with - // non-Java sockets. - - this.iStream_ = new DataInputStream(new BufferedInputStream(s.getInputStream())); - - this.oStream_ = new DataOutputStream(new BufferedOutputStream(s.getOutputStream())); - } - - /* Get the underlying Socket. - *@return the underlying socket - */ - public Socket socket () - { - return this.socket_; - } - - /** - * Close the streams and the underlying socket. - */ - public void close () throws IOException - { - if (this.socket_ != null) - this.socket_.close (); - this.socket_ = null; - } - - // = The following send and recv methods are overloaded to provide a - // flexible interface - - /** - * Send a StringBuffer. Note that the method blocks. - *@param s the StringBuffer to send - *@return the length of the StringBuffer - */ - public int send (StringBuffer s) throws IOException - { - // Get the data out - String buf = s.toString (); - - //this.oStream_.println(buf); - this.oStream_.writeChars(buf.toString()); - this.oStream_.writeChar('\n'); - this.oStream_.flush (); - - return buf.length (); - } - - /** - * Send a String. Note that the method blocks. - *@param s the String to send - *@return the length of the String - */ - public int send (String s) throws IOException - { - this.oStream_.writeChars(s); - this.oStream_.writeChar('\n'); - - //this.oStream_.println(s); - this.oStream_.flush(); - - return s.length (); - } - - /** - * Send an array of bytes. Note that the method blocks. - *@param b array of bytes to send - *@param offset offset into the byte array to start sending from - *@param length number of bytes to send - *@return number of bytes sent - */ - public int sendN (byte[] b, int offset, int length) throws IOException - { - this.oStream_.write (b, offset, length); - this.oStream_.flush (); - return length; - } - - /** - * Receive data and append it to the StringBuffer that was passed - * in. Note that the method blocks. - *@param s the StringBuffer to append the result of the recv to - *@return the length of the String received - */ - public int recv (StringBuffer s) throws IOException - { - int len = 0; - char in = (char)this.iStream_.readByte(); - - while (in != '\n') { - s.append(in); - in = (char)this.iStream_.readByte(); - len++; - } - - return len; - } - - /** - * Receive an array of characters. This method blocks until either - * all the bytes are read, the end of the stream is detected, or - * an exception is thrown. - *@param b byte array to receive the data in - *@param offset the start offset of the data in the byte array. - *@param n number of bytes to receive - *@return n - */ - public int recvN (byte[] b, int offset, int n) throws IOException - { - this.iStream_.readFully (b, offset, n); - return n; - } - - /** - * Set the underlying input stream. - *@param iStream the input stream - */ - public void inputStream (InputStream iStream) - { - this.iStream_ = new DataInputStream(new BufferedInputStream(iStream)); - } - - /** - * Get the underlying input stream. - *@return the underlying input stream - */ - public InputStream inputStream () - { - return this.iStream_; - } - - /** - * Set the underlying output stream. - *@param iStream the output stream - */ - public void outputStream (OutputStream oStream) - { - this.oStream_ = new DataOutputStream(new BufferedOutputStream(oStream)); - } - - /** - * Get the underlying output stream. - *@return the underlying output stream - */ - public OutputStream outputStream () - { - return this.oStream_; - } - - /** - * Cleanup when the SOCK Stream is garbage collected. - *@exception Throwable (Probably IOException from the socket level) - */ - protected void finalize () throws Throwable - { - super.finalize (); - this.close (); - } - - private Socket socket_; - - // = The input and output streams (by default null) - private DataInputStream iStream_; - private DataOutputStream oStream_; -} diff --git a/java/src/Semaphore.java b/java/src/Semaphore.java deleted file mode 100644 index 4762712d722..00000000000 --- a/java/src/Semaphore.java +++ /dev/null @@ -1,103 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * Semaphore.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Concurrency; - -import java.util.*; -import JACE.ASX.*; - -class TimedWaitSAdapter extends JACE.ASX.TimedWait -{ - TimedWaitSAdapter (Object obj) - { - super (obj); - } - - // Check to see if there are any semaphores available. - public boolean condition () - { - return this.count_ > 0; - } - - // Increment the count by one - public void increment () - { - this.count_++; - } - - // Decrement the count by one - public void decrement () - { - this.count_--; - } - - // Set the count - public void count (int c) - { - this.count_ = c; - } - - private int count_ = 0; -} - -/** - * <hr> - * <h2>SYNOPSIS</h2> - * Implementation of Dijkstra's counting semaphore in java. - */ -public class Semaphore -{ - /** - * Create a Semaphore. - *@param count semaphore count - */ - public Semaphore (int c) - { - this.monitor_.count (c); - } - - /** - * Acquire the Semaphore. Note that this will block. - *@exception InterruptedException exception during wait - */ - public synchronized void acquire () throws InterruptedException - { - this.monitor_.timedWait (); - this.monitor_.decrement (); - } - - /** - * Acquire the Semaphore. Note that the call will return if <timeout> - * amount of time expires. - *@param tv amount of time (TimeValue) to wait before returning - * (unless operation completes before) - *@exception TimeoutException wait timed out exception - *@exception InterruptedException exception during wait - */ - public synchronized void acquire (TimeValue tv) - throws JACE.ASX.TimeoutException, InterruptedException - { - this.monitor_.timedWait (tv); - this.monitor_.decrement (); - } - - /** - * Release the Semaphore. - */ - public synchronized void release () - { - this.monitor_.increment (); - this.monitor_.signal (); - } - - private TimedWaitSAdapter monitor_ = new TimedWaitSAdapter (this); - // The monitor (adapter) to wait on -} diff --git a/java/src/ServiceConfig.java b/java/src/ServiceConfig.java deleted file mode 100644 index e749076137b..00000000000 --- a/java/src/ServiceConfig.java +++ /dev/null @@ -1,375 +0,0 @@ - /************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceConfig.java - * - * Services can be suspended, resumed, removed, and reloaded. Reloading requires a - * call to prepareForReload method after removing a service (done in remove()). You can't access - * the ServiceObjects that are loaded directly -- anything loaded with a class loader - * must be wrapped and have its methods called via reflection. This is because a - * loaded class doesn't exist in the same space as one loaded with the system loader. - * - * - *@author Prashant Jain, Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import java.util.*; -import java.net.*; -import JACE.OS.*; -import JACE.Misc.*; - -/** - * <hr> - * <p><b>TITLE</b><br> - * Provide the base class that supplies common server daemon - * operations. Also provides a global point for interacting with - * the service repository. - */ -public class ServiceConfig -{ - /** Begins the process of loading a service configurator file: - * parses the command line and calls processDirectives - * - *@exception FileNotFoundException Couldn't find service config file - *@exception IOException Problem reading or parsing - *@exception ClassNotFoundException Couldn't find a certain class - *@exception IllegalAccessException Inappropriate method call on a class - *@exception InstantiationException Couldn't create a certain class instance - */ - public static int open (String [] args) throws FileNotFoundException, IOException, ClassNotFoundException, IllegalAccessException, InstantiationException - { - // Parse the command line - ServiceConfig.parseArgs (args); - - // Create a repository and class loader - if (ServiceConfig.svcRep_ == null) - ServiceConfig.svcRep_ = new ServiceRepository (); - if (ServiceConfig.loader_ == null) - ServiceConfig.loader_ = new ServiceLoader(); - - return ServiceConfig.processDirectives (); - - } - - /** Parses the command line - * Valid command line options: - * -b Run as a daemon (not implemented yet) - * -d Debug mode - * -n No defaults - * -f <filename> Load services in the given file [see below for info] - * - */ - protected static void parseArgs (String [] args) - { - GetOpt getopt = new GetOpt (args, "bdnf:"); - for (int c; (c = getopt.next ()) != -1; ) - switch (c) - { - case 'b': - // Note: not supported yet! - ServiceConfig.beADaemon_ = true; - break; - case 'd': - ServiceConfig.debug_ = true; - break; - case 'n': - ServiceConfig.noDefaults_ = true; - break; - case 'f': - ServiceConfig.serviceConfigFile_ = getopt.optarg (); - break; - default: - ACE.ERROR ((char ) c + " is not a ServiceConfig option"); - break; - } - } - - /** Called by ParseNode subclass - * Asks the Service Repository to spend a service - */ - public static int suspend (String name) - { - return svcRep_.suspend(name); - } - - /** Called by ParseNode subclass - * Asks the Service Repository to resume a service - */ - public static int resume (String name) - { - return svcRep_.resume(name); - } - - /** Called by ParseNode subclass - * Asks the Service Repository to remove a service, also calls - * prepareForReload so the user doesn't have to. - */ - public static int remove (String name) - { - int result = svcRep_.remove(name); - - prepareForReload(); - - return result; - } - - /** Should be called before the user wants to reload - * a service. This calls garbage collection to - * (hopefully) obliterate the names of any unused - * service classes, and creates a new instance - * of the ClassLoader so there won't be problems - * reloading. - */ - public static void prepareForReload() - { - ServiceConfig.loader_ = new ServiceLoader(); - - System.gc(); - - } - - /** - * Parse a service configurator file, creating classes as necessary - * - * This is getting complicated, but there were too many installation problems when using - * CUP and JLex to merit developing a grammar. - * - * Current formats: - * - * load <Service Name> <Full Class Name> Service_Object "<argument list>" - * - * resume <Service Name> - * suspend <Service Name> - * remove <Service Name> - * - *@exception FileNotFoundException Couldn't find the file (default "svc.conf") - *@exception IOException Problem reading/parsing - *@exception ClassNotFoundException Couldn't find a certain class - *@exception IllegalAccessException Inappropriate method call - *@exception InstantiationException Couldn't create a class instance - */ - protected static int processDirectives () throws FileNotFoundException, IOException, ClassNotFoundException, IllegalAccessException, InstantiationException - { - if (ServiceConfig.serviceConfigFile_ == null) - ServiceConfig.serviceConfigFile_ = "svc.conf"; - - ACE.DEBUG("Processing directives in file " + ServiceConfig.serviceConfigFile_); - - File configFile = new File (ServiceConfig.serviceConfigFile_); - - // Check if file exists and is a normal file - if (!configFile.exists () || !configFile.isFile ()) - throw new FileNotFoundException ("File " + ServiceConfig.serviceConfigFile_ + " not found"); - - // Check if the file is readable - if (!configFile.canRead ()) - throw new IOException ("File " + ServiceConfig.serviceConfigFile_ + " not readable"); - - // Set up the stream - FileInputStream fileIn = new FileInputStream (configFile); - - // Parse the file - Reader r = new BufferedReader(new InputStreamReader(fileIn)); - StreamTokenizer in = new StreamTokenizer (r); - - // Set '#' as comment character to be ignored and set '/' as - // ordinary character (was original comment character) - // in.commentChar ('#'); - in.ordinaryChar ('/'); - - // Set characters in ASCII range 33 to 47, ASCII range 91 to 96, - // and ASCII range 123 to 126 as ordinary characters - in.wordChars ('!', '/'); // ASCII range 33 to 47 - in.wordChars (':', '@'); // ASCII range 58 to 64 - in.wordChars ('[', '`'); // ASCII range 91 to 96 - in.wordChars ('{', '~'); // ASCII range 123 to 126 - - String commandName = null; - String serviceName = null; - String className = null; - String classType = null; - String args = null; - // Create a state machine - int state = ServiceConfig.COMMAND_NAME; - - // The apply() method on ParseNode starts the process of actually executing the - // desired action (suspend, load, etc) - ParseNode result = null; - - while (in.nextToken () != StreamTokenizer.TT_EOF) - { - switch (state) - { - case ServiceConfig.COMMAND_NAME: - if (in.ttype == StreamTokenizer.TT_WORD) { - commandName = in.sval; - - // **** This should be changed so that instantiation is only done - // when we find out the type (ServiceObject or something else) a few - // words later. Right now it works because we only have ServiceObjects - // to load. - if (commandName.equals("load")) - result = new AddServiceObjectNode(); - else - if (commandName.equals("remove")) - result = new RemoveNode(); - else - if (commandName.equals("suspend")) - result = new SuspendNode(); - else - if (commandName.equals("resume")) - result = new ResumeNode(); - else - throw new IOException ("COMMAND NAME missing or invalid: " + commandName); - - ACE.DEBUG("Command node type: " + ((Object)result).getClass().getName()); - - - } else - throw new IOException ("Illegal COMMAND NAME argument in file " + ServiceConfig.serviceConfigFile_); - state = ServiceConfig.SERVICE_NAME; - break; - case ServiceConfig.SERVICE_NAME: - if (in.ttype == StreamTokenizer.TT_WORD) - serviceName = in.sval; - else - throw new IOException ("Illegal SERVICE NAME argument in file " + ServiceConfig.serviceConfigFile_); - - - if (!commandName.equals("load")) { - result.init(serviceName); - result.apply(); - in.whitespaceChars (' ', ' '); - state = ServiceConfig.SERVICE_NAME; - } else - state = ServiceConfig.CLASS_NAME; - break; - case ServiceConfig.CLASS_NAME: - if (in.ttype == StreamTokenizer.TT_WORD) - className = in.sval; - else - throw new IOException ("Illegal CLASS NAME argument in file " + ServiceConfig.serviceConfigFile_); - state = ServiceConfig.CLASS_TYPE; - break; - case ServiceConfig.CLASS_TYPE: - // This is only Service_Object or ServiceObject at this time - if (in.ttype == StreamTokenizer.TT_WORD) - classType = in.sval; - else - throw new IOException ("Illegal CLASS TYPE argument in file " + ServiceConfig.serviceConfigFile_); - state = ServiceConfig.ARGS; - // Set space to be an ordinary character to allow - // arguments to be parsed in - in.wordChars (' ', ' '); - break; - case ServiceConfig.ARGS: - ACE.DEBUG("Processing arguments"); - - args = new String(""); - - if (in.ttype == StreamTokenizer.TT_WORD) - { - args = in.sval; - - // If just two double quotes, there are no args - if (args.length() == 2) { - args = new String(""); - } else - args = args.substring(1, args.length() - 1); - } - - // Quick hack until more parsing necessary -- set the needed data - ((AddServiceObjectNode)result).init(serviceName, className, false); - ((AddServiceObjectNode)result).params(args); - - result.apply(); - - state = ServiceConfig.SERVICE_NAME; - // Set space back to whitespace-character to extract the - // next token - in.whitespaceChars (' ', ' '); - break; - default: - throw new IOException ("Illegal argument in file " + ServiceConfig.serviceConfigFile_); - } - } - return 0; - } - - - /** - * This is called when apply() is called on AddServiceObjectNodes. Similar - * methods could be developed for later data types (AddStreamNode, etc). This - * tries to load the ServiceObject and its classes. When trying to find info - * from the C++ files, this generates possible file paths. - */ - public static int initialize (AddServiceObjectNode son) - { - Class c = null; - - try { - - c = loader_.loadClass(son.locator(), true); - - } catch (ClassNotFoundException e) { - ACE.ERROR("Can't find class with locator: " + son.locator()); - return -1; - } - - try { - - Object service = c.newInstance(); - // Can't cast this to a ServiceObject, even though it will look just - // like one -- Java puts things loaded with a non-standard class loader - // in their own name space. The ServiceObjectRecord is a wrapper that - // gets around this by using reflection. - ServiceObjectRecord svcObjRec = new ServiceObjectRecord(service, son.name()); - - // Split the argument array up into smaller pieces - String [] argArray = OS.createStringArray (son.params(), " "); - - // Initialize the service -- start it running - svcObjRec.init(argArray); - - // Put it in the service repository - svcRep_.insert((ServiceRecord)svcObjRec); - - } catch (IllegalAccessException e) { - ACE.ERROR("Error " + e); - return -1; - } catch (InstantiationException e) { - ACE.ERROR("Error " + e); - return -1; - } - - return 0; - } - - // Set by command line options - private static boolean beADaemon_ = false; - private static boolean debug_ = false; - private static boolean noDefaults_ = false; - - public static String serviceConfigFile_ = "svc.conf"; - - private static ServiceRepository svcRep_ = null; - private static ServiceLoader loader_ = null; - - // States for the state-machine used in parsing the config file - private final static int SERVICE_NAME = 0; - private final static int CLASS_NAME = 1; - private final static int CLASS_TYPE = 2; - private final static int ARGS = 3; - private final static int COMMAND_NAME = 4; - - -} - - - diff --git a/java/src/ServiceLoader.java b/java/src/ServiceLoader.java deleted file mode 100644 index 86f15dc57c9..00000000000 --- a/java/src/ServiceLoader.java +++ /dev/null @@ -1,260 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceLoader.java - * - * Implementation of a ClassLoader - * - *@author Prashant Jain, Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import java.util.*; -import java.net.*; -import JACE.OS.*; -import JACE.Misc.*; - -public class ServiceLoader extends ClassLoader -{ - /** - * Constructor - */ - public ServiceLoader () - { - super (); - this.getClassPath (); - } - - /** - * Searches the class path for a given file - * - *@param filename File name to look for - *@return Returns the absolute path to the file - * (useful for package name) - */ - public String findFileInClasspath (String filename) - { - // Checks for the given name across the classpath - StringTokenizer tokens = new StringTokenizer (this.classPath_, - this.pathSeparator_); - - while (tokens.hasMoreTokens()) - { - String fn = tokens.nextToken() + this.fileSeparator_ + filename; - - File f = new File (fn); - - if (f.exists() && f.isFile() && f.canRead()) - return new String(f.getAbsolutePath()); - } - - return null; - } - - /** - * Load a class from across the network - *@exception ClassNotFoundException Couldn't find the class - */ - public Class loadClass (URL url, boolean resolve) throws ClassNotFoundException - { - Class newClass = null; - - // Extract the name of the class from the URL - - String className = url.getFile(); - - // Remove any directory information - int idx = className.lastIndexOf("/"); - if (idx != -1) - className = className.substring(idx + 1); - - // Get rid of the class suffix - idx = className.lastIndexOf(".class"); - if (idx != -1) - className = className.substring(0, idx); - - ACE.DEBUG("The name of the class about to load is " + className); - - // Try to load it the class by reading in the bytes. - // Note that we are not catching ClassNotFoundException here - // since our caller will catch it. - try - { - URLConnection urlConnection = url.openConnection (); - - // Get the input stream associated with the URL connection and - // pipe it to a newly created DataInputStream - DataInputStream i = new DataInputStream (urlConnection.getInputStream ()); - - // Allocate a buffer big enough to hold the contents of the - // data we are about to read - byte [] buf = new byte [urlConnection.getContentLength ()]; - - // Now read all the data into the buffer - i.readFully (buf); - - newClass = defineClass (className, buf, 0, buf.length); - // ACE.DEBUG ("Loaded class: "+ name); - - // Check if we need to load other classes referred to by this class. - if (resolve) - resolveClass (newClass); - } - catch (IOException e) - { - throw new ClassNotFoundException (e.toString ()); - } - return newClass; - } - - - /** - * Load a class file: - * - * @param fn A file name WITHOUT the .class extension - * @param resolve Standard resolve flag -- user should set to true - * - * @return A Class file capable of creating quasi-useful instances - * of the loaded class. They can't exist in the normal - * Java space, though, so it's impossible to cast them - * to something useful. Use a wrapper and reflection - * as in ServiceRecords. - *@exception ClassNotFoundException Couldn't find the class - */ - public Class loadClass (String fn, boolean resolve) throws ClassNotFoundException - { - Class newClass; - - // Load built-in java classes with the system loader - if (fn.startsWith("java")) { - newClass = findSystemClass(fn); - if (newClass == null) - throw (new ClassNotFoundException()); - else - return newClass; - } - - // If given a dot separated qualified name, put it in OS path format. - // This assumes the file separator is one char - String str = new String(fn); - if (str.indexOf('.') >= 0) - str = str.replace('.', this.fileSeparator_.charAt(0)); - str = str + ".class"; - - // Search the class path for the given file name - String fullname = this.findFileInClasspath(str); - if (fullname == null) { - - // If we can't find the class file, see if the - // system can - if ((newClass = findSystemClass(fn)) != null) { - return newClass; - } else - throw (new ClassNotFoundException()); - } - - try - { - // Try to load it the class by reading in the bytes. - // Note that we are not catching ClassNotFoundException here - // since our caller will catch it. - try - { - byte[] buf = bytesForClass (fullname); - - // ***** Note ***** - // This looks inside the class file and digs up the true - // fully qualified class name. You need this to - // load the class! - String className = ClassReader.getClassName(fullname); - - if (className != null) { - ACE.DEBUG("Defining class with name: " + className); - newClass = defineClass (className, buf, 0, buf.length); - } else { - // Try it anyway - newClass = defineClass (null, buf, 0, buf.length); - - ACE.ERROR("Unknown class name"); - } - - // Check if we need to load other classes referred to by this class. - if (resolve) - resolveClass (newClass); - - } catch (ClassNotFoundException e) { - - ACE.DEBUG ("Using default loader for class: " + fn); - - if ((newClass = findSystemClass (fn)) != null) - return newClass; - else - throw (e); // Rethrow the exception - } - } - catch (IOException e) - { - throw new ClassNotFoundException (e.toString ()); - } - - return newClass; - } - - /** - * Get system properties for later use - */ - private void getClassPath () - { - // Cache system properties that are needed when trying to find a - // class file - this.classPath_ = System.getProperty ("java.class.path", "."); - this.pathSeparator_ = System.getProperty ("path.separator", ":"); - this.fileSeparator_ = System.getProperty ("file.separator", "/"); - } - - /** - * Read file into a byte array - */ - private byte[] bytesForClass (String name) throws IOException, ClassNotFoundException - { - // Set up the stream - FileInputStream in = new FileInputStream (name); - - // Get byte count - int length = in.available (); - - if (length == 0) - throw new ClassNotFoundException (name); - - // Create an array of bytes to read the file in - byte[] buf = new byte[length]; - - // Read the file - in.read (buf); - - // Return byte array - return buf; - } - - private String classPath_; - // Class path that is loaded at construction - - private String pathSeparator_; - // Platform-dependent path separator (e.g., : or ;) - - private String fileSeparator_; - // Platform-dependent file separator (e.g., / or \) - - private String context_ = null; -} - - - - - - diff --git a/java/src/ServiceObject.java b/java/src/ServiceObject.java deleted file mode 100644 index 1c420c08f3b..00000000000 --- a/java/src/ServiceObject.java +++ /dev/null @@ -1,80 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceObject.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import JACE.ASX.*; -import JACE.Reactor.*; - -public class ServiceObject implements EventHandler -{ - /** - * Initialize object when dynamic loading occurs. Overwrite this - * method to do anything useful. - *@return -1 (default implementation) - */ - public int init (String [] args) - { - return -1; - } - - /** - * Terminate the object. Note that an object can not be explicitly - * unloaded. Overwrite this method to do anything useful. - *@return -1 (default implementation) - */ - public int fini () - { - return -1; - } - - /** - * Get information on an active object. Overwrite this method to do - * anything useful. - *@return null (default implementation) - */ - public String info () - { - return null; - } - - /** - * Called when timer expires. Overwrite this method to do - * anything useful. - *@param tv Time Value for which timer was set - *@param obj An arbitrary object that was passed to the Timer Queue - * (Asynchronous Completion Token) - *@return -1 - */ - public int handleTimeout (TimeValue tv, Object obj) - { - return -1; - } - - /** - * Request that this service suspend activity. Overwrite this - * method to do anything useful. - */ - public int suspend () - { - return -1; - } - - /** - * Request that this service resume activity. Overwrite this - * method to do anything useful. - */ - public int resume () - { - return -1; - } -} diff --git a/java/src/ServiceObjectRecord.java b/java/src/ServiceObjectRecord.java deleted file mode 100644 index 282d4360fbf..00000000000 --- a/java/src/ServiceObjectRecord.java +++ /dev/null @@ -1,33 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceObjectRecord.java - * - * Provided to show future symmetry. ServiceRecord currently - * provides all the desired behavior necessary for a record - * of a ServiceObject, but later there could be ModuleRecords, - * etc. - * - *@see JACE.ServiceConfigurator.ServiceRecord; - * - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -public class ServiceObjectRecord extends ServiceRecord -{ - public ServiceObjectRecord (Object so, String name) - { - super (so, name); - } - -}; - - - - - diff --git a/java/src/ServiceRecord.java b/java/src/ServiceRecord.java deleted file mode 100644 index e0bd75a1405..00000000000 --- a/java/src/ServiceRecord.java +++ /dev/null @@ -1,253 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceRecord.java - * - * This class structure is used in the ServiceRepository. Each service - * object, module, or stream in the repository should be wrapped by a - * type of ServiceRecord. The contained object does the real work. - * - * Modules and Streams will require records with more functionality. - * - * The caller should never be allowed to access the Object within the - * record -- casting will result in a ClassCastException because of - * the problem with loading classes with a ClassLoader. To get - * around this, all the method calls are made on the Object via - * reflection. - * - *@see JACE.ServiceConfigurator.ServiceObject - *@see JACE.ServiceConfigurator.ServiceRepository - * - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import java.lang.reflect.*; -import JACE.OS.*; - -public class ServiceRecord -{ - /** - * Constructor - * - *@param service A java Object, the service - *@param name Name of this service - */ - ServiceRecord (Object service, String name) - { - this.service_ = service; - this.name_ = name; - this.suspended_ = false; - } - - /** - * Forward the call to suspend - * @return -1 error - */ - public int suspend() - { - this.setSuspend(true); - - Object result = this.invokeSimpleReflected("suspend"); - - if (result == null) - return -1; - else - return ((Integer)result).intValue(); - } - - - /** - * Forward the call to resume - * @return -1 error - */ - public int resume() - { - this.setSuspend(false); - - Object result = this.invokeSimpleReflected("resume"); - - if (result == null) - return -1; - else - return ((Integer)result).intValue(); - } - - - /** - * Initialize the service, provide the given command line args to it. - * - */ - public int init(String [] args) - { - Class types[] = new Class[1]; - if (args == null) - args = new String[0]; - - types[0] = args.getClass(); - - // Find the method we want to call - Method m; - try { - m = this.object().getClass().getMethod("init", types); - } catch (NoSuchMethodException e) { - ACE.ERROR("" + e); - return -1; - } catch (SecurityException e) { - ACE.ERROR("" + e); - return -1; - } - - Class ptypes[] = m.getParameterTypes(); - //for (int x = 0; x < ptypes.length; x++) - // System.err.println(ptypes[x].getName()); - Object params[] = new Object[1]; - - params[0] = args; - - int result = -1; - try { - result = ((Integer)m.invoke(this.object(), params)).intValue(); - } catch (IllegalAccessException e) { - ACE.ERROR("" + e); - return -1; - } catch (IllegalArgumentException e) { - ACE.ERROR("" + e); - return -1; - } catch (InvocationTargetException e) { - ACE.ERROR("init(): " + e.getTargetException()); - return -1; - } - - return result; - } - - /** - * Prepare to close it - */ - public int fini() - { - Object result = this.invokeSimpleReflected("fini"); - - if (result == null) - return -1; - else - return ((Integer)result).intValue(); - } - - /** - * Obtain information about this service - */ - public String info() - { - Object result = this.invokeSimpleReflected("info"); - - if (result == null) - return null; - else - return new String((String)result); - } - - /** Invokes the method with the given name on the ServiceObject. - * The invoked method must take no parameters for this to work. - * Could be adjusted to throw a generic exception. - */ - private Object invokeSimpleReflected(String name) - { - Method m; - - // find the desired method - try { - m = this.object().getClass().getMethod(name, null); - } catch (NoSuchMethodException e) { - ACE.ERROR("" + e); - return null; - } catch (SecurityException e) { - ACE.ERROR("" + e); - return null; - } - - // Invoke it - Object result = null; - - try { - result = m.invoke(this.object(), null); - } catch (IllegalAccessException e) { - ACE.ERROR("" + e); - } catch (IllegalArgumentException e) { - ACE.ERROR("" + e); - } catch (InvocationTargetException e) { - ACE.ERROR(name + "(): " + e.getTargetException()); - } - - return result; - } - - /** - * Accessor for the name - */ - public String name() - { - return new String(this.name_); - } - - /** Set the name of the service - */ - public void name(String name) - { - this.name_ = name; - } - - /** Is this service suspended? - */ - public boolean suspended() - { - return this.suspended_; - } - - /** Set the suspended flag - */ - void setSuspend (boolean suspended) - { - this.suspended_ = suspended; - } - - /** Accessor for the contained Object. This should - * never be available to the end user since they - * might try casting the result. - */ - Object object() - { - return this.service_; - } - - /** - * Set the contained object - */ - void object(Object service) - { - this.service_ = service; - } - - Object service_; - String name_; - boolean suspended_; -}; - - -/* -class ModuleRecord extends ServiceRecord -{ -}; - -class StreamRecord extends ServiceRecord -{ -}; -*/ - - diff --git a/java/src/ServiceRepository.java b/java/src/ServiceRepository.java deleted file mode 100644 index 4190646d213..00000000000 --- a/java/src/ServiceRepository.java +++ /dev/null @@ -1,189 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceRepository.java - * - * The service repository stores the network services, allowing them to be removed, suspended, - * resumed, etc. To reload a service, ServiceConfig.prepareForReload() must be called. This is - * already done in the ServiceConfig.remove method. - * - *@see JACE.ServiceConfigurator.ServiceRecord; - *@see JACE.ServiceConfigurator.ServiceConfig; - * - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import java.util.*; - -public class ServiceRepository -{ - /** - * Constructor - */ - public ServiceRepository () - { - this.serviceVector_ = new Vector(); - } - - /** - * Constructor - * - *@param initialSize Initial vector size for the repository - */ - public ServiceRepository (int initialSize) - { - this.serviceVector_ = new Vector (initialSize); - } - - /** - * Shut down all the services, closing them in reverse order of insertion - * - * Maybe should be called by finalize? - */ - public int close() - { - for (int i = this.size() - 1; i >= 0; i--) { - ServiceRecord rec = (ServiceRecord)this.serviceVector_.elementAt(i); - - rec.fini(); - - this.serviceVector_.removeElementAt(i); - } - - return 0; - } - - /** - * Insert a ServiceRecord into the repository. - * (If already in, calls fini() and replaces) - * - *@param srvRec ServiceRecord to add - */ - public void insert (ServiceRecord srvRec) - { - ServiceRecord alreadyIn = find(srvRec.name()); - - // Replace the service - if (alreadyIn != null) { - alreadyIn.fini(); - this.serviceVector_.removeElement(alreadyIn); - } - - this.serviceVector_.addElement(srvRec); - } - - /** - * Finds the ServiceRecord associated with a given - * service name. Note -- the user should not try to - * get a ServiceObject out of the ServiceRecord. - * Same as saying ignoreSuspended is false on the - * next method. - * - *@param name Name of the service to find - */ - public ServiceRecord find (String name) - { - return this.find(name, false); - } - - /** Return the service record for the given service. The caller - * should NOT try to access a ServiceObject (or Module or Stream) - * by taking it out of the ServiceRecord -- just make the calls - * through the record! - * - *@param name Name of the service to find - *@param ignoreSuspended Allow finding suspended services? - */ - public ServiceRecord find (String name, boolean ignoreSuspended) - { - ServiceRecord rec; - - for (int i = 0; i < this.size(); i++) { - rec = (ServiceRecord)this.serviceVector_.elementAt(i); - - if ((rec.name().equals(name)) && ((!ignoreSuspended) || (!rec.suspended()))) - return rec; - } - - return null; - } - - /** Take the given service out of the repository. This also sets the - * reference in the repository to null to ensure there are no - * hidden references to the old ServiceObject. To reload, the - * ServiceConfig.prepareToReload method must be called. This is already - * done in the ServiceConfig.remove method. - */ - public int remove (String name) - { - ServiceRecord rec = this.find(name, false); - - if (rec == null) - return -1; - - int index = this.serviceVector_.indexOf(rec); - - // Shut down the service - rec.fini(); - - // Make sure there are no hidden references left - this.serviceVector_.setElementAt(null, index); - - this.serviceVector_.removeElementAt(index); - - return 0; - } - - /** - * Resume a suspended service - *@param name Name of the service to resume - */ - public int resume (String name) - { - ServiceRecord rec = this.find(name, false); - - if (rec == null) - return -1; - - return rec.resume(); - } - - /** - * Suspend a service - *@param name Name of the service to suspend - */ - public int suspend (String name) - { - ServiceRecord rec = this.find(name, true); - - if (rec == null) - return -1; - - return rec.suspend(); - } - - /** - * Returns the number of items in the repository - */ - public int size () - { - return this.serviceVector_.size(); - } - - // Vector representation - Vector serviceVector_; -}; - - - - - - - - diff --git a/java/src/StrategyAcceptor.java b/java/src/StrategyAcceptor.java deleted file mode 100644 index d73c7b93006..00000000000 --- a/java/src/StrategyAcceptor.java +++ /dev/null @@ -1,156 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * StrategyAcceptor.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.OS.*; -import JACE.SOCK_SAP.*; - -public class StrategyAcceptor -{ - /** - * Create an instance of StrategyAcceptor. - *@param handlerFactory Svc Handler factory that is used to create - * an instance of a Svc Handler when a connection is accepted. - */ - public StrategyAcceptor (Class handlerFactory) - { - this (handlerFactory, null, null, null); - } - - /** - * Create an instance of StrategyAcceptor. Use the creation - * strategy and the handlerFactory passed in to creae a new instance - * of the Svc Handler. - *@param handlerFactory Svc Handler factory that is used to create - * an instance of a Svc Handler when a connection is accepted. - *@param creStrategy Creation strategy to use to create a new - * instance of the Svc Handler. - *@param acceptStrategy Accept strategy to use to accept a new - * connection into the Svc Handler. - *@param activateStrategy Activate strategy to use to activate the - * instance of the Svc Handler. - */ - public StrategyAcceptor (Class handlerFactory, - CreationStrategy creStrategy, - AcceptStrategy acceptStrategy, - ActivateStrategy activateStrategy) - { - // Cache everything - this.handlerFactory_ = handlerFactory; - this.creStrategy_ = creStrategy; - this.acceptStrategy_ = acceptStrategy; - this.activateStrategy_ = activateStrategy; - } - - /** - * Initialize the Strategy Acceptor. The method creates the - * appropriate strategies as needed. - *@param port port number where the server will listen for connections - *@exception IOException Socket level error - */ - public void open (int port) throws IOException - { - if (this.creStrategy_ == null) - this.creStrategy_ = new CreationStrategy (this.handlerFactory_); - if (this.acceptStrategy_ == null) - this.acceptStrategy_ = new AcceptStrategy (port); - else - this.acceptStrategy_.open (port); - if (this.activateStrategy_ == null) - this.activateStrategy_ = new ActivateStrategy (); - } - - /** - * Accept a connection using the appropriate strategies. - * - *@exception SocketException Socket level error - *@exception InstantiationException Problem creating a handler - *@exception IllegalAccessException No strategy available - *@exception IOException Socket level error - */ - public void accept () throws SocketException, - InstantiationException, - IllegalAccessException, - IOException - { - // Create a Svc_Handler using the appropriate Creation_Strategy - SvcHandler sh = this.makeSvcHandler (); - - // Accept a connection into the Svc_Handler - this.acceptSvcHandler (sh); - - // Activate the Svc_Handler - this.activateSvcHandler (sh); - } - - /** - * Bridge method for creating a SvcHandler. The strategy for - * creating a SvcHandler is configured into the Acceptor via it's - * creStrategy_. If no strategy is passed in, the default behavior - * of this method is to use the default CreationStrategy. - *@return a new instance of the Svc Handler - *@exception InstantiationException Couldn't create SvcHandler - *@exception IllegalAccessException No strategy available - */ - protected SvcHandler makeSvcHandler () throws InstantiationException, IllegalAccessException - { - // Create a new handler for the connection - return this.creStrategy_.makeSvcHandler (); - } - - - /** - * Bridge method for accepting the new connection into the - * <SvcHandler>. The strategy for accepting into a SvcHandler is - * configured into the Acceptor via it's acceptStrategy_. If no - * strategy is passed in, the default behavior of this method is to - * use the default AcceptStrategy. - *@param sh Svc Handler in which to accept the connection - *@return result of accepting a connection using the accept strategy - *@exception SocketException Socket level error - *@exception IOException Socket level error - */ - protected int acceptSvcHandler (SvcHandler sh) throws SocketException, IOException - { - // Delegate responsibility to the appropriate strategy - return this.acceptStrategy_.acceptSvcHandler (sh); - } - - /** - * Bridge method for activating a <SvcHandler>. The strategy for - * activating a SvcHandler is configured into the Acceptor via it's - * activateStrategy_. If no strategy is passed in, the default - * behavior of this method is to use the default ActivateStrategy. - *@param sh Svc Handler to activate - *@return result of activating the Svc Handler - */ - protected int activateSvcHandler (SvcHandler sh) - { - // Delegate responsibility to the appropriate strategy - return this.activateStrategy_.activateSvcHandler (sh); - } - - // Handler class that should be instantiated when a connection is - // made with a client - private Class handlerFactory_; - - // Creation Strategy - private CreationStrategy creStrategy_; - - // Accept Strategy - private AcceptStrategy acceptStrategy_; - - // Activation Strategy - private ActivateStrategy activateStrategy_; -} diff --git a/java/src/Stream.java b/java/src/Stream.java deleted file mode 100644 index 030114d092f..00000000000 --- a/java/src/Stream.java +++ /dev/null @@ -1,438 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * Stream.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * This class is the primary abstraction for the ASX framework. - * It is moduled after System V Stream. - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * A Stream consists of a stack of <Modules>, each of which - * contains two <Tasks>. - *</blockquote> - */ - -public class Stream -{ - - public Stream () - { - this (null, null, null); - } - - // Create a Stream consisting of <head> and <tail> as the Stream - // head and Stream tail, respectively. If these are 0 then the - // <ACE_Stream_Head> and <ACE_Stream_Tail> are used, respectively. - // <arg> is the value past in to the open() methods of the tasks. - - public Stream (Object a, - Module head, - Module tail) - { - this.linkedUs_ = null; - // this.final_close_ = this.lock_; - - if (this.open (a, head, tail) == -1) - ACE.ERROR ("open" + head.name () + " " + tail.name ()); - } - - public int push (Module newTop) - { - if (this.pushModule (newTop, - this.streamHead_.next (), - this.streamHead_) == -1) - return -1; - else - return 0; - } - - public int put (MessageBlock mb, TimeValue tv) - { - return this.streamHead_.writer ().put (mb, tv); - } - - public MessageBlock get (TimeValue tv) throws InterruptedException - { - return this.streamHead_.reader ().getq (tv); - } - -// Return the "top" ACE_Module in a ACE_Stream, skipping over the -// stream_head. - - public Module top () - { - if (this.streamHead_.next () == this.streamTail_) - return null; - else - return this.streamHead_.next (); - } - -// Remove the "top" ACE_Module in a ACE_Stream, skipping over the -// stream_head. - - public int pop (long flags) - { - if (this.streamHead_.next () == this.streamTail_) - return -1; - else - { - // Skip over the ACE_Stream head. - Module top = this.streamHead_.next (); - Module newTop = top.next (); - - this.streamHead_.next (newTop); - - // Close the top ACE_Module. - - top.close (flags); - - this.streamHead_.writer ().next (newTop.writer ()); - newTop.reader ().next (this.streamHead_.reader ()); - - return 0; - } - } - -// Remove a named ACE_Module from an arbitrary place in the -// ACE_Stream. - - public int remove (String name, long flags) - { - Module prev = null; - - for (Module mod = this.streamHead_; - mod != null; mod = mod.next ()) - if (name.compareTo (mod.name ()) == 0) - { - if (prev == null) // Deleting ACE_Stream Head - this.streamHead_.link (mod.next ()); - else - prev.link (mod.next ()); - - mod.close (flags); - return 0; - } - else - prev = mod; - - return -1; - } - - public Module find (String name) - { - for (Module mod = this.streamHead_; - mod != null; - mod = mod.next ()) - if (name.compareTo (mod.name ()) == 0) - return mod; - - return null; - } - -// Actually push a module onto the stack... - - private int pushModule (Module newTop, - Module currentTop, - Module head) - { - Task ntReader = newTop.reader (); - Task ntWriter = newTop.writer (); - Task ctReader = null; - Task ctWriter = null; - - if (currentTop != null) - { - ctReader = currentTop.reader (); - ctWriter = currentTop.writer (); - ctReader.next (ntReader); - } - - ntWriter.next (ctWriter); - - if (head != null) - { - if (head != newTop) - head.link (newTop); - } - else - ntReader.next (null); - - newTop.next (currentTop); - - if (ntReader.open (newTop.arg ()) == -1) - return -1; - - if (ntWriter.open (newTop.arg ()) == -1) - return -1; - return 0; - } - - public synchronized int open (Object a, - Module head, - Module tail) - { - Task h1 = null, h2 = null; - Task t1 = null, t2 = null; - - if (head == null) - { - h1 = new StreamHead (); - h2 = new StreamHead (); - head = new Module ("ACEStreamHead", h1, h2, a); - } - - if (tail == null) - { - t1 = new StreamTail (); - t2 = new StreamTail (); - tail = new Module ("ACEStreamTail", - t1, t2, a); - } - - // Make sure *all* the allocation succeeded! - if (h1 == null || h2 == null || head == null - || t1 == null || t2 == null || tail == null) - { - // Close up! - head.close (0); - tail.close (0); - return -1; - } - - this.streamHead_ = head; - this.streamTail_ = tail; - - if (this.pushModule (this.streamTail_, - null, null) == -1) - return -1; - else if (this.pushModule (this.streamHead_, - this.streamTail_, - this.streamHead_) == -1) - return -1; - else - return 0; - } - - public synchronized int close (long flags) - { - if (this.streamHead_ != null - && this.streamTail_ != null) - { - // Don't bother checking return value here. - this.unlinkInternal (); - - int result = 0; - - // Remove and cleanup all the intermediate modules. - - while (this.streamHead_.next () != this.streamTail_) - { - if (this.pop (flags) == -1) - result = -1; - } - - // Clean up the head and tail of the stream. - if (this.streamHead_.close (flags) == -1) - result = -1; - if (this.streamTail_.close (flags) == -1) - result = -1; - - this.streamHead_ = null; - this.streamTail_ = null; - - // Tell all threads waiting on the close that we are done. - // this.final_close_.broadcast (); - return result; - } - return 0; - } - - public int control (int cmd, Object a) throws InterruptedException - { - IOCntlMsg ioc = new IOCntlMsg (cmd); - - // Create a data block that contains the user-supplied data. - MessageBlock db = - new MessageBlock (MessageType.MB_IOCTL, - null, - a); - - // Create a control block that contains the control field and a - // pointer to the data block. - MessageBlock cb = - new MessageBlock (MessageType.MB_IOCTL, - db, - (Object) ioc); - - int result = 0; - - if (this.streamHead_.writer ().put (cb, new TimeValue ()) == -1) - result = -1; - else if ((cb = this.streamHead_.reader ().getq (new TimeValue ())) == null) - result = -1; - else - result = ((IOCntlMsg ) cb.obj ()).rval (); - - return result; - } - -// Link two streams together at their bottom-most Modules (i.e., the -// one just above the Stream tail). Note that all of this is premised -// on the fact that the Stream head and Stream tail are non-NULL... -// This must be called with locks held. - - private int linkInternal (Stream us) - { - this.linkedUs_ = us; - // Make sure the other side is also linked to us! - us.linkedUs_ = this; - - Module myTail = this.streamHead_; - - if (myTail == null) - return -1; - - // Locate the module just above our Stream tail. - while (myTail.next () != this.streamTail_) - myTail = myTail.next (); - - Module otherTail = us.streamHead_; - - if (otherTail == null) - return -1; - - // Locate the module just above the other Stream's tail. - while (otherTail.next () != us.streamTail_) - otherTail = otherTail.next (); - - // Reattach the pointers so that the two streams are linked! - myTail.writer ().next (otherTail.reader ()); - otherTail.writer ().next (myTail.reader ()); - return 0; - } - - public synchronized int link (Stream us) - { - return this.linkInternal (us); - } - -// Must be called with locks held... - - private int unlinkInternal () - { - // Only try to unlink if we are in fact still linked! - - if (this.linkedUs_ != null) - { - Module myTail = this.streamHead_; - - // Only relink if we still exist! - if (myTail != null) - { - // Find the module that's just before our stream tail. - while (myTail.next () != this.streamTail_) - myTail = myTail.next (); - - // Restore the writer's next() link to our tail. - myTail.writer ().next (this.streamTail_.writer ()); - } - - Module otherTail = this.linkedUs_.streamHead_; - - // Only fiddle with the other side if it in fact still remains. - if (otherTail != null) - { - while (otherTail.next () != this.linkedUs_.streamTail_) - otherTail = otherTail.next (); - - otherTail.writer ().next (this.linkedUs_.streamTail_.writer ()); - - } - - // Make sure the other side is also aware that it's been unlinked! - this.linkedUs_.linkedUs_ = null; - - this.linkedUs_ = null; - return 0; - } - else - return -1; - } - - public synchronized int unlink () - { - return this.unlinkInternal (); - } - - public void dump () - { - ACE.DEBUG ("-------- module links --------"); - - for (Module mp = this.streamHead_; ; mp = mp.next ()) - { - ACE.DEBUG ("module name = " + mp.name ()); - if (mp == this.streamTail_) - break; - } - - ACE.DEBUG ("-------- writer links --------"); - - Task tp; - - for (tp = this.streamHead_.writer (); ; tp = tp.next ()) - { - ACE.DEBUG ("writer queue name = " + tp.name ()); - tp.dump (); - ACE.DEBUG ("-------\n"); - if (tp == this.streamTail_.writer () - || (this.linkedUs_ != null && tp == this.linkedUs_.streamHead_.reader ())) - break; - } - - ACE.DEBUG ("-------- reader links --------\n"); - for (tp = this.streamTail_.reader (); ; tp = tp.next ()) - { - ACE.DEBUG ("reader queue name = " + tp.name ()); - tp.dump (); - ACE.DEBUG ("-------\n"); - if (tp == this.streamHead_.reader () - || (this.linkedUs_ != null && tp == this.linkedUs_.streamHead_.writer ())) - break; - } - } - - Module streamHead_ = null; - // Pointer to the head of the stream. - - Module streamTail_ = null; - // Pointer to the tail of the stream. - - Stream linkedUs_ = null; - // Pointer to an adjoining linked stream. - - // = Synchronization objects used for thread-safe streams. - // ACE_SYNCH_MUTEX lock_; - // Protect the stream against race conditions. - - // ACE_SYNCH_CONDITION final_close_; - // Use to tell all threads waiting on the close that we are done. - -} - - diff --git a/java/src/StreamHead.java b/java/src/StreamHead.java deleted file mode 100644 index 37d9c2af0c3..00000000000 --- a/java/src/StreamHead.java +++ /dev/null @@ -1,120 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * StreamHead.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Standard module that acts as the head of a ustream. - *</blockquote> - */ - -public class StreamHead extends Task -{ - // Module that acts as the head of a Stream. - - public int open (Object obj) - { - return 0; - } - - public int close (long l) - { - return 0; - } - - public int svc () - { - return -1; - } - - private int control (MessageBlock mb) - { - - IOCntlMsg ioc = (IOCntlMsg) mb.obj (); - int cmd = ioc.cmd (); - - switch (cmd) - { - case IOCntlCmds.SET_LWM: - case IOCntlCmds.SET_HWM: - this.waterMarks (cmd, mb.cont ().length ()); - ioc.rval (0); - break; - default: - return 0; - } - return ioc.rval (); - } - - /* Performs canonical flushing at the ACE_Stream Head */ - - private int canonicalFlush (MessageBlock mb) - { - String s = mb.base (); - long f = (new Long (s)).longValue (); - - if ((f & TaskFlags.ACE_FLUSHR) != 0) - { - this.flush (TaskFlags.ACE_FLUSHALL); - f &= ~TaskFlags.ACE_FLUSHR; - } - if ((f & TaskFlags.ACE_FLUSHW) != 0) - return this.reply (mb, new TimeValue ()); - return 0; - } - - public int put (MessageBlock mb, TimeValue tv) - { - int res = 0; - if (mb.msgType () == MessageType.MB_IOCTL - && (res = this.control (mb)) == -1) - return res; - - if (this.isWriter ()) - { - return this.putNext (mb, tv); - } - else /* this.isReader () */ - { - switch (mb.msgType ()) - { - case MessageType.MB_FLUSH: - return this.canonicalFlush (mb); - default: - break; - } - - try - { - return this.putq (mb, tv); - } - catch (InterruptedException e) - { - return -1; - } - } - } - - public void dump () - { - } - - public int handleTimeout (TimeValue tv, Object obj) - { - return 0; - } - -} diff --git a/java/src/StreamTail.java b/java/src/StreamTail.java deleted file mode 100644 index 44f9dde6634..00000000000 --- a/java/src/StreamTail.java +++ /dev/null @@ -1,111 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * StreamTail.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Standard module that acts as the tail of a ustream. - *</blockquote> - */ - -public class StreamTail extends Task -{ - // Module that acts as the tail of a Stream. - - public int open (Object obj) - { - return 0; - } - - public int close (long l) - { - return 0; - } - - public int svc () - { - return -1; - } - - private int control (MessageBlock mb) - { - IOCntlMsg ioc = (IOCntlMsg) mb.obj (); - int cmd = ioc.cmd (); - - switch (cmd) - { - case IOCntlCmds.SET_LWM: - case IOCntlCmds.SET_HWM: - { - int size = mb.cont ().length (); - - this.waterMarks (cmd, size); - this.sibling ().waterMarks (cmd, size); - ioc.rval (0); - break; - } - default: - mb.msgType (MessageType.MB_IOCNAK); - } - return this.reply (mb, new TimeValue ()); - } - - // Perform flush algorithm as though we were the driver - private int canonicalFlush (MessageBlock mb) - { - String s = mb.base (); - long f = (new Long (s)).longValue (); - - if ((f & TaskFlags.ACE_FLUSHW) != 0) - { - this.flush (TaskFlags.ACE_FLUSHALL); - f &= ~TaskFlags.ACE_FLUSHW; - } - if ((f & TaskFlags.ACE_FLUSHR) != 0) - { - this.sibling ().flush (TaskFlags.ACE_FLUSHALL); - return this.reply (mb, new TimeValue ()); - } - return 0; - } - - public int put (MessageBlock mb, TimeValue tv) - { - if (this.isWriter ()) - { - switch (mb.msgType ()) - { - case MessageType.MB_IOCTL: - return this.control (mb); - /* NOTREACHED */ - default: - break; - } - } - - return -1; - } - - public void dump () - { - } - - public int handleTimeout (TimeValue tv, Object obj) - { - return 0; - } - -} diff --git a/java/src/SuspendNode.java b/java/src/SuspendNode.java deleted file mode 100644 index 5b16a368458..00000000000 --- a/java/src/SuspendNode.java +++ /dev/null @@ -1,34 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * SuspendNode.java - * - * Used when a service is specified to be suspended based on a line - * in a service configurator file. The actual implementation of the - * service being suspended does the work. - * - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import JACE.OS.*; - -class SuspendNode extends ParseNode -{ - public SuspendNode () - { - } - - public void apply () - { - ACE.DEBUG("Suspend Node apply: " + this.name_); - - if (JACE.ServiceConfigurator.ServiceConfig.suspend(this.name_) == -1) - ACE.ERROR("Error suspending " + this.name_); - } -}; diff --git a/java/src/SvcHandler.java b/java/src/SvcHandler.java deleted file mode 100644 index cb9af5a3334..00000000000 --- a/java/src/SvcHandler.java +++ /dev/null @@ -1,85 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * SvcHandler.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.SOCK_SAP.*; -import JACE.ASX.*; -import JACE.Reactor.*; - -public abstract class SvcHandler extends Task -{ - - /** - * Do nothing constructor. - */ - public SvcHandler () - { - } - - /** - * Set the stream using the SOCKStream passed in. This sets the - * underlying peer - *@param s SOCK Stream to use for the connection - */ - public void setHandle (SOCKStream s) throws IOException - { - this.stream_ = s; - } - - /** - * Get the underlying peer - *@return the underlying peer - */ - public SOCKStream peer () - { - return this.stream_; - } - - /** - * Abstract method that subclasses must define to allow - * initialization to take place. - */ - public abstract int open (Object obj); - - /** - * Provide a default implementation to simplify ancestors. - *@return 0 - */ - public int close (long flags) - { - return 0; - } - - /** - * Provide a default implementation to simplify ancestors. - *@return -1 - */ - public int put (MessageBlock mb, TimeValue tv) - { - return -1; - } - - /** - * Provide a default implementation to simplify ancestors. - *@param tv Time Value for which timer was set - *@param obj An arbitrary object that was passed to the Timer Queue - * (Asynchronous Completion Token) - */ - public int handleTimeout (TimeValue tv, Object obj) - { - return -1; - } - - protected SOCKStream stream_; -} diff --git a/java/src/Task.java b/java/src/Task.java deleted file mode 100644 index 24ed6a7eb07..00000000000 --- a/java/src/Task.java +++ /dev/null @@ -1,418 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * Task.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; -import JACE.Reactor.*; -import JACE.Concurrency.*; - -public abstract class Task implements Runnable, EventHandler -{ - // = Initialization/termination methods. - - /** - * Initialize a Task. Note, we allocate a message queue ourselves. - */ - public Task () - { - this.msgQueue_ = new MessageQueue (); - this.thrMgr_ = null; - } - - /** - * Initialize a Task. Note, we use the message queue and thread - * manager supplied by the user. - *@param mq Message Queue to hold list of messages on the Task - *@param thrMgr Thread Manager that manages all the spawned threads - */ - public Task (MessageQueue mq, - ThreadManager thrMgr) - { - this.msgQueue_ = mq; - this.thrMgr_ = thrMgr; - } - - /** - * Not meant to be invoked by the user directly!. This needs to be - * in the public interface in order to get invoked by Thread - * class. - */ - public void run () - { - this.svc (); - } - - // = Initialization and termination hooks (note that these *must* be - // defined by subclasses). - - /** - * Hook called to open a Task. - *@param obj used to pass arbitrary information - */ - public abstract int open (Object obj); - - /** - * Hook called to close a Task. - */ - public abstract int close (long flags); - - // = Immediate and deferred processing methods, respectively. - - /** - * Transfer a message into the queue to handle immediate - * processing. - *@param mb Message Block to handle immediately - *@param tv amount of time to wait for - */ - public abstract int put (MessageBlock mb, TimeValue tv); - - /** - * Run by a daemon thread to handle deferred processing. Note, that - * to do anything useful, this method should be overriden by the - * subclass. - *@return default implementation always returns 0. - */ - public int svc () - { - return 0; - } - - /** - * Set the underlying Thread Manager. - *@param t Thread Manager to use - */ - public synchronized void thrMgr (ThreadManager t) - { - this.thrMgr_ = t; - } - - /** - * Get the Thread Manager. - *@return Underlying Thread Manager - */ - public synchronized ThreadManager thrMgr () - { - return this.thrMgr_; - } - - // = Active object method. - - /** - * Turn the task into an active object. That is, having <nThreads> - * separate threads of control that all invoke Task::svc. - *@param flags Task Flags - *@param nThreads number of threads to spawn - *@param forceActive whether to force creation of new threads or not - *@return -1 if failure occurs, 1 if Task is already an active - * object and <forceActive> is false (doesn't *not* create a new - * thread in this case), and 0 if Task was not already an active - * object and a thread is created successfully or thread is an active - * object and <forceActive> is true. - */ - public synchronized int activate (long flags, int nThreads, boolean forceActive) - { - // Create a Thread Manager if we do not already have one - if (this.thrMgr_ == null) - this.thrMgr_ = new ThreadManager (); - - if (this.thrCount () > 0 && forceActive == false) - return 1; // Already active. - this.flags_ = flags; - - if (ACE.BIT_ENABLED (flags, TaskFlags.THR_DAEMON)) - this.thrMgr_.spawnN (nThreads, this, true); // Spawn off all threads as daemon threads - else // Spawn off all threads as normal threads - this.thrMgr_.spawnN (nThreads, this, false); - - return 0; - } - - // = Suspend/resume a Task - - /** - * Suspend a task. - */ - public synchronized void suspend () - { - // Suspend all threads - if (this.thrMgr_ != null) - this.thrMgr_.thrGrp ().suspend (); - } - - /** - * Resume a suspended task. - */ - public synchronized void resume () - { - // Resume all threads - if (this.thrMgr_ != null) - this.thrMgr_.thrGrp ().resume (); - } - - /** - * Get the current group name. - *@return name of the current thread group - */ - public synchronized String grpName () - { - if (this.thrMgr_ != null) - return this.thrMgr_.thrGrp ().getName (); - else - return null; - } - - /** - * Get the message queue associated with this task. - *@return the message queue associated with this task. - */ - public MessageQueue msgQueue () - { - return this.msgQueue_; - } - - /** - * Set the message queue associated with this task. - *@param mq Message Queue to use with this Task. - */ - public void msgQueue (MessageQueue mq) - { - this.msgQueue_ = mq; - } - - /** - * Get the number of threads currently running within the Task. - *@return the number of threads currently running within the Task. - * 0 if we're a passive object, else > 0. - */ - public synchronized int thrCount () - { - if (this.thrMgr_ != null) - return this.thrMgr_.thrGrp ().activeCount (); - else - return 0; - } - - /** - * Set the Task flags - *@param flags Task Flags - */ - public synchronized void flags (long flags) - { - this.flags_ = flags; - } - - /** - * Get the Task flags - *@return Task Flags - */ - public synchronized long flags () - { - return this.flags_; - } - - // = Message queue manipulation methods. - - - /* - * Dump debug information. - */ - public void dump () - { - } - - /** - * Insert message into the message queue. - *@param mb Message Block to insert into the Message Queue - *@param tv amount of time to wait for - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - protected int putq (MessageBlock mb, TimeValue tv) throws InterruptedException - { - return this.msgQueue_.enqueueTail (mb, tv); - } - - /** - * Extract the first message from the queue. Note that the call is blocking. - *@return the first Message Block from the Message Queue. - *@param tv amount of time to wait for - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - protected MessageBlock getq (TimeValue tv) throws InterruptedException - { - return this.msgQueue_.dequeueHead (tv); - } - - /** - * Return a message back to the queue. - *@param mb Message Block to return back to the Message Queue - *@param tv amount of time to wait for - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - protected int ungetq (MessageBlock mb, TimeValue tv) throws InterruptedException - { - return this.msgQueue_.enqueueHead (mb, tv); - } - - /** - * Transfer message to the adjacent ACETask in an ACEStream. - *@param mb Message Block to transfer to the adjacent Task - *@param tv amount of time to wait for - *@return -1 if there is no adjacent Task, else the return value of - * trying to put the Message Block on that Task's Message Queue. - */ - protected int putNext (MessageBlock mb, TimeValue tv) - { - return this.next_ == null ? -1 : this.next_.put (mb, tv); - } - - /** - * Turn the message back around. Puts the message in the sibling's - * Message Queue. - *@param mb Message Block to put into sibling's Message Queue - *@param tv amount of time to wait for - *@return -1 if there is no adjacent Task to the sibling, else the - * return value of trying to put the Message Block on sibling's - * Message Queue. - */ - protected int reply (MessageBlock mb, TimeValue tv) - { - return this.sibling ().putNext (mb, tv); - } - - // = ACE_Task utility routines to identify names et al. - - /** - * Get the name of the enclosing Module. - *@return the name of the enclosing Module if there's one associated - * with the Task, else null. - */ - protected String name () - { - if (this.mod_ == null) - return null; - else - return this.mod_.name (); - } - - /** - * Get the Task's sibling. - *@return the Task's sibling if there's one associated with the - * Task's Module, else null. - */ - protected Task sibling () - { - if (this.mod_ == null) - return null; - else - return this.mod_.sibling (this); - } - - /** - * Set the Task's module. - *@param mod the Task's Module. - */ - protected void module (Module mod) - { - this.mod_ = mod; - } - - /** - * Get the Task's module. - *@return the Task's Module if there is one, else null. - */ - protected Module module () - { - return this.mod_; - } - - /** - * Check if queue is a reader. - *@return true if queue is a reader, else false. - */ - protected boolean isReader () - { - return (ACE.BIT_ENABLED (this.flags_, TaskFlags.ACE_READER)); - } - - /** - * Check if queue is a writer. - *@return true if queue is a writer, else false. - */ - protected boolean isWriter () - { - return (ACE.BIT_DISABLED (this.flags_, TaskFlags.ACE_READER)); - } - - // = Pointers to next ACE_Queue (if ACE is part of an ACE_Stream). - - /** - * Get next Task pointer. - *@return pointer to the next Task - */ - protected Task next () - { - return this.next_; - } - - /** - * Set next Task pointer. - *@param task next task pointer - */ - protected void next (Task task) - { - this.next_ = task; - } - - // Special routines corresponding to certain message types. - - /** - * Flush the Message Queue - *@return 0 if Message Queue is null, 1 if flush succeeds, -1 if - * ACE_FLUSHALL bit is not enabled in flags. - */ - protected int flush (long flag) - { - if (ACE.BIT_ENABLED (flag, TaskFlags.ACE_FLUSHALL)) - return (this.msgQueue_ == null ? 0 : 1); - else - return -1; - } - - - /** - * Manipulate watermarks. - *@param cmd IOCntlCmd - *@param size watermark - */ - protected void waterMarks (int cmd, int size) - { - if (cmd == IOCntlCmds.SET_LWM) - this.msgQueue_.lowWaterMark (size); - else /* cmd == IOCntlMsg.SET_HWM */ - this.msgQueue_.highWaterMark (size); - } - - private ThreadManager thrMgr_ = null; - // Thread_Manager that manages all the spawned threads - - private long flags_; - // Task flags. - - private MessageQueue msgQueue_; - // List of messages on the Task.. - - private Task next_; - // Adjacent ACE_Task. - - private Module mod_; - // Back-pointer to the enclosing module. -} diff --git a/java/src/TaskFlags.java b/java/src/TaskFlags.java deleted file mode 100644 index 590e514b5e2..00000000000 --- a/java/src/TaskFlags.java +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * TaskFlags.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -public abstract class TaskFlags -{ - /** Identifies a Task as being the "reader" in a Module. */ - public static final int ACE_READER = 01; - - /** Just flush data messages in the queue. */ - public static final int ACE_FLUSHDATA = 02; - - /** Flush all messages in the Queue. */ - public static final int ACE_FLUSHALL = 04; - - /** Flush read queue */ - public static final int ACE_FLUSHR = 010; - - /** Flush write queue */ - public static final int ACE_FLUSHW = 020; - - /** Flush both queues */ - public static final int ACE_FLUSHRW = 030; - - /** Identifies a thread as suspended */ - public static final int THR_SUSPENDED = 0x00000080; - - /** Identifies a thread as a daemon thread */ - public static final int THR_DAEMON = 0x00000100; - - // Default private constructor to avoid instantiation - private TaskFlags () - { - } -} diff --git a/java/src/ThreadManager.java b/java/src/ThreadManager.java deleted file mode 100644 index 5043d26511e..00000000000 --- a/java/src/ThreadManager.java +++ /dev/null @@ -1,109 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * ThreadManager.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Concurrency; - -import java.util.*; -import JACE.OS.*; - -public class ThreadManager -{ - /** - * Default constructor - */ - public ThreadManager () - { - this (ACE.DEFAULT_THREAD_GROUP_NAME); - } - - /** - * Create a Thread Manager. - *@param groupName name of the thread group that the Thread Manager - * will manage - */ - public ThreadManager (String groupName) - { - this.thrGrp_ = new ThreadGroup (groupName); - if (this.thrGrp_ == null) - ACE.ERROR ("Thread group create failed"); - } - - /** - * Create a new thread. - *@param thr the caller whose run method will be invoked when the - * thread has been spawned - *@param daemon flag indicating whether the thread should be - * spawned off as a daemon thread - */ - public void spawn (Runnable thr, - boolean daemon) - { - Thread t = new Thread (this.thrGrp_, thr); - if (daemon) // Set the thread to be a daemon thread - t.setDaemon (true); - t.start (); - } - - /** - * Create a new thread and also give it a name. - *@param thr the caller whose run method will be invoked when the - * thread has been spawned - *@param threadName the name of the new thread - *@param daemon flag indicating whether the thread should be - * spawned off as a daemon thread - */ - public void spawn (Runnable thr, - String threadName, - boolean daemon) - { - Thread t = new Thread (this.thrGrp_, thr, threadName); - if (daemon) // Set the thread to be a daemon thread - t.setDaemon (true); - t.start (); - } - - - /** - * Create <n> new threads. - *@param n the number of threads to spawn - *@param thr the caller whose run method will be invoked by each of - * the <n> threads - *@param daemon flag indicating whether the threads should be - * spawned off as daemon threads - */ - public void spawnN (int n, - Runnable thr, - boolean daemon) - { - // Spawn off all the threads. - for (int i = 0; i < n; i++) - { - this.spawn (thr, daemon); - } - } - - /** - * Get the thread group containing all the threads. Note that the - * thread group can be used to get information regarding number of - * active threads as well as to suspend/resume all the threads in - * the group. - *@return the thread group that contains all the threads managed by - * the Thread Manager - */ - public ThreadGroup thrGrp () - { - return this.thrGrp_; - } - - private ThreadGroup thrGrp_; - // Thread Group that contains all the spawned threads - -} diff --git a/java/src/ThruTask.java b/java/src/ThruTask.java deleted file mode 100644 index aebc8eb1f48..00000000000 --- a/java/src/ThruTask.java +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * ThruTask.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Standard module that acts as a "no op", simply passing on all - * data to its adjacent neighbor. - *</blockquote> - */ -public class ThruTask extends Task -{ - public int open (Object obj) - { - return 0; - } - - public int close (long flags) - { - return 0; - } - - public int put (MessageBlock msg, TimeValue tv) - { - return this.putNext (msg, tv); - } - - public int svc () - { - return -1; - } - - public int handleTimeout (TimeValue tv, Object obj) - { - return 0; - } -} diff --git a/java/src/TimeValue.java b/java/src/TimeValue.java deleted file mode 100644 index 280f45ab0f1..00000000000 --- a/java/src/TimeValue.java +++ /dev/null @@ -1,256 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Reactor - * - * = FILENAME - * TimeValue.java - * - *@author Prashant Jain - * - *************************************************/ -//package JACE.Reactor; -package JACE.ASX; - -public class TimeValue -{ - public final static TimeValue zero = new TimeValue (0,0); - - /** - * Default constructor - */ - public TimeValue () - { - this (0, 0); - } - - /** - * Constructor - *@param sec seconds - */ - public TimeValue (long sec) - { - this (sec, 0); - } - - /** - * Constructor - *@param sec seconds - *@param nanos nanoseconds - */ - public TimeValue (long sec, int nanos) - { - this.set (sec, nanos); - } - - /** - * Sets the seconds and nanoseconds of Time Value - *@param sec seconds - *@param nanos nanoseconds - */ - public void set (long sec, int nanos) - { - this.millisec_ = sec * 1000; - this.nanos_ = nanos; - this.normalize (); - } - - /** - * Get seconds - *@return Seconds - */ - public long sec () - { - return this.millisec_/1000; - } - - /** - * Get nanoseconds - *@return Nanoseconds - */ - public int nanos () - { - return this.nanos_; - } - - /** - * Get time in milliseconds. - *@return time in milliseconds - */ - public long getMilliTime () - { - return this.millisec_; - } - - /** - * Get a String representation of the Time Value. - *@return String representation of the Time Value - */ - public String toString () - { - return (new Long (this.millisec_/1000)).toString () + ":" + - (new Integer (this.nanos_)).toString (); - } - - /** - * Get current time. - *@return the current system time - */ - public static TimeValue getTimeOfDay () - { - return new TimeValue (System.currentTimeMillis ()/1000); - } - - /** - * Compare two Time Values for equality. - *@param tv Time Value to compare with - *@return true if the two Time Values are equal, false otherwise - */ - public boolean equals (TimeValue tv) - { - return this.millisec_ == (tv.sec () * 1000) && this.nanos_ == tv.nanos (); - } - - /** - * Compare two Time Values for non-equality. - *@param tv Time Value to compare with - *@return true if the two Time Values are not equal, false otherwise - */ - public boolean notEquals (TimeValue tv) - { - return !this.equals (tv); - } - - /** - * Add two Time Values. - *@param tv1 The first Time Value - *@param tv2 The second Time Value - *@return sum of the two Time Values. - */ - public static TimeValue plus (TimeValue tv1, TimeValue tv2) - { - TimeValue tv = new TimeValue (tv1.sec () + tv2.sec (), - tv1.nanos () + tv2.nanos ()); - tv.normalize (); - return tv; - } - - /** - * Subtract two Time Values. - *@param tv1 The first Time Value - *@param tv2 The second Time Value - *@return difference of the two Time Values. - */ - public static TimeValue minus (TimeValue tv1, TimeValue tv2) - { - TimeValue tv = new TimeValue (tv1.sec () - tv2.sec (), - tv1.nanos () - tv2.nanos ()); - tv.normalize (); - return tv; - } - - /** - * Add Time Value to "this". - *@param tv The Time Value to add to this. - */ - public void plusEquals (TimeValue tv) - { - this.set (this.sec () + tv.sec (), - this.nanos () + tv.nanos ()); - this.normalize (); - } - - /** - * Subtract Time Value from "this". - *@param tv The Time Value to subtract from this. - */ - public void minusEquals (TimeValue tv) - { - this.set (this.sec () - tv.sec (), - this.nanos () - tv.nanos ()); - this.normalize (); - } - - /** - * Compare two Time Values for less than. - *@param tv Time Value to compare with - *@return true if "this" is less than tv, false otherwise - */ - public boolean lessThan (TimeValue tv) - { - return tv.greaterThan (this); - } - - /** - * Compare two Time Values for greater than. - *@param tv Time Value to compare with - *@return true if "this" is greater than tv, false otherwise - */ - public boolean greaterThan (TimeValue tv) - { - if (this.sec () > tv.sec ()) - return true; - else if (this.sec () == tv.sec () - && this.nanos () > tv.nanos ()) - return true; - else - return false; - } - - /** - * Compare two Time Values for <=. - *@param tv Time Value to compare with - *@return true if "this" <= tv, false otherwise - */ - public boolean lessThanEqual (TimeValue tv) - { - return tv.greaterThanEqual (this); - } - - /** - * Compare two Time Values for >=. - *@param tv Time Value to compare with - *@return true if "this" >= tv, false otherwise - */ - public boolean greaterThanEqual (TimeValue tv) - { - return this.sec () >= tv.sec () && this.nanos () >= tv.nanos (); - } - - private void normalize () - { - if (this.nanos_ >= ONE_MILLISECOND) - { - do - { - this.millisec_++; - this.nanos_ -= ONE_MILLISECOND; - } - while (this.nanos_ >= ONE_MILLISECOND); - } - else if (this.nanos_ <= -ONE_MILLISECOND) - { - do - { - this.millisec_--; - this.nanos_ += ONE_MILLISECOND; - } - while (this.nanos_ <= -ONE_MILLISECOND); - } - - if (this.millisec_ >= 1 && this.nanos_ < 0) - { - this.millisec_--; - this.nanos_ += ONE_MILLISECOND; - } - else if (this.millisec_ < 0 && this.nanos_ > 0) - { - this.millisec_++; - this.nanos_ -= ONE_MILLISECOND; - } - } - - private long millisec_; - private int nanos_; - private final static int ONE_MILLISECOND = 1000000; -} diff --git a/java/src/TimedWait.java b/java/src/TimedWait.java deleted file mode 100644 index e8402e96991..00000000000 --- a/java/src/TimedWait.java +++ /dev/null @@ -1,137 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * TimedWait.java - * - *@author Prashant Jain and Doug Schmidt - * - *************************************************/ -package JACE.ASX; - -public abstract class TimedWait -{ - /** - * Default Constructor. Sets "this" to be used for the delegation of - * the wait() call to. - */ - public TimedWait () - { - object_ = this; - } - - /** - * Constructor. Allows subclasses to supply us with an Object that - * is delegated the wait() call. - *@param obj The Object that is delegated the wait() call. - */ - public TimedWait (Object obj) - { - object_ = obj; - } - - /** - * Hook method that needs to be implemented by subclasses. - */ - public abstract boolean condition (); - - /** - * Wait until condition becomes true. Note that the method - * blocks. Also note that this method is final to ensure that no one - * overrides it. - * IMPORTANT: This method assumes it is called with the object_'s - * monitor lock already held. - *@exception InterruptedException Interrupted during wait - */ - public final void timedWait () throws InterruptedException - { - // Acquire the monitor lock. - if (!condition ()) - { - // Only attempt to perform the wait if the condition isn't - // true initially. - for (;;) - { - // Wait until we are notified. - object_.wait (); - - // Recheck the condition. - if (condition ()) - break; // Condition became true. - // else we were falsely notified so go back into wait - } - } - } - - /** - * Template Method that implements the actual timed wait. Note that - * this method is final to ensure that no one overrides it. - * IMPORTANT: This method assumes it is called with the object_'s - * monitor lock already held. - *@param tv Amount of time to do wait for. - *@exception java.lang.InterruptedException Interrupted during wait - *@exception JACE.ASX.TimeoutException Reached timeout specified - */ - public final void timedWait (TimeValue tv) - throws InterruptedException, - TimeoutException - { - // Acquire the monitor lock. - if (!condition ()) - { - // Only attempt to perform the timed wait if the condition isn't - // true initially. - long start = System.currentTimeMillis (); - long waitTime = tv.getMilliTime (); - - for (;;) { - // Wait until we are notified. - object_.wait (waitTime); - - // Recheck the condition. - if (!condition ()) { - long now = System.currentTimeMillis (); - long timeSoFar = now - start; - - // Timed out! - if (timeSoFar >= tv.getMilliTime ()) - throw new TimeoutException (); - else - // We still have some time left to wait, so adjust the - // wait_time. - waitTime = tv.getMilliTime () - timeSoFar; - } - else - break; // Condition became true. - } - } - } - - /** - * Notify any one thread waiting on the object_. - * IMPORTANT: This method assumes it is called with the object_'s - * monitor lock already held. - */ - public final void signal () { - object_.notify (); - } - - /** - * Notify all threads waiting on the object_. - * IMPORTANT: This method assumes it is called with the object_'s - * monitor lock already held. - */ - public final void broadcast () { - object_.notifyAll (); - } - - /** - * The object we delegate to. If a subclass gives us a particular - * object, we use that to delegate to, otherwise, we ``delegate'' - * to ourself (i.e., this). - */ - protected Object object_; - -} diff --git a/java/src/TimeoutException.java b/java/src/TimeoutException.java deleted file mode 100644 index b55549938dc..00000000000 --- a/java/src/TimeoutException.java +++ /dev/null @@ -1,34 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * TimeoutException.java - * - *@author Prashant Jain and Doug Schmidt - * - *************************************************/ -package JACE.ASX; - -public class TimeoutException extends Exception -{ - /** - * Default Constructor. - */ - public TimeoutException () - { - super ("Timed Out"); - } - - /** - * Constructor. - *@param timeout The timeout value which expired. - *@param desc Textual description of the exception - */ - public TimeoutException (TimeValue timeout, String desc) - { - super ("Timed Out in " + timeout + ": " + desc); - } - -} diff --git a/java/src/TimerQueue.java b/java/src/TimerQueue.java deleted file mode 100644 index e3aa30d9472..00000000000 --- a/java/src/TimerQueue.java +++ /dev/null @@ -1,433 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Reactor - * - * = FILENAME - * TimerQueue.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Reactor; - -import java.util.*; -import JACE.ASX.*; - -import JACE.OS.*; - -class TimerNode -{ - public TimerNode (EventHandler handler, - Object arg, - TimeValue timerValue, - TimeValue interval, - TimerNode next, - int timerId) - { - this.handler_ = handler; - this.arg_ = arg; - this.timerValue_ = timerValue; - this.interval_ = interval; - this.next_ = next; - this.timerId_ = timerId; - } - - public EventHandler handler_; - // Handler to invoke <handleTimeout> on when a timeout occurs. - - public Object arg_; - // Argument to pass to <handleTimeout>. - - public TimeValue timerValue_; - // Time until the timer expires. - - public TimeValue interval_; - // If this is a periodic timer this holds the time until the next - // timeout. - - public TimerNode next_; - // Pointer to next timer. - - public int timerId_; - // Id of this timer (used to cancel timers before they expire). -} - -class WaitObject extends TimedWait -{ - public boolean condition () - { - return this.condition_; - } - - public void condition (boolean c) - { - this.condition_ = c; - } - - private boolean condition_ = false; -} - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Class that provides an interface to timers. - * - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * This is a simple implementation that keeps a linked list of - * absolute timers. It allows multiple timers to be scheduled - * and returns a timer id for each timer scheduled. In addition, - * it allows periodic timers to be scheduled. - *</blockquote> - */ -public class TimerQueue implements Runnable -{ - /** - * Constructor. - *@param createInternalThread flag specifying whether to create an - * internal thread that runs the event loop. If it is true, a thread - * is spawned and it runs the event loop, handling all timeout - * events. If it is false, the caller is then responsible for calling - * handleEvents () to run the event loop. - */ - public TimerQueue (boolean createInternalThread) - { - this.eventLoopRunning_ = false; - if (createInternalThread) - new Thread (this).start (); - } - - /** - * The thread run method. Do *NOT* call this method! It gets called - * automatically. - */ - public void run () - { - this.handleEvents (); - } - - /** - * Handle timeout events. This forms the event loop and takes care - * of all scheduling. This method should only be called if the Timer - * Queue was constructed with the value of createInternalThread as - * false. - */ - public void handleEvents () - { - if (!this.eventLoopRunning_) - { - // Set the flag indicating that the event loop is now running - this.eventLoopRunning_ = true; - - TimeValue timeout = null; - TimeValue earliest = null; - - for (;;) - { - synchronized (this.obj_) - { - earliest = this.earliestTime (); - if (earliest != null) - timeout = TimeValue.minus (earliest, TimeValue.getTimeOfDay ()); - else - timeout = new TimeValue (); - try - { - // Extract the earliest time from the queue and do a timed wait - this.obj_.timedWait (timeout); - - // We have been notified. Check to see if we need to - // restart the wait with a different timeout - if (this.reset_) - { - this.reset_ = false; - this.obj_.condition (false); - timeout = TimeValue.minus (this.earliestTime (), TimeValue.getTimeOfDay ()); - } - } - catch (TimeoutException e) - { - // Timeout occurred. Call handleTimeout on appropriate - // Event Handlers - this.dispatchHandlers (); - } - catch (InterruptedException e) - { - } - } - } - } - } - - /** - * Check if the queue is empty. - *@return true if queue is empty, else false. - */ - boolean isEmpty () - { - return this.head_ == null; - } - - /** - * Get the node of the earliest node in the TimerQueue. - *@return the time of the earlier node in the TimerQueue. - */ - TimeValue earliestTime () - { - synchronized (this.obj_) - { - if (!this.isEmpty ()) - return this.head_.timerValue_; - else - return null; - } - } - - /** - * Schedule an <EventHandler> that will expire after <delta> amount - * of time. If it expires then <obj> is passed in as the value to - * the <EventHandler>'s <handleTimeout> callback method. This method - * returns a timer id that uniquely identifies the timer and can be - * used to cancel the timer before it expires. - *@param handler Event Handler that is to be scheduled with the timer - *@param obj Object that is passed back to the Event Handler when - * timeout occurs (Asynchronous Completion Token) - *@param delta amount of time for which to schedule the timer - *@return id of the timer scheduled - */ - public int scheduleTimer (EventHandler handler, - Object obj, - TimeValue delta) - { - return this.scheduleTimer (handler, obj, delta, TimeValue.zero); - } - - /** - * Schedule an <EventHandler> that will expire after <delta> amount - * of time. If it expires then <obj> is passed in as the value to - * the <EventHandler>'s <handleTimeout> callback method. If - * <interval> is != to <TimeValue.zero> then it is used to - * reschedule the <EventHandler> automatically. This method - * returns a timer id that uniquely identifies the timer and can be - * used to cancel the timer before it expires. - *@param handler Event Handler that is to be scheduled with the timer - *@param arg Object that is passed back to the Event Handler when - * timeout occurs (Asynchronous Completion Token) - *@param timeout amount of time for which to schedule the timer - *@param interval amount of time to use to reschedule the timer - *@return id of the timer scheduled - */ - public int scheduleTimer (EventHandler handler, - Object arg, - TimeValue timeout, - TimeValue interval) - { - - // Increment the sequence number (it will wrap around). - this.timerId_++; - - ACE.DEBUG("scheduleTimer (" + this.timerId_ + "): " + timeout + ", " + interval); - - - TimeValue futureTime = TimeValue.plus (timeout, TimeValue.getTimeOfDay ()); - TimerNode node = new TimerNode (handler, - arg, - futureTime, - interval, - null, - this.timerId_); - synchronized (this.obj_) - { - // Check if event loop is running. If it is not, then we can - // just place it at the appropriate place in the queue and - // don't need to do any notification. If event loop is - // running, then check if the node is the first node in the - // queue (either because the queue is empty or because the - // time for the node is earlier than the currently scheduled - // timer node). - if (this.eventLoopRunning_ && - (this.isEmpty () || futureTime.lessThan (this.earliestTime ()))) - { - // Insert the node into (the beginning of) the queue to be - // scheduled. - this.reschedule (node); - - // Notify the waiting thread so that it can reschedule - // using the earliest timeout - this.obj_.notify (); - } - else // Place in the appropriate position in the queue. - { - this.reschedule (node); - } - } - return this.timerId_; - } - - - /** - * Cancel the single timer associated with <timerId>. - *@param timerId id of the timer that needs to be cancelled. - *@return Object that was passed in when timer was scheduled - * (Asynchronous Completion Token). - */ - public Object cancelTimer (int timerId) - { - TimerNode prev = null; - TimerNode curr = null; - - synchronized (this.obj_) - { - // Try to locate the TimerNode that matches the timerId. - for (curr = this.head_; - curr != null && curr.timerId_ != timerId; - curr = curr.next_) - prev = curr; - - if (curr != null) - { - if (prev == null) - this.head_ = curr.next_; - else - prev.next_ = curr.next_; - - return curr.arg_; - } - } - return null; - } - - /** - * Cancel all timers associated with <Event Handler>. - *@param handler Event Handler whose associated timers need to be cancelled. - */ - public void cancelTimer (EventHandler handler) - { - TimerNode prev = null; - TimerNode curr = this.head_; - - synchronized (this.obj_) - { - while (curr != null) - { - if (curr.handler_ == handler) - { - if (prev == null) - { - this.head_ = curr.next_; - curr = this.head_; - } - else - { - prev.next_ = curr.next_; - curr = prev.next_; - } - } - else - { - prev = curr; - curr = curr.next_; - } - } - } - } - - // Call handleTimeout() on all handlers whose timers have expired. - private void dispatchHandlers () - { - TimeValue currentTime = TimeValue.getTimeOfDay (); - - for (;;) - { - if (this.isEmpty () || this.earliestTime ().greaterThan (currentTime)) - break; // There aren't any more timers eligible to expire. - - TimerNode expired = this.head_; - EventHandler handler = expired.handler_; - Object arg = expired.arg_; - int result; - - this.head_ = this.head_.next_; - - // Check whether this is an interval timer. - if (expired.interval_.greaterThan (TimeValue.zero)) - { - // Make sure that we skip past values that have already - // "expired". - do - expired.timerValue_.plusEquals (expired.interval_); - while (expired.timerValue_.lessThanEqual (currentTime)); - - // Since this is an interval timer, we need to reschedule - // it. - this.reschedule (expired); - } - - ACE.DEBUG("handleTimeout " + expired.timerId_); - - // Perform the callback. - result = handler.handleTimeout (currentTime, arg); - - if (result == -1) - this.cancelTimer (handler); - } - } - - // Reschedule a TimerNode by inserting it at the appropriate - // position in the queue. - private void reschedule (TimerNode expired) - { - ACE.DEBUG("reschedule " + expired.timerId_ + " for " + expired.timerValue_); - // *** Shouldn't it use interval here? - - if (this.isEmpty () || - expired.timerValue_.lessThan (this.earliestTime ())) - { - expired.next_ = this.head_; - this.head_ = expired; - // Set the condition to true so that the waiting thread can be - // notified and it can reschedule. - this.obj_.condition (true); - this.reset_ = true; - } - else - { - TimerNode prev = this.head_; - TimerNode after = this.head_.next_; - - // Locate the proper position in the queue. - - while (after != null - && expired.timerValue_.greaterThan (after.timerValue_)) - { - prev = after; - after = after.next_; - } - - expired.next_ = after; - prev.next_ = expired; - } - } - - private WaitObject obj_ = new WaitObject (); - // Synchronization object (as well as object to use to do wait on) - - private TimerNode head_; - // Pointer to linked list of TimerHandles. - - private int timerId_; - // Keeps track of the timer id that uniquely identifies each timer. - // This id can be used to cancel a timer via the <cancel (int)> - // method. - - private boolean reset_; - // Flag indicating whether to start the wait again - - private boolean eventLoopRunning_; - // Flag indicating whether the event loop is running or not -} - diff --git a/java/src/Token.java b/java/src/Token.java deleted file mode 100644 index a17be013ad5..00000000000 --- a/java/src/Token.java +++ /dev/null @@ -1,298 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * Token.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Concurrency; - -import java.util.*; -import JACE.ASX.*; - -class WaitObject extends TimedWait -{ - public boolean condition () - { - return this.condition_; - } - - public void condition (boolean c) - { - this.condition_ = c; - } - - private boolean condition_ = false; -} - -/** - * <hr> - * <h2>SYNOPSIS</h2> - *<blockquote> - * Class that acquires, renews, and releases a synchronization - * token that is serviced in strict FIFO ordering. - * - *</blockquote> - * - * <h2>DESCRIPTION</h2> - *<blockquote> - * This is a general-purpose synchronization mechanism that offers - * several benefits. For example, it implements "recursive mutex" - * semantics, where a thread that owns the token can reacquire it - * without deadlocking. In addition, threads that are blocked - * awaiting the token are serviced in strict FIFO order as other - * threads release the token. The solution makes use of the - * Specific Notification pattern presented by Tom Cargill in - * "Specific Notification for Java Thread Synchronization," PLoP96. - *</blockquote> - */ -public class Token -{ - /** - * Acquire the token. Note that this will block. The method uses - * synchronized blocks internally to avoid race conditions. - *@return 0 if acquires without calling <sleepHook> - * 1 if <sleepHook> is called. - * -1 if failure occurs - *@exception InterruptedException exception during wait - */ - public int acquire () throws InterruptedException - { - try - { - return this.acquire (new TimeValue ()); - } - catch (TimeoutException e) - { - // This really shouldn't happen since we are supposed to - // block. - return -1; - } - } - - /** - * Acquire the token. Wait for timeout amount of time. The method - * uses synchronized blocks internally to avoid race conditions. - *@param timeout Amount of time to wait for in trying to acquire the - * token. - *@return 0 if acquires without calling <sleepHook> - * 1 if <sleepHook> is called. - * -1 if failure occurs - *@exception TimeoutException exception if timeout occurs - *@exception InterruptedException exception during wait - */ - public int acquire (TimeValue timeout) throws InterruptedException, TimeoutException - { - int result = 0; - WaitObject snl = new WaitObject (); - boolean mustWait; - synchronized (snl) - { - synchronized (this) - { - mustWait = !this.snq_.isEmpty (); - if (mustWait && - Thread.currentThread ().toString ().compareTo (this.owner_) == 0) - { - // I am the one who has the token. So just increment - // the nesting level - this.nestingLevel_++; - return result; - } - // Add local lock to the queue - this.snq_.addElement (snl); - } - if (mustWait) - { - result = 1; - // Call sleep hook - sleepHook (); - snl.timedWait (timeout); // Do a blocking wait - } - // Set the owner of the token - this.owner_ = Thread.currentThread ().toString (); - } - return result; - } - - /** - * Try to acquire the token. Implements a non-blocking acquire. - *@return 0 if acquires without calling <sleepHook> - * 1 if <sleepHook> is called. - * -1 if failure occurs - */ - public synchronized int tryAcquire () - { - int result = 0; - if (!this.snq_.isEmpty ()) - { - // No one has the token, so acquire it - this.snq_.addElement (new WaitObject ()); - } - // Check if I am the one holding the token. - else if (Thread.currentThread ().toString ().compareTo (this.owner_) == 0) - { - this.nestingLevel_++; - } - // Someone else has the token. - else - { - // Will have to block to acquire the token, so call - // sleepHook and return - sleepHook (); - result = 1; - } - return result; - } - - /** - * Method that is called before a thread goes to sleep in an - * acquire(). This should be overridden by a subclass to define - * the appropriate behavior before acquire() goes to sleep. - * By default, this is a no-op. - */ - public void sleepHook () - { - } - - /** - * 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. - *@param requeuePosition Position in the queue where to insert the - * lock. If requeuePosition == -1 and there are other threads - * waiting to obtain the token we are queued at the end of the list - * of waiters. If requeuePosition > -1 then it indicates how many - * entries to skip over before inserting our thread into the list of - * waiters (e.g.,requeuePosition == 0 means "insert at front of the - * queue"). - *@exception InterruptedException exception during wait - */ - public void renew (int requeuePosition) throws InterruptedException - { - try - { - this.renew (requeuePosition, new TimeValue ()); - } - catch (TimeoutException e) - { - // This really shouldn't happen since we are supposed to - // block. - } - } - - /** - * 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. - *@param requeuePosition Position in the queue where to insert the - * lock. If requeuePosition == -1 and there are other threads - * waiting to obtain the token we are queued at the end of the list - * of waiters. If requeuePosition > -1 then it indicates how many - * entries to skip over before inserting our thread into the list of - * waiters (e.g.,requeuePosition == 0 means "insert at front of the - * queue"). - *@param timeout Amount of time to wait for in trying to acquire the - * token. - *@exception TimeoutException exception if timeout occurs - *@exception InterruptedException exception during wait - */ - public void renew (int requeuePosition, TimeValue timeout) - throws InterruptedException, TimeoutException - { - WaitObject snl = null; - int saveNestingLevel = 0; - - synchronized (this) - { - // Check if there is a thread waiting to acquire the token. If - // not or if requeuePosition == 0, then we don't do anything - // and we simply keep the token. - if (this.snq_.size () > 1 && requeuePosition != 0) - { - // Save the nesting level - saveNestingLevel = this.nestingLevel_; - this.nestingLevel_ = 0; - - // Reinsert ourselves at requeuePosition in the queue - snl = (WaitObject) this.snq_.firstElement (); - this.snq_.removeElementAt (0); - - if (requeuePosition < 0) - this.snq_.addElement (snl); // Insert at end - else - this.snq_.insertElementAt (snl, requeuePosition); - - synchronized (this.snq_.firstElement ()) - { - // Notify the first waiting thread in the queue - WaitObject obj = (WaitObject) this.snq_.firstElement (); - // Set its condition to be true so that it falls out - // of the for loop - obj.condition (true); - // Now signal the thread - obj.signal (); - } - } - } - - // Check if we reinserted the lock in the queue and therefore need - // to do a wait - if (snl != null) - { - synchronized (snl) - { - // Set the condition to be false so that we can begin the - // wait - snl.condition (false); - // Do a blocking wait - snl.timedWait (timeout); - } - // Restore the nesting level and current owner of the lock - this.nestingLevel_ = saveNestingLevel; - this.owner_ = Thread.currentThread ().toString (); - } - } - - /** - * Release the token. - */ - public synchronized void release () - { - // Check if nestingLevel > 0 and if so, decrement it - if (this.nestingLevel_ > 0) - this.nestingLevel_--; - else - { - this.snq_.removeElementAt (0); - if (!this.snq_.isEmpty ()) - { - synchronized (this.snq_.firstElement ()) - { - // Notify the first waiting thread in the queue - WaitObject obj = (WaitObject) this.snq_.firstElement (); - // Set its condition to be true so that it falls out - // of the for loop - obj.condition (true); - // Now signal the thread - obj.signal (); - } - } - } - } - - private Vector snq_ = new Vector (); - // Vector of lock objects - - private int nestingLevel_ = 0; - // Current Nesting Level - - private String owner_ = null; - // Current owner of the token. -} |