KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tanukisoftware > wrapper > test > Restarter


1 package org.tanukisoftware.wrapper.test;
2
3 /*
4  * Copyright (c) 1999, 2006 Tanuki Software Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of the Java Service Wrapper and associated
8  * documentation files (the "Software"), to deal in the Software
9  * without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sub-license,
11  * and/or sell copies of the Software, and to permit persons to
12  * whom the Software is furnished to do so, subject to the
13  * following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  *
28  * Portions of the Software have been derived from source code
29  * developed by Silver Egg Technology under the following license:
30  *
31  * Copyright (c) 2001 Silver Egg Technology
32  *
33  * Permission is hereby granted, free of charge, to any person
34  * obtaining a copy of this software and associated documentation
35  * files (the "Software"), to deal in the Software without
36  * restriction, including without limitation the rights to use,
37  * copy, modify, merge, publish, distribute, sub-license, and/or
38  * sell copies of the Software, and to permit persons to whom the
39  * Software is furnished to do so, subject to the following
40  * conditions:
41  *
42  * The above copyright notice and this permission notice shall be
43  * included in all copies or substantial portions of the Software.
44  */

45
46 import org.tanukisoftware.wrapper.WrapperManager;
47 import org.tanukisoftware.wrapper.WrapperListener;
48
49 /**
50  *
51  *
52  * @author Leif Mortenson <leif@tanukisoftware.com>
53  */

54 public class Restarter implements WrapperListener {
55     /**************************************************************************
56      * Constructors
57      *************************************************************************/

58     private Restarter() {
59     }
60     
61     /**************************************************************************
62      * WrapperListener Methods
63      *************************************************************************/

64     public Integer JavaDoc start(String JavaDoc[] args) {
65         System.out.println("start()");
66         
67         // Start up a thread whose job it is to request a restart in 5 seconds.
68
Thread JavaDoc restarter = new Thread JavaDoc("restarter") {
69             public void run() {
70                 try {
71                     Thread.sleep(5000);
72                 } catch (InterruptedException JavaDoc e) {}
73                 
74                 // Start up a thread whose only job is to dump output to the console.
75
Thread JavaDoc outputter = new Thread JavaDoc("outputter") {
76                     public void run() {
77                         int counter = 0;
78                         while(true) {
79                             /*
80                             try {
81                                 Thread.sleep(50);
82                             } catch (InterruptedException e) {}
83                             */

84                             Thread.yield();
85                             
86                             System.out.println(" outputer line #" + (++counter));
87                             System.out.println(" 1) A long line of test data to cause lots of data to be sent to the console.");
88                             System.out.println(" 2) A long line of test data to cause lots of data to be sent to the console.");
89                             System.out.println(" 3) A long line of test data to cause lots of data to be sent to the console.");
90                             System.out.println(" 4) A long line of test data to cause lots of data to be sent to the console.");
91                             System.out.println(" 5) A long line of test data to cause lots of data to be sent to the console.");
92                             System.out.println(" 6) A long line of test data to cause lots of data to be sent to the console.");
93                             System.out.println(" 7) A long line of test data to cause lots of data to be sent to the console.");
94                             System.out.println(" 8) A long line of test data to cause lots of data to be sent to the console.");
95                             System.out.println(" 9) A long line of test data to cause lots of data to be sent to the console.");
96                             System.out.println(" 10)A long line of test data to cause lots of data to be sent to the console.");
97                             System.out.flush();
98                         }
99                     }
100                 };
101                 //outputter.start();
102

103                 System.out.println("Requesting restart...");
104                 WrapperManager.restart();
105             }
106         };
107         restarter.start();
108         
109         return null;
110     }
111     
112     public int stop(int exitCode) {
113         System.out.println("stop(" + exitCode + ")");
114         
115         return exitCode;
116     }
117     
118     public void controlEvent(int event) {
119         System.out.println("controlEvent(" + event + ")");
120         if (event == WrapperManager.WRAPPER_CTRL_C_EVENT) {
121             WrapperManager.stop(0);
122         }
123     }
124     
125     /**************************************************************************
126      * Main Method
127      *************************************************************************/

128     public static void main(String JavaDoc[] args) {
129         System.out.println("Initializing...");
130         
131         // Start the application. If the JVM was launched from the native
132
// Wrapper then the application will wait for the native Wrapper to
133
// call the application's start method. Otherwise the start method
134
// will be called immediately.
135
WrapperManager.start(new Restarter(), args);
136     }
137 }
138
139
Popular Tags