Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MuleServerWrapper |
|
| 2.0;2 |
1 | /* | |
2 | * $Id: MuleServerWrapper.java 9984 2007-12-04 16:26:56Z aguenther $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | ||
11 | package org.mule.modules.boot; | |
12 | ||
13 | import org.mule.MuleServer; | |
14 | ||
15 | import org.tanukisoftware.wrapper.WrapperListener; | |
16 | import org.tanukisoftware.wrapper.WrapperManager; | |
17 | ||
18 | public class MuleServerWrapper implements WrapperListener | |
19 | { | |
20 | /*--------------------------------------------------------------- | |
21 | * Constructors | |
22 | *-------------------------------------------------------------*/ | |
23 | public MuleServerWrapper() | |
24 | { | |
25 | 0 | super(); |
26 | 0 | } |
27 | ||
28 | /*--------------------------------------------------------------- | |
29 | * WrapperListener Methods | |
30 | *-------------------------------------------------------------*/ | |
31 | /** | |
32 | * The start method is called when the WrapperManager is signaled by the native | |
33 | * wrapper code that it can start its application. This method call is expected | |
34 | * to return, so a new thread should be launched if necessary. | |
35 | * | |
36 | * @param args List of arguments used to initialize the application. | |
37 | * @return Any error code if the application should exit on completion of the | |
38 | * start method. If there were no problems then this method should return | |
39 | * null. | |
40 | */ | |
41 | public Integer start(String[] args) | |
42 | { | |
43 | try | |
44 | { | |
45 | 0 | MuleServer.main(args); |
46 | 0 | return null; |
47 | } | |
48 | 0 | catch (Exception e) |
49 | { | |
50 | 0 | e.printStackTrace(); |
51 | 0 | return new Integer(1); |
52 | } | |
53 | } | |
54 | ||
55 | /** | |
56 | * Called when the application is shutting down. The Wrapper assumes that this | |
57 | * method will return fairly quickly. If the shutdown code code could potentially | |
58 | * take a long time, then WrapperManager.signalStopping() should be called to | |
59 | * extend the timeout period. If for some reason, the stop method can not return, | |
60 | * then it must call WrapperManager.stopped() to avoid warning messages from the | |
61 | * Wrapper. | |
62 | * | |
63 | * @param exitCode The suggested exit code that will be returned to the OS when | |
64 | * the JVM exits. | |
65 | * @return The exit code to actually return to the OS. In most cases, this should | |
66 | * just be the value of exitCode, however the user code has the option of | |
67 | * changing the exit code if there are any problems during shutdown. | |
68 | */ | |
69 | public int stop(int exitCode) | |
70 | { | |
71 | 0 | return exitCode; |
72 | } | |
73 | ||
74 | /** | |
75 | * Called whenever the native wrapper code traps a system control signal against | |
76 | * the Java process. It is up to the callback to take any actions necessary. | |
77 | * Possible values are: WrapperManager.WRAPPER_CTRL_C_EVENT, | |
78 | * WRAPPER_CTRL_CLOSE_EVENT, WRAPPER_CTRL_LOGOFF_EVENT, or | |
79 | * WRAPPER_CTRL_SHUTDOWN_EVENT | |
80 | * | |
81 | * @param event The system control signal. | |
82 | */ | |
83 | public void controlEvent(int event) | |
84 | { | |
85 | 0 | if (WrapperManager.isControlledByNativeWrapper()) |
86 | { | |
87 | // The Wrapper will take care of this event | |
88 | } | |
89 | else | |
90 | { | |
91 | // We are not being controlled by the Wrapper, so | |
92 | // handle the event ourselves. | |
93 | 0 | if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT) |
94 | || (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT) | |
95 | || (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)) | |
96 | { | |
97 | 0 | WrapperManager.stop(0); |
98 | } | |
99 | } | |
100 | 0 | } |
101 | } |