| | @@ -5404,93 +5399,89 @@ |
| 5404 | 5399 | // Initialize the last ping tick count. |
| 5405 | 5400 | m_lastPingTicks = getTicks(); |
| 5406 | 5401 | |
| 5407 | | - boolean gotPortOnce = false; |
| 5408 | | - while ( !m_disposed ) |
| 5402 | + try |
| 5409 | 5403 | { |
| 5410 | | - try |
| 5404 | + openBackend(); |
| 5405 | + |
| 5406 | + // After the socket has been opened the first time, mark the thread as |
| 5407 | + // started. This must be done here to make sure that exits work correctly |
| 5408 | + // when called on startup. |
| 5409 | + if ( !m_commRunnerStarted ) |
| 5411 | 5410 | { |
| 5412 | | - openBackend(); |
| 5413 | | - |
| 5414 | | - // After the socket has been opened the first time, mark the thread as |
| 5415 | | - // started. This must be done here to make sure that exits work correctly |
| 5416 | | - // when called on startup. |
| 5417 | | - if ( !m_commRunnerStarted ) |
| 5411 | + synchronized( WrapperManager.class ) |
| 5418 | 5412 | { |
| 5419 | | - synchronized( WrapperManager.class ) |
| 5420 | | - { |
| 5421 | | - m_commRunnerStarted = true; |
| 5422 | | - WrapperManager.class.notifyAll(); |
| 5423 | | - } |
| 5413 | + m_commRunnerStarted = true; |
| 5414 | + WrapperManager.class.notifyAll(); |
| 5424 | 5415 | } |
| 5425 | | - |
| 5426 | | - if ( m_backendSocket != null || m_backendConnected == true) |
| 5427 | | - { |
| 5428 | | - handleBackend(); |
| 5429 | | - } |
| 5430 | | - else |
| 5431 | | - { |
| 5432 | | - // Failed, so wait for just a moment |
| 5433 | | - try |
| 5434 | | - { |
| 5435 | | - Thread.sleep( 100 ); |
| 5436 | | - } |
| 5437 | | - catch ( InterruptedException e ) |
| 5438 | | - { |
| 5439 | | - } |
| 5440 | | - } |
| 5441 | 5416 | } |
| 5442 | | - catch ( ThreadDeath td ) |
| 5417 | + |
| 5418 | + if ( m_backendSocket != null || m_backendConnected == true) |
| 5443 | 5419 | { |
| 5444 | | - m_outError.println( getRes().getString( "Server daemon killed" ) ); |
| 5420 | + handleBackend(); |
| 5445 | 5421 | } |
| 5446 | | - catch ( Throwable t ) |
| 5422 | + else |
| 5447 | 5423 | { |
| 5448 | | - if ( !isShuttingDown() ) |
| 5424 | + // Failed, so wait for just a moment |
| 5425 | + try |
| 5449 | 5426 | { |
| 5450 | | - // Show a stack trace here because this is fairly critical |
| 5451 | | - m_outError.println( getRes().getString( "Server daemon died!" ) ); |
| 5452 | | - t.printStackTrace( m_outError ); |
| 5427 | + Thread.sleep( 100 ); |
| 5453 | 5428 | } |
| 5454 | | - else |
| 5429 | + catch ( InterruptedException e ) |
| 5455 | 5430 | { |
| 5456 | | - if ( m_debug ) |
| 5457 | | - { |
| 5458 | | - m_outDebug.println( getRes().getString( "Server daemon died!" ) ); |
| 5459 | | - t.printStackTrace( m_outDebug ); |
| 5460 | | - } |
| 5461 | 5431 | } |
| 5462 | 5432 | } |
| 5463 | | - finally |
| 5433 | + } |
| 5434 | + catch ( ThreadDeath td ) |
| 5435 | + { |
| 5436 | + m_outError.println( getRes().getString( "Server daemon killed" ) ); |
| 5437 | + } |
| 5438 | + catch ( Throwable t ) |
| 5439 | + { |
| 5440 | + if ( !isShuttingDown() ) |
| 5464 | 5441 | { |
| 5442 | + // Show a stack trace here because this is fairly critical |
| 5443 | + m_outError.println( getRes().getString( "Server daemon died!" ) ); |
| 5444 | + t.printStackTrace( m_outError ); |
| 5445 | + } |
| 5446 | + else |
| 5447 | + { |
| 5465 | 5448 | if ( m_debug ) |
| 5466 | 5449 | { |
| 5467 | | - m_outDebug.println( getRes().getString( "Returned from backend handler." ) ); |
| 5450 | + m_outDebug.println( getRes().getString( "Server daemon died!" ) ); |
| 5451 | + t.printStackTrace( m_outDebug ); |
| 5468 | 5452 | } |
| 5469 | | - // Always close the backend here. |
| 5470 | | - closeBackend(); |
| 5471 | | - if ( !isShuttingDown() ) |
| 5453 | + } |
| 5454 | + } |
| 5455 | + finally |
| 5456 | + { |
| 5457 | + if ( m_debug ) |
| 5458 | + { |
| 5459 | + m_outDebug.println( getRes().getString( "Returned from backend handler." ) ); |
| 5460 | + } |
| 5461 | + // Always close the backend here. |
| 5462 | + closeBackend(); |
| 5463 | + if ( !isShuttingDown() ) |
| 5464 | + { |
| 5465 | + if ( m_detachStarted && m_started ) |
| 5472 | 5466 | { |
| 5473 | | - if ( m_detachStarted && m_started ) |
| 5467 | + // This and all further output will not be visible anywhere as the Wrapper is now gone. |
| 5468 | + m_outInfo.println( getRes().getString( "The backend was closed as expected." ) ); |
| 5469 | + |
| 5470 | + try |
| 5474 | 5471 | { |
| 5475 | | - // This and all further output will not be visible anywhere as the Wrapper is now gone. |
| 5476 | | - m_outInfo.println( getRes().getString( "The backend was closed as expected." ) ); |
| 5477 | | - |
| 5478 | | - try |
| 5479 | | - { |
| 5480 | | - nativeRedirectPipes(); |
| 5481 | | - } |
| 5482 | | - catch ( UnsatisfiedLinkError t ) |
| 5483 | | - { |
| 5484 | | - m_outError.println( getRes().getString( "Failed to redirect stdout and stderr before the Wrapper exits.\nOutput from the JVM may block.\nPlease make sure the native library has been properly initialized.")); |
| 5485 | | - } |
| 5472 | + nativeRedirectPipes(); |
| 5486 | 5473 | } |
| 5487 | | - else |
| 5474 | + catch ( UnsatisfiedLinkError t ) |
| 5488 | 5475 | { |
| 5489 | | - m_outError.println( getRes().getString( "The backend was closed unexpectedly. Restart to resync with the Wrapper." ) ); |
| 5490 | | - restart(); |
| 5491 | | - // Will not get here. |
| 5476 | + m_outError.println( getRes().getString( "Failed to redirect stdout and stderr before the Wrapper exits.\nOutput from the JVM may block.\nPlease make sure the native library has been properly initialized.")); |
| 5492 | 5477 | } |
| 5493 | 5478 | } |
| 5479 | + else |
| 5480 | + { |
| 5481 | + m_outError.println( getRes().getString( "The backend was closed unexpectedly. Restart to resync with the Wrapper." ) ); |
| 5482 | + restart(); |
| 5483 | + // Will not get here. |
| 5484 | + } |
| 5494 | 5485 | } |
| 5495 | 5486 | } |
| 5496 | 5487 | |