1 23 24 package org.objectweb.dream.control.lifecycle; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.NoSuchInterfaceException; 28 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 29 import org.objectweb.fractal.api.factory.InstantiationException; 30 import org.objectweb.fractal.julia.InitializationContext; 31 import org.objectweb.fractal.julia.control.lifecycle.ChainedIllegalLifeCycleException; 32 import org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator; 33 import org.objectweb.fractal.julia.factory.ChainedInstantiationException; 34 import org.objectweb.util.monolog.api.BasicLevel; 35 import org.objectweb.util.monolog.api.Logger; 36 37 53 public abstract class SimpleLifeCycleControllerMixin 54 implements 55 LifeCycleCoordinator 56 { 57 58 62 public int weaveableFcState; 63 64 68 71 public void initFcController(final InitializationContext ic) 72 throws InstantiationException 73 { 74 try 75 { 76 if (!(ic.getInterface("lifecycle-controller") instanceof LifeCycleCoordinator)) 77 { 78 throw new Exception (); 79 } 80 } 81 catch (Exception e) 82 { 83 try 84 { 85 ic.getInterface("/lifecycle-coordinator"); 86 } 87 catch (Exception f) 88 { 89 throw new ChainedInstantiationException(f, null, 90 "The component must provide a LifeCycleCoordinator interface"); 91 } 92 } 93 94 _super_initFcController(ic); 95 } 96 97 101 104 public String getFcState() 105 { 106 return weaveableFcState == 0 ? STOPPED : STARTED; 107 } 108 109 112 public void startFc() throws IllegalLifeCycleException 113 { 114 if (weaveableFcState != 2) 115 { 116 _this_weaveableLCCLogger.log(BasicLevel.DEBUG, "Start component"); 117 _this_setFcState(true); 118 } 119 } 120 121 128 public void stopFc() throws IllegalLifeCycleException 129 { 130 if (weaveableFcState == 2) 131 { 132 throw new ChainedIllegalLifeCycleException(null, _this_weaveableC, 133 "This component can't be stopped alone"); 134 } 135 } 136 137 141 144 public boolean setFcStarted() throws IllegalLifeCycleException 145 { 146 synchronized (this) 147 { 148 if (weaveableFcState == 2) 149 { 150 return false; 151 } 152 _this_weaveableLCCLogger.log(BasicLevel.DEBUG, "Component started"); 153 weaveableFcState = 2; 154 return true; 155 } 156 } 157 158 163 public void setFcStopping(LifeCycleCoordinator coordinator) 164 throws IllegalLifeCycleException 165 { 166 synchronized (this) 167 { 168 _this_weaveableLCCLogger.log(BasicLevel.DEBUG, "Stopping component"); 169 weaveableFcState = 1; 170 isInactivated(coordinator); 172 } 173 } 174 175 178 public boolean setFcStopped() throws IllegalLifeCycleException 179 { 180 synchronized (this) 181 { 182 if (weaveableFcState == 0) 183 { 184 return false; 185 } 186 _this_weaveableLCCLogger.log(BasicLevel.DEBUG, "Component stopped"); 187 weaveableFcState = 0; 188 return true; 189 } 190 } 191 192 199 public boolean checkInactivity() 200 { 201 return true; 202 } 203 204 213 public boolean isInactivated(LifeCycleCoordinator coordinator) 214 { 215 if (checkInactivity()) 216 { 217 _this_weaveableLCCLogger.log(BasicLevel.DEBUG, "Component inactivated"); 218 coordinator.fcInactivated(getFcCoordinator()); 219 return true; 220 } 221 return false; 222 } 223 224 228 234 public LifeCycleCoordinator getFcCoordinator() 235 { 236 try 237 { 238 return (LifeCycleCoordinator) _this_weaveableC 239 .getFcInterface("lifecycle-controller"); 240 } 241 catch (Exception e) 242 { 243 try 244 { 245 return (LifeCycleCoordinator) _this_weaveableC 246 .getFcInterface("/lifecycle-coordinator"); 247 } 248 catch (NoSuchInterfaceException f) 249 { 250 throw new Error ("Internal error"); } 252 } 253 } 254 255 259 264 public Component _this_weaveableC; 265 266 270 public Logger _this_weaveableLCCLogger; 271 272 283 public abstract void _this_setFcState(boolean started) 284 throws IllegalLifeCycleException; 285 286 295 public abstract void _super_initFcController(InitializationContext ic) 296 throws InstantiationException ; 297 } | Popular Tags |