1 24 25 package org.objectweb.dream.control.activity.task; 26 27 import java.util.Collections ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 31 import org.objectweb.fractal.api.NoSuchInterfaceException; 32 import org.objectweb.fractal.api.control.BindingController; 33 import org.objectweb.fractal.api.factory.InstantiationException; 34 import org.objectweb.fractal.julia.InitializationContext; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 import org.objectweb.util.monolog.api.Logger; 37 38 50 public abstract class BasicTaskControllerMixin implements TaskController 51 { 52 53 54 protected Map taskRegistrationHints; 55 56 protected Map taskControls; 57 58 62 private BasicTaskControllerMixin() 63 { 64 } 65 66 69 public void initFcController(final InitializationContext ic) 70 throws InstantiationException 71 { 72 _super_initFcController(ic); 73 74 taskRegistrationHints = Collections.synchronizedMap(new HashMap ()); 75 taskControls = Collections.synchronizedMap(new HashMap ()); 76 } 77 78 82 85 public Task[] getTasks() 86 { 87 Task[] tasks = new Task[taskRegistrationHints.keySet().size()]; 88 return (Task[]) taskRegistrationHints.keySet().toArray(tasks); 89 } 90 91 94 public void addTask(Task task, Map hints) throws IllegalTaskException 95 { 96 if (taskRegistrationHints.containsKey(task)) 97 { 98 throw new IllegalTaskException(task, 99 "The given task has already been added in the task controller", null); 100 } 101 taskRegistrationHints.put(task, hints); 102 } 103 104 107 public Object getTaskControl(Task task) throws NoSuchTaskException 108 { 109 if (!taskRegistrationHints.containsKey(task)) 110 { 111 throw new NoSuchTaskException(task); 112 } 113 return taskControls.get(task); 114 } 115 116 119 public void removeTask(Task task) throws NoSuchTaskException, 120 IllegalTaskException 121 { 122 if (!taskRegistrationHints.containsKey(task)) 123 { 124 throw new NoSuchTaskException(task); 125 } 126 _this_weaveableTCLogger.log(BasicLevel.DEBUG, "remove a task"); 127 try 128 { 129 taskRegistrationHints.remove(task); 130 } 131 catch (Exception e) 132 { 133 throw new IllegalTaskException(task, "Unable to unregister task", e); 134 } 135 _this_weaveableTCLogger.log(BasicLevel.DEBUG, "task removed"); 136 } 137 138 142 private TaskManagerController getTaskManagerBinding() 143 throws IllegalTaskException 144 { 145 try 146 { 147 return (TaskManagerController) _this_weaveableBC.lookupFc("task-manager"); 148 } 149 catch (NoSuchInterfaceException e) 150 { 151 throw new IllegalTaskException(null, 152 "This component has no task-manager client interface", null); 153 } 154 } 155 156 160 164 public Logger _this_weaveableTCLogger; 165 166 172 public BindingController _this_weaveableBC; 173 174 181 public abstract void _super_initFcController(InitializationContext ic) 182 throws InstantiationException ; 183 } | Popular Tags |