1 24 25 package org.objectweb.dream.control.lifecycle; 26 27 import org.objectweb.dream.control.activity.task.IllegalTaskException; 28 import org.objectweb.dream.control.activity.task.NoSuchTaskException; 29 import org.objectweb.dream.control.activity.task.Task; 30 import org.objectweb.dream.control.activity.task.TaskActivationController; 31 import org.objectweb.dream.control.activity.task.TaskController; 32 import org.objectweb.dream.control.activity.task.TaskStoppedListener; 33 import org.objectweb.dream.util.Error; 34 import org.objectweb.fractal.api.Component; 35 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 36 import org.objectweb.fractal.julia.control.lifecycle.ChainedIllegalLifeCycleException; 37 import org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 import org.objectweb.util.monolog.api.Logger; 40 41 63 public abstract class ActivityLifeCycleMixin implements TaskStoppedListener 64 { 65 66 protected int fcNbStoppingTask; 67 protected LifeCycleCoordinator fcActivityCoordinator; 68 69 73 private ActivityLifeCycleMixin() 74 { 75 } 76 77 81 87 public synchronized boolean setFcStarted() throws IllegalLifeCycleException 88 { 89 if (!_super_setFcStarted()) 90 { 91 return false; 92 } 93 94 Task[] tasks = _this_weaveableTC.getTasks(); 96 for (int i = 0; i < tasks.length; i++) 97 { 98 if (_this_weaveableLCCLogger.isLoggable(BasicLevel.DEBUG)) 99 { 100 _this_weaveableLCCLogger.log(BasicLevel.DEBUG, "activate task " 101 + tasks[i]); 102 } 103 try 104 { 105 _this_weaveableTAC.activateTask(tasks[i]); 106 } 107 catch (NoSuchTaskException e) 108 { 109 Error.bug(_this_weaveableLCCLogger, e); 111 } 112 catch (IllegalTaskException e) 113 { 114 throw new ChainedIllegalLifeCycleException(e, _this_weaveableC, 115 "Error while registering task"); 116 } 117 } 118 return true; 119 } 120 121 127 public void setFcStopping(final LifeCycleCoordinator coordinator) 128 throws IllegalLifeCycleException 129 { 130 Task[] tasks = _this_weaveableTC.getTasks(); 131 synchronized (this) 132 { 133 fcNbStoppingTask += tasks.length; 134 135 fcActivityCoordinator = coordinator; 136 for (int i = 0; i < tasks.length; i++) 137 { 138 if (_this_weaveableLCCLogger.isLoggable(BasicLevel.DEBUG)) 139 { 140 _this_weaveableLCCLogger.log(BasicLevel.DEBUG, "interrupt task " 141 + tasks[i]); 142 } 143 try 144 { 145 _this_weaveableTAC.deactivateTask(tasks[i], this); 146 } 147 catch (NoSuchTaskException e) 148 { 149 Error.bug(_this_weaveableLCCLogger, e); 151 } 152 catch (IllegalTaskException e) 153 { 154 throw new ChainedIllegalLifeCycleException(e, _this_weaveableC, 155 "Error while unregistering task"); 156 } 157 } 158 } 159 _super_setFcStopping(coordinator); 160 } 161 162 168 public boolean checkInactivity() 169 { 170 return fcNbStoppingTask == 0 && _super_checkInactivity(); 171 } 172 173 177 180 public void taskStopped(Task task) 181 { 182 synchronized (this) 183 { 184 if (_this_weaveableLCCLogger.isLoggable(BasicLevel.DEBUG)) 185 { 186 _this_weaveableLCCLogger.log(BasicLevel.DEBUG, "task stopped" + task); 187 } 188 fcNbStoppingTask--; 189 _this_isInactivated(fcActivityCoordinator); 190 } 191 } 192 193 197 202 public Component _this_weaveableC; 203 204 208 public Logger _this_weaveableLCCLogger; 209 210 215 public TaskController _this_weaveableTC; 216 217 222 public TaskActivationController _this_weaveableTAC; 223 224 230 public abstract boolean _super_setFcStarted() 231 throws IllegalLifeCycleException; 232 233 239 public abstract void _super_setFcStopping( 240 final LifeCycleCoordinator coordinator) throws IllegalLifeCycleException; 241 242 249 public abstract boolean _super_checkInactivity(); 250 251 258 public abstract boolean _this_isInactivated(LifeCycleCoordinator coordinator); 259 } | Popular Tags |