public void start ( String rmc ) throws GassException { if ( rmc == null ) { throw new IllegalArgumentException ( "Resource manager contact not specified" ) ; } GassServer gassServer = null ; String error = null ; try { gassServer = new GassServer ( this . cred , 0 ) ; String gassURL = gassServer . getURL ( ) ; String rsl = getRSL ( gassURL ) ; logger . debug ( "RSL: " + rsl ) ; stderrListener = new OutputListener ( ) ; stdoutListener = new OutputListener ( ) ; gassServer . registerJobOutputStream ( "err-rgs" , new JobOutputStream ( stderrListener ) ) ; gassServer . registerJobOutputStream ( "out-rgs" , new JobOutputStream ( stdoutListener ) ) ; job = new GramJob ( this . cred , rsl ) ; gassJobListener = new GassServerListener ( ) ; job . addListener ( gassJobListener ) ; job . request ( rmc ) ; int status = gassJobListener . waitFor ( 1000 * 60 * 2 ) ; if ( status == GramJob . STATUS_ACTIVE ) { while ( true ) { if ( stderrListener . hasData ( ) ) { // got some error error = stderrListener . getOutput ( ) ; break ; } else if ( stdoutListener . hasData ( ) ) { // this could be the url String fl = stdoutListener . getOutput ( ) ; if ( fl . startsWith ( "https://" ) || fl . startsWith ( "http://" ) ) { // extract url url = fl . trim ( ) ; break ; } else { // something is wrong with stdout error = "Unable to extract gass url : " + fl ; break ; } } else { // wait for stdout/err logger . debug ( "waiting for stdout/err" ) ; sleep ( 500 ) ; } } } else if ( status == GramJob . STATUS_FAILED || status == GramJob . STATUS_DONE ) { int errorCode = gassJobListener . getError ( ) ; if ( stderrListener . hasData ( ) ) { error = stderrListener . getOutput ( ) ; } else if ( errorCode != 0 ) { error = "Remote gass server stopped with error : " + errorCode ; } else { error = "Remote gass server stopped and returned no error" ; } } else { error = "Unexpected state or received no notification" ; } } catch ( Exception e ) { throw new GassException ( e . getMessage ( ) ) ; } finally { if ( gassServer != null ) { gassServer . shutdown ( ) ; } } if ( error != null ) { throw new GassException ( error ) ; } }
Starts the gass server on the remote machine .