1 21 28 package org.apache.derbyTesting.functionTests.tests.junitTests.compatibility; 29 30 import org.apache.derby.drda.NetworkServerControl; 31 32 public class Pinger 33 { 34 40 public static final long SLEEP_TIME_MILLIS = 5000L; 41 42 public static final int SUCCESS_EXIT = 0; 43 public static final int FAILURE_EXIT = 1; 44 45 51 57 public Pinger() {} 58 59 65 public static void main( String [] args ) 66 throws Exception 67 { 68 Pinger me = new Pinger(); 69 70 me.ping( 5 ); 71 } 72 73 79 private void println( String text ) 80 { 81 System.err.println( text ); 82 System.err.flush(); 83 } 84 85 private void exit( int exitStatus ) 86 { 87 Runtime.getRuntime().exit( exitStatus ); 88 } 89 90 96 102 public void ping( int iterations ) 103 throws Exception 104 { 105 ping( new NetworkServerControl(), iterations ); 106 } 107 108 109 private void ping( NetworkServerControl controller, int iterations ) 110 throws Exception 111 { 112 Exception finalException = null; 113 114 for ( int i = 0; i < iterations; i++ ) 115 { 116 try { 117 controller.ping(); 118 119 return; 120 } 121 catch (Exception e) { finalException = e; } 122 123 Thread.sleep( SLEEP_TIME_MILLIS ); 124 } 125 126 println( "Server did not come up: " + finalException.getMessage() ); 127 exit( FAILURE_EXIT ); 128 } 129 130 131 } 132 133 | Popular Tags |