1 /*==================================================================== 2 3 OpenCCM: The Open CORBA Component Model Platform 4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL 5 Contact: openccm@objectweb.org 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 20 USA 21 22 Initial developer(s): Briclet Frédéric. 23 Contributor(s): ______________________________________. 24 25 ====================================================================*/ 26 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.managers; 27 28 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.Deployer; 29 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeployerFailureState; 30 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeployerInitializationFailureState; 31 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeployerNotInitializeState; 32 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeployerState; 33 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeploymentLogger; 34 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.LifeCycleManager; 35 36 /** 37 * This is the default implementation of the deployer life cycle manager 38 * 39 * @author <a HREF="mailto:briclet@lifl.fr">Briclet Frédéric</a> 40 * 41 * @version 0.1 42 */ 43 public class DefaultLifeCycleManager 44 implements LifeCycleManager 45 { 46 // ================================================================== 47 // 48 // Internal state. 49 // 50 // ================================================================== 51 private DeployerState status= new DeployerNotInitializeState(); 52 private DeploymentLogger logger; 53 private Deployer deployer; 54 // ================================================================== 55 // 56 // Constructors. 57 // 58 // ================================================================== 59 // ================================================================== 60 // 61 // Internal methods. 62 // 63 // ================================================================== 64 /** 65 * Internal accessor to the current deployment logger. 66 * @return the current deployment logger 67 */ 68 private DeploymentLogger 69 getLogger() 70 { 71 return logger; 72 } 73 /** 74 * Log the current deployer status 75 * 76 */ 77 private void 78 logDeployerStatus() 79 { 80 getLogger().log(">>"+deployer.getIdentifier()+" is in "+status.getStateName()); 81 } 82 // ================================================================== 83 // 84 // Public methods. 85 // 86 // ================================================================== 87 /** 88 * This method return the current status of the deployer 89 * monitored. 90 * 91 * @return The deployer current status 92 */ 93 public DeployerState 94 getStatus() 95 { 96 return status; 97 } 98 99 /** 100 * This method indicates to the manager that the deployer 101 * ended succefully the current step. So the deployer can be 102 * put in the following state. 103 * 104 * @return The new deployer state. 105 */ 106 public DeployerState 107 stepEndedSuccessFully() 108 { 109 status=status.followingState(); 110 logDeployerStatus(); 111 return status; 112 } 113 114 /** 115 * This method indicates to the manager that the 116 * deployer has aborted the current step. The manager 117 * return the new state. 118 * 119 * @return The new deployer state. 120 */ 121 public DeployerState 122 stepAborded() 123 { 124 if(status instanceof DeployerNotInitializeState) 125 status=new DeployerInitializationFailureState(); 126 else status=new DeployerFailureState(); 127 128 logDeployerStatus(); 129 return status; 130 } 131 /** 132 * Connect to this life cycle manager the deployer to 133 * monitor. 134 * 135 * @param deployer to monitor 136 */ 137 public void 138 connectManagedDeployer(Deployer deployer) 139 { 140 this.deployer=deployer; 141 logDeployerStatus(); 142 } 143 144 /** 145 * Connect the logger to use to log information 146 * 147 * @param logger to use to signal event 148 */ 149 public void 150 connectLogger(DeploymentLogger logger) 151 { 152 this.logger = logger; 153 } 154 /** 155 * This method return the deployer managed by tis 156 * lifecycle manager. 157 * 158 * @return The managed deployer 159 */ 160 public Deployer 161 getManagedDeployer() 162 { 163 return deployer; 164 } 165 166 } 167