KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > WrapperMain


1 package org.jacorb.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * 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 org.tanukisoftware.wrapper.WrapperListener;
25 import org.tanukisoftware.wrapper.WrapperManager;
26
27 /**
28  * @author Alphonse Bendt
29  * @version $Id: WrapperMain.java,v 1.2 2005/05/04 13:21:10 alphonse.bendt Exp $
30  */

31
32 public class WrapperMain implements WrapperListener
33 {
34     private static final Runnable JavaDoc CMD_WRAPPERMANAGER_STOP = new Runnable JavaDoc()
35     {
36         public void run()
37         {
38             WrapperManager.stop(0);
39         }
40     };
41     
42     private static final EventChannelFactoryImpl.ShutdownCallback WRAPPERMANAGER_BEGIN_SHUTDOWN = new EventChannelFactoryImpl.ShutdownCallback()
43     {
44         public void needTime(int time)
45         {
46             WrapperManager.signalStopping(time);
47         }
48
49         public void shutdownComplete()
50         {
51             // no operation
52
}
53     };
54
55     private AbstractChannelFactory application_;
56
57     // //////////////////////////////////////
58

59     private WrapperMain()
60     {
61         super();
62     }
63
64     // //////////////////////////////////////
65

66     // Implementation of org.tanukisoftware.wrapper.WrapperListener
67

68     public Integer JavaDoc start(String JavaDoc[] args)
69     {
70         try
71         {
72             application_ = ConsoleMain.newFactory(args);
73
74             application_.setDestroyMethod(CMD_WRAPPERMANAGER_STOP);
75
76             return null;
77         } catch (Exception JavaDoc e)
78         {
79             e.printStackTrace();
80
81             return new Integer JavaDoc(1);
82         }
83     }
84
85     public int stop(int n)
86     {
87         application_.shutdown(WRAPPERMANAGER_BEGIN_SHUTDOWN);
88
89         return 0;
90     }
91
92     public void controlEvent(int event)
93     {
94         if (WrapperManager.isControlledByNativeWrapper())
95         {
96             // The Wrapper will take care of this event
97
}
98         else
99         {
100             // We are not being controlled by the Wrapper, so
101
// handle the event ourselves.
102

103             if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT)
104                     || (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT)
105                     || (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT))
106             {
107                 WrapperManager.stop(0);
108             }
109         }
110     }
111
112     public static void main(String JavaDoc[] args)
113     {
114         WrapperManager.start(new WrapperMain(), args);
115     }
116 }
117
Popular Tags