summaryrefslogtreecommitdiff
path: root/java/netsvcs/Time/TSServerHandler.java
diff options
context:
space:
mode:
authoreea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-25 20:46:18 +0000
committereea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-25 20:46:18 +0000
commit4e86e97b7da359d9135dcd5a248f2260777cd32a (patch)
tree653e990f6f71579ccd0791b8e54760146c8eacfa /java/netsvcs/Time/TSServerHandler.java
parentaa495bcca4b6cfff953a61a75477b6a9d950652d (diff)
downloadATCD-4e86e97b7da359d9135dcd5a248f2260777cd32a.tar.gz
This is the first version of the JACE Time Service. Clerk and Server
are drivers in case someone needs to run it without the Service Configurator. It is based on Prashant's earlier test version, but adds support for reconnecting to time servers, etc. The main difference between this and the C++ version is that apps on a machine will have to use sockets to communicate with the time clerk -- you can't use shared memory in Java.
Diffstat (limited to 'java/netsvcs/Time/TSServerHandler.java')
-rwxr-xr-xjava/netsvcs/Time/TSServerHandler.java99
1 files changed, 99 insertions, 0 deletions
diff --git a/java/netsvcs/Time/TSServerHandler.java b/java/netsvcs/Time/TSServerHandler.java
new file mode 100755
index 00000000000..0fa940d2388
--- /dev/null
+++ b/java/netsvcs/Time/TSServerHandler.java
@@ -0,0 +1,99 @@
+/*************************************************
+ *
+ * = PACKAGE
+ * netsvcs.Time
+ *
+ * = FILENAME
+ * TS_Server_Handler.java
+ *
+ *@author Prashant Jain, Everett Anderson
+ *
+ *************************************************/
+package netsvcs.Time;
+
+import java.io.*;
+import java.util.*;
+import JACE.OS.*;
+import JACE.Connection.*;
+import JACE.Reactor.*;
+
+/**
+ * <hr>
+ * <p><h2>DESCRIPTION</h2>
+ *
+ * <blockquote>Handles requests from a TSClerkHandler and sends
+ * back the current local time.</blockquote>
+ *
+ * @see netsvcs.Time.TSClerkHandler. netsvcs.Time.TSServerAcceptor
+ */
+
+public class TSServerHandler extends SvcHandler
+{
+ // Constructor
+ public TSServerHandler ()
+ {
+ }
+
+ // Start this handler in its own thread
+ public int open (Object obj)
+ {
+
+ new Thread (this).start ();
+ return 0;
+ }
+
+ // Wait for messages from the Client and send the current local
+ // time back as a string.
+ public void run ()
+ {
+ int msgLen;
+ try
+ {
+ while (true)
+ {
+ // Use a new one each time since recv appends
+ StringBuffer msg = new StringBuffer ();
+
+ // Get the message from the client (blocks)
+ msgLen = this.peer ().recv (msg);
+
+ // Just keep waiting if there's a problem
+ if (msgLen <= 0)
+ break;
+
+ // Is the message for the right thing?
+ if (msg.toString().compareTo ("TIME_UPDATE_REQUEST") != 0) {
+ System.err.println("Unknown message: \"" + msg + '\"');
+ this.peer().send("\n"); // send so other side isn't stuck
+ break;
+ }
+
+ // Get local time
+ long time = System.currentTimeMillis();
+
+ // Send as a string
+ this.peer ().send ("" + time + '\n');
+
+ ACE.DEBUG("Time: " + new Date(time));
+ }
+ }
+ catch (NullPointerException e)
+ {
+ ACE.ERROR ("Connection reset by peer");
+ }
+ catch (IOException e)
+ {
+ ACE.ERROR (e);
+ }
+ finally
+ {
+ try
+ {
+ this.peer ().close ();
+ }
+ catch (IOException e)
+ {
+ }
+ }
+ }
+}