Skip to content

Commit

Permalink
refactored HTTP Connector Startup
Browse files Browse the repository at this point in the history
now without separate thread
  • Loading branch information
pedela committed Jan 29, 2014
1 parent 1f08837 commit faa2da3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
<classpathentry kind="lib" path="lib/junit-4.11.jar"/>
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/i5-simpleXML-0.2.jar"/>
<classpathentry kind="lib" path="lib/i5-httpConnector-0.1.jar"/>
<classpathentry kind="lib" path="lib/i5-httpConnector-0.1.1.jar"/>
<classpathentry kind="output" path="output"/>
</classpath>
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<property name="lib" location="lib" />
<property name="lib.cp"
location="${lib}/i5-simpleXML-0.2.jar:${lib}/commons-codec-1.7.jar:${lib}/FreePastry-2.1.jar:${lib}/i5-httpConnector-0.1.jar:${lib}/i5-httpServer-0.3.jar:${lib}/junit-4.11.jar:${lib}/xpp3-1.1.4c.jar" />
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" />
<property name="lib.junit" location="${lib}/junit-4.11.jar:${lib}/hamcrest-core-1.3.jar" />


Expand Down Expand Up @@ -211,7 +211,7 @@
<attribute name="Main-Class" value="i5.las2peer.tools.L2pNodeLauncher"/>
<attribute
name="Class-Path"
value="i5-simpleXML-0.2.jar commons-codec-1.7.jar FreePastry-2.1.jar i5-httpServer-0.3.jar i5-httpConnector-0.1.jar xpp3-1.1.4c.jar"
value="i5-simpleXML-0.2.jar commons-codec-1.7.jar FreePastry-2.1.jar i5-httpServer-0.3.jar i5-httpConnector-0.1.1.jar xpp3-1.1.4c.jar"
/>
</manifest>
</jar>
Expand Down
2 changes: 1 addition & 1 deletion ivy/ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<dependency org="junit" name="junit" rev="4.11" />
<dependency org="i5" name="i5-simpleXML" rev="0.2" />
<dependency org="FreePastry" name="FreePastry" rev="2.1" />
<dependency org="i5" name="i5-httpConnector" rev="0.1"/>
<dependency org="i5" name="i5-httpConnector" rev="0.1.1"/>
</dependencies>
</ivy-module>
16 changes: 12 additions & 4 deletions src/main/java/i5/las2peer/api/Connector.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,34 @@ 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
*/
public abstract void start ( Node node ) throws ConnectorException ;


/**
* stop the connector
* Stops the connector.
*
* @throws ConnectorException
*/
public abstract void stop () throws ConnectorException;
public abstract void stop () throws ConnectorException;



Expand Down
78 changes: 28 additions & 50 deletions src/main/java/i5/las2peer/tools/L2pNodeLauncher.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -83,7 +84,7 @@ public class L2pNodeLauncher {

private CommandPrompt commandPrompt;


private static Connector connector = null;
/**
* is this launcher finished?
*/
Expand Down Expand Up @@ -624,7 +625,6 @@ public Object[] findService (String serviceClass ) throws AgentNotKnownException
*/
public void shutdown () {
node.shutDown();

this.bFinished = true;
}

Expand Down Expand Up @@ -725,6 +725,7 @@ else if ( agent instanceof ServiceAgent )
uploadLoginList();
}


/**
* upload the contents of <i>startup</i> sub directory to the global storage of the
* las2peer network.
Expand All @@ -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
Expand All @@ -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 ) {
Expand All @@ -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 );
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/i5/las2peer/tools/ServiceStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit faa2da3

Please sign in to comment.