001: package org.tanukisoftware.wrapper.test;
002:
003: /*
004: * Copyright (c) 1999, 2006 Tanuki Software Inc.
005: *
006: * Permission is hereby granted, free of charge, to any person
007: * obtaining a copy of the Java Service Wrapper and associated
008: * documentation files (the "Software"), to deal in the Software
009: * without restriction, including without limitation the rights
010: * to use, copy, modify, merge, publish, distribute, sub-license,
011: * and/or sell copies of the Software, and to permit persons to
012: * whom the Software is furnished to do so, subject to the
013: * following conditions:
014: *
015: * The above copyright notice and this permission notice shall be
016: * included in all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
020: * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
021: * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
022: * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
023: * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
024: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
025: * OTHER DEALINGS IN THE SOFTWARE.
026: *
027: *
028: * Portions of the Software have been derived from source code
029: * developed by Silver Egg Technology under the following license:
030: *
031: * Copyright (c) 2001 Silver Egg Technology
032: *
033: * Permission is hereby granted, free of charge, to any person
034: * obtaining a copy of this software and associated documentation
035: * files (the "Software"), to deal in the Software without
036: * restriction, including without limitation the rights to use,
037: * copy, modify, merge, publish, distribute, sub-license, and/or
038: * sell copies of the Software, and to permit persons to whom the
039: * Software is furnished to do so, subject to the following
040: * conditions:
041: *
042: * The above copyright notice and this permission notice shall be
043: * included in all copies or substantial portions of the Software.
044: */
045:
046: import org.tanukisoftware.wrapper.WrapperManager;
047: import org.tanukisoftware.wrapper.WrapperListener;
048:
049: /**
050: *
051: *
052: * @author Leif Mortenson <leif@tanukisoftware.com>
053: */
054: public class Restarter implements WrapperListener {
055: /**************************************************************************
056: * Constructors
057: *************************************************************************/
058: private Restarter() {
059: }
060:
061: /**************************************************************************
062: * WrapperListener Methods
063: *************************************************************************/
064: public Integer start(String[] args) {
065: System.out.println("start()");
066:
067: // Start up a thread whose job it is to request a restart in 5 seconds.
068: Thread restarter = new Thread("restarter") {
069: public void run() {
070: try {
071: Thread.sleep(5000);
072: } catch (InterruptedException e) {
073: }
074:
075: // Start up a thread whose only job is to dump output to the console.
076: Thread outputter = new Thread("outputter") {
077: public void run() {
078: int counter = 0;
079: while (true) {
080: /*
081: try {
082: Thread.sleep(50);
083: } catch (InterruptedException e) {}
084: */
085: Thread.yield();
086:
087: System.out
088: .println(" outputer line #"
089: + (++counter));
090: System.out
091: .println(" 1) A long line of test data to cause lots of data to be sent to the console.");
092: System.out
093: .println(" 2) A long line of test data to cause lots of data to be sent to the console.");
094: System.out
095: .println(" 3) A long line of test data to cause lots of data to be sent to the console.");
096: System.out
097: .println(" 4) A long line of test data to cause lots of data to be sent to the console.");
098: System.out
099: .println(" 5) A long line of test data to cause lots of data to be sent to the console.");
100: System.out
101: .println(" 6) A long line of test data to cause lots of data to be sent to the console.");
102: System.out
103: .println(" 7) A long line of test data to cause lots of data to be sent to the console.");
104: System.out
105: .println(" 8) A long line of test data to cause lots of data to be sent to the console.");
106: System.out
107: .println(" 9) A long line of test data to cause lots of data to be sent to the console.");
108: System.out
109: .println(" 10)A long line of test data to cause lots of data to be sent to the console.");
110: System.out.flush();
111: }
112: }
113: };
114: //outputter.start();
115:
116: System.out.println("Requesting restart...");
117: WrapperManager.restart();
118: }
119: };
120: restarter.start();
121:
122: return null;
123: }
124:
125: public int stop(int exitCode) {
126: System.out.println("stop(" + exitCode + ")");
127:
128: return exitCode;
129: }
130:
131: public void controlEvent(int event) {
132: System.out.println("controlEvent(" + event + ")");
133: if (event == WrapperManager.WRAPPER_CTRL_C_EVENT) {
134: WrapperManager.stop(0);
135: }
136: }
137:
138: /**************************************************************************
139: * Main Method
140: *************************************************************************/
141: public static void main(String[] args) {
142: System.out.println("Initializing...");
143:
144: // Start the application. If the JVM was launched from the native
145: // Wrapper then the application will wait for the native Wrapper to
146: // call the application's start method. Otherwise the start method
147: // will be called immediately.
148: WrapperManager.start(new Restarter(), args);
149: }
150: }
|