KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tanukisoftware > wrapper > event > WrapperControlEvent


1 package org.tanukisoftware.wrapper.event;
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 /**
29  * WrapperControlEvent are used to notify the listener whenever the native
30  * wrapper code traps a system control signal against the Java process.
31  * It is up to the listener to take any actions necessary.
32  * <p>
33  * The Wrapper will send this event to any registered listeners first,
34  * then it will pass the control code to the WrapperListener.controlEvent
35  * method. If the consume method is called, it will still be passed to
36  * other WrapperEventListeners, but will not be passed to the
37  * WrapperListener.controlEvent method. Other WrapperEventListeners should
38  * check the isConsumed method to decide whether or not the even has already
39  * been handled.
40  * <p>
41  * If the wrapper.ignore_signals property is set to true then the event will
42  * still be fired, but its isConsumed() method will return true initially.
43  * <p>
44  * Possible values are:
45  * <dl>
46  * <dt>WrapperManager.WRAPPER_CTRL_C_EVENT</dt>
47  * <dd>The user pressed CTRL-C in a command windown (Windows or UNIX).
48  * Or the kill INT signal was received (UNIX).</dd>
49  * <dt>WRAPPER_CTRL_CLOSE_EVENT</dt>
50  * <dd>The user is trying to close the console in which the Wrapper is
51  * running (Windows).</dd>
52  * <dt>WRAPPER_CTRL_LOGOFF_EVENT</dt>
53  * <dd>The user logged off (Windows).</dd>
54  * <dt>WRAPPER_CTRL_SHUTDOWN_EVENT</dt>
55  * <dd>The system is being shutdown (Windows).</dd>
56  * <dt>WRAPPER_CTRL_TERM_EVENT</td>
57  * <dd>The kill TERM signal was received (UNIX).</dd>
58  * <dt>WRAPPER_CTRL_HUP_EVENT</td>
59  * <dd>The kill HUP signal was received (UNIX).</dd>
60  * </dl>
61  *
62  * @author Leif Mortenson <leif@tanukisoftware.com>
63  */

64 public class WrapperControlEvent
65     extends WrapperEvent
66 {
67     /** The system control event. */
68     private int m_controlEvent;
69     
70     /** The name of the event. */
71     private String JavaDoc m_controlEventName;
72     
73     /** True if the event has been consumed. */
74     private boolean m_consumed;
75     
76     /*---------------------------------------------------------------
77      * Constructors
78      *-------------------------------------------------------------*/

79     /**
80      * Creates a new WrapperControlEvent.
81      *
82      * @param controlEvent Service control event.
83      * @param controlEventName The name of the event.
84      */

85     public WrapperControlEvent( int controlEvent, String JavaDoc controlEventName )
86     {
87         m_controlEvent = controlEvent;
88         m_controlEventName = controlEventName;
89     }
90     
91     /*---------------------------------------------------------------
92      * WrapperEvent Methods
93      *-------------------------------------------------------------*/

94     /**
95      * Returns a set of event flags for which the event should be fired.
96      * This value is compared with the mask supplied when when a
97      * WrapperEventListener is registered to decide which listeners should
98      * receive the event.
99      * <p>
100      * If a subclassed, the return value of the super class should usually
101      * be ORed with any additional flags.
102      *
103      * @return a set of event flags.
104      */

105     public long getFlags()
106     {
107         return super.getFlags() | WrapperEventListener.EVENT_FLAG_CONTROL;
108     }
109     
110     /*---------------------------------------------------------------
111      * Methods
112      *-------------------------------------------------------------*/

113     /**
114      * Returns the system control event.
115      * <p>
116      * Possible values are: WrapperManager.WRAPPER_CTRL_C_EVENT,
117      * WRAPPER_CTRL_CLOSE_EVENT, WRAPPER_CTRL_LOGOFF_EVENT,
118      * WRAPPER_CTRL_SHUTDOWN_EVENT, WRAPPER_CTRL_TERM_EVENT, or
119      * WRAPPER_CTRL_HUP_EVENT.
120      *
121      * @return The system control event.
122      */

123     public int getControlEvent()
124     {
125         return m_controlEvent;
126     }
127     
128     /**
129      * Returns the name of the control event.
130      *
131      * @return The name of the control event.
132      */

133     public String JavaDoc getControlEventName()
134     {
135         return m_controlEventName;
136     }
137     
138     /**
139      * Mark the event as consumed. This should be done if the event
140      * has been handled.
141      * <p>
142      * On Windows, some events are sent both to the JVM and Wrapper processes.
143      * Event if the CTRL-C event is ignored within the JVM, the Wrapper
144      * process may still initiate a shutdown.
145      */

146     public void consume()
147     {
148         m_consumed = true;
149     }
150     
151     /**
152      * Returns true if the event has been consumed.
153      *
154      * @return True if the event has been consumed.
155      */

156     public boolean isConsumed()
157     {
158         return m_consumed;
159     }
160     
161     /**
162      * Returns a string representation of the event.
163      *
164      * @return A string representation of the event.
165      */

166     public String JavaDoc toString()
167     {
168         return "WrapperControlEvent[controlEvent=" + getControlEvent()
169             + ", controlEventName=" + getControlEventName() + ", consumed=" + isConsumed() + "]";
170     }
171 }
172
Popular Tags