summaryrefslogtreecommitdiff
path: root/java/examples/Logger/simple-server/LoggingClient.java
diff options
context:
space:
mode:
authorChris Cleeland <chris.cleeland@gmail.com>1997-01-30 04:39:40 +0000
committerChris Cleeland <chris.cleeland@gmail.com>1997-01-30 04:39:40 +0000
commit5ab2976b8f0f0d6546a4457c2f4d57d485a2a619 (patch)
tree67b72bd5a78351cd30b5979e2baf46cac6d082ef /java/examples/Logger/simple-server/LoggingClient.java
parent0025c62efcf3f7e3a3afbee16b677fb701aec394 (diff)
downloadATCD-5ab2976b8f0f0d6546a4457c2f4d57d485a2a619.tar.gz
*** empty log message ***
Diffstat (limited to 'java/examples/Logger/simple-server/LoggingClient.java')
-rw-r--r--java/examples/Logger/simple-server/LoggingClient.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/java/examples/Logger/simple-server/LoggingClient.java b/java/examples/Logger/simple-server/LoggingClient.java
new file mode 100644
index 00000000000..9fe14e44284
--- /dev/null
+++ b/java/examples/Logger/simple-server/LoggingClient.java
@@ -0,0 +1,106 @@
+/**
+ * Main class that acts as an example logging client.
+ */
+
+import java.io.*;
+import java.net.*;
+import ACE.SOCK_SAP.*;
+import LogRecord;
+import LoggerConstants;
+
+public class LoggingClient implements Runnable
+{
+ private String loggerHost_;
+ private int port_;
+ private int maxIter_;
+ private static final int DEFAULT_ITERATIONS = 10;
+
+ public static void main(String[] args)
+ {
+ // Really need to put code in here to parse options
+ int iter;
+ int port;
+ String host;
+
+ iter = (args.length > 0) ? Integer.parseInt(args[0])
+ : DEFAULT_ITERATIONS;
+ port = (args.length > 1) ? Integer.parseInt(args[1])
+ : LoggerConstants.DEFAULT_SERVER_PORT;
+ host = (args.length > 2) ? args[2]
+ : LoggerConstants.DEFAULT_SERVER_HOSTNAME;
+
+ LoggingClient lc = new LoggingClient(iter, port, host);
+ lc.run();
+ }
+
+ public LoggingClient()
+ {
+
+ this(DEFAULT_ITERATIONS,
+ LoggerConstants.DEFAULT_SERVER_PORT,
+ LoggerConstants.DEFAULT_SERVER_HOSTNAME);
+ }
+
+ public LoggingClient(int iterations, int thePort, String theHost)
+ {
+ maxIter_ = iterations;
+ port_ = thePort;
+ loggerHost_ = theHost;
+ }
+
+ public void run()
+ {
+ SOCKStream logger = new SOCKStream();
+ SOCKConnector connector = new SOCKConnector();
+ // INETAddr addr = new INETAddr(port_, loggerHost_);
+
+ LogRecord rec = new LogRecord(9, 2, 0);
+
+ try
+ {
+ connector.connect(logger, loggerHost_, port_);
+
+ int oneSecond = 1000;
+ // Currently SOCKStream uses DataInputStream for its input stream,
+ // and PrintStream for its output stream. It probably ought to use
+ // DataOutputStream for the output stream for symmetry, or at least
+ // provide a mechanism for changing the type of the filter stream
+ // used (which might be better in the long run...give it the class
+ // id).
+ DataOutputStream dos = new DataOutputStream((OutputStream) logger.outputStream());
+
+ for (int i = 0; i < maxIter_; i++)
+ {
+ // Need to overload LogRecord.msgData to take a String
+ // argument so that it's easy to create instances with text
+ // inside.
+ rec.msgData("message = " + i);
+ try
+ {
+ dos.writeInt(rec.length());
+ rec.streamOutTo(dos);
+ rec.print("localhost", true, System.err);
+ }
+ catch (IOException ex) { }
+
+ try
+ {
+ Thread.sleep(oneSecond);
+ }
+ catch (InterruptedException ex) { }
+ }
+
+ try { logger.close(); } catch (IOException ex) { }
+
+ }
+ catch (SocketException ex)
+ {
+ System.err.println("socket exception: " + ex);
+ }
+ catch (IOException ex)
+ {
+ System.err.println("io exception: " + ex);
+ }
+
+ }
+}