diff options
Diffstat (limited to 'java/examples/Logger')
-rw-r--r-- | java/examples/Logger/README | 29 | ||||
-rw-r--r-- | java/examples/Logger/simple-server/LogRecord.java | 145 | ||||
-rw-r--r-- | java/examples/Logger/simple-server/LoggerConstants.java | 7 | ||||
-rw-r--r-- | java/examples/Logger/simple-server/LoggingAcceptor.java | 33 | ||||
-rw-r--r-- | java/examples/Logger/simple-server/LoggingClient.java | 108 | ||||
-rw-r--r-- | java/examples/Logger/simple-server/LoggingHandler.java | 121 | ||||
-rw-r--r-- | java/examples/Logger/simple-server/Makefile | 34 | ||||
-rw-r--r-- | java/examples/Logger/simple-server/README | 25 | ||||
-rw-r--r-- | java/examples/Logger/simple-server/SimpleLogger.java | 44 |
9 files changed, 0 insertions, 546 deletions
diff --git a/java/examples/Logger/README b/java/examples/Logger/README deleted file mode 100644 index 1da7dbcbb19..00000000000 --- a/java/examples/Logger/README +++ /dev/null @@ -1,29 +0,0 @@ -This directory contains a simple client/server Java implementation of the -distributed logging server described in several papers in the C++ -Report (which can be obtained via the following WWW URLs: -http://www.cs.wustl.edu/~schmidt/{Reactor1-93.ps.gz,Reactor2-93.ps.gz}). - -The example consists of the following two directories: - - . client - NOT YET CONVERTED - This program talks directly to the server logging - daemon. The server daemon must be started before you - can run this test. - - . simple-server - - This program runs a simple - implementation of the - distributed logging server daemon. It also contains - code for a simple client as well. - - . Acceptor-server - NOT YET CONVERTED - This program runs templated, Acceptor-based - single-threaded Reactive implementation of the - distributed logging server daemon. - -The server implemented in "simple" is completely compatible with the -client defined in the C++ version of ACE. - diff --git a/java/examples/Logger/simple-server/LogRecord.java b/java/examples/Logger/simple-server/LogRecord.java deleted file mode 100644 index 4b7e7e87003..00000000000 --- a/java/examples/Logger/simple-server/LogRecord.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Class used to communicate logging information; compatible with - * the C++ ACE ACE_Log_Record class. - * - * @author Chris Cleeland - */ - -//package ACE.SimpleLogger; - -import java.util.Date; -import java.io.DataOutputStream; -import java.io.DataInputStream; -import java.io.PrintStream; -import java.io.IOException; - -public class LogRecord -{ - final public int MAXLOGMSGLEN = 4 * 1024; - - private int type_; - private int length_; - private int timeStamp_; - private int pid_; - private byte[] msgData_ = new byte[MAXLOGMSGLEN]; - private final static int numIntMembers = 4; - private final static int sizeofIntInBytes = 4; - - /** - * Create a default instance. - */ - public LogRecord() - { - this(0, (int) ((new Date()).getTime()/1000), 0); - } - - /** - * Create a LogRecord. This is the designated initializer. - * @param priority a numeric specification of the priority (ascending) - * @param time_stamp time attached to the log entry in Unix <pre>time_t</pre> format - * @param pid the process ID; not currently used - */ - public LogRecord(int priority, - int timeStamp, - int pid) - { - type(priority); - timeStamp(timeStamp); - length(0); - pid(pid); - } - - /** - * Conversion to string. Only includes the <pre>msgData_</pre> member. - */ - public String toString() - { - return new String(msgData_, 0); - } - - /** - * Place a textual representation of the record on a PrintStream. - * @param hostname name of the host generating this record - * @param verbose if <b>true</b>, print information in the form, (give example) - * @param ps A PrintStream instance to which the output should go. - * @see PrintStream,String - */ - public void print(String hostname, - boolean verbose, - PrintStream ps) - { - String toprint; - if (verbose) - { - long cur = (long)timeStamp() * (long)1000; - Date now = new Date(cur); - - /* 01234567890123456789012345 */ - /* Wed Oct 18 14:25:36 1989n0 */ - toprint = now.toString().substring(4) + "@" - + hostname + "@" + pid_ + "@" + type_ + "@" - + this.toString(); - } - else - { - toprint = this.toString(); - } - ps.println(toprint); - } - - /** - * Streaming methods - */ - public void streamInFrom(DataInputStream dis) throws IOException - { - // Order here must match layout order in the C++ class. - // This, of course, is VERY fragile, and ought not be used as - // a model for anything except how NOT to do anything. - type(dis.readInt()); - length(dis.readInt()); - timeStamp(dis.readInt()); - pid(dis.readInt()); - - // Does readFully() allocate space for the buffer? Either - // way, we won't have memory leaks :-) - int dataLength = (int) (length_ - numIntMembers * sizeofIntInBytes); - msgData_ = new byte[dataLength]; - dis.readFully(msgData_, 0, dataLength); - } - - public void streamOutTo(DataOutputStream dos) throws IOException - { - dos.writeInt(type()); - dos.writeInt(length()); - dos.writeInt(timeStamp()); - dos.writeInt(pid()); - int dataLength = (int) (length_ - numIntMembers * sizeofIntInBytes); - dos.write(msgData_, 0, dataLength); - } - - /** - * Accessor methods - */ - public int type() { return type_; } - public void type(int t) { type_ = t; } - - public int length() { return length_; } - public void length(int l) { length_ = l; } - private void setLen(int msgLen) - { length(msgLen + numIntMembers * sizeofIntInBytes); } - - public int timeStamp() { return timeStamp_; } - public void timeStamp(int t){ timeStamp_ = t; } - - public int pid() { return pid_; } - public void pid(int p) { pid_ = p; } - - public byte[] msgData() { return msgData_; } - public void msgData(byte[] m){ msgData_ = m; setLen(m.length); } - public void msgData(String m) - { - m.getBytes(0, m.length(), msgData_, 0); - setLen(m.length()); - } -}; - diff --git a/java/examples/Logger/simple-server/LoggerConstants.java b/java/examples/Logger/simple-server/LoggerConstants.java deleted file mode 100644 index db62d2fff6e..00000000000 --- a/java/examples/Logger/simple-server/LoggerConstants.java +++ /dev/null @@ -1,7 +0,0 @@ -// package ACE.Logger; - -public class LoggerConstants -{ - final public static int DEFAULT_SERVER_PORT = 4000; - final public static String DEFAULT_SERVER_HOSTNAME = "localhost"; -} diff --git a/java/examples/Logger/simple-server/LoggingAcceptor.java b/java/examples/Logger/simple-server/LoggingAcceptor.java deleted file mode 100644 index 7925e3d5a15..00000000000 --- a/java/examples/Logger/simple-server/LoggingAcceptor.java +++ /dev/null @@ -1,33 +0,0 @@ -//package ACE.SimpleLogger; - -import JACE.SOCK_SAP.*; -import java.io.IOException; - -public class LoggingAcceptor extends Thread -{ - private SOCKAcceptor peerAcceptor_; - - public LoggingAcceptor(int port) throws IOException - { - peerAcceptor_ = new SOCKAcceptor(port); - this.setName("LoggingAcceptor"); - System.err.println("Waiting for connection on port " + - port); - } - - public void run() - { - try - { - while (true) - { - LoggingHandler handler = new LoggingHandler(); - peerAcceptor_.accept(handler.stream()); - handler.open(); - } - } - catch (IOException e) - { - } - } -}; diff --git a/java/examples/Logger/simple-server/LoggingClient.java b/java/examples/Logger/simple-server/LoggingClient.java deleted file mode 100644 index e6ea986c011..00000000000 --- a/java/examples/Logger/simple-server/LoggingClient.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Main class that acts as an example logging client. - */ - -import java.io.*; -import java.net.*; -import JACE.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). - BufferedOutputStream bos = new BufferedOutputStream((OutputStream) logger.outputStream(), LogRecord.MAXLOGMSGLEN); - DataOutputStream dos = new DataOutputStream(bos); - - 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); - bos.flush(); - 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); - } - - } -} diff --git a/java/examples/Logger/simple-server/LoggingHandler.java b/java/examples/Logger/simple-server/LoggingHandler.java deleted file mode 100644 index aeffc991ac3..00000000000 --- a/java/examples/Logger/simple-server/LoggingHandler.java +++ /dev/null @@ -1,121 +0,0 @@ -/************************************************* - * - *@author Chris Cleeland - * - * What we really need to define is a run() (or whatever - * the Thread class has as its method to execute code), and - * have that do the usual delegated work of handle_input. - * We also need to figure out the best place to close the - * the socket, which probably ISN'T the finalizer. - * - *************************************************/ - -//package ACE.SimpleLogger; - -import JACE.SOCK_SAP.*; -import java.util.*; -import java.io.*; - -// Should this extend or simply be handed to a Thread instance to -// be run? -public class LoggingHandler extends Thread -{ - private SOCKStream cliStream_; - - /** - * Create a default Logging Handler - */ - public LoggingHandler() - { - this(new SOCKStream()); - } - - /** - * Create a LoggingHandler with an existing stream - */ - public LoggingHandler(SOCKStream aStream) - { - cliStream_ = aStream; - setName(); - } - - private void setName() - { - int portnum = ((cliStream_.socket() == null) - ? 0 - : cliStream_.socket().getLocalPort()); - this.setName("LoggingHandler#" + portnum); - } - - /** - * Start - */ - public void open() - { - this.start(); - } - - /** - */ - public SOCKStream stream() - { - return cliStream_; - } - - /** - * Handle logging events - */ - public void run() - { - DataInputStream dis = (DataInputStream) cliStream_.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) - { - rec.print(cliStream_.socket().getInetAddress().getHostName(), - true, System.out); - System.out.flush(); - } - else - { - System.err.println("Logging_Handler: Length error receiving logging message\n"); - } - } - catch (EOFException eof) - { - System.err.println(Thread.currentThread().getName() - + ": end-of-file condition found; terminating."); - try { cliStream_.close(); } catch (IOException n) { } - this.stop(); - } - catch (IOException ioe) - { - System.err.println(Thread.currentThread().getName() - + ": IOException received -- " - + ioe.getMessage()); - } - } - } -}; diff --git a/java/examples/Logger/simple-server/Makefile b/java/examples/Logger/simple-server/Makefile deleted file mode 100644 index 5be1b0d048e..00000000000 --- a/java/examples/Logger/simple-server/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -.SUFFIXES: .java .class - -CLASSDIR = . -DOCDIR = . - -JC = javac_g -JCOPTS = -g -d $(CLASSDIR) -JD = javadoc -JDOPTS = -d $(DOCDIR) - -COMPILE.java = $(JC) $(JCOPTS) $< -DOCCOMP.java = $(JD) $(JDOPTS) $< - -CLASSPATH := $(CLASSDIR):$(CLASSPATH) - -CLASSES = LoggerConstants LogRecord LoggingHandler \ - LoggingAcceptor SimpleLogger LoggingClient -CLASSFILES = $(addsuffix .class,$(CLASSES)) -DOCFILES = $(addsuffix .html,$(CLASSES)) - -%.class: %.java - $(COMPILE.java) - -%.html: %.java - $(DOCCOMP.java) - -all: classes doc - -classes: $(CLASSFILES) -doc: $(DOCFILES) - -clean: - $(RM) *~ $(CLASSFILES) $(DOCFILES) - diff --git a/java/examples/Logger/simple-server/README b/java/examples/Logger/simple-server/README deleted file mode 100644 index 90393c1aae8..00000000000 --- a/java/examples/Logger/simple-server/README +++ /dev/null @@ -1,25 +0,0 @@ -====== -BASICS -====== - -This directory contains both the client (LoggingClient.java) and the -server (SimpleLogger.java). To compile, use GNU make with no specific -target. - -To execute, use "java <classname>" where <classname> is from the -following table: - - Application <classname> - =========================================== - client LoggingClient - server SimpleLogger - - -============== -KNOWN PROBLEMS -============== - -Interoperability between the C++ client and the Java server -implementation is fine. Interoperability between the C++ server and -the Java client seems to work right now. See the CVS information on -LoggingClient.java for details. diff --git a/java/examples/Logger/simple-server/SimpleLogger.java b/java/examples/Logger/simple-server/SimpleLogger.java deleted file mode 100644 index f562689e283..00000000000 --- a/java/examples/Logger/simple-server/SimpleLogger.java +++ /dev/null @@ -1,44 +0,0 @@ -//package ACE.SimpleLogger; - -import java.io.IOException; - -class SimpleLogger implements Runnable -{ - private LoggingAcceptor la; - private int port; - - public static void main(String[] args) - { - SimpleLogger sl = new SimpleLogger(); - sl.run(); - } - - public SimpleLogger() - { - this(LoggerConstants.DEFAULT_SERVER_PORT); - } - - public SimpleLogger(int port) - { - try - { - la = new LoggingAcceptor(port); - } - catch (IOException ioe) - { - System.err.println("SimpleLogger: unable to create LoggingAcceptor (" - + ioe.getMessage() + ")"); - } - } - - public void run() - { - la.run(); - try - { - la.join(); - } - catch (InterruptedException ie) - { } - } -}; |