01: package org.jacorb.notification;
02:
03: /*
04: * JacORB - a free Java ORB
05: *
06: * Copyright (C) 1999-2004 Gerald Brose
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Library General Public
10: * License as published by the Free Software Foundation; either
11: * version 2 of the License, or (at your option) any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Library General Public License for more details.
17: *
18: * You should have received a copy of the GNU Library General Public
19: * License along with this library; if not, write to the Free
20: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21: *
22: */
23:
24: import java.io.PrintWriter;
25: import java.io.StringWriter;
26:
27: import org.tanukisoftware.wrapper.WrapperListener;
28: import org.tanukisoftware.wrapper.WrapperManager;
29:
30: /**
31: * @author Alphonse Bendt
32: * @version $Id: WrapperMain.java,v 1.4 2005/10/27 21:35:35 alphonse.bendt Exp $
33: */
34:
35: public class WrapperMain implements WrapperListener {
36: private static final EventChannelFactoryImpl.ShutdownCallback WRAPPERMANAGER_BEGIN_SHUTDOWN = new EventChannelFactoryImpl.ShutdownCallback() {
37: public void needTime(int time) {
38: WrapperManager.signalStopping(time);
39: }
40:
41: public void shutdownComplete() {
42: // no operation
43: }
44: };
45:
46: private AbstractChannelFactory application_;
47:
48: private WrapperMain() {
49: super ();
50: }
51:
52: public Integer start(String[] args) {
53: try {
54: application_ = ConsoleMain.newFactory(args);
55:
56: return null;
57: } catch (Exception e) {
58: final StringWriter stringWriter = new StringWriter();
59: final PrintWriter printWriter = new PrintWriter(
60: stringWriter);
61: e.printStackTrace(printWriter);
62: printWriter.flush();
63: printWriter.close();
64: WrapperManager.log(WrapperManager.WRAPPER_LOG_LEVEL_FATAL,
65: stringWriter.toString());
66:
67: return new Integer(1);
68: }
69: }
70:
71: public int stop(int n) {
72: application_.shutdown(WRAPPERMANAGER_BEGIN_SHUTDOWN);
73:
74: return 0;
75: }
76:
77: public void controlEvent(int event) {
78: if (WrapperManager.isControlledByNativeWrapper()) {
79: // The Wrapper will take care of this event
80: } else {
81: // We are not being controlled by the Wrapper, so
82: // handle the event ourselves.
83:
84: if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT)
85: || (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT)
86: || (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)) {
87: WrapperManager.stop(0);
88: }
89: }
90: }
91:
92: public static void main(String[] args) {
93: WrapperManager.start(new WrapperMain(), args);
94: }
95: }
|