KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > junitTests > compatibility > Pinger


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.compatibility.JDBCDriverTest
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21 /**
22  * <p>
23  * Ping the server, waiting till it comes up.
24  * </p>
25  *
26  * @author Rick
27  */

28 package org.apache.derbyTesting.functionTests.tests.junitTests.compatibility;
29
30 import org.apache.derby.drda.NetworkServerControl;
31
32 public class Pinger
33 {
34     /////////////////////////////////////////////////////////////
35
//
36
// CONSTANTS
37
//
38
/////////////////////////////////////////////////////////////
39

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     /////////////////////////////////////////////////////////////
46
//
47
// STATE
48
//
49
/////////////////////////////////////////////////////////////
50

51     /////////////////////////////////////////////////////////////
52
//
53
// CONSTRUCTOR
54
//
55
/////////////////////////////////////////////////////////////
56

57     public Pinger() {}
58
59     /////////////////////////////////////////////////////////////
60
//
61
// ENTRY POINT
62
//
63
/////////////////////////////////////////////////////////////
64

65     public static void main( String JavaDoc[] args )
66         throws Exception JavaDoc
67     {
68         Pinger me = new Pinger();
69         
70         me.ping( 5 );
71     }
72
73     /////////////////////////////////////////////////////////////
74
//
75
// MINIONS
76
//
77
/////////////////////////////////////////////////////////////
78

79     private void println( String JavaDoc 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     /////////////////////
91
//
92
// SERVER MANAGEMENT
93
//
94
/////////////////////
95

96     /**
97      * <p>
98      * Checks to see that the server is up. If the server doesn't
99      * come up in a reasonable amount of time, brings down the VM.
100      * </p>
101      */

102     public void ping( int iterations )
103         throws Exception JavaDoc
104     {
105         ping( new NetworkServerControl(), iterations );
106     }
107
108
109     private void ping( NetworkServerControl controller, int iterations )
110         throws Exception JavaDoc
111     {
112         Exception JavaDoc finalException = null;
113         
114         for ( int i = 0; i < iterations; i++ )
115         {
116             try {
117                 controller.ping();
118
119                 return;
120             }
121             catch (Exception JavaDoc 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