diff --git a/.classpath b/.classpath index ee31d4770..20931e8f2 100644 --- a/.classpath +++ b/.classpath @@ -15,6 +15,6 @@ - + diff --git a/build.xml b/build.xml index f50e976b2..bd3fa188a 100644 --- a/build.xml +++ b/build.xml @@ -31,7 +31,7 @@ + location="${lib}/i5-simpleXML-0.2.jar:${lib}/commons-codec-1.7.jar:${lib}/FreePastry-2.1.jar:${lib}/i5-httpConnector-0.1.1.jar:${lib}/i5-httpServer-0.3.jar:${lib}/junit-4.11.jar:${lib}/xpp3-1.1.4c.jar" /> @@ -211,7 +211,7 @@ diff --git a/ivy/ivy.xml b/ivy/ivy.xml index 650427639..143ed7c31 100644 --- a/ivy/ivy.xml +++ b/ivy/ivy.xml @@ -6,6 +6,6 @@ - + diff --git a/src/main/java/i5/las2peer/api/Connector.java b/src/main/java/i5/las2peer/api/Connector.java index e7ca8576e..eb64ed19e 100644 --- a/src/main/java/i5/las2peer/api/Connector.java +++ b/src/main/java/i5/las2peer/api/Connector.java @@ -13,14 +13,22 @@ public abstract class Connector extends Configurable { /** - * method stub, may be overridden in implementing subclasses + * Initialize the connector. */ public void init () { } + /** + * Sets the port of a connector. + * + * @param port + */ + public void setPort ( int port ) { + + } /** - * start a connector at the given node + * Start a connector at the given node. * * @param node */ @@ -28,11 +36,11 @@ public void init () { /** - * stop the connector + * Stops the connector. * * @throws ConnectorException */ - public abstract void stop () throws ConnectorException; + public abstract void stop () throws ConnectorException; diff --git a/src/main/java/i5/las2peer/tools/L2pNodeLauncher.java b/src/main/java/i5/las2peer/tools/L2pNodeLauncher.java index 766dc563e..fae1eaf49 100644 --- a/src/main/java/i5/las2peer/tools/L2pNodeLauncher.java +++ b/src/main/java/i5/las2peer/tools/L2pNodeLauncher.java @@ -1,5 +1,6 @@ package i5.las2peer.tools; +import i5.las2peer.api.Connector; import i5.las2peer.api.ConnectorException; import i5.las2peer.communication.ListMethodsContent; import i5.las2peer.communication.Message; @@ -83,7 +84,7 @@ public class L2pNodeLauncher { private CommandPrompt commandPrompt; - + private static Connector connector = null; /** * is this launcher finished? */ @@ -624,7 +625,6 @@ public Object[] findService (String serviceClass ) throws AgentNotKnownException */ public void shutdown () { node.shutDown(); - this.bFinished = true; } @@ -725,6 +725,7 @@ else if ( agent instanceof ServiceAgent ) uploadLoginList(); } + /** * upload the contents of startup sub directory to the global storage of the * las2peer network. @@ -739,10 +740,7 @@ public void uploadStartupDirectory () { uploadStartupDirectory ("startup"); } - - - //private Object nodeHandleForTestService = null; - + /** * first get the agent description for TestService * and then try to find 2 running versions @@ -769,9 +767,6 @@ public void searchTestService () { /** * start the HTTP connector at the given port * - * be aware: all method called after the connector (at this node) will - * be started after the connector has been closed! - * * @param port */ public void startHttpConnector ( String port ) { @@ -780,10 +775,8 @@ public void startHttpConnector ( String port ) { /** - * start the HTTP connector at the standard port (8080) + * start the HTTP connector at the default port (8080) * - * be aware: all method called after the connector (at this node) will - * be started after the connector has been closed! */ public void startHttpConnector () { startHttpConnector ( 8080 ); @@ -792,47 +785,16 @@ public void startHttpConnector () { /** * start the HTTP connector at the given port * - * be aware: all method called after the connector (at this node) will - * be started after the connector has been closed! - * * @param iPort */ public void startHttpConnector ( final int iPort ) { try { printMessage( "Starting Http Connector!"); - final HttpConnector connector = new HttpConnector (); - connector.setHttpPort( iPort ); + connector = new HttpConnector (); + connector.setPort( iPort ); connector.start( node ); - // work around: start a non-daemon thread to keep the connector open... - Thread reminder = new Thread ( new Runnable () { - @Override - public void run() { - try { - while ( true ) { - System.out.println("--- http connector still running at port " + iPort +" ---" ); - Thread.sleep( 10000 ); - } - } catch (InterruptedException e) { - } - - try { - connector.stop(); - } catch (ConnectorException e) { - } - printMessage ( "--> http connector stopped!"); - - } - - }); - reminder.start(); - - try { - System.in.read(); - } catch (IOException e) { - } - } catch (FileNotFoundException e) { printWarning ( " --> Error finding connector logfile!" + e ); } catch (ConnectorException e) { @@ -1666,7 +1628,8 @@ public static void printHelp ( String message ) { /** - * main method for command line processing + * + * Main method for command line processing. * * * The method will start a node and try to invoke all command line parameters as @@ -1701,15 +1664,30 @@ public static void main ( String[] argv ) throws InterruptedException, Malformed // launch a single node L2pNodeLauncher launcher = launchSingle( args, -1); - if ( launcher.isFinished() ) + if ( launcher.isFinished() ){ System.out.println( "single node has handled all commands and shut down!"); + try { + if(connector != null) + connector.stop(); + } catch (ConnectorException e) { + e.printStackTrace(); + } + } else { System.out.println ( "single node has handled all commands -- keeping node open\n"); System.out.println ( "press Strg-C to exit\n"); - - do { + try{ + while (true) { Thread.sleep(5000); - } while ( true ); + } + } catch (InterruptedException e) { + try { + if(connector != null) + connector.stop(); + } catch (ConnectorException ce) { + ce.printStackTrace(); + } + } } } else if ( argv[0].equals ( "-d")) { // launch from a directory diff --git a/src/main/java/i5/las2peer/tools/ServiceStarter.java b/src/main/java/i5/las2peer/tools/ServiceStarter.java index 1044435d5..8985148df 100644 --- a/src/main/java/i5/las2peer/tools/ServiceStarter.java +++ b/src/main/java/i5/las2peer/tools/ServiceStarter.java @@ -426,7 +426,7 @@ private static void startHttpConnector ( Node node, final int iPort ) { try { System.out.println ( "Starting Http Connector!"); final HttpConnector connector = new HttpConnector (); - connector.setHttpPort( iPort ); + connector.setPort( iPort ); connector.start( node ); try {