1 10 11 package org.mule.registry.impl; 12 13 import org.mule.registry.Assembly; 14 import org.mule.registry.Registry; 15 import org.mule.registry.RegistryComponent; 16 import org.mule.registry.RegistryException; 17 import org.mule.registry.Unit; 18 19 22 public abstract class AbstractUnit extends AbstractEntry implements Unit 23 { 24 25 private String assembly; 26 27 protected AbstractUnit(Registry registry) 28 { 29 super(registry); 30 } 31 32 37 public Assembly getAssembly() 38 { 39 return getRegistry().getAssembly(this.assembly); 40 } 41 42 public void setAssembly(Assembly assembly) 43 { 44 this.assembly = assembly.getName(); 45 } 46 47 52 public final synchronized String deploy() throws RegistryException 53 { 54 if (!getCurrentState().equals(UNKNOWN)) 55 { 56 throw new RegistryException("Illegal status: " + getCurrentState()); 57 } 58 String result = null; 59 try 60 { 61 result = doDeploy(); 62 } 63 catch (Exception e) 64 { 65 throw new RegistryException(e); 66 } 67 getRegistryComponent().addUnit(this); 69 ((AbstractAssembly)getAssembly()).addUnit(this); 70 setCurrentState(STOPPED); 71 return result; 72 } 73 74 public abstract String doDeploy() throws Exception ; 75 76 81 public final synchronized void init() throws RegistryException 82 { 83 if (!getCurrentState().equals(UNKNOWN)) 84 { 85 throw new RegistryException("Illegal status: " + getCurrentState()); 86 } 87 try 88 { 89 doInit(); 90 } 91 catch (Exception e) 92 { 93 throw new RegistryException(e); 94 } 95 setCurrentState(STOPPED); 96 } 97 98 protected abstract void doInit() throws Exception ; 99 100 105 public final synchronized void start() throws RegistryException 106 { 107 if (getCurrentState().equals(UNKNOWN)) 108 { 109 throw new RegistryException("Illegal status: " + getCurrentState()); 110 } 111 if (!getCurrentState().equals(RUNNING)) 112 { 113 try 114 { 115 doStart(); 116 } 117 catch (Exception e) 118 { 119 throw new RegistryException(e); 120 } 121 setCurrentState(RUNNING); 122 } 123 } 124 125 protected abstract void doStart() throws Exception ; 126 127 132 public final synchronized void stop() throws RegistryException 133 { 134 if (getCurrentState().equals(UNKNOWN) || getCurrentState().equals(SHUTDOWN)) 135 { 136 throw new RegistryException("Illegal status: " + getCurrentState()); 137 } 138 if (!getCurrentState().equals(STOPPED)) 139 { 140 try 141 { 142 doStop(); 143 } 144 catch (Exception e) 145 { 146 throw new RegistryException(e); 147 } 148 setCurrentState(STOPPED); 149 } 150 } 151 152 protected abstract void doStop() throws Exception ; 153 154 159 public final synchronized void shutDown() throws RegistryException 160 { 161 if (getCurrentState().equals(UNKNOWN)) 162 { 163 throw new RegistryException("Illegal status: " + getCurrentState()); 164 } 165 if (!getCurrentState().equals(SHUTDOWN)) 166 { 167 stop(); 168 try 169 { 170 doShutDown(); 171 } 172 catch (Exception e) 173 { 174 throw new RegistryException(e); 175 } 176 setCurrentState(SHUTDOWN); 177 } 178 } 179 180 protected abstract void doShutDown() throws Exception ; 181 182 187 public synchronized String undeploy() throws RegistryException 188 { 189 if (!getCurrentState().equals(SHUTDOWN)) 190 { 191 throw new RegistryException("Illegal status: " + getCurrentState()); 192 } 193 String result = null; 194 try 195 { 196 result = doUndeploy(); 197 } 198 catch (Exception e) 199 { 200 throw new RegistryException(e); 201 } 202 getRegistryComponent().removeUnit(this); 204 ((AbstractAssembly)getAssembly()).removeUnit(this); 205 setCurrentState(UNKNOWN); 206 return result; 207 } 208 209 protected abstract String doUndeploy() throws Exception ; 210 211 public void setRegistryComponent(RegistryComponent component) 212 { 213 } 215 216 } 217 | Popular Tags |