diff options
author | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-11-12 04:07:19 +0000 |
---|---|---|
committer | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-11-12 04:07:19 +0000 |
commit | cd24ef45f3530a5ea236448045a744c0a3880788 (patch) | |
tree | 8083209f472038f67114bd51a1dab1a0cfd5792e /java | |
parent | 178a9dc48e18353fd3f80524c427f12026e5afca (diff) | |
download | ATCD-cd24ef45f3530a5ea236448045a744c0a3880788.tar.gz |
A few extra comments, and now the default LogMessageReceiver is in its
own file.
Diffstat (limited to 'java')
-rw-r--r-- | java/netsvcs/Logger/DefaultLMR.java | 38 | ||||
-rw-r--r-- | java/netsvcs/Logger/LogMessageReceiver.java | 12 | ||||
-rw-r--r-- | java/netsvcs/Logger/LoggerTest.java | 112 | ||||
-rw-r--r-- | java/netsvcs/Logger/Makefile | 1 | ||||
-rw-r--r-- | java/netsvcs/Logger/ServerLoggingAcceptor.java | 43 | ||||
-rw-r--r-- | java/netsvcs/Logger/ServerLoggingHandler.java | 23 |
6 files changed, 87 insertions, 142 deletions
diff --git a/java/netsvcs/Logger/DefaultLMR.java b/java/netsvcs/Logger/DefaultLMR.java new file mode 100644 index 00000000000..dd0e5750645 --- /dev/null +++ b/java/netsvcs/Logger/DefaultLMR.java @@ -0,0 +1,38 @@ +/************************************************* + * + * = PACKAGE + * netsvcs.Logger + * + * = FILENAME + * DefaultLMR.java + * + * + *@author Everett Anderson + * + *************************************************/ +package netsvcs.Logger; + +import java.lang.*; +import java.io.*; +import netsvcs.Logger.LogRecord; + +/** + * + * <p><h2>DESCRIPTION</h2> + * + * <blockquote> + * The LogMessageReceiver removes the code that handles a log message from + * the logging service acceptor. The DefaultLMR simply calls the LogRecord's + * print method. + * + * @see netsvcs.Logger.ServerLoggingAcceptor + * @see netsvcs.Logger.LogRecord + */ +class DefaultLMR implements LogMessageReceiver +{ + public void logRecord (String hostname, + LogRecord record) + { + record.print(hostname, true, System.err); + } +} diff --git a/java/netsvcs/Logger/LogMessageReceiver.java b/java/netsvcs/Logger/LogMessageReceiver.java index a2e6df9fba5..3c34ac48658 100644 --- a/java/netsvcs/Logger/LogMessageReceiver.java +++ b/java/netsvcs/Logger/LogMessageReceiver.java @@ -25,19 +25,11 @@ import netsvcs.Logger.LogRecord; * print method. Other implementations of this interface can be built and * given to the ServerLoggingAcceptor to change the result. * - * @see netsvcs.Logger.ServerLoggingAcceptor, netsvcs.Logger.LogRecord + * @see netsvcs.Logger.ServerLoggingAcceptor + * @see netsvcs.Logger.LogRecord */ public interface LogMessageReceiver { public void logRecord (String hostname, LogRecord record); }; - -class DefaultLMR implements LogMessageReceiver -{ - public void logRecord (String hostname, - LogRecord record) - { - record.print(hostname, true, System.err); - } -} diff --git a/java/netsvcs/Logger/LoggerTest.java b/java/netsvcs/Logger/LoggerTest.java deleted file mode 100644 index 52a952ce5ee..00000000000 --- a/java/netsvcs/Logger/LoggerTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/************************************************* - * - * = FILENAME - * LoggerTest.java - * - *@author Everett Anderson - * - *************************************************/ -import JACE.SOCK_SAP.*; -import java.io.*; -import java.net.*; -import JACE.OS.*; -import netsvcs.Logger.LogRecord; - -/** - * - * <p><h2>DESCRIPTION</h2> - * - * <blockquote> - * This is an example/test log client very similar to the direct_logging client of - * C++ ACE. The server logging service should correctly receive messages from both - * of these examples. - * </blockquote> - * - * @see netsvcs.Logger.ServerLoggingAcceptor, netsvcs.Logger.LogRecord - */ -public class LoggerTest { - - // Command line: <port> <hostname> - // - // Creates a "hello world" log message and sends it to the server logging service. - // If no command line arguments are given, it uses ACE.DEFAULT_SERVER_PORT, and the - // current machine for the service location. - // - public static void main(String args[]) - { - int port = args.length > 0 ? (new Integer(args[0])).intValue() : ACE.DEFAULT_SERVER_PORT; - - SOCKStream cli_stream = new SOCKStream(); - INETAddr remote_addr; - String host; - - try { - - host = args.length > 1 ? args[1] : InetAddress.getLocalHost().getHostName(); - - remote_addr = new INETAddr(port, host) -; - } catch (UnknownHostException uhe) { - ACE.ERROR("UnknownHostException " + uhe); - return; - } - - System.out.println("Connecting to " + host + " on port " + port); - - SOCKConnector con = new SOCKConnector(); - - try { - - // Connect to the service - con.connect(cli_stream, remote_addr); - - } catch (SocketException se) { - - ACE.ERROR("Socket Exception " + se); - return; - - } catch (IOException ie) { - - ACE.ERROR("IOException " + ie); - return; - } - - - // Send a message with priority 4, the current time, - // and 0 for the process ID. - LogRecord record = new LogRecord(4, - System.currentTimeMillis(), - 0); - - // Set the message - record.msgData("hello world"); - - try { - - // Get a transmission system from the socket - OutputStream os = cli_stream.socket().getOutputStream(); - DataOutputStream dos = new DataOutputStream(os); - - // Send it - record.streamOutTo(dos); - - // Close the socket - cli_stream.close(); - - } catch (IOException ie) { - - ACE.ERROR("IOException, loop: " + ie); - return; - } - } -}; - - - - - - - - - - diff --git a/java/netsvcs/Logger/Makefile b/java/netsvcs/Logger/Makefile index 77fe971c777..0f024034839 100644 --- a/java/netsvcs/Logger/Makefile +++ b/java/netsvcs/Logger/Makefile @@ -10,6 +10,7 @@ doc: javadoc -d ${JACE_WRAPPER}/doc $(files) $(packages) files = LogMessageReceiver.java \ + DefaultLMR.java \ LogRecord.java \ ServerLoggingAcceptor.java \ ServerLoggingHandler.java diff --git a/java/netsvcs/Logger/ServerLoggingAcceptor.java b/java/netsvcs/Logger/ServerLoggingAcceptor.java index c68c089a0f7..a44f2cfa585 100644 --- a/java/netsvcs/Logger/ServerLoggingAcceptor.java +++ b/java/netsvcs/Logger/ServerLoggingAcceptor.java @@ -32,8 +32,14 @@ import JACE.Misc.*; */ public class ServerLoggingAcceptor extends Acceptor implements Runnable { - // Main function so the service can be started without the service - // configurator. + /** Main function to bootstrap the process + * + * Command line arguments: + * + * -p <port> Select a port for listening for requests + * -r <class name> Specify a LogMessageReceiver (make sure it's a full class name) + * + */ public static void main (String [] args) { ServerLoggingAcceptor sla = new ServerLoggingAcceptor(); @@ -41,14 +47,15 @@ public class ServerLoggingAcceptor extends Acceptor implements Runnable sla.init(args); } - // Called by the service configurator, receives the command line and - // launches its own thread. + /** + * Receives the command line and launches its own thread + */ public int init (String [] args) { this.parseArgs(args); - // *** should contain choices like what the default is - // in an options singleton? + // If the user didn't specify a LogMessageReceiver, use the default + // (which just calls a print method on LogMessage) if (this.receiver_ == null) this.receiver_ = new DefaultLMR(); @@ -56,34 +63,41 @@ public class ServerLoggingAcceptor extends Acceptor implements Runnable return 0; } - // Specify what LogMessageReceiver to use + /** + * Specify what LogMessageReceiver to use + */ public void setLMR(LogMessageReceiver receiver) { this.receiver_ = receiver; } - // Accessor for the LogMessageReceiver + /** + * Accessor for the LogMessageReceiver + */ public LogMessageReceiver getLMR () { return this.receiver_; } - // Create a new ServerLoggingHandler + /** + * Create a new ServerLoggingHandler + */ protected SvcHandler makeSvcHandler () throws InstantiationException, IllegalAccessException { - // ** could contain this choice in a singleton, too return new netsvcs.Logger.ServerLoggingHandler (this.receiver_); } - // Run forever accepting new connections + /** + * Run forever accepting new connections + */ public void run () { try { this.open (this.port_); while (true) - this.accept(); // blocks + this.accept(); } catch (SocketException e) { @@ -105,7 +119,9 @@ public class ServerLoggingAcceptor extends Acceptor implements Runnable ACE.ERROR("ServerLoggingAcceptor has exited"); } - // Process the command line + /** + * Process the command line + */ protected void parseArgs (String args[]) { String s; @@ -145,7 +161,6 @@ public class ServerLoggingAcceptor extends Acceptor implements Runnable } } - // port should be in options singleton ** private int port_ = ACE.DEFAULT_SERVER_PORT; private LogMessageReceiver receiver_ = null; }; diff --git a/java/netsvcs/Logger/ServerLoggingHandler.java b/java/netsvcs/Logger/ServerLoggingHandler.java index c8a364526cc..9088e17d9d1 100644 --- a/java/netsvcs/Logger/ServerLoggingHandler.java +++ b/java/netsvcs/Logger/ServerLoggingHandler.java @@ -33,30 +33,41 @@ public class ServerLoggingHandler extends SvcHandler // Processes log messages private LogMessageReceiver receiver_; - // Constructor + /** + * Constructor + * + *@param receiver LogMessageReceiver that handles what to do with a message + */ public ServerLoggingHandler (LogMessageReceiver receiver) { super(); this.receiver_ = receiver; } - // Start this handler in its own thread + /** + * 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 + /** + * Accessor: get the host name of the connected client + */ protected String hostName () { - return new String(this.stream_.socket().getInetAddress().getHostName()); + return new String(this.peer().socket().getInetAddress().getHostName()); } - // Receive input from the client, and send it to the LMR + /** + * Receive input from the client, and send it to the LMR. This is the + * main loop for this thread. + */ public void run() { - DataInputStream dis = (DataInputStream) this.stream_.inputStream(); + DataInputStream dis = new DataInputStream(this.peer().inputStream()); for (;;) { |