[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2295: Let jetty start in own thread.

revision-diff.txt (3.02 KB)

------------------------------------------------------------
revno: 2295
committer: Bob Jolliffe bobjolliffe@gmail.com
branch nick: trunk
timestamp: Mon 2010-12-06 10:21:18 +0000
message:
Let jetty start in own thread.
modified:
dhis-live/src/main/java/org/hisp/dhis/TrayApp.java
dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java

Some odd behaviour. When i run on linux and try and start dhis-live
twice - then the second instance does as expected. It (eventually)
tries to open the listening port and fails with:

2010-12-06 13:34:09.760:WARN::failed Server@9504f2:
java.net.BindException: Address already in use

as it should. And with the server thread now implemented properly,
the lifecycle event bubbles through to the handler, the user is shown
a error message and dhis-live exits. (This can happen much quicker if
we start the server listening first then load the dhis context but
that's for later).

The odd thing is when I run the same thing on windoze7 it seems that I
can run multiple instances without any error and 'netstat -a' shows
them all happily bound to the same listening port. This doesn't make
any sense to me. Anybody got any ideas?

Regards
Bob

ยทยทยท

On 6 December 2010 10:23, <noreply@launchpad.net> wrote:

--
lp:dhis2
trunk : Code : DHIS

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to OpenID transaction in progress

=== modified file 'dhis-live/src/main/java/org/hisp/dhis/TrayApp.java'
--- dhis-live/src/main/java/org/hisp/dhis/TrayApp.java 2010-11-29 15:11:43 +0000
+++ dhis-live/src/main/java/org/hisp/dhis/TrayApp.java 2010-12-06 10:21:18 +0000
@@ -151,16 +151,9 @@

    appServer = new WebAppServer\(\);
    appServer\.init\( installDir, this \);

+
+ appServer.start();

- try
- {
- appServer.start();
- }
- catch ( Exception ex )
- {
- String message = "Web server failed to start: \n" + ex.toString();
- JOptionPane.showMessageDialog( (JFrame) null, message );
- }
}

// \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-

@@ -182,7 +175,8 @@
trayIcon.displayMessage( "Started", "DHIS 2 is running. Your browser will\n be pointed to " + getUrl() + ".",
TrayIcon.MessageType.INFO );
trayIcon.setToolTip( "DHIS 2 Server running" );
- trayIcon.setImage( createImage( RUNNING_ICON, "Running icon" ) );
+ trayIcon.setImage( createImage( RUNNING_ICON, "Running icon" ) );
+
launchBrowser();
}

@@ -242,7 +236,7 @@
log.info( "Graceful shutdown..." );
try
{
- appServer.stop();
+ appServer.shutdown();
}
catch ( Exception ex )
{

=== modified file 'dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java'
--- dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java 2010-11-29 15:11:43 +0000
+++ dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java 2010-12-06 10:21:18 +0000
@@ -50,7 +50,7 @@
/**
* @author Bob Jolliffe
*/
-public class WebAppServer
+public class WebAppServer extends Thread
{
public static final String DHIS_DIR = "/webapps/dhis";

@@ -87,24 +87,35 @@
}

    server\.setConnectors\( new Connector\[\] \{ connector \} \);

-
+ server.addLifeCycleListener( serverListener );
+
+ loadDHISContext(installDir+DHIS_DIR);
+ }
+
+ public void loadDHISContext(String webappPath)
+ {
WebAppContext dhisWebApp = new WebAppContext();
dhisWebApp.setMaxFormContentSize( 5000000 );
- dhisWebApp.setWar( installDir + DHIS_DIR );
- log.info( "Setting DHIS 2 web app context to: " + installDir + DHIS_DIR );
+ dhisWebApp.setWar( webappPath );
+ log.info( "Setting DHIS 2 web app context to: " + webappPath );

    server\.setHandler\( dhisWebApp \);

- server.addLifeCycleListener( serverListener );
}

- public void start()
- throws Exception
+ public void run()
{
- server.start();
- server.join();
+ try
+ {
+ log.debug("Server thread starting");
+ server.start();
+ log.debug("Server thread exiting");
+ } catch ( Exception ex )
+ {
+ log.error( "Server wouldn't start : " + ex);
+ }
}

- public void stop()
+ public void shutdown()
throws Exception
{
server.stop();

_______________________________________________
Mailing list: DHIS 2 developers in Launchpad
Post to : dhis2-devs@lists.launchpad.net
Unsubscribe : DHIS 2 developers in Launchpad
More help : ListHelp - Launchpad Help