From 6803d545979635f9fc0fb817b1e0841e69a96472 Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 1 Jul 2001 16:18:56 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'TAO-1_1_18'. --- java/JACE/ASX/IOCntlCmds.java | 38 -- java/JACE/ASX/IOCntlMsg.java | 124 ---- java/JACE/ASX/MessageBlock.java | 447 --------------- java/JACE/ASX/MessageQueue.java | 633 --------------------- java/JACE/ASX/MessageType.java | 102 ---- java/JACE/ASX/Module.java | 246 -------- java/JACE/ASX/Stream.java | 436 -------------- java/JACE/ASX/StreamHead.java | 123 ---- java/JACE/ASX/StreamTail.java | 114 ---- java/JACE/ASX/Task.java | 443 -------------- java/JACE/ASX/TaskFlags.java | 49 -- java/JACE/ASX/ThruTask.java | 44 -- java/JACE/ASX/TimeValue.java | 296 ---------- java/JACE/ASX/TimedWait.java | 157 ----- java/JACE/ASX/TimeoutException.java | 37 -- java/JACE/ASX/package.html | 11 - java/JACE/Concurrency/AbstractLock.java | 269 --------- java/JACE/Concurrency/Condition.java | 124 ---- java/JACE/Concurrency/LockAdapter.java | 262 --------- java/JACE/Concurrency/LockException.java | 28 - java/JACE/Concurrency/Mutex.java | 239 -------- java/JACE/Concurrency/RWMutex.java | 268 --------- java/JACE/Concurrency/RenewObject.java | 36 -- java/JACE/Concurrency/Semaphore.java | 263 --------- java/JACE/Concurrency/ThreadManager.java | 113 ---- java/JACE/Concurrency/Token.java | 301 ---------- java/JACE/Concurrency/WaitObject.java | 39 -- java/JACE/Concurrency/package.html | 15 - java/JACE/Connection/AcceptStrategy.java | 87 --- java/JACE/Connection/Acceptor.java | 215 ------- java/JACE/Connection/ActivateStrategy.java | 40 -- java/JACE/Connection/Blob.java | 114 ---- java/JACE/Connection/BlobHandler.java | 35 -- java/JACE/Connection/BlobReader.java | 108 ---- java/JACE/Connection/BlobWriter.java | 224 -------- java/JACE/Connection/Connector.java | 148 ----- java/JACE/Connection/CreationStrategy.java | 57 -- java/JACE/Connection/HTTPHelper.java | 182 ------ java/JACE/Connection/StrategyAcceptor.java | 174 ------ java/JACE/Connection/SvcHandler.java | 101 ---- java/JACE/Connection/package.html | 7 - java/JACE/Makefile | 234 -------- java/JACE/Misc/GetOpt.java | 171 ------ java/JACE/Misc/package.html | 6 - java/JACE/OS/ACE.java | 156 ----- java/JACE/OS/OS.java | 65 --- java/JACE/OS/package.html | 6 - java/JACE/Reactor/EventHandler.java | 43 -- java/JACE/Reactor/TimerQueue.java | 437 -------------- java/JACE/Reactor/package.html | 6 - java/JACE/SOCK_SAP/INETAddr.java | 96 ---- java/JACE/SOCK_SAP/SOCKAcceptor.java | 113 ---- java/JACE/SOCK_SAP/SOCKConnector.java | 73 --- java/JACE/SOCK_SAP/SOCKStream.java | 227 -------- java/JACE/SOCK_SAP/package.html | 8 - java/JACE/ServiceConfigurator/Service.java | 96 ---- java/JACE/ServiceConfigurator/ServiceConfig.java | 482 ---------------- java/JACE/ServiceConfigurator/ServiceLoader.java | 254 --------- java/JACE/ServiceConfigurator/ServiceObject.java | 130 ----- .../ServiceConfigurator/ServiceRepository.java | 274 --------- java/JACE/ServiceConfigurator/package.html | 10 - java/JACE/Timers/ProfileTimer.java | 46 -- java/JACE/Timers/package.html | 8 - java/JACE/makebat.zip | Bin 1326 -> 0 bytes java/JACE/netsvcs/Handler.java | 185 ------ java/JACE/netsvcs/Logger/LogRecord.java | 290 ---------- java/JACE/netsvcs/Logger/LoggingStrategy.java | 35 -- .../JACE/netsvcs/Logger/ServerLoggingAcceptor.java | 147 ----- java/JACE/netsvcs/Logger/ServerLoggingHandler.java | 60 -- java/JACE/netsvcs/Logger/StderrStrategy.java | 36 -- java/JACE/netsvcs/Logger/c.bat | 2 - java/JACE/netsvcs/Logger/package.html | 17 - java/JACE/netsvcs/Naming/NameAcceptor.java | 313 ---------- java/JACE/netsvcs/Naming/NameHandler.java | 473 --------------- java/JACE/netsvcs/Naming/NameProxy.java | 405 ------------- java/JACE/netsvcs/Naming/NameReply.java | 169 ------ java/JACE/netsvcs/Naming/NameRequest.java | 373 ------------ java/JACE/netsvcs/Naming/c.bat | 2 - java/JACE/netsvcs/Naming/package.html | 11 - java/JACE/netsvcs/Server.java | 356 ------------ java/JACE/netsvcs/Time/TSClerkHandler.java | 195 ------- java/JACE/netsvcs/Time/TSClerkProcessor.java | 307 ---------- java/JACE/netsvcs/Time/TSServerAcceptor.java | 116 ---- java/JACE/netsvcs/Time/TSServerHandler.java | 53 -- java/JACE/netsvcs/Time/TimeInfo.java | 90 --- java/JACE/netsvcs/Time/TimeRequest.java | 121 ---- java/JACE/netsvcs/Time/c.bat | 1 - java/JACE/netsvcs/Time/package.html | 10 - java/JACE/netsvcs/Time/r.bat | 1 - java/JACE/netsvcs/Token/LockHandler.java | 38 -- java/JACE/netsvcs/Token/LockHandlerAdapter.java | 380 ------------- java/JACE/netsvcs/Token/LockOperations.java | 16 - java/JACE/netsvcs/Token/LockTypes.java | 19 - java/JACE/netsvcs/Token/MutexHandler.java | 51 -- java/JACE/netsvcs/Token/RWMutexHandler.java | 54 -- java/JACE/netsvcs/Token/RemoteLock.java | 543 ------------------ java/JACE/netsvcs/Token/RemoteMutex.java | 28 - java/JACE/netsvcs/Token/RemoteRWMutex.java | 29 - java/JACE/netsvcs/Token/TokenAcceptor.java | 353 ------------ java/JACE/netsvcs/Token/TokenReply.java | 171 ------ java/JACE/netsvcs/Token/TokenRequest.java | 426 -------------- java/JACE/netsvcs/Token/TokenRequestHandler.java | 180 ------ java/JACE/netsvcs/Token/package.html | 16 - java/JACE/netsvcs/package.html | 11 - java/JACE/overview.html | 84 --- java/JACE/package.html | 32 -- java/JACE/tests/ASX/BufferStreamTest.java | 189 ------ java/JACE/tests/ASX/MessageQueueTest.java | 54 -- java/JACE/tests/ASX/PriorityBufferTest.java | 118 ---- java/JACE/tests/ASX/TaskTest.java | 95 ---- java/JACE/tests/ASX/ThreadPoolTest.java | 187 ------ .../JACE/tests/Concurrency/Condition/Consumer.java | 75 --- .../Concurrency/Condition/JoinableThreadGroup.java | 24 - .../JACE/tests/Concurrency/Condition/Producer.java | 70 --- .../tests/Concurrency/Condition/QueueTest.java | 68 --- .../Concurrency/Condition/SimpleMessageQueue.java | 86 --- java/JACE/tests/Concurrency/IterationTest.java | 235 -------- java/JACE/tests/Concurrency/RWMutexTest.java | 137 ----- java/JACE/tests/Concurrency/TimingTest.java | 290 ---------- java/JACE/tests/Concurrency/TokenTest.java | 95 ---- java/JACE/tests/Connection/AcceptorTest.java | 83 --- java/JACE/tests/Connection/ClientHandler.java | 77 --- java/JACE/tests/Connection/ConnectorTest.java | 78 --- java/JACE/tests/Connection/HTTPHelperTest.java | 34 -- java/JACE/tests/Connection/ServerHandler.java | 68 --- java/JACE/tests/Makefile | 115 ---- java/JACE/tests/Misc/ParseArgsTest.java | 48 -- java/JACE/tests/Reactor/TimeValueTest.java | 52 -- java/JACE/tests/Reactor/TimerQueueTest.java | 84 --- java/JACE/tests/SOCK_SAP/SOCKAcceptorTest.java | 110 ---- java/JACE/tests/SOCK_SAP/SOCKConnectorTest.java | 97 ---- java/JACE/tests/ServiceConfigurator/Main.java | 113 ---- java/JACE/tests/ServiceConfigurator/svc.conf | 4 - java/JACE/tests/netsvcs/Logger/LoggerTest.java | 115 ---- java/JACE/tests/netsvcs/Naming/ClientTest.java | 107 ---- java/JACE/tests/netsvcs/Time/TSClient.java | 37 -- java/JACE/tests/netsvcs/Token/ProxyClientTest.java | 200 ------- 137 files changed, 19034 deletions(-) delete mode 100644 java/JACE/ASX/IOCntlCmds.java delete mode 100644 java/JACE/ASX/IOCntlMsg.java delete mode 100644 java/JACE/ASX/MessageBlock.java delete mode 100644 java/JACE/ASX/MessageQueue.java delete mode 100644 java/JACE/ASX/MessageType.java delete mode 100644 java/JACE/ASX/Module.java delete mode 100644 java/JACE/ASX/Stream.java delete mode 100644 java/JACE/ASX/StreamHead.java delete mode 100644 java/JACE/ASX/StreamTail.java delete mode 100644 java/JACE/ASX/Task.java delete mode 100644 java/JACE/ASX/TaskFlags.java delete mode 100644 java/JACE/ASX/ThruTask.java delete mode 100644 java/JACE/ASX/TimeValue.java delete mode 100644 java/JACE/ASX/TimedWait.java delete mode 100644 java/JACE/ASX/TimeoutException.java delete mode 100644 java/JACE/ASX/package.html delete mode 100644 java/JACE/Concurrency/AbstractLock.java delete mode 100644 java/JACE/Concurrency/Condition.java delete mode 100644 java/JACE/Concurrency/LockAdapter.java delete mode 100644 java/JACE/Concurrency/LockException.java delete mode 100644 java/JACE/Concurrency/Mutex.java delete mode 100644 java/JACE/Concurrency/RWMutex.java delete mode 100644 java/JACE/Concurrency/RenewObject.java delete mode 100644 java/JACE/Concurrency/Semaphore.java delete mode 100644 java/JACE/Concurrency/ThreadManager.java delete mode 100644 java/JACE/Concurrency/Token.java delete mode 100644 java/JACE/Concurrency/WaitObject.java delete mode 100644 java/JACE/Concurrency/package.html delete mode 100644 java/JACE/Connection/AcceptStrategy.java delete mode 100644 java/JACE/Connection/Acceptor.java delete mode 100644 java/JACE/Connection/ActivateStrategy.java delete mode 100644 java/JACE/Connection/Blob.java delete mode 100644 java/JACE/Connection/BlobHandler.java delete mode 100644 java/JACE/Connection/BlobReader.java delete mode 100644 java/JACE/Connection/BlobWriter.java delete mode 100644 java/JACE/Connection/Connector.java delete mode 100644 java/JACE/Connection/CreationStrategy.java delete mode 100644 java/JACE/Connection/HTTPHelper.java delete mode 100644 java/JACE/Connection/StrategyAcceptor.java delete mode 100644 java/JACE/Connection/SvcHandler.java delete mode 100644 java/JACE/Connection/package.html delete mode 100644 java/JACE/Makefile delete mode 100644 java/JACE/Misc/GetOpt.java delete mode 100644 java/JACE/Misc/package.html delete mode 100644 java/JACE/OS/ACE.java delete mode 100644 java/JACE/OS/OS.java delete mode 100644 java/JACE/OS/package.html delete mode 100644 java/JACE/Reactor/EventHandler.java delete mode 100644 java/JACE/Reactor/TimerQueue.java delete mode 100644 java/JACE/Reactor/package.html delete mode 100644 java/JACE/SOCK_SAP/INETAddr.java delete mode 100644 java/JACE/SOCK_SAP/SOCKAcceptor.java delete mode 100644 java/JACE/SOCK_SAP/SOCKConnector.java delete mode 100644 java/JACE/SOCK_SAP/SOCKStream.java delete mode 100644 java/JACE/SOCK_SAP/package.html delete mode 100644 java/JACE/ServiceConfigurator/Service.java delete mode 100644 java/JACE/ServiceConfigurator/ServiceConfig.java delete mode 100644 java/JACE/ServiceConfigurator/ServiceLoader.java delete mode 100644 java/JACE/ServiceConfigurator/ServiceObject.java delete mode 100644 java/JACE/ServiceConfigurator/ServiceRepository.java delete mode 100644 java/JACE/ServiceConfigurator/package.html delete mode 100644 java/JACE/Timers/ProfileTimer.java delete mode 100644 java/JACE/Timers/package.html delete mode 100644 java/JACE/makebat.zip delete mode 100644 java/JACE/netsvcs/Handler.java delete mode 100644 java/JACE/netsvcs/Logger/LogRecord.java delete mode 100644 java/JACE/netsvcs/Logger/LoggingStrategy.java delete mode 100644 java/JACE/netsvcs/Logger/ServerLoggingAcceptor.java delete mode 100644 java/JACE/netsvcs/Logger/ServerLoggingHandler.java delete mode 100644 java/JACE/netsvcs/Logger/StderrStrategy.java delete mode 100644 java/JACE/netsvcs/Logger/c.bat delete mode 100644 java/JACE/netsvcs/Logger/package.html delete mode 100644 java/JACE/netsvcs/Naming/NameAcceptor.java delete mode 100644 java/JACE/netsvcs/Naming/NameHandler.java delete mode 100644 java/JACE/netsvcs/Naming/NameProxy.java delete mode 100644 java/JACE/netsvcs/Naming/NameReply.java delete mode 100644 java/JACE/netsvcs/Naming/NameRequest.java delete mode 100644 java/JACE/netsvcs/Naming/c.bat delete mode 100644 java/JACE/netsvcs/Naming/package.html delete mode 100644 java/JACE/netsvcs/Server.java delete mode 100644 java/JACE/netsvcs/Time/TSClerkHandler.java delete mode 100644 java/JACE/netsvcs/Time/TSClerkProcessor.java delete mode 100644 java/JACE/netsvcs/Time/TSServerAcceptor.java delete mode 100644 java/JACE/netsvcs/Time/TSServerHandler.java delete mode 100644 java/JACE/netsvcs/Time/TimeInfo.java delete mode 100644 java/JACE/netsvcs/Time/TimeRequest.java delete mode 100644 java/JACE/netsvcs/Time/c.bat delete mode 100644 java/JACE/netsvcs/Time/package.html delete mode 100644 java/JACE/netsvcs/Time/r.bat delete mode 100644 java/JACE/netsvcs/Token/LockHandler.java delete mode 100644 java/JACE/netsvcs/Token/LockHandlerAdapter.java delete mode 100644 java/JACE/netsvcs/Token/LockOperations.java delete mode 100644 java/JACE/netsvcs/Token/LockTypes.java delete mode 100644 java/JACE/netsvcs/Token/MutexHandler.java delete mode 100644 java/JACE/netsvcs/Token/RWMutexHandler.java delete mode 100644 java/JACE/netsvcs/Token/RemoteLock.java delete mode 100644 java/JACE/netsvcs/Token/RemoteMutex.java delete mode 100644 java/JACE/netsvcs/Token/RemoteRWMutex.java delete mode 100644 java/JACE/netsvcs/Token/TokenAcceptor.java delete mode 100644 java/JACE/netsvcs/Token/TokenReply.java delete mode 100644 java/JACE/netsvcs/Token/TokenRequest.java delete mode 100644 java/JACE/netsvcs/Token/TokenRequestHandler.java delete mode 100644 java/JACE/netsvcs/Token/package.html delete mode 100644 java/JACE/netsvcs/package.html delete mode 100644 java/JACE/overview.html delete mode 100644 java/JACE/package.html delete mode 100644 java/JACE/tests/ASX/BufferStreamTest.java delete mode 100644 java/JACE/tests/ASX/MessageQueueTest.java delete mode 100644 java/JACE/tests/ASX/PriorityBufferTest.java delete mode 100644 java/JACE/tests/ASX/TaskTest.java delete mode 100644 java/JACE/tests/ASX/ThreadPoolTest.java delete mode 100644 java/JACE/tests/Concurrency/Condition/Consumer.java delete mode 100644 java/JACE/tests/Concurrency/Condition/JoinableThreadGroup.java delete mode 100644 java/JACE/tests/Concurrency/Condition/Producer.java delete mode 100644 java/JACE/tests/Concurrency/Condition/QueueTest.java delete mode 100644 java/JACE/tests/Concurrency/Condition/SimpleMessageQueue.java delete mode 100644 java/JACE/tests/Concurrency/IterationTest.java delete mode 100644 java/JACE/tests/Concurrency/RWMutexTest.java delete mode 100644 java/JACE/tests/Concurrency/TimingTest.java delete mode 100644 java/JACE/tests/Concurrency/TokenTest.java delete mode 100644 java/JACE/tests/Connection/AcceptorTest.java delete mode 100644 java/JACE/tests/Connection/ClientHandler.java delete mode 100644 java/JACE/tests/Connection/ConnectorTest.java delete mode 100644 java/JACE/tests/Connection/HTTPHelperTest.java delete mode 100644 java/JACE/tests/Connection/ServerHandler.java delete mode 100644 java/JACE/tests/Makefile delete mode 100644 java/JACE/tests/Misc/ParseArgsTest.java delete mode 100644 java/JACE/tests/Reactor/TimeValueTest.java delete mode 100644 java/JACE/tests/Reactor/TimerQueueTest.java delete mode 100644 java/JACE/tests/SOCK_SAP/SOCKAcceptorTest.java delete mode 100644 java/JACE/tests/SOCK_SAP/SOCKConnectorTest.java delete mode 100644 java/JACE/tests/ServiceConfigurator/Main.java delete mode 100644 java/JACE/tests/ServiceConfigurator/svc.conf delete mode 100644 java/JACE/tests/netsvcs/Logger/LoggerTest.java delete mode 100644 java/JACE/tests/netsvcs/Naming/ClientTest.java delete mode 100644 java/JACE/tests/netsvcs/Time/TSClient.java delete mode 100644 java/JACE/tests/netsvcs/Token/ProxyClientTest.java (limited to 'java/JACE') diff --git a/java/JACE/ASX/IOCntlCmds.java b/java/JACE/ASX/IOCntlCmds.java deleted file mode 100644 index 3cc7c76256d..00000000000 --- a/java/JACE/ASX/IOCntlCmds.java +++ /dev/null @@ -1,38 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * TaskFlags.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -/** - * Constants used for IOCTL messages. - * - *@see JACE.ASX.IOCntlMsg - */ -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/JACE/ASX/IOCntlMsg.java b/java/JACE/ASX/IOCntlMsg.java deleted file mode 100644 index 4eea18b36f6..00000000000 --- a/java/JACE/ASX/IOCntlMsg.java +++ /dev/null @@ -1,124 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * IOCntlMsg.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * Data format for IOCTL messages. - */ -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/JACE/ASX/MessageBlock.java b/java/JACE/ASX/MessageBlock.java deleted file mode 100644 index 4035e34a7bd..00000000000 --- a/java/JACE/ASX/MessageBlock.java +++ /dev/null @@ -1,447 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * MessageBlock.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * Object used to store messages in the ASX framework.

- * - * MessageBlock is modeled after the message data structures - * used in System V STREAMS. A MessageBlock is composed of - * one or more MessageBlocks that are linked together by - * PREV and NEXT pointers. In addition, a - * MessageBlock may also be linked to a chain of other - * MessageBlocks. This structure enables efficient manipulation - * of arbitrarily-large messages without incurring memory - * copying overhead. - * - *@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, - * messages and 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 - * 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 - * 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 - * 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 - * 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/JACE/ASX/MessageQueue.java b/java/JACE/ASX/MessageQueue.java deleted file mode 100644 index df25870dd52..00000000000 --- a/java/JACE/ASX/MessageQueue.java +++ /dev/null @@ -1,633 +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_; -} - - -/** - * A thread-safe message queueing facility, modeled after the - * queueing facilities in System V StreamS.

- * - * MessageQueue 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 (e.g., a producer and - * consumer thread joined by a MessageQueue). The queue - * consists of MessageBlocks. - * - * - *@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; - } - - // ************ Note! *********** - // = For enqueue, enqueueHead, enqueueTail, and dequeueHead if - // timeout is specified, the caller will wait until the *absolute time* - // tv. Calls will return, however, when queue is closed, - // deactivated, or if it is past the time tv - - /** - * Enqueue a into the in accordance - * with its (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 into the in accordance - * with its (0 is lowest priority). Note that the - * call will return if the queue has been deactivated or it is - * later than the specified absolute time value. - *@param newItem item to enqueue onto the Message Queue - *@param tv absolute TimeValue to timeout after - *@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 at the end of the . 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 at the end of the . Note - * that the call will return when it's later than the given TimeValue or - * if the queue has been deactivated. - *@param newItem item to enqueue onto the Message Queue - *@param tv absolute TimeValue to wait until before returning (unless - * the operation compeltes before this time) - *@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 at the head of the . 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 at the head of the . Note - * that the call will return when it's later than the given TimeValue or - * if the queue has been deactivated. - *@param newItem item to enqueue onto the Message Queue - *@param tv absolute TimeValue to wait until before returning (unless - * the operation completes before that time) - *@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 at the head of the - * . Note that the call will block (unless the queue - * has been deactivated). - *@return null on failure, else the 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 at the head of the - * . Note that the call when return if the queue has - * been deactivated or when the current time is later than the given - * time value. - *@param tv absolute time timeout (blocks indefinitely if null) - *@return null on failure, else the 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 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 . - break; - } - - if (temp == null) - // Check for simple case of inserting at the end of the queue, - // where all we need to do is insert 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 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/JACE/ASX/MessageType.java b/java/JACE/ASX/MessageType.java deleted file mode 100644 index 97e33a6c6ba..00000000000 --- a/java/JACE/ASX/MessageType.java +++ /dev/null @@ -1,102 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * MessageType.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -/** - * Message types used by MessageBlock.

- * - * Defines bit masks used to identify various types of messages.

- * - * This class is not intended to be instantiable. - * - *@see MessageBlock - */ -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/JACE/ASX/Module.java b/java/JACE/ASX/Module.java deleted file mode 100644 index 2b80cd690c9..00000000000 --- a/java/JACE/ASX/Module.java +++ /dev/null @@ -1,246 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * Module.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * Provides an abstraction for managing a bi-directional flow of - * messages.

- * - * 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. - */ -public class Module -{ - // = Initialization and termination methods. - - /** - * Create an empty Module. - */ - public Module () - { - // Do nothing... - this.name (""); - } - - /* - * 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/JACE/ASX/Stream.java b/java/JACE/ASX/Stream.java deleted file mode 100644 index 6a968714ab7..00000000000 --- a/java/JACE/ASX/Stream.java +++ /dev/null @@ -1,436 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * Stream.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * This class is the primary abstraction for the ASX framework. - * It is moduled after System V Stream.

- * - * A Stream consists of a stack of Modules, each of which - * contains two Tasks. - * - *@see Module - *@see Task - */ - -public class Stream -{ - - public Stream () - { - this (null, null, null); - } - - // Create a Stream consisting of and as the Stream - // head and Stream tail, respectively. If these are 0 then the - // and are used, respectively. - // 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; - } - - // Note that the timeout tv is absolute time - public int put (MessageBlock mb, TimeValue tv) - { - return this.streamHead_.writer ().put (mb, tv); - } - - // Note that the timeout tv is absolute time - 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, null) == -1) - result = -1; - else if ((cb = this.streamHead_.reader ().getq (null)) == 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/JACE/ASX/StreamHead.java b/java/JACE/ASX/StreamHead.java deleted file mode 100644 index 1492b43a297..00000000000 --- a/java/JACE/ASX/StreamHead.java +++ /dev/null @@ -1,123 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * StreamHead.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * Standard module that acts as the head of a ustream. - */ - -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, null); - return 0; - } - - // Will block forever to add the given MessageBlock - public int put (MessageBlock mb) - { - return this.put (mb, null); - } - - // tv is absolute time - 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/JACE/ASX/StreamTail.java b/java/JACE/ASX/StreamTail.java deleted file mode 100644 index c1148a4c0f1..00000000000 --- a/java/JACE/ASX/StreamTail.java +++ /dev/null @@ -1,114 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * StreamTail.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; - -/** - * Standard module that acts as the tail of a ustream. - */ -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, null); - } - - // 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, null); - } - return 0; - } - - // put the given MessageBlock without a timeout (block forever if - // necessary) - public int put (MessageBlock mb) - { - return this.put (mb, null); - } - - // tv is an absolute time timeout - 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/JACE/ASX/Task.java b/java/JACE/ASX/Task.java deleted file mode 100644 index b13de64f16a..00000000000 --- a/java/JACE/ASX/Task.java +++ /dev/null @@ -1,443 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * Task.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -import JACE.OS.*; -import JACE.Reactor.*; -import JACE.Concurrency.*; - -/** - * Primary interface for application message processing, as well - * as input and output message queueing.

- * - * This class serves as the basis for passive and active objects - * in ACE. - * - *@see MessageQueue - *@see EventHandler - */ -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 Latest time to wait until (absolute time) - */ - 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 - * 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 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 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. Default implementation is a no-op. - */ - public synchronized void suspend () - { - } - - /** - * Resume a suspended task. Default implementation is a no-op. - */ - public synchronized void 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 a message into the queue, blocking forever if necessary. - *@param mb Message Block to insert - *@exception java.lang.InterruptedException Interrupted while accessing queue - */ - protected int putq (MessageBlock mb) throws InterruptedException - { - return this.putq(mb, null); - } - - /** - * Insert message into the message queue. - *@param mb Message Block to insert into the Message Queue - *@param tv time to wait until (absolute time) - *@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, blocking forever if - * necessary. - *@return the first Message Block from the Message Queue. - *@exception InterrupteException Interrupted while accessing queue - */ - protected MessageBlock getq() throws InterruptedException - { - return this.getq(null); - } - - /** - * Extract the first message from the queue. Note that the call is blocking. - *@return the first Message Block from the Message Queue. - *@param tv Latest time to wait until (absolute time) - *@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 Latest time to wait until (absolute time) - *@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 Latest time to wait until (absolute time) - *@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 Latest time to wait until (absolute time) - *@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/JACE/ASX/TaskFlags.java b/java/JACE/ASX/TaskFlags.java deleted file mode 100644 index 13347283adf..00000000000 --- a/java/JACE/ASX/TaskFlags.java +++ /dev/null @@ -1,49 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * TaskFlags.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -/** - * Flags used within Task. - * - *@see Task - */ -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/JACE/ASX/ThruTask.java b/java/JACE/ASX/ThruTask.java deleted file mode 100644 index 3fd0bbd4476..00000000000 --- a/java/JACE/ASX/ThruTask.java +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * ThruTask.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.ASX; - -/** - * Standard module that acts as a "no op", simply passing on all - * data to its adjacent neighbor. - */ -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/JACE/ASX/TimeValue.java b/java/JACE/ASX/TimeValue.java deleted file mode 100644 index 452f80447c4..00000000000 --- a/java/JACE/ASX/TimeValue.java +++ /dev/null @@ -1,296 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Reactor - * - * = FILENAME - * TimeValue.java - * - *@author Prashant Jain - * - *************************************************/ -//package JACE.Reactor; -package JACE.ASX; - -/** - * Encapsulates a specific time or time interval.

- * - * Also provides methods for generating absolute times from - * relative times. This is used throughout JACE for timeouts. - * - *@see TimedWait - */ -public class TimeValue -{ - /** - * TimeValue representing 0 seconds and 0 nanoseconds. - */ - public final static TimeValue zero = new TimeValue (0,0); - - /** - * Default constructor. This creates a TimeValue that is - * equal to TimeValue.zero. - */ - 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 as a new TimeValue - */ - public static TimeValue getTimeOfDay () - { - return new TimeValue (System.currentTimeMillis ()/1000); - } - - /** - * Return a new TimeValue that represents the current system time - * of day offset by the given number of seconds and nanoseconds. - *@param sec Number of seconds to offset by - *@param nanos Number of nanoseconds to offset by - *@see JACE.ASX.TimeValue - *@return TimeValue for the system time plus the given offset - */ - public static TimeValue relativeTimeOfDay(long sec, int nanos) - { - return new TimeValue ((System.currentTimeMillis() / 1000) + sec, - nanos); - } - - /** - * Return a new TimeValue that represents the current system time - * of day offset by the given TimeValue. - *@param tv TimeValue to offset by - *@see JACE.ASX.TimeValue - *@return TimeValue for the system time plus the given offset - */ - public static TimeValue relativeTimeOfDay(TimeValue offset) - { - return new TimeValue ((System.currentTimeMillis() / 1000) + - offset.sec(), - offset.nanos()); - } - - /** - * 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/JACE/ASX/TimedWait.java b/java/JACE/ASX/TimedWait.java deleted file mode 100644 index dc1d0bab673..00000000000 --- a/java/JACE/ASX/TimedWait.java +++ /dev/null @@ -1,157 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * TimedWait.java - * - *@author Prashant Jain and Doug Schmidt - * - *************************************************/ -package JACE.ASX; - -/** - * A wait/notify system with absolute time timeouts and built-in - * check of a condition.

- * - * Subclasses define the condition to check, and the object to - * wait on can be specified. - */ -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. - * If the specified wait time is zero, this checks the condition, - * then returns on success or throws a TimeoutException on failure. - *@param tv Absolute time to wait until before throwing an exception - * if the condition isn't satisfied - *@exception java.lang.InterruptedException Interrupted during wait - *@exception JACE.ASX.TimeoutException Reached timeout specified - */ - public final void timedWait (TimeValue tv) - throws InterruptedException, - TimeoutException - { - if (tv == null) { - this.timedWait(); - return; - } - - // Acquire the monitor lock. - if (!condition ()) - { - long start = System.currentTimeMillis(); - long waitTime = tv.getMilliTime() - start; - - for (;;) { - - // Prevent a conversion from absolute to relative time from - // generating a zero or negative waitTime. - if (waitTime < 1) - throw new TimeoutException (); - - // Wait until we are notified. - object_.wait (waitTime); - - // Recheck the condition. - if (!condition ()) { - - long now = System.currentTimeMillis(); - - // Timed out! - if (now >= tv.getMilliTime ()) - throw new TimeoutException (); - else - // We still have some time left to wait, so adjust the - // wait_time. - waitTime = tv.getMilliTime() - now; - } - 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/JACE/ASX/TimeoutException.java b/java/JACE/ASX/TimeoutException.java deleted file mode 100644 index d55cc4fe999..00000000000 --- a/java/JACE/ASX/TimeoutException.java +++ /dev/null @@ -1,37 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ASX - * - * = FILENAME - * TimeoutException.java - * - *@author Prashant Jain and Doug Schmidt - * - *************************************************/ -package JACE.ASX; - -/** - * Thrown when a timer has expired. - */ -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/JACE/ASX/package.html b/java/JACE/ASX/package.html deleted file mode 100644 index 346782ed083..00000000000 --- a/java/JACE/ASX/package.html +++ /dev/null @@ -1,11 +0,0 @@ - - - -Message queueing facilities. -

-@see -Documents on ACE interprocess communication components -@see -Documents on the ACE streams framework - - diff --git a/java/JACE/Concurrency/AbstractLock.java b/java/JACE/Concurrency/AbstractLock.java deleted file mode 100644 index c8afaf789ae..00000000000 --- a/java/JACE/Concurrency/AbstractLock.java +++ /dev/null @@ -1,269 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * Lock.java - * - *@author Everett Anderson - * - *************************************************/ -package JACE.Concurrency; - -import JACE.ASX.*; - -/** - * Interface for any Java ACE synchronization mechanism. - *

- * Defines the interface for Token, Mutex, RWMutex, Semaphore, - * and the RemoteLock proxies in the Token service, as well as - * the possible constant return values. - *

- * Methods which take TimeValue timeouts can throw - * JACE.ASX.TimeoutExceptions. The locks should continue to - * function properly after a thread times out or is interrupted. - * Also note that the timeouts are absolute time-of-day - * values, not relative times. - *

- * An AbstractLock.FAILURE can be returned for an undefined type of - * failure. - *

- * You can assume that - * AbstractLock.FAILURE < AbstractLock.SUCCESS < AbstractLock.SLEEPHOOK - *

- * Any method can throw a LockException, providing a way to return - * unusual error cases in future types of locks (such as the Token - * service). - *

- * It is safe to call release () in a finally block, since it will - * return FAILURE if the accessing thread is not the owner. - * - */ -public interface AbstractLock -{ - /** - * Generic failure indication, used as a return value. - */ - public static final int FAILURE = -1; - - /** - * Success indication, used as a return value. - */ - int SUCCESS = 0; - - /** - * Success indication, but notes that the thread had to sleep - * to complete it (and it called the sleep hook). Used as a - * return value. - */ - int SLEEPHOOK = 1; - - - /** - * Acquire ownership of the lock, blocking indefinitely if necessary. - *

- *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception LockException special exception defined by a later - * implementation - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - */ - public int acquire () throws LockException, InterruptedException; - - /** - * Acquire ownership of the lock by the given absolute time time-out. - * A value of null for the timeout parameter results in a blocking - * acquire. - * A value of TimeValue.zero throws a TimeoutException if the - * acquire would block. - *

- *@param timeout absolute time by which the lock must be acquired - *@return appropriate Lock return value (AbstractLock.FAILURE, - * AbstractLock.SUCCESS or AbstractLock.SLEEPHOOK) - *@exception LockException special exception defined by a later - * implementation - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - *@see AbstractLock#tryAcquire - */ - public int acquire (TimeValue timeout) - throws LockException, TimeoutException, InterruptedException; - - /** - * Acquire a read lock, blocking indefinitely if necessary. This can - * be used to implement Reader-Writer locks in which multiple readers - * may have simultaneous access. - *

- *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception LockException special exception defined by a later - * implementation - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - */ - public int acquireRead () throws LockException, InterruptedException; - - /** - * Acquire a read lock by the given absolute time time-out. This can - * be used to implement Reader-Writer locks in which multiple readers - * may have simultaneous access. - *

- *@param timeout absolute time by which the lock must be acquired - *@return appropriate lock return value (AbstractLock.FAILURE, - * AbstractLock.SUCCESS or AbstractLock.SLEEPHOOK) - *@exception LockException special exception defined by a later - * implementation - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - *@see AbstractLock#tryAcquireRead - */ - public int acquireRead (TimeValue timeout) - throws LockException, TimeoutException, InterruptedException; - - /** - * Acquire a write lock, blocking indefinitely if necessary. This can - * be used to implement Reader-Writer locks in which a writer has - * exclusive access. - *

- *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception LockException special exception defined by a later - * implementation - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - */ - public int acquireWrite () throws LockException, InterruptedException; - - /** - * Acquire a write lock by the given absolute time time-out. This can - * be used to implement Reader-Writer locks in which a writer has - * exclusive access. - *

- *@param timeout absolute time by which the lock must be acquired - *@return appropriate AbstractLock return value (AbstractLock.FAILURE, - * AbstractLock.SUCCESS or AbstractLock.SLEEPHOOK) - *@exception LockException special exception defined by a later - * implementation - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - *@see AbstractLock#tryAcquireWrite - */ - public int acquireWrite (TimeValue timeout) - throws LockException, TimeoutException, InterruptedException; - - /** - * Give up the lock to some number of waiting threads (if any), then - * reacquire, blocking indefinitely if necessary. - *

- * 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 waiters queue to insert - * this thread. If this value is -1 and there are other - * threads waiting to obtain the token, this thread is queued - * at the end. If this value is greater than -1, then it - * indicates how many entries to skip over before inserting - * our thread into the queue. (For example, if it is 0, - * this thread is put at the front of the queue.) If this - * value is greater than the number of waiters, this thread is - * simply put at the end of the current waiters queue. - *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception LockException special exception defined by a later - * implementation - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - */ - public int renew (int requeuePosition) throws LockException, - InterruptedException; - - /** - * Give up the lock to some waiting threads (if any), then reacquire - * by the given absolute time time-out. - *

- * 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. - *

- * A value of null for the timeout should indicate a blocking renew. - *

- *@param requeuePosition position in the waiters queue to insert - * this thread. If this value is -1 and there are other - * threads waiting to obtain the token, this thread is queued - * at the end. If this value is greater than -1, then it - * indicates how many entries to skip over before inserting - * our thread into the queue. (For example, if it is 0, - * this thread is put at the front of the queue.) If this - * value is greater than the number of waiters, this thread is - * simply put at the end of the current waiters queue. - * - *@param timeout absolute time by which the lock must be reacquired - * - *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException special exception defined by a later - * implementation - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - */ - public int renew (int requeuePosition, TimeValue timeout) - throws LockException, TimeoutException, InterruptedException; - - /** - * Try to acquire the lock without blocking. - *

- *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException special exception defined by a later - * implementation - */ - public int tryAcquire () throws LockException; - - /** - * Try to acquire a read lock without blocking. - *

- *@see #acquireRead - *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException special exception defined by a later - * implementation - */ - public int tryAcquireRead () throws LockException; - - /** - * Try to acquire a write lock without blocking. - *

- *@see #acquireWrite - *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException special exception defined by a later - * implementation - */ - public int tryAcquireWrite () throws LockException; - - /** - * 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. - */ - public void sleepHook (); - - /** - * Release ownership of this lock. - *

- *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception LockException special exception defined by a later - * implementation - */ - public int release () throws LockException; -} diff --git a/java/JACE/Concurrency/Condition.java b/java/JACE/Concurrency/Condition.java deleted file mode 100644 index 1889f6e1edf..00000000000 --- a/java/JACE/Concurrency/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; - -/** - * Abstraction for traditional - * condition variable - *

- * This condition variable allows the use of one - * mutex between multiple conditions. - * This implementation is based on the C++ version of ACE. - */ -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(); - synchronized (waitObject_) { - waitObject_.wait (); - } - mutex_.acquire (); - } - finally - { - waiters_--; - } - } - - /** - * TimedWait for condition to become signaled. Note that the - * given TimeValue is an absolute time, not a relative time. - * - *@param tv Absolute time to wait until before timing out - *@exception TimeoutException wait timed out exception - *@exception InterruptedException exception during wait - */ - public void Wait (TimeValue tv) - throws TimeoutException, InterruptedException - { - waiters_++; - - try - { - mutex_.release(); - - synchronized (waitObject_) { - long start = System.currentTimeMillis(); - long waitTime = tv.getMilliTime() - start; - if (waitTime < 1) - throw new TimeoutException (); - waitObject_.wait (waitTime); - } - - mutex_.acquire (tv); - } - finally - { - waiters_--; - } - } - - /** - * Signal condition. Wake one waiter (if any). - */ - public void signal () - { - synchronized (waitObject_) { - waitObject_.notify (); - } - } - - /** - * Signal condition. Wake up all waiters (if any). - */ - public void broadcast () - { - synchronized (waitObject_) { - waitObject_.notifyAll (); - } - } - - /** - * Accessor to lock - *@return Mutex - */ - public Mutex mutex () - { - return mutex_; - } - - private int waiters_; - private Object waitObject_ = new Object (); - private Mutex mutex_; -} diff --git a/java/JACE/Concurrency/LockAdapter.java b/java/JACE/Concurrency/LockAdapter.java deleted file mode 100644 index db2e9de05c7..00000000000 --- a/java/JACE/Concurrency/LockAdapter.java +++ /dev/null @@ -1,262 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * Lock.java - * - *@author Everett Anderson - * - *************************************************/ -package JACE.Concurrency; - -import JACE.ASX.*; - -/** - * Abstract adapter class which provides useful default implementations - * for several methods in the AbstractLock interface, as well as - * protected helper functions for making sure only the owner - * can perform certain operations. - * - *@see JACE.Concurrency.AbstractLock - */ -public abstract class LockAdapter implements AbstractLock -{ - /** - * Default implementation that calls acquire (TimeValue) with a null - * timeout. - * - *@see AbstractLock#acquire - */ - public int acquire () throws InterruptedException - { - try { - return acquire (null); - } catch (TimeoutException e) { - // This should never happen - return AbstractLock.FAILURE; - } - } - - /** - * Acquire ownership of the lock by the given absolute time time-out. - * A value of null for the timeout parameter results in a blocking - * acquire. - * A value of TimeValue.zero throws a TimeoutException if the - * acquire would block. - *

- *@param timeout absolute time by which the lock must be acquired - *@return appropriate Lock return value (AbstractLock.FAILURE, - * AbstractLock.SUCCESS or AbstractLock.SLEEPHOOK) - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - *@see AbstractLock#tryAcquire - */ - public abstract int acquire (TimeValue timeout) - throws TimeoutException, InterruptedException; - - /** - * Default implementation that calls acquireRead (TimeValue) with a - * null timeout. - * - *@see AbstractLock#acquireRead - */ - public int acquireRead () throws InterruptedException - { - try { - return acquireRead (null); - } catch (TimeoutException e) { - // This should never happen - } - - return AbstractLock.FAILURE; - } - - /** - * Default implementation that calls acquire (TimeValue). - * - *@see AbstractLock#acquireRead(TimeValue) - */ - public int acquireRead (TimeValue timeout) - throws TimeoutException, InterruptedException - { - return acquire (timeout); - } - - /** - * Default implementation that calls acquire with a null - * timeout. - * - *@see AbstractLock#acquireWrite - */ - public int acquireWrite () throws InterruptedException - { - try { - return acquire (null); - } catch (TimeoutException e) { - // This should never happen - } - - return AbstractLock.FAILURE; - } - - /** - * Default implementation that calls acquire (TimeValue). - * - *@see AbstractLock#acquireWrite(TimeValue) - */ - public int acquireWrite (TimeValue timeout) - throws TimeoutException, InterruptedException - { - return acquire (timeout); - } - - /** - * Default implementation that calls renew (int, TimeValue) with - * a null timeout. - * - *@see AbstractLock#renew(int) - */ - public int renew (int requeuePosition) throws InterruptedException - { - try - { - return renew (requeuePosition, null); - } catch (TimeoutException e) { - // Note that this should never happen since we requested a - // blocking acquire. - return AbstractLock.FAILURE; - } - } - - /** - * Give up the lock to some waiting threads (if any), then reacquire - * by the given absolute time time-out. - *

- * 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. - *

- * A value of null for the timeout should indicate a blocking renew. - *

- *@param requeuePosition position in the waiters queue to insert - * this thread. If this value is -1 and there are other - * threads waiting to obtain the token, this thread is queued - * at the end. If this value is greater than -1, then it - * indicates how many entries to skip over before inserting - * our thread into the queue. (For example, if it is 0, - * this thread is put at the front of the queue.) If this - * value is greater than the number of waiters, this thread is - * simply put at the end of the current waiters queue. - * - *@param timeout absolute time by which the lock must be reacquired - * - *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - *@exception JACE.ASX.TimeoutException thrown when the lock is not - * obtained by the desired time - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - */ - public abstract int renew (int requeuePosition, - TimeValue timeout) - throws TimeoutException, - InterruptedException; - - /** - * Default implementation that calls tryAcquire (). - * - *@see AbstractLock#tryAcquireRead - */ - public int tryAcquireRead () - { - return tryAcquire (); - } - - /** - * Default implementation that calls tryAcquire (). - * - *@see AbstractLock#tryAcquireWrite - */ - public int tryAcquireWrite () - { - return tryAcquire (); - } - /** - * Try to acquire the lock without blocking. - *

- *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - */ - public abstract int tryAcquire (); - - /** - * Default implementation as a no-op. - * - *@see AbstractLock#sleepHook - */ - public void sleepHook () - { - } - - /** - * Release ownership of this lock. - *

- *@return appropriate AbstractLock return value - * (AbstractLock.FAILURE or AbstractLock.SUCCESS) - */ - public abstract int release (); - - /** - * Obtains an Object which uniquely identifies the current accessor - * (usually a thread). This is used to make sure only an owner can - * perform certain operations like release. Subclasses can redefine - * the behavior as necessary, such as in the Token service where it is - * defined to be the client ID sent by the proxy. - *

- * When using Java 1.2 or later, it might be more efficient to use - * ThreadLocal and an Integer for the ID. The current default - * implementation returns the Thread.currentThread () reference. - * - *@return Object representing a unique ID for this accessor - */ - protected Object accessorID () - { - return Thread.currentThread(); - } - - /** - * Check to see if the current accessor is the (or a) owner of this - * lock. - */ - protected boolean isOwner() - { - return accessorID().equals(this.owner_); - } - - /** - * Set the current accessor to be the (or a) owner of this lock. - */ - protected void setOwner() - { - this.owner_ = accessorID(); - } - - /** - * Make sure that this accessor is no longer the (or a) owner of this - * lock. - */ - protected void clearOwner() - { - this.owner_ = null; - } - - /** - * Reference to the accessorID of the owner. - */ - private Object owner_; -} diff --git a/java/JACE/Concurrency/LockException.java b/java/JACE/Concurrency/LockException.java deleted file mode 100644 index dff4c09c626..00000000000 --- a/java/JACE/Concurrency/LockException.java +++ /dev/null @@ -1,28 +0,0 @@ -package JACE.Concurrency; - -/** - * Base class for possible exceptions thrown from Lock - * mechanisms. This can be used by later Lock - * implementations to signal special types of exceptions, such - * as a remote failure, etc. - *

- */ -public class LockException extends java.lang.Exception -{ - /** - * Default constructor - */ - public LockException () { } - - /** - * Constructor with a string message that will be returned - * via the getMessage() method on Exception. - *

- *@see java.lang.Exception#getMessage - */ - public LockException (String message) - { - super(message); - } -} - diff --git a/java/JACE/Concurrency/Mutex.java b/java/JACE/Concurrency/Mutex.java deleted file mode 100644 index 856fdbd79eb..00000000000 --- a/java/JACE/Concurrency/Mutex.java +++ /dev/null @@ -1,239 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * Mutex.java - * - *@author Prashant Jain - *@author Everett Anderson - * - *************************************************/ -package JACE.Concurrency; - -import java.util.*; -import JACE.ASX.*; - -/** - * Value added abstraction for mutex variable creation. - * - * A mutex whose operations do not block forever and can time out. - *

- * This class does not support recursive semantics. - */ -public class Mutex extends LockAdapter -{ - /** - * Acquire ownership of the lock, blocking indefinitely if necessary. - *

- *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - */ - public synchronized int acquire () throws InterruptedException - { - if (this.monitor_.condition ()) { - this.monitor_.condition (false); - setOwner (); - return AbstractLock.SUCCESS; - } - - this.numberOfWaiters_++; - try { - sleepHook (); - this.monitor_.timedWait (); - } finally { - this.numberOfWaiters_--; - } - this.monitor_.condition (false); - setOwner(); - - return AbstractLock.SLEEPHOOK; - } - - public int renew (int requeuePosition, - TimeValue timeout) - throws InterruptedException, - TimeoutException - { - RenewObject rwo; - - synchronized (this) { - - if (!this.isOwner ()) - return AbstractLock.FAILURE; - - if (numberOfWaiters_ == 0 || requeuePosition == 0) - return AbstractLock.SUCCESS; - - if (requeuePosition < 0 || requeuePosition > numberOfWaiters_) - requeuePosition = numberOfWaiters_; - - rwo = new RenewObject (requeuePosition); - - this.release (); - this.renewers_.addElement (rwo); - } - - // We can't have the method synchronized, or synchronize on (this) - // in here because then the Thread that was woken up won't be able - // to continue its acquire. - // - // Normally when an exception occurs in timedWait, this thread just - // needs to remove itself from the renewers queue. - // - // However, the following situation exists: - // Thread A is the current owner, and is doing processing in release() - // This thread generates a timeout exception in timedWait - // Thread A signals this thread to wake up and take ownership, and - // removes it from the queue. - // This thread never takes ownership -- the exception keeps going up. - // - // This could lead to other renewers waiting in limbo forever. - // - // Solution: If this thread has an exception and it looks like it - // has been proclaimed the owner, then it calls release and lets - // the exception continue. - - boolean exceptionOccured = true; - try { - synchronized (rwo) { - rwo.timedWait (timeout); - - exceptionOccured = false; - } - } finally { - if (exceptionOccured) { - synchronized (this) { - if (!renewers_.removeElement (rwo)) { - setOwner (); - release (); - } - } - } - } - - synchronized (this) { - setOwner (); - } - - // By this point, we should know that we have the lock. The condition - // flag is never set to true in the release() call from the Thread - // that gave us control. - - return AbstractLock.SUCCESS; - } - - public synchronized int tryAcquire () { - if (this.monitor_.condition ()) { - this.monitor_.condition (false); - setOwner(); - return AbstractLock.SUCCESS; - } else - return AbstractLock.FAILURE; - } - - public synchronized int acquire (TimeValue tv) - throws TimeoutException, InterruptedException - { - if (this.monitor_.condition ()) { - this.monitor_.condition (false); - setOwner (); - return AbstractLock.SUCCESS; - } - - this.numberOfWaiters_++; - try { - sleepHook (); - this.monitor_.timedWait (tv); - } finally { - this.numberOfWaiters_--; - } - this.monitor_.condition (false); - setOwner(); - - return AbstractLock.SLEEPHOOK; - } - - /** - * Checks any objects in the renewers queue, giving one of them - * the lock if it is appropriate. Assumes the synchronization - * lock is already held. - * - *@return true if a renewer was signaled, else false - */ - protected boolean signalNextRenewer () - { - // First find the renewer with the minimum yieldTo count, processing - // all of them along the way. - if (this.renewers_.size() > 0) { - - RenewObject renewer = (RenewObject)renewers_. - elementAt (renewers_.size () - 1); - - renewer.decrementYieldTo (); - - for (int i = this.renewers_.size() - 2; i >=0; i--) { - - RenewObject rwo = (RenewObject)renewers_.elementAt (i); - - rwo.decrementYieldTo (); - - renewer = renewer.min (rwo); - } - - // If the renewer with the minimum yieldTo count has yielded to - // enough threads, or if there are no waiting threads, it should - // be signaled (thus, it wakes up and obtains the lock again). - - if (renewer.condition () || numberOfWaiters_ == 0) { - // Note that we leave monitor_.condition in the false state so - // we are assured that only the renewer (and not another - // Thread that does an acquire) will gain control. This - // is important since the renew method can't be synchronized - // in its current implementation. - renewers_.removeElement(renewer); - - synchronized (renewer) { - renewer.signal (); - } - - return true; - } - } - - return false; - } - - public synchronized int release () - { - if (!isOwner()) - return AbstractLock.FAILURE; - - if (!signalNextRenewer ()) { - // Do a normal release if there are no threads waiting to renew - // or no such threads are ready to renew. - this.monitor_.condition (true); - this.monitor_.signal (); - } - - return AbstractLock.SUCCESS; - } - - /** - * Monitor used to signal whether or not this Mutex is available. - */ - protected WaitObject monitor_ = new WaitObject (true, this); - // The monitor (adapter) to wait on - - /** - * Queue of waiting renewers. - */ - protected Vector renewers_ = new Vector (); - - /** - * Number of waiting threads. - */ - protected int numberOfWaiters_ = 0; -} diff --git a/java/JACE/Concurrency/RWMutex.java b/java/JACE/Concurrency/RWMutex.java deleted file mode 100644 index abb30ce3bc8..00000000000 --- a/java/JACE/Concurrency/RWMutex.java +++ /dev/null @@ -1,268 +0,0 @@ -package JACE.Concurrency; - -import java.util.*; -import JACE.ASX.*; - -/** - * A read/write lock allows multiple - * readers or a single writer to access the guarded element. - *

- * This class does not support recursive semantics. - */ -public class RWMutex extends LockAdapter -{ - public synchronized int tryAcquire () - { - if (referenceCount_ == 0) { - referenceCount_ = -1; - setOwner (); - return AbstractLock.SUCCESS; - } else - return AbstractLock.FAILURE; - } - - public synchronized int tryAcquireRead () - { - if (referenceCount_ > -1 && waiters_.size () == 0) { - referenceCount_++; - setOwner (); - return AbstractLock.SUCCESS; - } else - return AbstractLock.FAILURE; - } - - public int acquire(TimeValue timeout) - throws TimeoutException, InterruptedException - { - return acquireWrite(timeout); - } - - public void waitUntilIsOwner (RWWaitObject waitObj, TimeValue timeout) - throws TimeoutException, InterruptedException - { - boolean exceptionOccured = true; - try { - sleepHook (); - synchronized (waitObj) { - waitObj.timedWait (timeout); - } - exceptionOccured = false; - } finally { - - synchronized (this) { - - if (exceptionOccured) { - if (!waiters_.removeElement (waitObj)) { - setOwner (); - release (); - } - } else - setOwner(); - } - } - } - - public int acquireRead(TimeValue timeout) - throws TimeoutException, InterruptedException - { - RWWaitObject waitObj = null; - - synchronized (this) { - - if (referenceCount_ > -1 && waiters_.size () == 0) { - referenceCount_++; - setOwner (); - return AbstractLock.SUCCESS; - } - - waitObj = new RWWaitObject (true); - - waiters_.addElement (waitObj); - } - - waitUntilIsOwner (waitObj, timeout); - - return AbstractLock.SLEEPHOOK; - } - - public int acquireWrite(TimeValue timeout) - throws TimeoutException, InterruptedException - { - RWWaitObject waitObj = null; - - synchronized (this) { - - if (referenceCount_ == 0) { - referenceCount_ = -1; - setOwner (); - return AbstractLock.SUCCESS; - } - - waitObj = new RWWaitObject (false); - - waiters_.addElement (waitObj); - } - - waitUntilIsOwner (waitObj, timeout); - - // When the writer gets here, it has been cleared to go by - // whatever thread specifically gave control to this writer in - // release. The referenceCount_ and numberOfWaitingWriters_ - // variables are also adjusted by the releasing thread since - // it already has a synchronization lock. Not doing that, - // and then having another synchronized (this) block in here - // could lead to a situation in which another thread sneaks - // in inbetween when this thread leaves timedWait and goes to - // adjust them. - - return AbstractLock.SLEEPHOOK; - } - - - public synchronized int release () - { - if (!isOwner ()) - return AbstractLock.FAILURE; - - clearOwner (); - - // Releasing a reader. - if (referenceCount_ > 0) { - referenceCount_--; - - if (referenceCount_ != 0) - return AbstractLock.SUCCESS; - - } else { - // releasing a writer - referenceCount_ = 0; - } - - if (waiters_.size () == 0) - return AbstractLock.SUCCESS; - - if (releaseFirstReaders () == 0) { - RWWaitObject waitObj = (RWWaitObject)waiters_.firstElement (); - waiters_.removeElementAt (0); - - referenceCount_ = -1; - - waitObj.condition (true); - synchronized (waitObj) { - waitObj.signal (); - } - } - - return AbstractLock.SUCCESS; - } - - // Releases all waiting readers up to the first waiting writer - // or the end of the queue. Returns the number of readers - // released. - protected int releaseFirstReaders () - { - int releasedReaders = 0; - - do { - - RWWaitObject waitObj = (RWWaitObject)waiters_.firstElement (); - if (!waitObj.isReader ()) - break; - - waiters_.removeElementAt (0); - - referenceCount_++; - releasedReaders++; - - waitObj.condition (true); - synchronized (waitObj) { - waitObj.signal (); - } - - } while (waiters_.size () > 0); - - return releasedReaders; - } - - public int renew (int requeuePosition, - JACE.ASX.TimeValue timeout) - throws InterruptedException, - TimeoutException - { - RWWaitObject waitObj = null; - - synchronized (this) { - - if (!isOwner ()) - return AbstractLock.FAILURE; - - if (requeuePosition == 0 || waiters_.size () == 0) - return AbstractLock.SUCCESS; - - waitObj = new RWWaitObject (referenceCount_ > 0); - - if (requeuePosition < 0 || requeuePosition > waiters_.size ()) { - requeuePosition = waiters_.size (); - } - - waiters_.insertElementAt (waitObj, requeuePosition); - - release (); - } - - waitUntilIsOwner (waitObj, timeout); - - // When the writer gets here, it has been cleared to go by - // whatever thread specifically gave control to this writer in - // release. The referenceCount_ and numberOfWaitingWriters_ - // variables are also adjusted by the releasing thread since - // it already has a synchronization lock. Not doing that, - // and then having another synchronized (this) block in here - // could lead to a situation in which another thread sneaks - // in inbetween when this thread leaves timedWait and goes to - // adjust them. - - return AbstractLock.SUCCESS; - } - - static class RWWaitObject extends WaitObject - { - public RWWaitObject (boolean isReader) - { - isReader_ = isReader; - } - - public boolean isReader () - { - return isReader_; - } - - private boolean isReader_ = false; - } - - protected boolean isOwner () - { - return owners_.containsKey (accessorID()); - } - - protected void setOwner () - { - owners_.put (accessorID(), this); - } - - protected void clearOwner () - { - owners_.remove (accessorID()); - } - - private Vector waiters_ = new Vector (); - - private int referenceCount_ = 0; - // Value is -1 if writer has the lock, else this keeps track of the - // number of readers holding the lock. - - private Hashtable owners_ = new Hashtable (); - - private int nestingLevel_ = 0; -} - diff --git a/java/JACE/Concurrency/RenewObject.java b/java/JACE/Concurrency/RenewObject.java deleted file mode 100644 index b690958968a..00000000000 --- a/java/JACE/Concurrency/RenewObject.java +++ /dev/null @@ -1,36 +0,0 @@ -package JACE.Concurrency; - -import JACE.ASX.TimedWait; - -class RenewObject extends TimedWait -{ - public RenewObject (int maxYieldTo) - { - yieldTo_ = maxYieldTo; - } - - public boolean condition () - { - return yieldTo_ <= 0; - } - - public void decrementYieldTo() - { - this.yieldTo_--; - } - - public int yieldTo () - { - return this.yieldTo_; - } - - public RenewObject min (RenewObject other) - { - if (other.yieldTo_ < this.yieldTo_) - return other; - else - return this; - } - - private int yieldTo_; -} diff --git a/java/JACE/Concurrency/Semaphore.java b/java/JACE/Concurrency/Semaphore.java deleted file mode 100644 index 5e558035aee..00000000000 --- a/java/JACE/Concurrency/Semaphore.java +++ /dev/null @@ -1,263 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * Semaphore.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Concurrency; - -import java.util.*; -import JACE.ASX.*; - -/** - * Implementation of Dijkstra's counting semaphore in java. - *

- * This class does not support recursive semantics. - */ -public class Semaphore extends LockAdapter -{ - static 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; - } - - public int count () - { - return this.count_; - } - - private int count_ = 0; - } - - /** - * Create a Semaphore. - *@param count semaphore count - */ - public Semaphore (int c) - { - this.monitor_.count (c); - this.owners_ = new Hashtable (c); - } - - /** - * Create a binary Semaphore. - */ - public Semaphore () - { - this.monitor_.count (1); - this.owners_ = new Hashtable (1); - } - - public synchronized int tryAcquire () - { - if (this.monitor_.condition ()) { - this.monitor_.decrement (); - setOwner (); - return AbstractLock.SUCCESS; - } else - return AbstractLock.FAILURE; - } - - /** - * Acquire the Semaphore. Throws a TimeoutException if the semaphore - * isn't acquired before the given absolute time. - *@param tv time (TimeValue) to wait until before throwing a - * TimeoutException (unless the semaphore is acquired before that) - *@exception TimeoutException wait timed out exception - *@exception InterruptedException exception during wait - */ - public synchronized int acquire (TimeValue tv) - throws TimeoutException, InterruptedException - { - if (this.monitor_.condition ()) { - this.monitor_.decrement (); - setOwner (); - return AbstractLock.SUCCESS; - } - - numberOfWaiters_++; - - try { - sleepHook (); - this.monitor_.timedWait (tv); - } finally { - numberOfWaiters_--; - } - - this.monitor_.decrement (); - setOwner (); - - return AbstractLock.SLEEPHOOK; - } - - public synchronized int release () - { - if (!isOwner ()) - return AbstractLock.FAILURE; - - if (!signalNextRenewer ()) { - this.monitor_.increment (); - this.monitor_.signal (); - clearOwner (); - } - - return AbstractLock.SUCCESS; - } - - /** - * Checks any objects in the renewers queue, giving one of them - * the lock if it is appropriate. Assumes the synchronization - * lock is already held. - * - *@return true if a renewer was signaled, else false - */ - protected boolean signalNextRenewer () - { - // First find the renewer with the minimum yieldTo count, processing - // all of them along the way. - if (this.renewers_.size() > 0) { - - RenewObject renewer = (RenewObject)renewers_. - elementAt (renewers_.size () - 1); - - renewer.decrementYieldTo (); - - for (int i = this.renewers_.size() - 2; i >=0; i--) { - - RenewObject rwo = (RenewObject)renewers_.elementAt (i); - - rwo.decrementYieldTo (); - - renewer = renewer.min (rwo); - } - - // If the renewer with the minimum yieldTo count has yielded to - // enough threads, or if there are no waiting threads, it should - // be signaled (thus, it wakes up and obtains the lock again). - - if (renewer.condition () || numberOfWaiters_ == 0) { - // Note that we leave monitor_.inUse in the true state so - // we are assured that only the renewer (and not another - // Thread that does an acquire) will gain control. This - // is important since the renew method can't be synchronized - // in its current implementation. - renewers_.removeElement(renewer); - - synchronized (renewer) { - renewer.signal (); - } - - return true; - } - } - - return false; - } - - public int renew (int requeuePosition, - JACE.ASX.TimeValue timeout) - throws InterruptedException, - TimeoutException - { - RenewObject rwo; - - synchronized (this) { - - if (!this.isOwner ()) - return AbstractLock.FAILURE; - - if (numberOfWaiters_ == 0 || - requeuePosition == 0 || - this.monitor_.condition ()) - return AbstractLock.SUCCESS; - - if (requeuePosition < 0 || requeuePosition > numberOfWaiters_) - requeuePosition = numberOfWaiters_; - - rwo = new RenewObject (requeuePosition); - - this.release (); - this.renewers_.addElement (rwo); - } - - boolean exceptionOccured = true; - try { - synchronized (rwo) { - rwo.timedWait (timeout); - - exceptionOccured = false; - } - } finally { - synchronized (this) { - - if (exceptionOccured) { - if (!renewers_.removeElement (rwo)) { - setOwner (); - release (); - } - } else { - setOwner(); - } - } - } - - // By this point, we should know that we have the lock. The inUse - // flag is never set to false in the release() call from the Thread - // that gave us control. That thread also set the owner value. - - return AbstractLock.SUCCESS; - } - - protected boolean isOwner () - { - return owners_.containsKey (accessorID()); - } - - protected void setOwner () - { - owners_.put (accessorID(), this); - } - - protected void clearOwner () - { - owners_.remove (accessorID()); - } - - private TimedWaitSAdapter monitor_ = new TimedWaitSAdapter (this); - // The monitor (adapter) to wait on - - private Hashtable owners_; - private Vector renewers_ = new Vector (); - private int numberOfWaiters_ = 0; -} diff --git a/java/JACE/Concurrency/ThreadManager.java b/java/JACE/Concurrency/ThreadManager.java deleted file mode 100644 index d23e2410676..00000000000 --- a/java/JACE/Concurrency/ThreadManager.java +++ /dev/null @@ -1,113 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * ThreadManager.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Concurrency; - -import java.util.*; -import JACE.OS.*; - -/** - * Wrapper for a ThreadGroup which provides additional methods for - * creating a certain number of Runnable instances. - */ -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 new threads. - *@param n the number of threads to spawn - *@param thr the caller whose run method will be invoked by each of - * the 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/JACE/Concurrency/Token.java b/java/JACE/Concurrency/Token.java deleted file mode 100644 index c9080b47fbe..00000000000 --- a/java/JACE/Concurrency/Token.java +++ /dev/null @@ -1,301 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Concurrency - * - * = FILENAME - * Token.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Concurrency; - -import java.util.*; -import JACE.ASX.*; - -import JACE.OS.*; - -/** - * Class that acquires, renews, and releases a synchronization - * token that is serviced in strict FIFO ordering. - *

- * 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. - * - *

- * This class DOES support recursive semantics. - */ -public class Token extends LockAdapter -{ - /** - * Acquire ownership of the lock, blocking indefinitely if necessary. - *

- *@return AbstractLock.FAILURE or AbstractLock.SUCCESS - *@exception InterruptedException indicates another thread has - * interrupted this one during wait - */ - public int acquire () throws InterruptedException - { - try - { - return this.acquire (null); - } - catch (TimeoutException e) - { - // This really shouldn't happen since we are supposed to - // block. - return AbstractLock.FAILURE; - } - } - - /** - * Acquire the token by the given absolute time time-out. The - * method uses synchronized blocks internally to avoid race conditions. - *@param timeout time to wait until before throwing a - * TimeoutException (unless the token is acquired before that). - * Performs a blocking acquire if the given timeout is null. - *@return AbstractLock.SUCCESS if acquires without calling - * AbstractLock.SLEEPHOOK if is called. - * AbstractLock.FAILURE if failure occurs - *@exception TimeoutException if time-out occurs - *@exception InterruptedException exception during wait - */ - public int acquire (TimeValue timeout) throws TimeoutException, - InterruptedException - { - int result = AbstractLock.SUCCESS; - WaitObject snl = new WaitObject (); - boolean mustWait; - synchronized (snl) - { - synchronized (this) - { - mustWait = !this.snq_.isEmpty (); - - if (mustWait && isOwner ()) - { - // I am the one who has the token. So just increment - // the nesting level - this.nestingLevel_++; - return AbstractLock.SUCCESS; - } - // Add local lock to the queue - this.snq_.addElement (snl); - } - if (mustWait) - { - result = AbstractLock.SLEEPHOOK; - sleepHook(); - - boolean exceptionOccured = true; - try { - snl.timedWait(timeout); - exceptionOccured = false; - } finally { - if (exceptionOccured) { - synchronized (this) { - if (!snq_.removeElement (snl)) { - setOwner (); - release (); - } - } - } - } - } - - // Set the owner of the token - synchronized (this) { - setOwner(); - } - } - - return result; - } - - /** - * Try to acquire the token. Implements a non-blocking acquire. - * - *@return AbstractLock.SUCCESS if acquires - * AbstractLock.FAILURE if failure occurs - */ - public synchronized int tryAcquire () - { - int result = AbstractLock.SUCCESS; - - if (this.snq_.isEmpty ()) - { - // No one has the token, so acquire it - this.snq_.addElement (new WaitObject ()); - - setOwner(); - } - else if (isOwner()) - { - this.nestingLevel_++; - } - // Someone else has the token. - else - { - // Would have to block to acquire the token, so return - // failure. - result = AbstractLock.FAILURE; - } - return result; - } - - /** - * 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. If the given TimeValue - * is null, it's the same as calling renew(int requeuePosition). - *@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 Throw a TimeoutException if the token isn't renewed - * before this absolute time timeout. - *@return AbstractLock.SUCCESS if renewed the lock - * AbstractLock.FAILURE if failure occurs - *@exception TimeoutException exception if timeout occurs - *@exception InterruptedException exception during wait - */ - public int renew (int requeuePosition, TimeValue timeout) - throws TimeoutException, InterruptedException - { - WaitObject snl = null; - int saveNestingLevel = 0; - - synchronized (this) - { - if (!isOwner ()) - return AbstractLock.FAILURE; - - // 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, Math.min(requeuePosition, - this.snq_.size())); - - 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); - // Wait until the given absolute time (or until notified - // if the timeout is null) - - boolean exceptionOccured = true; - try { - - snl.timedWait (timeout); - - exceptionOccured = false; - - } finally { - if (exceptionOccured) { - synchronized (this) { - if (!snq_.removeElement (snl)) { - setOwner (); - release (); - } - } - } - } - } - - synchronized (this) { - // Restore the nesting level and current owner of the lock - this.nestingLevel_ = saveNestingLevel; - - // Set the owner of the token - setOwner(); - } - } - - return AbstractLock.SUCCESS; - } - - /** - * Release the token. It is safe for non-owners to call - * this. - *@return AbstractLock.SUCCESS on success - * AbstractLock.FAILURE on failure (for instance, a non-owner - * calling release) - */ - public synchronized int release () - { - if (!isOwner()) - return AbstractLock.FAILURE; - - // Check if nestingLevel > 0 and if so, decrement it - if (this.nestingLevel_ > 0) - this.nestingLevel_--; - else - { - clearOwner (); - 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 (); - } - } - } - - return AbstractLock.SUCCESS; - } - - private Vector snq_ = new Vector (); - // Vector of lock objects - - private int nestingLevel_ = 0; - // Current Nesting Level -} diff --git a/java/JACE/Concurrency/WaitObject.java b/java/JACE/Concurrency/WaitObject.java deleted file mode 100644 index b7c8cbc7191..00000000000 --- a/java/JACE/Concurrency/WaitObject.java +++ /dev/null @@ -1,39 +0,0 @@ -package JACE.Concurrency; - -import JACE.ASX.TimedWait; - -class WaitObject extends TimedWait -{ - public WaitObject () - { - super (); - } - - public WaitObject (Object obj) - { - super (obj); - } - - public WaitObject (boolean initialState) - { - condition_ = initialState; - } - - public WaitObject (boolean initialState, Object obj) - { - super (obj); - condition_ = initialState; - } - - public boolean condition () - { - return this.condition_; - } - - public void condition (boolean c) - { - this.condition_ = c; - } - - private boolean condition_ = false; -} diff --git a/java/JACE/Concurrency/package.html b/java/JACE/Concurrency/package.html deleted file mode 100644 index ceadb36f662..00000000000 --- a/java/JACE/Concurrency/package.html +++ /dev/null @@ -1,15 +0,0 @@ - - - -Collection of concurrency mechanisms and a Thread manager. -

-JACE concurrency mechanisms now inherit from a common base class, -AbstractLock. This allows users to write code without regard to -whether a lock is local or remote. - -@see JACE.netsvcs.Token.RemoteLock -@see Documents on ACE concurrency components - - - - diff --git a/java/JACE/Connection/AcceptStrategy.java b/java/JACE/Connection/AcceptStrategy.java deleted file mode 100644 index 3af87865c79..00000000000 --- a/java/JACE/Connection/AcceptStrategy.java +++ /dev/null @@ -1,87 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * AcceptStrategy.java - * - *@author Prashant Jain - *@author Everett Anderson - * - *************************************************/ -package JACE.Connection; - -import java.io.*; -import java.net.*; -import JACE.SOCK_SAP.*; - -/** - * Interface for specifying a passive connection - * acceptance strategy for a - * SvcHandler - * . - *

- * This class provides a strategy that manages passive - * connection setup for an application, and can be extended - * to define new strategies. - *

- * - * The default implementation delegates to a generic Acceptor. - * - *@see SvcHandler - *@see Acceptor - */ -public class AcceptStrategy -{ - /** - * Create an instance of AcceptStrategy that delegates to the given - * Acceptor. - *@param port port number where the server will listen for connections - *@param peer Acceptor instance to delegate to - */ - AcceptStrategy (int port, Acceptor peer) throws IOException - { - this.acceptor_ = peer; - this.open (port); - } - - /** - * Create an instance of Accept Strategy that delegates to Acceptor. - *@param port port number where the server will listen for connections - *@exception IOException couldn't open port - */ - AcceptStrategy (int port) throws IOException - { - this.acceptor_ = new Acceptor (); - 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 - { - this.acceptor_.open (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 - { - return this.acceptor_.acceptSvcHandler (sh); - } - - // The Acceptor we delegate to (if any) - private Acceptor acceptor_; -} diff --git a/java/JACE/Connection/Acceptor.java b/java/JACE/Connection/Acceptor.java deleted file mode 100644 index 00dbed4c056..00000000000 --- a/java/JACE/Connection/Acceptor.java +++ /dev/null @@ -1,215 +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.*; - -/** - * Abstract factory for creating a service handler - * (SvcHandler), - * accepting into the - * SvcHandler, and activating the - * SvcHandler. - *

- * - * Implements the basic strategy for passively establishing - * connections with applications. The Acceptor - * is a factory for SvcHandler instances, and, by default - * generates a new SvcHandler instance for each connection - * esablished. - * - *

- * - * The user of this class must provide a - * reference to a handler factory prior to calling accept, or an exception will be - * thrown. The handler factory is identified by the meta-class for - * the SvcHandler, and is typically obtained by calling Class.classForName("SvcHandler"). - * - *

- * - * TCP is the transport mechanism used, via - * SOCKAcceptor, - * et.al. The SvcHandler is instantiated with a concrete type - * that performs the application-specific service. - * - *

- * - * This class is not directly related to the - * AcceptorStrategy class. - * - * - * @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, setHandlerFactory - * must be called prior to using accept. - * - * @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 Class.classForName). - * - *@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 Class.forName). - * - *@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.port_ = port; - this.sockAcceptor_ = new SOCKAcceptor (port); - } - - /** - * Template method for accepting connections. Delegates operational - * activities to the following bridge methods: - *

- * - *

- * - * The method first obtains a SvcHandler via - * makeSvcHandler, accepts the connection into the - * handler using acceptSvcHandler, and finally turns over - * control to the handler with activateSvcHandler. - * - *@exception SocketException socket level error - *@exception InstantiationException makeSvcHandler failure - *@exception IllegalAccessException makeSvcHandler 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 SvcHandler. The default is to - * create a new . However, subclasses can override this - * policy to perform creation in any way that they like - * (such as creating subclass instances of , 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 - * SvcHandler. The default behavior delegates the work to - * SOCKAcceptor.accept. 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 SvcHandler. The default - * behavior of this method is to activate the SvcHandler by - * calling its open() method (which allows the SvcHandler 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; - } - - protected int port_ = ACE.DEFAULT_SERVER_PORT; - - // Handler class that should be instantiated when a connection is - // made with a client - protected Class handlerFactory_; - - // Our connection acceptance factory - protected SOCKAcceptor sockAcceptor_; -} - diff --git a/java/JACE/Connection/ActivateStrategy.java b/java/JACE/Connection/ActivateStrategy.java deleted file mode 100644 index 91072a6c823..00000000000 --- a/java/JACE/Connection/ActivateStrategy.java +++ /dev/null @@ -1,40 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * ActivateStrategy.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - - -/** - * Bridge supporting activation strategy used by - * StrategyAcceptor - *

- * Subclass and overload - * activateSvcHandler - * in order change the activation strategy. Then, submit this subclass to - * StrategyAcceptor - * 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/JACE/Connection/Blob.java b/java/JACE/Connection/Blob.java deleted file mode 100644 index d3102c81aa2..00000000000 --- a/java/JACE/Connection/Blob.java +++ /dev/null @@ -1,114 +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.*; - -/** - * Provides a way of reading from or writing to a remote file - * using MessageBlocks. - */ -public class Blob -{ - /** - * Initialize the Blob. - * - *@param filename File to read or write - *@param hostname Host to contact for the file - *@param port Port on which to connect - */ - public int open (String filename, String hostname , int port) - { - this.filename_ = filename; - this.hostname_ = hostname; - this.port_ = port; - return 0; - } - - /** - * Read a certain amount from the file. - */ - 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; - } - - /** - * Write a certain amount to the file. - */ - 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/JACE/Connection/BlobHandler.java b/java/JACE/Connection/BlobHandler.java deleted file mode 100644 index ec282bdeaa9..00000000000 --- a/java/JACE/Connection/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/JACE/Connection/BlobReader.java b/java/JACE/Connection/BlobReader.java deleted file mode 100644 index 4de6b65bedc..00000000000 --- a/java/JACE/Connection/BlobReader.java +++ /dev/null @@ -1,108 +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.*; - -/** - * Provides a way to read from a remote file using - * MessageBlocks (and HTTP).

- * - * Created by Blob during a call to read. - */ -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/JACE/Connection/BlobWriter.java b/java/JACE/Connection/BlobWriter.java deleted file mode 100644 index 18c9b092964..00000000000 --- a/java/JACE/Connection/BlobWriter.java +++ /dev/null @@ -1,224 +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.*; - -/** - * Provides a way to write to a remote file using MessageBlocks - * (and HTTP).

- * - * Created by Blob during a write. - */ -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/JACE/Connection/Connector.java b/java/JACE/Connection/Connector.java deleted file mode 100644 index dbe72b8c359..00000000000 --- a/java/JACE/Connection/Connector.java +++ /dev/null @@ -1,148 +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.*; - -/** - * Abstract factory for connecting a - * (SvcHandler), - * to an application. - *

- * Implements the basic strategy for actively establishing connections - * with applications. The Connector establishes the connection, - * passing it on to a SvcHandler instance, and handing over - * control to that instance. - *

- * TCP is the transport mechanism used, via - * SOCKConnector. - *

- * This class, as currently implemented, does not work like its C++ - * counterpart. - * Future versions are expected to rectify this discrepancy. - * - *@see SOCKConnector - *@see SvcHandler - */ -public class Connector extends ServiceObject -{ - /** - * Create a Connector. Do nothing constructor. Allows user to - * call open() later. - */ - public Connector () - { - } - - /** - * Create a Connector passing in server hostname and port - * number, effectively shorthand for calling - * open(). - *@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 - * 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 . The default - * behavior of this method is to activate the 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/JACE/Connection/CreationStrategy.java b/java/JACE/Connection/CreationStrategy.java deleted file mode 100644 index f4828d5bff5..00000000000 --- a/java/JACE/Connection/CreationStrategy.java +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Connection - * - * = FILENAME - * CreationStrategy.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Connection; - -/** - * Defines the interface for specifying a creation strategy for a - * SvcHandler to the - * StrategyAcceptor. - *

- * 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.). - * - *@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/JACE/Connection/HTTPHelper.java b/java/JACE/Connection/HTTPHelper.java deleted file mode 100644 index 2901d74a14a..00000000000 --- a/java/JACE/Connection/HTTPHelper.java +++ /dev/null @@ -1,182 +0,0 @@ -package JACE.Connection; - -import JACE.OS.*; - -/** - * Collection of methods concerning HTTP. - */ -public class HTTPHelper -{ - /** - * Alphabet used in encoding and decoding basic base64 authentication. - * See the HTTP 1.1 RFC for details. - */ - public static String Alphabet - = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - /** - * Decode a secret encrypted with the basic base64 HTTP 1.1 authentication - * scheme. - * - *@param secret Message to decode - *@return null on error, decoded String on success - */ - public static String DecodeBase64 (String secret) - { - StringBuffer output = new StringBuffer (); - boolean inalphabet [] = new boolean[256]; - char decoder [] = new char [256]; - - for (int i = 0; i < 256; i++) { - inalphabet [i] = false; - decoder [i] = 0; - } - - for (int i = Alphabet.length () - 1; - i >= 0; - i--) - { - inalphabet [(int)Alphabet.charAt (i)] = true; - decoder [(int)Alphabet.charAt (i)] = (char)i; - } - - int inidx = 0; - int c = 0; - int char_count = 0; - int bits = 0; - boolean error = false; - - while (inidx < secret.length ()) - { - c = secret.charAt (inidx++); - - if (c == '=') - break; - - if (c > 255 || !inalphabet[(int)c]) - continue; - - bits += decoder[c]; - char_count++; - if (char_count == 4) { - output.append ((char) (bits >> 16)); - output.append ((char) ((bits >> 8) & 0xff)); - output.append ((char) (bits & 0xff)); - bits = 0; - char_count = 0; - } else - bits <<= 6; - } - - if (c == '\0') { - if (char_count != 0) { - ACE.DEBUG ("base64 encoding incomplete: at least " - + ((4 - char_count) * 6) + " bits truncated"); - error = true; - } - } else { - // c == '=' - switch (char_count) - { - case 1: - ACE.DEBUG ("output so far: " + output.toString ()); - ACE.DEBUG ("base64 encoding incomplete: at least 2 bits missing"); - error = true; - break; - case 2: - output.append ((char) (bits >> 10)); - break; - case 3: - output.append ((char) (bits >> 16)); - output.append ((char) ((bits >> 8) & 0xff)); - break; - } - } - - if (!error) - return output.toString (); - else - return null; - } - - /** - * Encode a message with the basic base64 HTTP 1.1 authentication - * scheme. Adapted from James' JAWS HTTP_Helpers code. - * - *@param secret Message to encode - *@return null on error, an encoded String on success - */ - 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; - } - - private HTTPHelper () {} -} - - diff --git a/java/JACE/Connection/StrategyAcceptor.java b/java/JACE/Connection/StrategyAcceptor.java deleted file mode 100644 index 743d384776f..00000000000 --- a/java/JACE/Connection/StrategyAcceptor.java +++ /dev/null @@ -1,174 +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.*; - -/** - * Abstract factory for creating, accepting into, and activating - * a service handler. - *

- * Uses instances of CreationStrategy, AcceptStrategy, and - * ActivateStrategy. - * - *@see SvcHandler - *@see CreationStrategy - *@see AcceptStrategy - *@see ActivateStrategy - */ -public class StrategyAcceptor extends Acceptor -{ - /** - * Create an instance of StrategyAcceptor. The caller must - * call setHandlerFactory before open! - */ - public StrategyAcceptor () - { - this (null, null, null, null); - } - - /** - * 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 - * . 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 . 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); - } - - // Creation Strategy - private CreationStrategy creStrategy_; - - // Accept Strategy - private AcceptStrategy acceptStrategy_; - - // Activation Strategy - private ActivateStrategy activateStrategy_; -} diff --git a/java/JACE/Connection/SvcHandler.java b/java/JACE/Connection/SvcHandler.java deleted file mode 100644 index 1df62247baa..00000000000 --- a/java/JACE/Connection/SvcHandler.java +++ /dev/null @@ -1,101 +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.*; - -/** - * Defines the interface for a service that exchanges data with its - * connected peer. - *

- * This class provides a well-defined interface that the Acceptor and - * Connector pattern factories use as their target. Typically, client - * applications will subclass SvcHandler and do all the interesting work - * in the subclass. One thing that the SvcHandler does contain is a - * peer SOCKStream endpoint that is initialized by Acceptor or Connector - * when a connection is established successfully. This endpoint is used - * to exchange data between a SvcHandler and the peer it is connected - * with. - */ -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 when the event occured - *@param obj An arbitrary object that was passed to the Timer Queue - * (Asynchronous Completion Token) - */ - public int handleTimeout (TimeValue tv, Object obj) - { - return -1; - } - - /** - * Underlying peer socket stream. - */ - protected SOCKStream stream_; -} diff --git a/java/JACE/Connection/package.html b/java/JACE/Connection/package.html deleted file mode 100644 index 429904216d5..00000000000 --- a/java/JACE/Connection/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - - -Collection of factories for services. -@see Documents on ACE object and service initialization components - - diff --git a/java/JACE/Makefile b/java/JACE/Makefile deleted file mode 100644 index fd8d7b7a68a..00000000000 --- a/java/JACE/Makefile +++ /dev/null @@ -1,234 +0,0 @@ -# Makefile -# $Id$ - -.SUFFIXES: .java .class - -VERSION = 1.5 -JACE_WRAPPER = .. -CLASSDIR = $(JACE_WRAPPER)/classes -DOCDIR = $(JACE_WRAPPER)/doc - -JC = javac -JCOPTS = -d $(CLASSDIR) -JD = javadoc -JDOPTS = -classpath $(CLASSDIR) -sourcepath $(JACE_WRAPPER) -windowtitle \ - "Java ACE $(VERSION) Documentation" -bottom \ - "Java ACE Version $(VERSION)
\ - \ - http://www.cs.wustl.edu/~schmidt" \ - -doctitle "Java ACE Version $(VERSION) Documentation" -d $(DOCDIR) \ - -overview overview.html - -COMPILE.java = $(JC) $(JCOPTS) $(filter %.java,$?) - -CLASSPATH := $(CLASSDIR):$(CLASSPATH) - -all: asx os concurrency connection timers misc reactor svcconfig socksap netsvcs - -pkg_all = $(pkg_asx_timestuff) $(pkg_asx) $(pkg_os) $(pkg_concurrency) \ - $(pkg_connection) $(pkg_timers) $(pkg_misc) $(pkg_reactor) \ - $(pkg_socksap) $(pkg_svcconfig) $(pkg_netsvcs) - -doc: - $(JD) $(JDOPTS) $(packages) - -docclean: - find ${JACE_WRAPPER}/doc -name '*.html' -print | xargs ${RM} - -clean: - find ${JACE_WRAPPER}/classes/JACE -name '*.class' -print | xargs ${RM} - -realclean: clean docclean - - -pkg_asx_timestuff = \ - TimeValue \ - TimeoutException \ - TimedWait - -asx_timestuff: $(addprefix ASX/,$(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 \ - $(addprefix ASX/,$(addsuffix .java,$(pkg_asx))) - $(COMPILE.java) - -pkg_os = \ - OS \ - ACE - -os: $(addprefix OS/,$(addsuffix .java,$(pkg_os))) - $(COMPILE.java) - -pkg_concurrency = \ - AbstractLock \ - LockAdapter \ - LockException \ - WaitObject \ - RenewObject \ - Condition \ - Mutex \ - RWMutex \ - Semaphore \ - ThreadManager \ - Token - -concurrency: $(addprefix 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 $(addprefix Connection/,\ - $(addsuffix .java,$(pkg_connection))) - $(COMPILE.java) - -pkg_timers = \ - ProfileTimer - -timers: $(addprefix Timers/,$(addsuffix .java,$(pkg_timers))) - $(COMPILE.java) - -pkg_misc = \ - GetOpt - -misc: $(addprefix Misc/,$(addsuffix .java,$(pkg_misc))) - $(COMPILE.java) - -pkg_reactor = \ - EventHandler \ - TimerQueue - -reactor: asx_timestuff $(addprefix Reactor/,\ - $(addsuffix .java,$(pkg_reactor))) - $(COMPILE.java) - -pkg_socksap = \ - INETAddr \ - SOCKStream \ - SOCKAcceptor \ - SOCKConnector - -socksap: os $(addprefix SOCK_SAP/,\ - $(addsuffix .java,$(pkg_socksap))) - $(COMPILE.java) - -pkg_svcconfig = \ - Service \ - ServiceLoader \ - ServiceObject \ - ServiceConfig \ - ServiceRepository - -svcconfig: os reactor misc $(addprefix ServiceConfigurator/,\ - $(addsuffix .java,$(pkg_svcconfig))) - $(COMPILE.java) - -netsvcs: netsvcs_base netsvcs_logger netsvcs_naming netsvcs_time \ - netsvcs_token - -pkg_netsvcs = $(pkg_netsvcs_base) $(pkg_netsvcs_logger) \ - $(pkg_netsvcs_time) $(pkg_netsvcs_naming) $(pkg_netsvcs_token) - -pkg_netsvcs_base = \ - Server \ - Handler - -netsvcs_base: os asx concurrency connection socksap svcconfig \ - $(addprefix netsvcs/,$(addsuffix .java,$(pkg_netsvcs_base))) - $(COMPILE.java) - -pkg_netsvcs_logger = \ - LogRecord \ - LoggingStrategy \ - StderrStrategy \ - ServerLoggingHandler \ - ServerLoggingAcceptor - -netsvcs_logger: netsvcs_base $(addprefix netsvcs/Logger/,\ - $(addsuffix .java,$(pkg_netsvcs_logger))) - $(COMPILE.java) - -pkg_netsvcs_naming = \ - NameRequest \ - NameReply \ - NameProxy \ - NameHandler \ - NameAcceptor - -netsvcs_naming: netsvcs_base $(addprefix netsvcs/Naming/,\ - $(addsuffix .java,$(pkg_netsvcs_naming))) - $(COMPILE.java) - -pkg_netsvcs_time = \ - TimeInfo \ - TimeRequest \ - TSClerkHandler \ - TSClerkProcessor \ - TSServerHandler \ - TSServerAcceptor - -netsvcs_time: netsvcs_base $(addprefix netsvcs/Time/,\ - $(addsuffix .java,$(pkg_netsvcs_time))) - $(COMPILE.java) - -pkg_netsvcs_token = \ - TokenRequest \ - TokenReply \ - TokenRequestHandler \ - LockHandler \ - LockHandlerAdapter \ - LockOperations \ - LockTypes \ - TokenAcceptor \ - RemoteLock \ - RemoteMutex \ - RemoteRWMutex \ - MutexHandler \ - RWMutexHandler - -netsvcs_token: netsvcs_base $(addprefix netsvcs/Token/,\ - $(addsuffix .java,$(pkg_netsvcs_token))) - $(COMPILE.java) - -packages = \ - JACE.ASX \ - JACE.Connection \ - JACE.Concurrency \ - JACE.Misc \ - JACE.OS \ - JACE.Reactor \ - JACE.SOCK_SAP \ - JACE.ServiceConfigurator \ - JACE.Timers \ - JACE.netsvcs \ - JACE.netsvcs.Logger \ - JACE.netsvcs.Naming \ - JACE.netsvcs.Time \ - JACE.netsvcs.Token diff --git a/java/JACE/Misc/GetOpt.java b/java/JACE/Misc/GetOpt.java deleted file mode 100644 index e373baedb67..00000000000 --- a/java/JACE/Misc/GetOpt.java +++ /dev/null @@ -1,171 +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; - -/** - * Iterator for parsing command-line arguments. - *

- * 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. - * - *

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. - */ -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) - { - this (args, optstring, false); - } - - /** - * 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". - *@param returnAllArgs specify true if next() should return any - * arguments, even if not in the optstring. This is useful for - * providing an error message. - */ - public GetOpt (String[] args, String optstring, boolean returnAllArgs) - { - returnAllArgs_ = returnAllArgs; - - // 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) { - if (returnAllArgs_) - return arg.charAt (1); - else - 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 - - private boolean returnAllArgs_; - // When true, GetOpt returns arguments even if not present in the - // given optstring. -} diff --git a/java/JACE/Misc/package.html b/java/JACE/Misc/package.html deleted file mode 100644 index 31803472e19..00000000000 --- a/java/JACE/Misc/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - - -Miscellaneous utility classes. - - diff --git a/java/JACE/OS/ACE.java b/java/JACE/OS/ACE.java deleted file mode 100644 index 3979fa6c2d2..00000000000 --- a/java/JACE/OS/ACE.java +++ /dev/null @@ -1,156 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.OS - * - * = FILENAME - * JACE.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.OS; - -/** - * Constants, utility "functions", etc. - *

- * 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. - *

- * This class is non-instantiable, and intended only to provide a constrained - * namespace. - */ -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_ = false; - - // Default private constructor to avoid instantiation - private ACE () - { - } -} - - diff --git a/java/JACE/OS/OS.java b/java/JACE/OS/OS.java deleted file mode 100644 index 3f15a028cc2..00000000000 --- a/java/JACE/OS/OS.java +++ /dev/null @@ -1,65 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.OS - * - * = FILENAME - * OS.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.OS; - -import java.util.StringTokenizer; - -/** - * Methods to extend the capabilities of the Java runtime system. - *

- * This non-instantiable class contains little utility functions - * that should have been in Java to begin with :-) - */ -public class OS -{ - /** - * Create an array of Strings from a single String using 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/JACE/OS/package.html b/java/JACE/OS/package.html deleted file mode 100644 index 01245ef0b51..00000000000 --- a/java/JACE/OS/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - - -Extensions to the Java runtime system. - - diff --git a/java/JACE/Reactor/EventHandler.java b/java/JACE/Reactor/EventHandler.java deleted file mode 100644 index 220f999fcb5..00000000000 --- a/java/JACE/Reactor/EventHandler.java +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Reactor - * - * = FILENAME - * EventHandler.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Reactor; - -import JACE.ASX.TimeValue; - -/** - * Provides an abstract interface for handling timer events. - *

- * Classes implementing this interface handle a timer's - * expiration. - *

- * 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. - * - *@see JACE.Reactor.TimerQueue - *@see JACE.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/JACE/Reactor/TimerQueue.java b/java/JACE/Reactor/TimerQueue.java deleted file mode 100644 index 638cffe3391..00000000000 --- a/java/JACE/Reactor/TimerQueue.java +++ /dev/null @@ -1,437 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Reactor - * - * = FILENAME - * TimerQueue.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Reactor; - -import java.util.*; -import JACE.ASX.*; - -import JACE.OS.*; - -/** - * Timer Queue implementation which calls back to the handleTimeout - * method on EventHandler implementations when their timers expire. - *

- * 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. - *

- * Note that timeouts given to the TimerQueue are relative time - * ("2 seconds from now", etc). - */ -public class TimerQueue implements Runnable -{ - static 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 on when a timeout occurs. - - public Object arg_; - // Argument to pass to . - - 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). - } - - static class WaitObject extends TimedWait - { - public boolean condition () - { - return this.condition_; - } - - public void condition (boolean c) - { - this.condition_ = c; - } - - private boolean condition_ = false; - } - - /** - * Constructor. The caller is responsible for calling handleEvents () - * to run the event loop. - */ - public TimerQueue () - { - this (false); - } - - /** - * 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. The thread that is created - * is set to be a daemon thread. - */ - public TimerQueue (boolean createInternalThread) - { - this.eventLoopRunning_ = false; - if (createInternalThread) { - Thread queueThread = new Thread (this, "Timer Queue"); - queueThread.setDaemon (true); - queueThread.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; - - for (;;) - { - synchronized (this.obj_) - { - try { - // Extract the earliest time from the queue and do a - // timed wait - - this.obj_.timedWait (this.earliestTime ()); - - // 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); - } - - } catch (TimeoutException e) { - // Timeout occurred. Call handleTimeout on appropriate - // Event Handlers - this.dispatchHandlers (); - - } catch (InterruptedException e) { - ACE.ERROR ("TimerQueue was interrupted"); - return; - } - } - } - } - } - - /** - * 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 that will expire after amount - * of time. If it expires then is passed in as the value to - * the 's 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 that will expire after amount - * of time. If it expires then is passed in as the value to - * the 's callback method. If - * is != to then it is used to - * reschedule the 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 . - *@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 . - *@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("Calling handleTimeout for ID " + 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) - { - 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; - } - } - - public boolean eventLoopRunning () - { - return eventLoopRunning_; - } - - 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 - // 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/JACE/Reactor/package.html b/java/JACE/Reactor/package.html deleted file mode 100644 index 8cf9b2a941a..00000000000 --- a/java/JACE/Reactor/package.html +++ /dev/null @@ -1,6 +0,0 @@ - - - -Timer queue implementation and a system for handling timeout events. - - diff --git a/java/JACE/SOCK_SAP/INETAddr.java b/java/JACE/SOCK_SAP/INETAddr.java deleted file mode 100644 index 11b74a2b0ba..00000000000 --- a/java/JACE/SOCK_SAP/INETAddr.java +++ /dev/null @@ -1,96 +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.*; - -/** - * Defines an endpoint of a connection, encapsulating host and port. - * This is only a part-way implementation of C++ ACE's ACE_INET_Addr. - *

- * 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", e.g.

tango.cs.wustl.edu:1234
or
128.252.166.57:1234
; if no ':' is present address is assumed to be INADDR_ANY 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/JACE/SOCK_SAP/SOCKAcceptor.java b/java/JACE/SOCK_SAP/SOCKAcceptor.java deleted file mode 100644 index dc9e12c8496..00000000000 --- a/java/JACE/SOCK_SAP/SOCKAcceptor.java +++ /dev/null @@ -1,113 +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.*; - -/** - * Defines a factory that creates new SOCKStreams passively. - */ -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/JACE/SOCK_SAP/SOCKConnector.java b/java/JACE/SOCK_SAP/SOCKConnector.java deleted file mode 100644 index cc3a558f77f..00000000000 --- a/java/JACE/SOCK_SAP/SOCKConnector.java +++ /dev/null @@ -1,73 +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.*; - -/** - * 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/JACE/SOCK_SAP/SOCKStream.java b/java/JACE/SOCK_SAP/SOCKStream.java deleted file mode 100644 index 05e2535e62a..00000000000 --- a/java/JACE/SOCK_SAP/SOCKStream.java +++ /dev/null @@ -1,227 +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.*; - -/** - * 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 - - 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_; - } - - /** - * Get the underlying stream wrapped in a buffered DataOutputStream - */ - public DataOutputStream dataOutputStream () - { - return this.oStream_; - } - - /** - * Get the underlying stream wrapped in a buffered DataInputStream - */ - public DataInputStream dataInputStream () - { - return this.iStream_; - } - - /** - * 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/JACE/SOCK_SAP/package.html b/java/JACE/SOCK_SAP/package.html deleted file mode 100644 index fa4b9346aab..00000000000 --- a/java/JACE/SOCK_SAP/package.html +++ /dev/null @@ -1,8 +0,0 @@ - - - -Wrappers for the sockets system. - -@see JACE.Connection.Acceptor - - diff --git a/java/JACE/ServiceConfigurator/Service.java b/java/JACE/ServiceConfigurator/Service.java deleted file mode 100644 index fac0b0fc54b..00000000000 --- a/java/JACE/ServiceConfigurator/Service.java +++ /dev/null @@ -1,96 +0,0 @@ -package JACE.ServiceConfigurator; - -/** - * Interface common to all services loaded with the - * Service Configurator. - *

- * In order to create a completely new type of service, all that - * is necessary is to implement this interface, and ServiceConfig - * will be able to load it. A concrete example is ServiceObject, - * the base class for the network services. - *

- * Implementing classes must also: - *

- *

- * Implementing classes should also: - *

- * - *@see JACE.ServiceConfigurator.ServiceObject - *@see JACE.ServiceConfigurator.ServiceConfig - *@author Everett Anderson - */ -public interface Service -{ - /** - * Temporarily disable this service. This will only be called for a - * service which returns false from its suspended() method. - *

- *@return -1 on failure, 0 on success - */ - int suspend (); - - /** - * Re-enable this service. This will only be called for a service - * which returns true from its suspended() method. - *

- *@return -1 on failure, 0 on success - */ - int resume (); - - /** - * Initialize this service. The arguments will be given as if they - * were from the command line, separated into Strings using spaces - * as the delimiters. - *

- *@param args set of command line arguments - *@return -1 on failure, 0 on success - */ - int init (String [] args); - - /** - * Close this service and free any internal resources. - *

- *@return -1 on failure, 0 on success - */ - int fini (); - - /** - * Provide a status message for this service. - *

- *@return status message - */ - String info (); - - /** - * Return the name of this service. The name is typically set - * in ServiceConfig to a name supplied in a configuration file. - *

- *@return name of this service - */ - String name (); - - /** - * Set the name of this service. This is typically caled in - * ServiceConfig, setting the name to one supplied in a configuration - * file. - *

- *@param name new name for this service - */ - void name (String name); - - /** - * Returns whether or not this service is suspended. The result - * determines whether or not this service's resume() and suspend() - * methods will be called by ServiceConfig. (For instance, while - * a service returns true, its suspend() method will not be called.) - *

- *@return true if suspended, else false - */ - boolean suspended (); -} diff --git a/java/JACE/ServiceConfigurator/ServiceConfig.java b/java/JACE/ServiceConfigurator/ServiceConfig.java deleted file mode 100644 index 894cf415f06..00000000000 --- a/java/JACE/ServiceConfigurator/ServiceConfig.java +++ /dev/null @@ -1,482 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceConfig.java - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import java.util.*; -import java.net.*; -import JACE.OS.*; -import JACE.Misc.*; - -/** - * Provide the base class that supplies common server daemon - * operations. Also provides a global point for interacting with - * the service repository. Services can be suspended, resumed, - * removed, and reloaded. - *

- * ServiceConfig files contain lines of the following forms: - * - *

- *  load (Service Name) (Class Name) (Type) "argument list" (opt URL path)
- *
- *  resume (Service Name)
- *  suspend (Service Name)
- *  remove (Service Name)
- *
- * where (Type) is currently only ServiceObject or Service_Object 
- * [Note:  This is not enforced by the ServiceConfig program, but
- * something must be there.]
- * 
- *

- * Valid command line arguments: - *

- *    -f (filename)     Specify name of the service config file
- *    -d                Enable debugging
- *    -p (URL path)     If not found locally, search this URL path
- *                      for classes (multiple -p options allowed)
- * 
- * - *@author Prashant Jain - *@author Everett Anderson - */ -public class ServiceConfig -{ - /** Begins the process of loading a service configurator file: - * parses the command line and calls processDirectives - * - *@param args command line arguments to the Service Configurator - *@exception FileNotFoundException Couldn't find service config file - *@exception IOException Problem reading or parsing the config file - *@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 - *@return -1 on failure, 0 on success - */ - public static int open (String [] args) - throws FileNotFoundException, IOException, ClassNotFoundException, - IllegalAccessException, InstantiationException - { - // Parse the command line - if (ServiceConfig.parseArgs (args) < 0) { - printUsage (); - return -1; - } - - return ServiceConfig.processDirectives (); - } - - protected static void printUsage () - { - ACE.ERROR ("Valid options:\n"); - ACE.ERROR ("-f Specify name of the service config file"); - ACE.ERROR ("-d Enable debugging"); - ACE.ERROR ("-p If not found locally, search this URL path"); - ACE.ERROR (" for classes (multiple -p options allowed)"); - } - - /** Parse the command line. - *

- * Currently, valid command line options are the following: - *

-   * -d             Debug mode
-   * -f (filename)  Load services in the given file
-   * -p (URL path)  If not found locally, search this URL path for classes
-   *                (there can be multiple -p URL options)
-   * 
- *@param args command line arguments - *@exception ClassNotFoundException Couldn't find a specified Service - *@exception IllegalAccessException Inappropriate method call on a Service - *@exception InstantiationException Couldn't create a Service instance - */ - protected static int parseArgs (String [] args) - throws ClassNotFoundException, IllegalAccessException, - InstantiationException - { - GetOpt getopt = new GetOpt (args, "df:p:", true); - for (int c; (c = getopt.next ()) != -1; ) - switch (c) - { - case 'p': - // Specify a URL path - try { - ServiceConfig.loader_.addURLPath (getopt.optarg ()); - } catch (MalformedURLException e) { - ACE.ERROR ("Invalid URL: " + getopt.optarg ()); - } - break; - /* - Not supported: - - case 'b': - ServiceConfig.beADaemon_ = true; - break; - case 'n': - break; - */ - case 'd': - ACE.enableDebugging (); - ACE.DEBUG ("Debugging is enabled"); - break; - case 'f': - // Specify the file name of the config file - ServiceConfig.serviceConfigFile_ = getopt.optarg (); - break; - default: - ACE.ERROR ((char ) c + " is not a ServiceConfig option"); - return -1; - } - - return 0; - } - - /** - * Uses the Service Repository to suspend a service with the given name. - * - *@param name name of the Service to suspend - *@return -1 on failure, 0 on success - */ - public static int suspend (String name) - { - return ServiceConfig.svcRep_.suspend (name); - } - - /** - * Uses the Service Repository to resume a service with the given name. - * - *@param name name of the Service to resume - *@return -1 on failure, 0 on success - */ - public static int resume (String name) - { - return ServiceConfig.svcRep_.resume (name); - } - - /** - * Removes the specified Service from the Service Repository. - * - *@param name name of the Service to remove - *@return -1 on failure, 0 on success - */ - public static int remove (String name) - { - return ServiceConfig.svcRep_.remove (name); - } - - /** - * Returns the info String from the specified Service. - * - *@param name name of the Service to query - *@return information about the Service - */ - public static String info (String name) - { - return ServiceConfig.svcRep_.info (name); - } - - /** - * Call fini on the specified Service. - * - *@param name name of the Service to shut down - *@return -1 on failure, 0 on success - */ - public static int fini (String name) - { - return ServiceConfig.svcRep_.fini (name); - } - - /** - * Call init on the specified Service. This is only needed - * when a user wants to add a Service to the repository without - * using service config files. - * - *@param name name of the Service to initialize - *@param args command line arguments to pass to the Service - *@return -1 on failure, 0 on success - *@see ServiceConfig#insert - */ - public static int init (String name, String [] args) - { - return ServiceConfig.svcRep_.init (name, args); - } - - /** - * Adds the given Service to the Service Repository. This is - * only needed when a user wants to add a Service to the repository - * without using service config files. - * - *@param service Service to insert - *@see ServiceConfig#init - */ - public static void insert (Service service) - { - ServiceConfig.svcRep_.insert (service); - } - - /** - * Check to see if the specified Service is suspended. - * - *@param name name of the Service to check - *@return true if it is suspended, else false - */ - public static boolean suspended (String name) - { - return ServiceConfig.svcRep_.suspended (name); - } - - /** - * Check to see if the repository contains a service with the given - * name. - * - *@param name name of the Service to check - *@return true if it is in the repository, else false - */ - public static boolean contains (String name) - { - return (ServiceConfig.svcRep_.find (name) == null ? false : true); - } - - /** - * Get an Enumeration of all of the names of the Services in the - * repository. - * - *@return Enumeration of Service names - */ - public static Enumeration serviceNames () - { - return ServiceConfig.svcRep_.serviceNames (); - } - - /** - * Get an Enumeration of all Services in the repository. - * - *@return Enumeration of Services - */ - public static Enumeration services () - { - return ServiceConfig.svcRep_.services (); - } - - /** - * Load a service of the given name, type, and arguments, then - * initialize it with the given arguments. - * - * Should be aware that this could also throw a class cast exception if - * the author of the service didn't implement the Service interface. - * - *@param serviceName name of the service to load - *@param className class name to load - *@param args command line arguments to initialize the service - *@exception ClassNotFoundException couldn't find the specified class file - *@exception IllegalAccessException problem calling a method on the service - *@exception InstantiationException problem creating an instance - *@exception IOException problem reading the class file - *@return -1 on failure, 0 on success - */ - public static int load (String serviceName, - String className, - String [] args) - throws ClassNotFoundException, IllegalAccessException, - InstantiationException, IOException - { - Class svcClass = ServiceConfig.loader_.loadClass (className); - - Service svc = (Service)(svcClass.newInstance()); - - svc.name (serviceName); - - ServiceConfig.svcRep_.insert (svc); - - return ServiceConfig.svcRep_.init (serviceName, args); - } - - /** - * Same as load (String, String, String[]) but creates the - * String array from the given args parameter using the space - * character as a delimiter. - * - */ - public static int load (String serviceName, - String className, - String args) - throws ClassNotFoundException, IllegalAccessException, - InstantiationException, IOException - { - return ServiceConfig.load (serviceName, - className, - OS.createStringArray (args, " ")); - } - - /** - * Parse a service configurator file, creating classes as necessary. - * - *@return -1 on failure, 0 on success - *@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 - { - 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 characters in ASCII range 32 to 47, ASCII range 91 to 96, - // and ASCII range 123 to 126 as ordinary characters - in.wordChars ('.', '/'); // ASCII range 32 to 47 - in.wordChars (':', '@'); // ASCII range 58 to 64 - in.wordChars ('[', '`'); // ASCII range 91 to 96 - in.wordChars ('{', '~'); // ASCII range 123 to 126 - in.quoteChar ('\"'); - in.commentChar ('#'); - in.eolIsSignificant(true); - in.lowerCaseMode(false); - - Vector strs = new Vector(); - int lineNumber = 1; - - while (in.nextToken () != StreamTokenizer.TT_EOF) { - - if (in.ttype == StreamTokenizer.TT_EOL) { - - String command = ((String)strs.elementAt(COMMAND_NAME)).toLowerCase(); - String name = (String)strs.elementAt(SERVICE_NAME); - - if (strs.size() == 2) { - if (command.equals("remove")) - ServiceConfig.remove(name); - else - if (command.equals("suspend")) - ServiceConfig.suspend(name); - else - if (command.equals("resume")) - ServiceConfig.resume(name); - } else { - - if (!command.equals("load")) - throw new IOException ("Unknown command: " + - command + - " at line " + - lineNumber); - - if (strs.size() < 5) - throw new IOException ("Line " + lineNumber + - " requires 5 values, not " + - strs.size()); - - // Type is currently unenforced since everything must descend - // from Service anyway. - //String type = (String)strs.elementAt (SERVICE_TYPE); - String className = (String)strs.elementAt (CLASS_NAME); - - if (strs.size () > CODE_BASE) { - try { - String url = (String)strs.elementAt (CODE_BASE); - - ServiceConfig.loader_.addURLPath (url); - - } catch (MalformedURLException e) { - ACE.ERROR("Bad code base on line " + lineNumber); - } - } - - ServiceConfig.load(name, - className, - (String)strs.elementAt(ARGS)); - } - - lineNumber++; - strs.removeAllElements(); - continue; - } - - // Skip over non-strings - if ((in.ttype == StreamTokenizer.TT_WORD) || - (in.ttype == '\"')) - strs.addElement(new String(in.sval)); - else - ACE.DEBUG ("Invalid string on line " + lineNumber + - " element " + strs.size() + - " type " + in.ttype); - } - - return 0; - } - - /** - * Close all services. - */ - public static void close () - { - ServiceConfig.svcRep_.close (); - } - - /** - * Return a reference to the ServiceLoader used to load - * classes. - * - *@return ServiceLoader used internally by ServiceConfig. - */ - public static ServiceLoader loader () - { - return ServiceConfig.loader_; - } - - /** - * Specify the ServiceLoader to be used by ServiceConfig. - * - *@param loader ServiceLoader instance to use (should support remote - * loading) - */ - public static void loader (ServiceLoader loader) - { - ServiceConfig.loader_ = loader; - } - - // Set by command line options - private static boolean beADaemon_ = false; - - private static String serviceConfigFile_ = "svc.conf"; - - private static ServiceRepository svcRep_ = new ServiceRepository (); - private static ServiceLoader loader_ = new ServiceLoader (); - - // Order for the commands on a line in the config file - private final static int COMMAND_NAME = 0; - private final static int SERVICE_NAME = 1; - private final static int CLASS_NAME = 2; - private final static int SERVICE_TYPE = 3; - private final static int ARGS = 4; - private final static int CODE_BASE = 5; -} diff --git a/java/JACE/ServiceConfigurator/ServiceLoader.java b/java/JACE/ServiceConfigurator/ServiceLoader.java deleted file mode 100644 index 75297f9631d..00000000000 --- a/java/JACE/ServiceConfigurator/ServiceLoader.java +++ /dev/null @@ -1,254 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceLoader.java - * - * Implementation of a network-capable class loader - * - *@author Prashant Jain - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import java.util.*; -import java.net.*; -import JACE.OS.*; -import JACE.Misc.*; - -/** - * ClassLoader that can load classes from across the network - * via provided URL search paths, or from the local machine. - *

- * This operates in the same way as the JDK 1.2 ClassLoader by - * first checking for preloaded classes, then trying to use the system - * loader, and finally trying to load it via the network. The user can also - * provide URL search paths, or explicitly call the loadClass method which - * takes a URL. - * - *@see java.lang.ClassLoader - *@see java.lang.Class - */ -public class ServiceLoader extends ClassLoader -{ - /** - * Creates a loader that will only search the local machine for classes - * until URL paths are registered via addURLPath. - */ - public ServiceLoader () - { - this.URLSearchPaths_ = new Vector(); - } - - /** - * Creates a loader that will search the local machine followed by - * this array of URL paths when loading classes. Note that additional - * paths can be added later with the addURLPath method. - *@param remotePaths array of URLs to search when loading classes, after - *attempts to load from the local machine have failed - */ - public ServiceLoader (URL remotePaths[]) - { - this(); - - if (remotePaths == null) - return; - - for (int i = 0; i < remotePaths.length; i++) - this.addURLPath(remotePaths[i]); - } - - /** - * Add the given URL to the list of URL paths to search when loading - * classes. - *@param url URL ending in '/' where classes can be found - */ - public void addURLPath (URL url) - { - if (!URLSearchPaths_.contains(url)) - URLSearchPaths_.addElement(url); - } - - /** - * Add the given URL to the list of URL paths to search when loading - * classes. - *@param String representation of a URL ending in '/' - *@exception MalformedURLException the given String wasn't a valid URL - */ - public void addURLPath (String url) throws MalformedURLException - { - URL resource = new URL (url); - this.addURLPath (resource); - } - - /** - * Tries to load the given class by following the example of JDK 1.2 - * ClassLoader. First check loaded classes, then try to use the system - * loader, and only then perform the user defined subclass behavior - * from findClass (in this case, it's searching over the network). - *@param name name of the class to load - *@param resolve whether or not to resolve the class - *@exception ClassNotFoundException if the class could not be found - *@return loaded Class instance - */ - protected Class loadClass(String name, - boolean resolve) - throws ClassNotFoundException - { - - Class c = null; - - // Has this class already been loaded once? - c = findLoadedClass(name); - if (c != null) - return c; - - try { - - // Can the system loader find it? - c = findSystemClass(name); - return c; - - } catch (ClassNotFoundException e2) { - // The system loader couldn't find it - } - - // If none of the above, try searching our way - return findClass(name); - } - - /** - * This should duplicate the behavior of this class in JDK 1.2. It is - * called by the protected loadClass method after trying to load the - * class in other ways. It simply calls loadClassData and then defines - * the class. - *@param name name of the class to load - *@exception ClassNotFoundException couldn't find the class - *@return loaded Class - */ - protected Class findClass(String name) throws ClassNotFoundException - { - byte[] b = loadClassData(name); - return defineClass(name, b, 0, b.length); - } - - /** - * Try loading a class with the given name, searching the remote - * URL paths that have been registered. Note that this will only - * be called after first checking to see if the class has already - * been loaded, then checking to see whether or not the system - * loader can find it. - *

- * This could be overriden by subclasses to define different - * loading behavior. - * - *@param className name of the class (not file name) of the class to load - *@exception ClassNotFoundException couldn't find the class - *@return bytes of a .class file - */ - private byte[] loadClassData(String className) throws ClassNotFoundException - { - byte data[] = null; - - // Try to load it by reading in the bytes from the net - Enumeration e = URLSearchPaths_.elements(); - - while (e.hasMoreElements()) - { - try - { - URL path = (URL)e.nextElement(); - URL classFileURL; - - try - { - classFileURL = new URL(path.toExternalForm() + - className + - ".class"); - } catch (MalformedURLException ex) { - ACE.ERROR("Bad URL: " + ex.getMessage()); - continue; - } - - ACE.DEBUG("Looking for " + classFileURL.toExternalForm()); - URLConnection urlConnection = classFileURL.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 - data = new byte [urlConnection.getContentLength ()]; - - // Now read all the data into the buffer - i.readFully (data); - - } catch (IOException ex) { - // Either the URL wasn't there or we couldn't get the data - continue; - } - } - - // Couldn't find it or it loaded improperly - if (data == null) - throw new ClassNotFoundException("Can't obtain " + className); - - return data; - } - - /** - * Load a class from across the network - * - * The newer way to do this is similar to JDK 1.2 URLClassLoader: - * Add URLs that end in '/' via the addURLPath method - * Call loadClass (class name without .class extension) method - * - *@param url URL of the class to load - *@exception ClassNotFoundException Couldn't find the class - *@return loaded Class - */ - public Class loadClass (URL url) throws ClassNotFoundException - { - // Extract the name of the class from the URL - String URLPath = url.getFile(); - - // Get the class name by removing any directory information - int idx = URLPath.lastIndexOf("/"); - if (idx == -1) - throw new ClassNotFoundException("Can't find " + URLPath); - String className = URLPath.substring(idx + 1); - URLPath = URLPath.substring(0, 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 { - // Add the URL to the list of URL search paths - URL path = new URL(URLPath); - - this.addURLPath(path); - - } catch (MalformedURLException e) { - throw new ClassNotFoundException("Can't find " + URLPath); - } - - // Try to load the class - return loadClass(className); - } - - /** - * Collection of URLs which end in the HTTP path separator. Used - * for searching for classes across the network. - */ - protected Vector URLSearchPaths_; -} diff --git a/java/JACE/ServiceConfigurator/ServiceObject.java b/java/JACE/ServiceConfigurator/ServiceObject.java deleted file mode 100644 index 4538698e8a6..00000000000 --- a/java/JACE/ServiceConfigurator/ServiceObject.java +++ /dev/null @@ -1,130 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceObject.java - * - *@author Prashant Jain - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import JACE.ASX.*; -import JACE.Reactor.*; - -/** - * Provides a default implementation of the Service interface, and can also - * be registered with the Reactor. - * - *@see JACE.Reactor - *@see Service - */ -public class ServiceObject implements EventHandler, Service -{ - /** - * 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 when timer expired - *@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. Currently, this sets an internal - * state variable to true. - */ - public int suspend () - { - this.suspended_ = true; - - return 0; - } - - /** - * Request that this service resume activity. Currently, this sets - * an internal state variable to false. - */ - public int resume () - { - this.suspended_ = false; - - return 0; - } - - /** - * Is this service suspended? - */ - public boolean suspended () - { - return this.suspended_; - } - - /** - * Return the name of the Service. Implementation provided. - */ - public String name () - { - return this.name_; - } - - /** - * Set the name of the Service. Should be called when a Service is - * created -- this is done automatically by ServiceConfig when loading - * from a file. Implementation provided. - */ - public void name (String name) - { - this.name_ = name; - } - - /** - * Name of this ServiceObject. - */ - protected String name_ = null; - - /** - * Status of whether this ServiceObject is suspended or not. - * (Initially false) - */ - protected boolean suspended_ = false; -} diff --git a/java/JACE/ServiceConfigurator/ServiceRepository.java b/java/JACE/ServiceConfigurator/ServiceRepository.java deleted file mode 100644 index 33f9a088077..00000000000 --- a/java/JACE/ServiceConfigurator/ServiceRepository.java +++ /dev/null @@ -1,274 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.ServiceConfigurator - * - * = FILENAME - * ServiceRepository.java - * - * The service repository stores the network services, allowing them to be - * removed, suspended, resumed, etc. - * - *@see JACE.ServiceConfigurator.ServiceConfig; - *@see JACE.ServiceConfigurator.Service; - * - *@author Everett Anderson - * - *************************************************/ -package JACE.ServiceConfigurator; - -import java.io.*; -import java.util.*; - -/** - * Stores Services, providing operations such as remove, suspend, resume, etc. - */ -public class ServiceRepository -{ - /** - * Constructor - */ - public ServiceRepository () - { - this.serviceMap_ = new Hashtable (); - this.serviceNames_ = new Vector (); - } - - /** - * Constructor - * - *@param initialSize Initial vector size for the repository - */ - public ServiceRepository (int initialSize) - { - this.serviceMap_ = new Hashtable (initialSize); - this.serviceNames_ = new Vector (initialSize); - } - - /** - * Shut down all the services, closing them in reverse order of insertion. - * This calls fini on each service. - *@return -1 on failure, 0 on sucess - */ - public int close() - { - int result = 0; - - for (int i = this.size() - 1; i >= 0; i--) { - - String name = (String)this.serviceNames_.elementAt (i); - - Service s = (Service)this.serviceMap_.get (name); - - result = (s.fini () == -1 ? -1 : result); - } - - this.serviceMap_.clear (); - this.serviceNames_.removeAllElements (); - - return result; - } - - /** - * Insert a Service into the repository. - * (If already in, calls fini() and replaces) - * - *@param service Service to add - */ - public void insert (Service service) - { - String name = service.name (); - Service alreadyIn = this.find (name); - - if (alreadyIn != null) { - - alreadyIn.fini (); - this.remove (alreadyIn); - - } else { - - this.serviceMap_.put (name, service); - this.serviceNames_.addElement (name); - - } - } - - /** - * Returns an enumeration of all the Service objects. - * - */ - public Enumeration services () - { - return this.serviceMap_.elements (); - } - - /** - * Returns an enumeration of all the Service names - */ - public Enumeration serviceNames () - { - return this.serviceMap_.keys (); - } - - /** - * Convenience method that returns null when the service isn't - * found. - */ - public Service find (String name) - { - Object serviceObj = this.serviceMap_.get (name); - - if (serviceObj == null) - return null; - - return (Service)serviceObj; - } - - /** - * Finds the Service associated with a given - * name. - * - *@param name Name of the service to find - *@exception NoSuchElementException if the given service is not found - */ - protected Service findService (String name) throws NoSuchElementException - { - Object serviceObj = this.serviceMap_.get (name); - - if (serviceObj == null) - throw new NoSuchElementException ("Service " + name + " not found."); - - return (Service)serviceObj; - } - - /** - * Removes the given Service and calls its fini () method. - *@param service Service to remove - *@return -1 on failure, 0 on success - */ - protected int remove (Service service) - { - String name = service.name (); - - this.serviceMap_.remove (name); - - int index = this.serviceNames_.indexOf (name); - - this.serviceNames_.removeElementAt (index); - - return service.fini (); - } - - /** - * Shut down the specified Service. - * - *@param name name of the Service to shut down - *@return -1 on failure, 0 on success - */ - public int fini (String name) - { - Service service = this.findService (name); - - return service.fini (); - } - - /** - * Remove the specified Service, calling its fini () method. - * - *@param name name of the Service to remove - *@return -1 on failure, 0 on success - */ - public int remove (String name) - { - Service service = this.findService (name); - - return this.remove (service); - } - - /** - * Resume a suspended service - *@param name Name of the service to resume - *@return -1 on failure, 0 on success - */ - public int resume (String name) - { - Service service = this.findService (name); - - return service.resume(); - } - - /** - * Suspend a service - *@param name Name of the service to suspend - *@return -1 on failure, 0 on success - */ - public int suspend (String name) - { - Service service = this.findService (name); - - if (service.suspended ()) - return 0; - - return service.suspend (); - } - - /** - * Returns status information about the specified Service. - * - *@param name name of the Service to query - *@return String of information about the Service's status - */ - public String info (String name) - { - Service service = this.findService (name); - - return service.info (); - } - - /** - * Check to see if the specified Service is suspended or not - */ - public boolean suspended (String name) - { - Service service = this.findService (name); - - return service.suspended (); - } - - /** - * Initialize the specified Service with the given command - * line arguments. - */ - public int init (String name, String [] args) - { - Service service = this.findService (name); - - return service.init (args); - } - - /** - * Returns the number of items in the repository - */ - public int size () - { - return this.serviceNames_.size(); - } - - /** - * Stores the Service names in order of insertion - */ - Vector serviceNames_; - - /** - * A mapping between Service names and Service objects - */ - Hashtable serviceMap_; -}; - - - - - - - - diff --git a/java/JACE/ServiceConfigurator/package.html b/java/JACE/ServiceConfigurator/package.html deleted file mode 100644 index 2092fc34f5a..00000000000 --- a/java/JACE/ServiceConfigurator/package.html +++ /dev/null @@ -1,10 +0,0 @@ - - - -Point for loading and managing services. -

-See also: - -Documents on the ACE Service Configurator - - diff --git a/java/JACE/Timers/ProfileTimer.java b/java/JACE/Timers/ProfileTimer.java deleted file mode 100644 index 210d8887907..00000000000 --- a/java/JACE/Timers/ProfileTimer.java +++ /dev/null @@ -1,46 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.Timers - * - * = FILENAME - * ProfileTimer.java - * - *@author Prashant Jain - * - *************************************************/ -package JACE.Timers; - -/** - * 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/JACE/Timers/package.html b/java/JACE/Timers/package.html deleted file mode 100644 index 4aa67ec1fd6..00000000000 --- a/java/JACE/Timers/package.html +++ /dev/null @@ -1,8 +0,0 @@ - - - -Time related classes. - -@see JACE.ASX.TimeValue - - diff --git a/java/JACE/makebat.zip b/java/JACE/makebat.zip deleted file mode 100644 index a05c72f274e..00000000000 Binary files a/java/JACE/makebat.zip and /dev/null differ diff --git a/java/JACE/netsvcs/Handler.java b/java/JACE/netsvcs/Handler.java deleted file mode 100644 index 7bf73f01206..00000000000 --- a/java/JACE/netsvcs/Handler.java +++ /dev/null @@ -1,185 +0,0 @@ -package JACE.netsvcs; - -import java.io.*; -import java.net.*; -import JACE.OS.*; -import JACE.Connection.*; - -/** - * Abstract class representing a handler for a Server. Provides - * default implementations and template methods. - * - *@see Server - *@author Everett Anderson - */ -public abstract class Handler extends SvcHandler -{ - /** - * Initialize this Handler. The default implementation sets the - * done flag to false. - * - *@return -1 on failure, 0 on success - */ - public int open (Object obj) - { - done_ = false; - return 0; - } - - /** - * Shut down this handler. Default implementation calls close (). - */ - public int close (long flags) - { - return close (); - } - - /** - * Shut down this handler, setting the done flag, and removing it - * from the parent Server's handler list. - */ - public synchronized int close () - { - if (!done ()) { - try { - done_ = true; - parent_.removeHandler (this); - peer ().close (); - } catch (IOException e) { - return -1; - } - } - - return 0; - } - - /** - * Returns the name of the host that is connected to this handler, - * or null if not connected. - */ - public String hostName () - { - if (done ()) - return null; - else - return this.peer().socket().getInetAddress().getHostName(); - } - - /** - * Process a single request and handle any errors. The default - * implementation calls handleRequest with an Object from - * newRequest (). - */ - public void handleRequest () - { - handleRequest (newRequest ()); - } - - /** - * Process a single request and handle any errors. The default - * implementation calls processRequest with the given request - * Object, and then handles exceptions appropriately. Subclasses - * normally just implement processRequest rather than override - * this method. - * - *@param request request to process - */ - public void handleRequest (Object request) - { - try { - - processRequest (request); - - } catch (NullPointerException e) { - if (!done ()) { - ACE.ERROR("Failure: " + e); - close (); - } - } catch (SocketException e) { - if (!done ()) { - ACE.DEBUG (hostName () + " disconnected"); - close (); - } - } catch (EOFException e) { - if (!done ()) { - ACE.DEBUG (hostName () + " disconnected"); - close (); - } - } catch (IOException e) { - if (!done ()) { - ACE.ERROR ("Lost connection: " + e); - close (); - } - } - } - - /** - * Process a single request (including reading it from the wire) - * without handling errors. Subclasses must define the behavior. - * - *@param requestObject request to process - *@exception SocketException problem with the socket - *@exception EOFException end of connection, - * usually means client disconnected - *@exception IOException error during transmission - */ - protected abstract void processRequest (Object requestObject) - throws SocketException, EOFException, IOException; - - /** - * Returns a new instance of a request object. Subclasses must - * define the behavior. - */ - public abstract Object newRequest (); - - /** - * Called by the JVM when a Handler is run in its own Thread. The - * default implementation creates a single request object which is - * reused during multiple handleRequest calls. The loop exits - * when the Handler's done() method returns true. - */ - public void run() - { - Object request = newRequest (); - - while (!done ()) - handleRequest (request); - - close (); - } - - /** - * Set the Server parent of this Handler. - */ - public void parent (Server parent) - { - parent_ = parent; - } - - /** - * Return the Server parent of this Handler. - */ - public Server parent () - { - return parent_; - } - - /** - * Check to see if this Handler should shut down. - */ - protected synchronized boolean done () - { - return done_; - } - - /** - * Closes the handler, freeing resources. - */ - protected void finalize () throws Throwable - { - close (); - } - - private boolean done_ = true; - private Server parent_; -} diff --git a/java/JACE/netsvcs/Logger/LogRecord.java b/java/JACE/netsvcs/Logger/LogRecord.java deleted file mode 100644 index 972cf45af74..00000000000 --- a/java/JACE/netsvcs/Logger/LogRecord.java +++ /dev/null @@ -1,290 +0,0 @@ -/************************************************* - * - * = PACKAGE - * JACE.netsvcs.Logger - * - * = FILENAME - * LogRecord.java - * - *@author Chris Cleeland, Everett Anderson - * - *************************************************/ -package JACE.netsvcs.Logger; - -import java.util.*; -import java.io.*; -import JACE.OS.*; - -/** - * Communicates logging information. Compatible with the C++ ACE - * ACE_Log_Record class. - */ -public class LogRecord -{ - /** - * Maximum size of a LogRecord - */ - final public int MAXLOGMSGLEN = 4 * 1024; - - private int type_; - private int length_; - private long msec_; - private int pid_; - private byte[] msgData_; - private final static int numIntMembers = 5; - private final static int sizeofIntInBytes = 4; - - /** - * Create a default instance. - */ - public LogRecord() - { - type(0); - timeStamp((int)new Date().getTime()); - length(0); - pid(0); - } - - /** - * Create a LogRecord. This is the designated initializer. - * @param priority a numeric specification of the priority (ascending) - * @param milliseconds time attached to the log entry in Unix

time_t
format - * @param pid the process ID - */ - public LogRecord(int priority, - long milliseconds, - int pid) - { - type(priority); - timeStamp(milliseconds); - length(0); - pid(pid); - } - - /** - * Create a LogRecord with the current time and the given message. - * - *@param message message to log - */ - public LogRecord (String message) - { - this (); - - msgData (message); - } - - /** - * Conversion to string. Only includes the
msgData_
member. - */ - public String toString() - { - String result = null; - try { - result = new String (msgData_, - "US-ASCII"); - } catch (UnsupportedEncodingException e) { - result = new String (msgData_); - } - - return result; - } - - /** - * Place a textual representation of the record on a PrintStream. - * When verbose is specified to be true, the output takes the form - *
(Date)@(host name)@(PID)@(type)@(message)
- * Otherwise it just prints the message. - * @param hostname name of the host generating this record - * @param verbose specify how much information to print (see above) - * @param ps A PrintStream instance to which the output should go. - */ - public void print(String hostname, - boolean verbose, - PrintStream ps) - { - String toprint; - if (verbose) - { - Date now = new Date(this.timeStamp()); - - /* 01234567890123456789012345 */ - /* Wed Oct 18 14:25:36 1989n0 */ - toprint = now.toString().substring(4) + "@" - + hostname + "@" + pid_ + "@" + type_ + "@" - + this.toString(); - } - else - { - toprint = this.toString(); - } - ps.println(toprint); - } - - /** - * Read in the data for this LogRecord from the given InputStream. - * - *@param is InputStream to read from - *@exception IOException error during transmission - */ - public void streamInFrom (InputStream is) throws IOException - { - BufferedInputStream bis = new BufferedInputStream (is); - - DataInputStream dis = new DataInputStream (bis); - - streamInFrom (dis); - } - - /** - * Read in the data for this LogRecord from the given DataInputStream. - * - *@param dis DataInputStream to read from - *@exception IOException error during transmission - */ - public void streamInFrom(DataInputStream dis) throws IOException - { - // Order here must match layout order in the C++ class. - length(dis.readInt()); - type(dis.readInt()); - this.timeStamp((long)dis.readInt() * 1000); - - // Skip smaller time resolution info since we're lucky if Java's - // timer can handle more than millisecond precision, anyway - dis.skipBytes(4); - - pid(dis.readInt()); - - int dataLength = (int) (length_ - numIntMembers * sizeofIntInBytes); - - msgData_ = new byte[dataLength]; - - dis.readFully(msgData_, 0, dataLength); - } - - /** - * Write this LogRecord out to the given OutputStream. - * - *@param os OutputStream to write to - *@exception IOException error during transmission - */ - public void streamOutTo (OutputStream os) throws IOException - { - BufferedOutputStream bos = new BufferedOutputStream (os); - - DataOutputStream dos = new DataOutputStream (bos); - - streamOutTo (dos); - } - - /** - * Write this LogRecord out to the given DataOutputStream. - * - *@param dos OutputStream to write to - *@exception IOException error during transmission - */ - public void streamOutTo(DataOutputStream dos) throws IOException - { - dos.writeInt(length()); - dos.writeInt(type()); - dos.writeInt((int)(this.msec_ / 1000)); - dos.writeInt(0); - dos.writeInt(pid()); - - dos.write(msgData_); - - dos.flush (); - } - - /** - * Return the LogRecord type. - */ - public int type() { return type_; } - - /** - * Set the LogRecord type. - */ - public void type(int t) { type_ = t; } - - /** - * Return the length of this LogRecord. - */ - public int length() { return length_; } - - /** - * Set the length of this LogRecord. - */ - public void length(int l) { length_ = l; } - - /** - * Calculate the length of this LogRecord from the size of - * the message and the header. - */ - private void setLen(int msgLen) - { length(msgLen + numIntMembers * sizeofIntInBytes); } - - /** - * Return the millisec time stamp of this LogRecord. - */ - public long timeStamp() { return this.msec_; } - - /** - * Set the millisec time stamp of this LogRecord. - */ - public void timeStamp(long msec){ this.msec_ = msec; } - - /** - * Return the PID of this LogRecord. - */ - public int pid() { return pid_; } - - /** - * Set the PID of this LogRecord. - */ - public void pid(int p) { pid_ = p; } - - /** - * Return the message of this LogRecord as a byte array. - */ - public byte[] msgData() { return msgData_; } - - /** - * Set the message of this LogRecord to a given byte array. - */ - public void msgData(byte[] m) - { - int size = m.length; - - if (size > MAXLOGMSGLEN) - size = MAXLOGMSGLEN; - - this.msgData_ = new byte[size]; - - System.arraycopy(m, 0, msgData_, 0, size); - - setLen(size); - } - - /** - * Set the message of this LogRecord to a given byte array. First - * tries to use US-ASCII encoding, then uses the default encoding - * if that fails. The toString method is essentially the opposite - * version. - */ - public void msgData(String m) - { - byte temp[] = null; - try { - temp = m.getBytes("US-ASCII"); - } catch (UnsupportedEncodingException e) { - temp = m.getBytes (); - } - if (temp.length > MAXLOGMSGLEN) { - this.msgData_ = new byte[MAXLOGMSGLEN]; - - System.arraycopy(temp, 0, msgData_, 0, MAXLOGMSGLEN); - } else - this.msgData_ = temp; - - setLen(msgData_.length); - } -} diff --git a/java/JACE/netsvcs/Logger/LoggingStrategy.java b/java/JACE/netsvcs/Logger/LoggingStrategy.java deleted file mode 100644 index b7912499385..00000000000 --- a/java/JACE/netsvcs/Logger/LoggingStrategy.java +++ /dev/null @@ -1,35 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Logger - * - * = FILENAME - * LogMessageReceiver.java - * - *@author Everett Anderson - * - *************************************************/ -package JACE.netsvcs.Logger; - -import java.io.*; - -/** - * Encapsulates the handling of a LogRecord from a given host, allowing - * easy swapping of behavior in the logging service. Strategies could - * be developed to save to a file, print on a certain stream, forward - * to another service, etc. - * - *@see StderrStrategy - *@see LogRecord - */ -public interface LoggingStrategy -{ - /** - * Process the given LogRecord. - * - *@param hostname host from which this LogRecord originated - *@param record LogRecord instance to process - */ - public void logRecord (String hostname, - LogRecord record); -} diff --git a/java/JACE/netsvcs/Logger/ServerLoggingAcceptor.java b/java/JACE/netsvcs/Logger/ServerLoggingAcceptor.java deleted file mode 100644 index c0ef8831fc6..00000000000 --- a/java/JACE/netsvcs/Logger/ServerLoggingAcceptor.java +++ /dev/null @@ -1,147 +0,0 @@ -package JACE.netsvcs.Logger; - -import java.util.*; -import java.io.*; -import java.net.*; -import JACE.SOCK_SAP.*; -import JACE.Connection.*; -import JACE.OS.*; -import JACE.Misc.*; -import JACE.netsvcs.Server; - -/** - * Server for the logging service. Sets the default logging strategy - * to StderrStrategy so that logging requests are printed on the - * System.err stream. Other strategies can be specified on the - * command line. - *

- * Valid command line arguments: - *

- *   -r (class name)  Specify a LoggingStrategy
- *                    (Default is StdErrStrategy)
- *   -p (port)        Port to listen on for clients
- *   -d               Enable debugging messages
- *   -a (class name)  Specify ActivateStrategy
- *                    (Default is thread per connection)
- * 
- * - *@see LoggingStrategy - *@see StderrStrategy - */ -public class ServerLoggingAcceptor extends Server -{ - /** - * Default constructor. Sets the default LoggingStrategy to - * StderrStrategy. - */ - public ServerLoggingAcceptor () - { - name ("Logging Service"); - logStrategy_ = new StderrStrategy (); - } - - /** - * Simple main program for running the logging service without the - * service configurator. - * - *@param args command line arguments - */ - public static void main (String [] args) - { - ServerLoggingAcceptor sla = new ServerLoggingAcceptor(); - - sla.init(args); - } - - /** - * Accessor for the LoggingStrategy - */ - public LoggingStrategy loggingStrategy () - { - return this.logStrategy_; - } - - /** - * Creates a new ServerLoggingHandler instance. - */ - protected SvcHandler makeSvcHandler () - { - return new ServerLoggingHandler (); - } - - /** - * Prints out the valid command line arguments. See the class - * description for more information. Called by Server.init when - * parseArgs returns -1. - */ - protected void printUsage () - { - ACE.ERROR ("Valid options:\n"); - ACE.ERROR ("-r Specify a LoggingStrategy"); - ACE.ERROR (" (Default is StdErrStrategy"); - ACE.ERROR ("-p Port to listen on for clients"); - ACE.ERROR ("-d Enable debugging messages"); - ACE.ERROR ("-a Specify ActivateStrategy"); - ACE.ERROR (" (Default is single threaded"); - } - - /** - * Parses the command line arguments. See the class description - * for more information. - * - *@param args command line arguments - *@return -1 on failure, 0 on success - */ - protected int parseArgs (String args[]) - { - String s; - Object strategy; - GetOpt opt = new GetOpt (args, "p:r:da:", true); - int c = 0; - - try { - - while ((c = opt.next ()) != -1) - { - switch (c) - { - case 'd': - ACE.enableDebugging (); - ACE.DEBUG ("Debugging is enabled"); - break; - case 'p': - if (!port (opt.optarg ())) - return -1; - break; - case 'a': - strategy = newStrategyInstance (opt.optarg (), - "ActivateStrategy"); - if (strategy == null) - return -1; - - activateStrategy ((ActivateStrategy) strategy); - break; - case 'r': - // Load the Strategy with the given name - strategy = newStrategyInstance (opt.optarg (), - "LoggingStrategy"); - if (strategy == null) - return -1; - - logStrategy_ = (LoggingStrategy)strategy; - break; - default: - ACE.ERROR ("Unknown argument: " + c); - return -1; - } - } - } catch (ArrayIndexOutOfBoundsException e) { - ACE.ERROR ("Option -" + (char)c + " requires an argument"); - return -1; - } - - return 0; - } - - private LoggingStrategy logStrategy_; -} diff --git a/java/JACE/netsvcs/Logger/ServerLoggingHandler.java b/java/JACE/netsvcs/Logger/ServerLoggingHandler.java deleted file mode 100644 index 88a564c2c34..00000000000 --- a/java/JACE/netsvcs/Logger/ServerLoggingHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Logger - * - * = FILENAME - * ServerLoggingHandler.java - * - *@author Everett Anderson - * - *************************************************/ -package JACE.netsvcs.Logger; - -import java.io.*; -import java.util.*; -import java.net.*; -import JACE.SOCK_SAP.*; -import JACE.Connection.*; -import JACE.OS.*; -import JACE.netsvcs.Handler; - -/** - * - * Created by ServerLoggingAcceptor to handle logging requests. This - * simply reads the record and hands it to the registered LoggingStrategy. - * - * @see JACE.netsvcs.Logger.ServerLoggingAcceptor - */ -public class ServerLoggingHandler extends Handler -{ - /** - * Reads in the given LogRecord request and hands it to the - * LoggingStrategy registered with the ServerLoggingAcceptor parent. - * - *@param request LogRecord instance to use - */ - public void processRequest (Object request) - throws SocketException, EOFException, IOException - { - LogRecord rec = (LogRecord)request; - - rec.streamInFrom (this.peer ().dataInputStream ()); - - ServerLoggingAcceptor parent = (ServerLoggingAcceptor)parent (); - - parent.loggingStrategy ().logRecord (this.hostName (), rec); - } - - /** - * Creates a new instance of LogRecord. - */ - public Object newRequest () - { - return new LogRecord (); - } -} - - - - diff --git a/java/JACE/netsvcs/Logger/StderrStrategy.java b/java/JACE/netsvcs/Logger/StderrStrategy.java deleted file mode 100644 index ee927e19062..00000000000 --- a/java/JACE/netsvcs/Logger/StderrStrategy.java +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Logger - * - * = FILENAME - * DefaultLMR.java - * - * - *@author Everett Anderson - * - *************************************************/ -package JACE.netsvcs.Logger; - -import java.io.*; - -/** - * Default LoggingStrategy for the logging service. This prints out the - * LogRecord on the System.err stream. - * - * @see JACE.netsvcs.Logger.LogRecord - */ -public class StderrStrategy implements LoggingStrategy -{ - /** - * Process the given LogRecord by printing it on the System.err stream. - * - *@param hostname host from which this LogRecord originated - *@param record LogRecord instance to process - */ - public void logRecord (String hostname, - LogRecord record) - { - record.print(hostname, true, System.err); - } -} diff --git a/java/JACE/netsvcs/Logger/c.bat b/java/JACE/netsvcs/Logger/c.bat deleted file mode 100644 index 6600766df1d..00000000000 --- a/java/JACE/netsvcs/Logger/c.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -javac -d C:\Everett\JACE\classes *.java diff --git a/java/JACE/netsvcs/Logger/package.html b/java/JACE/netsvcs/Logger/package.html deleted file mode 100644 index 84bffb246d9..00000000000 --- a/java/JACE/netsvcs/Logger/package.html +++ /dev/null @@ -1,17 +0,0 @@ - - - -Logging Service for processing logging records received from remote hosts. -

-The strategy for how to process the records can be easily changed via the -command line. -

-A simple test client is available in the tests directory under netsvcs\Logger. -The service itself can either be run on the command line (by running -ServerLoggingAcceptor) or by loading it with a ServiceConfig file (see -the tests for the service configurator). - -@see JACE.netsvcs.Logger.LoggingStrategy -@see ACE Network Services - - diff --git a/java/JACE/netsvcs/Naming/NameAcceptor.java b/java/JACE/netsvcs/Naming/NameAcceptor.java deleted file mode 100644 index 7e7be457d70..00000000000 --- a/java/JACE/netsvcs/Naming/NameAcceptor.java +++ /dev/null @@ -1,313 +0,0 @@ -/************************************************* - * - * = PACKAGE - * netsvcs.Naming - * - * = FILENAME - * NameAcceptor.java - * - *************************************************/ -package JACE.netsvcs.Naming; - -import java.io.*; -import java.net.*; -import java.util.*; -import JACE.OS.*; -import JACE.Misc.*; -import JACE.Connection.*; -import JACE.Reactor.*; -import JACE.ASX.TimeValue; -import JACE.netsvcs.Server; - -/** - * Server for the naming service. - * Listens on the specified port (command line option) and launches - * NameHandlers when connections are made. - *

- * The hash table for the mapping and a timer queue are created here. - * Periodically, if it has been changed, the mapping is saved to a file. - * If the data file exists at load time, it is read from disk. Currently, - * the service stores the entire mapping in one Hashtable (which is probably - * kept in memory at all times). - *

- * Valid command line arguments: - *

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