summaryrefslogtreecommitdiff
path: root/java/netsvcs/Logger/ServerLoggingHandler.java
diff options
context:
space:
mode:
authoreea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-25 20:42:38 +0000
committereea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-25 20:42:38 +0000
commitd4bee2e56bc3108a6e1aa960fddc37ef4495ee33 (patch)
treea94250e5ed5a3f9af1d02558c2582517c8aef88f /java/netsvcs/Logger/ServerLoggingHandler.java
parent8df8bff2c8082791128c443b06a72b60486a6259 (diff)
downloadATCD-d4bee2e56bc3108a6e1aa960fddc37ef4495ee33.tar.gz
This is the first version of the JACE Server Logging service. It
is based heavily on the example written by Chris Cleeland, and it should be compatible with the C++ ACE version. The Client Logging service isn't necessary in Java since applications have to use sockets to communicate with the services anyway (the C++ version let apps communicate with the middle-man Client Logging Service via named pipes).
Diffstat (limited to 'java/netsvcs/Logger/ServerLoggingHandler.java')
-rw-r--r--java/netsvcs/Logger/ServerLoggingHandler.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/java/netsvcs/Logger/ServerLoggingHandler.java b/java/netsvcs/Logger/ServerLoggingHandler.java
new file mode 100644
index 00000000000..c8a364526cc
--- /dev/null
+++ b/java/netsvcs/Logger/ServerLoggingHandler.java
@@ -0,0 +1,112 @@
+/*************************************************
+ *
+ * = PACKAGE
+ * netsvcs.Logger
+ *
+ * = FILENAME
+ * ServerLoggingHandler.java
+ *
+ *@author Chris Cleeland, Everett Anderson
+ *
+ *************************************************/
+package netsvcs.Logger;
+
+import JACE.SOCK_SAP.*;
+import JACE.Connection.*;
+import JACE.OS.*;
+import java.util.*;
+import java.io.*;
+
+/**
+ *
+ * <p><h2>DESCRIPTION</h2>
+ *
+ * <blockquote>
+ * Created by ServerLoggingAcceptor every time a client connects. This reads
+ * a logging statement passes it to the LogMessageReceiver for processing.
+ * </blockquote>
+ *
+ * @see netsvcs.Logger.ServerLoggingAcceptor
+ */
+public class ServerLoggingHandler extends SvcHandler
+{
+ // Processes log messages
+ private LogMessageReceiver receiver_;
+
+ // Constructor
+ public ServerLoggingHandler (LogMessageReceiver receiver)
+ {
+ super();
+ this.receiver_ = receiver;
+ }
+
+ // Start this handler in its own thread
+ public int open(Object obj)
+ {
+ new Thread (this).start();
+ return 0;
+ }
+
+ // Accessor: get the host name of the connected client
+ protected String hostName ()
+ {
+ return new String(this.stream_.socket().getInetAddress().getHostName());
+ }
+
+ // Receive input from the client, and send it to the LMR
+ public void run()
+ {
+ DataInputStream dis = (DataInputStream) this.stream_.inputStream();
+
+ for (;;)
+ {
+ // Messages arrive in the following format:
+ // o 4 byte length (network format)
+ // o message, in ACE.LogRecord format
+ //
+ // Hey! We need exception catching in here too!
+ try
+ {
+ // Reconstitute a log message from the wire
+ LogRecord rec = new LogRecord();
+
+ // We don't really need this, because
+ // the object already knows how to
+ // extract itself properly. However,
+ // in order to interoperate with the
+ // C++ version, this must be extracted.
+ // Plus, it makes a convenient way to
+ // check everything.
+ int length = dis.readInt();
+
+ rec.streamInFrom(dis);
+
+ if (rec.length() == length)
+ {
+ // Give the record to the log processor
+ this.receiver_.logRecord(this.hostName(),
+ rec);
+ }
+ else
+ {
+ ACE.ERROR(Thread.currentThread().getName() + ": Length error");
+ }
+ }
+ catch (EOFException eof)
+ {
+ try {
+ this.stream_.close();
+ } catch (IOException n) { }
+
+ return;
+ }
+ catch (IOException ioe)
+ {
+ ACE.ERROR(Thread.currentThread().getName()
+ + ": "
+ + ioe);
+ }
+ }
+ }
+};
+