001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.server.deploy;
031:
032: /**
033: * The start-mode="lazy", redeploy-model="manual" controller strategy.
034: *
035: * initial state = stop
036: *
037: * <table>
038: * <tr><th>input <th>stopped <th>active <th>modified <th>error
039: * <tr><td>start <td>startImpl<td>- <td>restartImpl<td>restartImpl
040: * <tr><td>update <td>startImpl<td>- <td>restartImpl<td>restartImpl
041: * <tr><td>stop <td>- <td>stopImpl<td>stopImpl <td>stopImpl
042: * <tr><td>request<td>- <td>- <td>- <td>-
043: * <tr><td>include<td>- <td>- <td>- <td>-
044: * <tr><td>alarm <td>- <td>- <td>- <td>-
045: * </table>
046: */
047: public class StartLazyRedeployManualStrategy extends
048: StartManualRedeployManualStrategy {
049: private final static StartLazyRedeployManualStrategy STRATEGY = new StartLazyRedeployManualStrategy();
050:
051: private StartLazyRedeployManualStrategy() {
052: }
053:
054: /**
055: * Returns the start="lazy" redeploy="automatic" strategy
056: *
057: * @return the singleton strategy
058: */
059: public static DeployControllerStrategy create() {
060: return STRATEGY;
061: }
062:
063: /**
064: * Called at initialization time for automatic start.
065: *
066: * @param controller the owning controller
067: */
068: public <I extends DeployInstance> void startOnInit(
069: DeployController<I> controller) {
070: controller.stopLazyImpl();
071: }
072:
073: /**
074: * Returns the current instance, redeploying if necessary.
075: *
076: * @param controller the owning controller
077: * @return the current deploy instance
078: */
079: public <I extends DeployInstance> I request(
080: DeployController<I> controller) {
081: if (controller.isStoppedLazy()) {
082: return controller.startImpl();
083: } else if (controller.isStopped()) {
084: return controller.getDeployInstance();
085: } else {
086: return controller.getDeployInstance();
087: }
088: }
089:
090: /**
091: * Returns the current instance, starting if necessary.
092: *
093: * @param controller the owning controller
094: * @return the current deploy instance
095: */
096: public <I extends DeployInstance> I subrequest(
097: DeployController<I> controller) {
098: if (controller.isStoppedLazy()) {
099: return controller.startImpl();
100: } else if (controller.isStopped()) {
101: return controller.getDeployInstance();
102: } else { /* active */
103: // server/1d0d
104: return controller.getDeployInstance();
105: }
106: }
107: }
|