KickJava   Java API By Example, From Geeks To Geeks.

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


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="lazy", 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 StartLazyRedeployAutomaticStrategy
46   extends AbstractDeployControllerStrategy {
47   private final static StartLazyRedeployAutomaticStrategy STRATEGY =
48           new StartLazyRedeployAutomaticStrategy();
49
50
51   private StartLazyRedeployAutomaticStrategy()
52   {
53   }
54
55   /**
56    * Returns the start="lazy" redeploy="automatic" strategy
57    *
58    * @return the singleton strategy
59    */

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

70   public<I extends DeployInstance>
71     void startOnInit(DeployController<I> controller)
72   {
73     controller.stopLazyImpl();
74   }
75
76
77   /**
78    * Checks for updates from an admin command. The target state will be the
79    * initial state, i.e. update will not start a lazy instance.
80    *
81    * @param controller the owning controller
82    */

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

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

141   public <I extends DeployInstance>
142           I subrequest(DeployController<I> controller)
143   {
144     if (controller.isStoppedLazy()) {
145       // server/1d07
146
return controller.startImpl();
147     }
148     else if (controller.isStopped()) {
149       // server/1d01
150
return controller.getDeployInstance();
151     }
152     else if (controller.isError() && controller.isModified()) {
153       // server/1d0x
154
return controller.restartImpl();
155     }
156     else if (controller.isModified()) {
157       // server/1d0j
158
return controller.getDeployInstance();
159     }
160     else { /* active */
161       // server/1d0d
162
return controller.getDeployInstance();
163     }
164   }
165
166   /**
167    * Redeployment on a timeout alarm.
168    *
169    * @param controller the owning controller
170    */

171   public <I extends DeployInstance>
172           void alarm(DeployController<I> controller)
173   {
174     if (controller.isStoppedLazy()) {
175       // server/1d08
176
}
177     else if (controller.isStopped()) {
178       // server/1d02
179
}
180     else if (controller.isError()) {
181       // server/1d0w
182
}
183     else if (controller.isModified()) {
184       // server/1d0k
185
controller.stopLazyImpl();
186     }
187     else if (controller.isActiveIdle()) {
188       controller.stopLazyImpl();
189     }
190     else { /* active */
191     }
192   }
193 }
194
Popular Tags