From d4bee2e56bc3108a6e1aa960fddc37ef4495ee33 Mon Sep 17 00:00:00 2001 From: eea1 Date: Fri, 25 Jul 1997 20:42:38 +0000 Subject: 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). --- java/netsvcs/Logger/ServerLoggingHandler.java | 112 ++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 java/netsvcs/Logger/ServerLoggingHandler.java (limited to 'java/netsvcs/Logger/ServerLoggingHandler.java') 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.*; + +/** + * + *

DESCRIPTION

+ * + *
+ * Created by ServerLoggingAcceptor every time a client connects. This reads + * a logging statement passes it to the LogMessageReceiver for processing. + *
+ * + * @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); + } + } + } +}; + -- cgit v1.2.1