KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > deploy > StartAutoRedeployAutoStrategy


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.server.deploy;
31
32 /**
33  * The start-mode="automatic", redeploy-model="automatic" controller strategy.
34  *
35  * <table>
36  * <tr><th>input <th>stopped <th>active <th>modified <th>error
37  * <tr><td>request<td>startImpl<td>- <td>restartImpl<td>restartImpl
38  * <tr><td>include<td>startImpl<td>- <td>- <td>-
39  * <tr><td>start <td>startImpl<td>- <td>restartImpl<td>restartImpl
40  * <tr><td>restart<td>startImpl<td>- <td>restartImpl<td>restartImpl
41  * <tr><td>stop <td>- <td>stopImpl<td>stopImpl <td>stopImpl
42  * <tr><td>alarm <td>- <td>- <td>stopImpl <td>stopImpl
43  * </table>
44  */

45 public class StartAutoRedeployAutoStrategy
46   extends AbstractDeployControllerStrategy {
47   private final static StartAutoRedeployAutoStrategy STRATEGY =
48           new StartAutoRedeployAutoStrategy();
49
50   private StartAutoRedeployAutoStrategy()
51   {
52   }
53
54   /**
55    * Returns the start="lazy" redeploy="automatic" strategy
56    *
57    * @return the singleton strategy
58    */

59   public static DeployControllerStrategy create()
60   {
61     return STRATEGY;
62   }
63
64   /**
65    * Called at initialization time for automatic start.
66    *
67    * @param controller the owning controller
68    */

69   public<I extends DeployInstance>
70     void startOnInit(DeployController<I> controller)
71   {
72     controller.startImpl();
73   }
74
75   /**
76    * Checks for updates from an admin command. The target state is
77    * the started state.
78    *
79    * @param controller the owning controller
80    */

81   public<I extends DeployInstance>
82     void update(DeployController<I> controller)
83   {
84     if (controller.isStoppedLazy()) {
85       // server/1d18
86
}
87     else if (controller.isStopped()) {
88       // server/1d15
89
controller.startImpl();
90     }
91     else if (controller.isModifiedNow()) {
92       // 1d1n, 1d1o
93
controller.restartImpl();
94     }
95     else if (controller.isError()) {
96       controller.restartImpl();
97     }
98     else if (controller.isActiveIdle()) {
99       controller.restartImpl();
100     }
101     else { /* active */
102     }
103   }
104
105
106   /**
107    * Returns the current instance, redeploying if necessary.
108    *
109    * @param controller the owning controller
110    * @return the current deploy instance
111    */

112   public <I extends DeployInstance>
113           I request(DeployController<I> controller)
114   {
115     if (controller.isStoppedLazy()) {
116       // server/1d16
117
return controller.startImpl();
118     }
119     else if (controller.isStopped()) {
120       // server/1d10
121
return controller.getDeployInstance();
122     }
123     else if (controller.isModified()) {
124       // server/1d1i
125
return controller.restartImpl();
126     }
127     else { /* active */
128       // server/1d1c
129
return controller.getDeployInstance();
130     }
131   }
132
133   /**
134    * Returns the current instance, starting if necessary.
135    *
136    * @param controller the owning controller
137    * @return the current deploy instance
138    */

139   public <I extends DeployInstance>
140           I subrequest(DeployController<I> controller)
141   {
142     if (controller.isStoppedLazy()) {
143       // server/1d17
144
return controller.startImpl();
145     }
146     else if (controller.isStopped()) {
147       // server/1d11
148
return controller.getDeployInstance();
149     }
150     else if (controller.isModified()) {
151       // server/1d1j
152
return controller.getDeployInstance();
153     }
154     else { /* active */
155       // server/1d1d
156
return controller.getDeployInstance();
157     }
158   }
159
160   /**
161    * Redeployment on a timeout alarm.
162    *
163    * @param controller the owning controller
164    */

165   public <I extends DeployInstance>
166           void alarm(DeployController<I> controller)
167   {
168     if (controller.isStopped()) {
169       // server/1d12
170
}
171     else if (controller.isStoppedLazy()) {
172       // server/1d18
173
}
174     else if (controller.isModified()) {
175       // server/1d1k
176
controller.restartImpl();
177     }
178     else if (controller.isActiveIdle()) {
179     }
180     else { /* active */
181     }
182   }
183 }
184
Popular Tags