1 23 24 package org.objectweb.dream.control.activity.task; 25 26 import java.util.Map ; 27 28 import org.objectweb.fractal.api.NoSuchInterfaceException; 29 import org.objectweb.fractal.api.control.BindingController; 30 import org.objectweb.util.monolog.api.BasicLevel; 31 import org.objectweb.util.monolog.api.Logger; 32 33 47 public abstract class BasicTaskActivationMixin 48 implements 49 TaskActivationController 50 { 51 52 56 59 public void activateTask(Task task) throws NoSuchTaskException, 60 IllegalTaskException 61 { 62 if (!_this_taskRegistrationHints.containsKey(task)) 63 { 64 throw new NoSuchTaskException(task); 65 } 66 if (_this_taskControls.containsKey(task)) 67 { 68 return; 69 } 70 _this_weaveableTCLogger.log(BasicLevel.DEBUG, "register a task"); 71 Map hints = (Map ) _this_taskRegistrationHints.get(task); 72 TaskManagerController tmc = getTaskManagerBinding(); 73 Object taskControl; 74 try 75 { 76 taskControl = tmc.registerTask(task, hints); 77 } 78 catch (Exception e) 79 { 80 throw new IllegalTaskException(task, "Unable to register component", e); 81 } 82 83 _this_taskControls.put(task, taskControl); 84 _this_weaveableTCLogger.log(BasicLevel.DEBUG, "task registered"); 85 } 86 87 90 public void deactivateTask(Task task) throws NoSuchTaskException, 91 IllegalTaskException 92 { 93 if (!_this_taskRegistrationHints.containsKey(task)) 94 { 95 throw new NoSuchTaskException(task); 96 } 97 if (!_this_taskControls.containsKey(task)) 98 { 99 return; 100 } 101 _this_weaveableTCLogger.log(BasicLevel.DEBUG, "deactivate a task"); 102 try 103 { 104 getTaskManagerBinding().unregisterTask(task); 105 } 106 catch (Exception e) 107 { 108 throw new IllegalTaskException(task, "Unable to unregister component", e); 109 } 110 _this_taskControls.remove(task); 111 _this_weaveableTCLogger.log(BasicLevel.DEBUG, "task deactivated"); 112 } 113 114 117 public void deactivateTask(Task task, TaskStoppedListener taskStoppedListener) 118 throws NoSuchTaskException, IllegalTaskException 119 { 120 if (!_this_taskRegistrationHints.containsKey(task)) 121 { 122 throw new NoSuchTaskException(task); 123 } 124 if (!_this_taskControls.containsKey(task)) 125 { 126 return; 127 } 128 _this_weaveableTCLogger.log(BasicLevel.DEBUG, "deactivate a task"); 129 try 130 { 131 getTaskManagerBinding().interruptTask( 132 task, 133 new TaskActivationStoppedListener(taskStoppedListener, 134 _this_taskControls)); 135 } 136 catch (Exception e) 137 { 138 throw new IllegalTaskException(task, "Unable to unregister component", e); 139 } 140 _this_taskControls.remove(task); 141 _this_weaveableTCLogger.log(BasicLevel.DEBUG, "task deactivated"); 142 } 143 144 148 private TaskManagerController getTaskManagerBinding() 149 throws IllegalTaskException 150 { 151 try 152 { 153 return (TaskManagerController) _this_weaveableBC.lookupFc("task-manager"); 154 } 155 catch (NoSuchInterfaceException e) 156 { 157 throw new IllegalTaskException(null, 158 "This component has no task-manager client interface", null); 159 } 160 } 161 162 166 170 public Logger _this_weaveableTCLogger; 171 172 179 public Map _this_taskRegistrationHints; 180 181 186 public Map _this_taskControls; 187 188 194 public BindingController _this_weaveableBC; 195 196 } | Popular Tags |