diff options
author | pjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-25 22:08:33 +0000 |
---|---|---|
committer | pjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-25 22:08:33 +0000 |
commit | ddf5f9be236bdcc327e713b6c8c73d0bea61f808 (patch) | |
tree | 607e158178511f33dc485b47e8e3c9a2389e23b6 /java/ImageProcessing | |
parent | 3e0461fc9fa0d722904a6f53b21635a982fcac52 (diff) | |
download | ATCD-ddf5f9be236bdcc327e713b6c8c73d0bea61f808.tar.gz |
Added new classes to implement the server side (for testing)
Diffstat (limited to 'java/ImageProcessing')
-rw-r--r-- | java/ImageProcessing/framework/ServerHandler.java | 50 | ||||
-rw-r--r-- | java/ImageProcessing/framework/ServerTest.java | 67 | ||||
-rw-r--r-- | java/ImageProcessing/framework/TestHandler.java | 149 | ||||
-rw-r--r-- | java/ImageProcessing/framework/Tester.java | 148 |
4 files changed, 315 insertions, 99 deletions
diff --git a/java/ImageProcessing/framework/ServerHandler.java b/java/ImageProcessing/framework/ServerHandler.java new file mode 100644 index 00000000000..88da64d6328 --- /dev/null +++ b/java/ImageProcessing/framework/ServerHandler.java @@ -0,0 +1,50 @@ +package imaging.framework; + +import java.io.*; +import java.net.*; +import JACE.OS.*; +import JACE.Connection.*; + +public class ServerHandler extends SvcHandler +{ + public int open (Object obj) + { + new Thread (this).start (); + return 0; + } + + public void run () + { + int msg_len; + try + { + while (true) + { + StringBuffer msg = new StringBuffer (); + msg_len = this.peer ().recv (msg); + if (msg_len == 0) + break; + System.out.println (msg); + } + } + catch (NullPointerException e) + { + ACE.ERROR ("connection reset by peer"); + } + catch (IOException e) + { + ACE.ERROR (e); + } + finally + { + try + { + this.peer ().close (); + } + catch (IOException e) + { + } + } + + } +} diff --git a/java/ImageProcessing/framework/ServerTest.java b/java/ImageProcessing/framework/ServerTest.java new file mode 100644 index 00000000000..b5ab00596ea --- /dev/null +++ b/java/ImageProcessing/framework/ServerTest.java @@ -0,0 +1,67 @@ +package imaging.framework; + +import java.io.*; +import java.net.*; +import JACE.OS.*; +import JACE.Connection.*; + +public class ServerTest +{ + void print_usage_and_die () + { + System.out.println ("Usage: ServerTest [<port>]"); + System.exit (0); + } + + public void init (int port) + { + try + { + Acceptor acceptor = new Acceptor (Class.forName ("imaging.framework.ServerHandler")); + acceptor.open (port); + while (true) + { + acceptor.accept (); + } + } + catch (ClassNotFoundException e) + { + ACE.ERROR (e); + } + catch (SocketException e) + { + ACE.ERROR ("Socket Exception: " + e); + } + catch (InstantiationException e) + { + ACE.ERROR (e); + } + catch (IllegalAccessException e) + { + ACE.ERROR ("Dang!" + e); + } + catch (IOException e) + { + ACE.ERROR (e); + } + } + + public static void main (String [] args) + { + int port = ACE.DEFAULT_SERVER_PORT; + ServerTest server = new ServerTest (); + + if (args.length == 1) + { + try + { + port = Integer.parseInt (args[0]); + } + catch (NumberFormatException e) + { + server.print_usage_and_die (); + } + } + server.init (port); + } +} diff --git a/java/ImageProcessing/framework/TestHandler.java b/java/ImageProcessing/framework/TestHandler.java new file mode 100644 index 00000000000..84af7809ae8 --- /dev/null +++ b/java/ImageProcessing/framework/TestHandler.java @@ -0,0 +1,149 @@ +package imaging.framework; + +import java.io.*; +import java.net.*; +import java.awt.*; +import java.awt.image.*; +import java.util.*; +import JACE.OS.*; +import JACE.Connection.*; +import JACE.Timers.*; + +public class TestHandler extends SvcHandler +{ + public TestHandler (String imageList, ImageApp parent) + { + this.imageList_ = imageList; + this.parent_ = parent; + this.filterTable_ = this.parent_.filterTable(); + } + + public int open (Object obj) + { + // We got called by the Connector so assume connection was set up + // fine and therfore do not use standard output + stdOut = false; + + doTesting (); + return 0; + } + + public void doTesting () + { + if (imageList_ != null) + { + StringTokenizer tokens = new StringTokenizer (imageList_); + String image = null; + + // Now parse the string, picking up image names. + while (tokens.hasMoreTokens ()) + { + // Get the next token + image = tokens.nextToken (); + this.process (image); + } + } + } + + private void process (String image) + { + try + { + if (stdOut) + System.out.println ("Image: " + image); + else + this.peer ().send ("Image: " + image + "\n"); + } + catch (IOException e) + { + ACE.ERROR (e); + } + + this.loadImage (image); + this.processImage (image); + this.uploadImage (image); + } + + private void loadImage (String image) + { + try + { + if (stdOut) + System.out.print ("\tLoading..."); + else + this.peer ().send ("\tLoading..."); + + // Start the timer + timer_.start (); + + // Load the image + parent_.openURL (image); + + // Stop the timer + timer_.stop (); + long time = timer_.elapsedTime (); + if (stdOut) + System.out.println ("done (" + ((double) time)/1000 + " seconds)."); + else + this.peer ().send ("done (" + ((double) time)/1000 + " seconds).\n"); + } + catch (IOException e) + { + ACE.ERROR (e); + } + + } + + private void processImage (String image) + { + try + { + if (stdOut) + System.out.println ("\tProcessing..."); + else + this.peer ().send ("\tProcessing...\n"); + + for (Enumeration e = filterTable_.keys (); e.hasMoreElements (); ) + { + String filterName = (String) e.nextElement (); + if (stdOut) + System.out.print ("\t\t" + filterName + "..."); + else + this.peer ().send ("\t\t" + filterName + "..."); + + ImageFilter filter = (ImageFilter) filterTable_.get (filterName); + + // Start the timer + timer_.start (); + + this.parent_.apply (filter); + + // Stop the timer + timer_.stop (); + long time = timer_.elapsedTime (); + + if (stdOut) + System.out.println ("done (" + ((double) time)/1000 + " seconds)."); + else + this.peer ().send ("done (" + ((double) time)/1000 + " seconds).\n"); + this.parent_.resetImage (); + } + } + catch (IOException e) + { + ACE.ERROR (e); + } + } + + private void uploadImage (String image) + { + + } + + private ImageApp parent_ = null; + private ProfileTimer timer_ = new ProfileTimer (); + private String imageList_ = null; + private boolean stdOut = true; + private Hashtable filterTable_ = null; + +} diff --git a/java/ImageProcessing/framework/Tester.java b/java/ImageProcessing/framework/Tester.java index 953bbe71e76..bb2dd8e31bd 100644 --- a/java/ImageProcessing/framework/Tester.java +++ b/java/ImageProcessing/framework/Tester.java @@ -5,16 +5,17 @@ import java.net.*; import java.awt.*; import java.awt.image.*; import java.util.*; -import JACE.Timers.*; +import JACE.Connection.*; +import JACE.OS.*; public class Tester implements Runnable { - public Tester (String testInFile, String testOutFile, ImageApp parent) + public Tester (String testInFile, String server, int port, ImageApp parent) { this.testInFile_ = testInFile; - this.testOutFile_ = testOutFile; + this.server_ = server; + this.port_ = port; this.parent_ = parent; - this.filterTable_ = this.parent_.filterTable(); // Run in your own thread of control (new Thread (this)).start (); @@ -22,25 +23,24 @@ public class Tester implements Runnable public void run () { + this.setupConnection (this.getImages ()); + } + + private String getImages () + { URL inputURL; - URL outputURL; - String imageList= null; + String imageList = null; try { System.out.println ("Test Input File: " + this.testInFile_); - System.out.println ("Test Output File: " + this.testOutFile_); + System.out.println ("Server: " + this.server_ + "\tPort: " + this.port_); - // Create URLs + // Create input URL inputURL = new URL (this.testInFile_); - outputURL = new URL (this.testOutFile_); - URLConnection connection = outputURL.openConnection (); // Get the input stream and pipe it to a DataInputStream DataInputStream iStream = new DataInputStream (inputURL.openStream ()); - // Get the output stream and pipe it to a PrintStream - oStream_ = new PrintStream (connection.getOutputStream ()); - // Create a buffer to hold all the data we get StringBuffer tempBuf = new StringBuffer (); // Keep reading the data until we are done @@ -55,105 +55,55 @@ public class Tester implements Runnable } catch (MalformedURLException e) { - System.err.println (e); + ACE.ERROR (e); } catch (IOException e) { - System.err.println (e); - } - - if (imageList != null) - { - StringTokenizer tokens = new StringTokenizer (imageList); - String image = null; - - // Now parse the string, picking up image names. - while (tokens.hasMoreTokens ()) - { - // Get the next token - image = tokens.nextToken (); - this.doTesting (image); - } + ACE.ERROR (e); } + return imageList; } - private void doTesting (String image) - { - if (oStream_ == null) - System.out.println ("Image: " + image); - else - oStream_.println ("Image: " + image); - - this.loadImage (image); - this.processImage (image); - this.uploadImage (image); - } - - private void loadImage (String image) + private void setupConnection (String imageList) { - if (oStream_ == null) - System.out.print ("\tLoading..."); - else - oStream_.print ("\tLoading..."); - - // Start the timer - timer_.start (); - - // Load the image - parent_.openURL (image); + // First try to connect to the server. If the server is not + // running then we will write to standard output. - // Stop the timer - timer_.stop (); - long time = timer_.elapsedTime (); - if (oStream_ == null) - System.out.println ("done (" + ((double) time)/1000 + " seconds)."); - else - oStream_.println ("done (" + ((double) time)/1000 + " seconds)."); - } - - private void processImage (String image) - { - if (oStream_ == null) - System.out.println ("\tProcessing..."); - else - oStream_.println ("\tProcessing..."); + // Create a handler which will handle our connection. + TestHandler handler = new TestHandler (imageList, this.parent_); - for (Enumeration e = filterTable_.keys (); e.hasMoreElements (); ) + try { - String filterName = (String) e.nextElement (); - if (oStream_ == null) - System.out.print ("\t\t" + filterName + "..."); - else - oStream_.print ("\t\t" + filterName + "..."); - - ImageFilter filter = (ImageFilter) filterTable_.get (filterName); - - // Start the timer - timer_.start (); - - this.parent_.apply (filter); - - // Stop the timer - timer_.stop (); - long time = timer_.elapsedTime (); - - if (oStream_ == null) - System.out.println ("done (" + ((double) time)/1000 + " seconds)."); - else - oStream_.println ("done (" + ((double) time)/1000 + " seconds)."); - this.parent_.resetImage (); + Connector connector = new Connector (); + connector.open (server_, port_); + connector.connect (handler); + } + catch (UnknownHostException e) + { + ACE.ERROR (e); + } + catch (SocketException e) + { + // The server is not running so write all the output to screen + handler.doTesting (); + } + catch (InstantiationException e) + { + ACE.ERROR (e); + } + catch (IllegalAccessException e) + { + ACE.ERROR (e); + } + catch (IOException e) + { + ACE.ERROR (e); } - } - - private void uploadImage (String image) - { - } private String testInFile_ = null; - private String testOutFile_ = null; private ImageApp parent_ = null; - private ProfileTimer timer_ = new ProfileTimer (); - private Hashtable filterTable_ = null; - PrintStream oStream_ = null; + private String server_ = "siesta.cs.wustl.edu"; + private int port_ = 7787; } + |