1 24 25 package org.objectweb.dream.control.activity.task; 26 27 import org.objectweb.dream.control.activity.scheduler.Scheduler; 28 import org.objectweb.dream.control.activity.task.thread.ThreadPoolTask; 29 import org.objectweb.dream.util.Error; 30 import org.objectweb.fractal.api.Component; 31 import org.objectweb.fractal.api.NoSuchInterfaceException; 32 import org.objectweb.fractal.api.control.NameController; 33 import org.objectweb.fractal.api.factory.GenericFactory; 34 import org.objectweb.fractal.api.factory.InstantiationException; 35 import org.objectweb.fractal.api.type.ComponentType; 36 import org.objectweb.fractal.api.type.InterfaceType; 37 import org.objectweb.fractal.api.type.TypeFactory; 38 import org.objectweb.fractal.util.Fractal; 39 40 43 public final class Util 44 { 45 46 private Util() 47 { 48 } 49 50 58 public static Component createTask(Task task, String controllerDesc) 59 throws InstantiationException 60 { 61 Component bootstrap = org.objectweb.fractal.api.Fractal 62 .getBootstrapComponent(); 63 TypeFactory typeFactory = null; 64 GenericFactory genericFactory = null; 65 try 66 { 67 genericFactory = Fractal.getGenericFactory(bootstrap); 68 typeFactory = Fractal.getTypeFactory(bootstrap); 69 } 70 catch (NoSuchInterfaceException e1) 71 { 72 Error.bug(null, e1); 73 } 74 75 InterfaceType taskItfType = typeFactory.createFcItfType(Task.ITF_NAME, 78 Task.class.getName(), false, false, false); 79 80 InterfaceType schedulerItfType = typeFactory.createFcItfType( 82 Scheduler.ITF_NAME, Scheduler.class.getName(), true, true, false); 83 84 ComponentType taskType = typeFactory.createFcType(new InterfaceType[]{ 86 taskItfType, schedulerItfType}); 87 88 Component component = genericFactory.newFcInstance(taskType, 90 controllerDesc, task); 91 92 if (task instanceof NameController) 93 { 94 try 95 { 96 Fractal.getNameController(component).setFcName( 97 ((NameController) task).getFcName()); 98 } 99 catch (NoSuchInterfaceException e) 100 { 101 } 103 } 104 105 return component; 106 } 107 108 119 public static Component createScheduler(Scheduler scheduler, String taskName) 120 throws InstantiationException 121 { 122 Component bootstrap = org.objectweb.fractal.api.Fractal 123 .getBootstrapComponent(); 124 TypeFactory typeFactory = null; 125 GenericFactory genericFactory = null; 126 try 127 { 128 genericFactory = Fractal.getGenericFactory(bootstrap); 129 typeFactory = Fractal.getTypeFactory(bootstrap); 130 } 131 catch (NoSuchInterfaceException e1) 132 { 133 Error.bug(null, e1); 134 } 135 136 InterfaceType schedulerItfType = typeFactory.createFcItfType( 139 Scheduler.ITF_NAME, Scheduler.class.getName(), false, false, false); 140 141 InterfaceType taskItfType = typeFactory.createFcItfType(Task.ITF_NAME, 143 Task.class.getName(), true, false, true); 144 145 ComponentType taskType = typeFactory.createFcType(new InterfaceType[]{ 147 schedulerItfType, taskItfType}); 148 149 Component component = genericFactory.newFcInstance(taskType, 151 "taskPrimitive", scheduler); 152 153 if (taskName != null) 154 { 155 try 156 { 157 Fractal.getNameController(component).setFcName(taskName); 158 } 159 catch (NoSuchInterfaceException e) 160 { 161 } 163 } 164 165 return component; 166 167 } 168 169 177 public static Component createThreadPoolTask(String taskName) 178 throws InstantiationException 179 { 180 Component bootstrap = org.objectweb.fractal.api.Fractal 181 .getBootstrapComponent(); 182 TypeFactory typeFactory = null; 183 GenericFactory genericFactory = null; 184 try 185 { 186 genericFactory = Fractal.getGenericFactory(bootstrap); 187 typeFactory = Fractal.getTypeFactory(bootstrap); 188 } 189 catch (NoSuchInterfaceException e1) 190 { 191 Error.bug(null, e1); 192 } 193 194 InterfaceType taskItfType = typeFactory.createFcItfType(Task.ITF_NAME, 197 Task.class.getName(), false, false, false); 198 199 InterfaceType schedulerItfType = typeFactory.createFcItfType( 201 Scheduler.ITF_NAME, Scheduler.class.getName(), true, true, false); 202 203 ComponentType taskType = typeFactory.createFcType(new InterfaceType[]{ 205 taskItfType, schedulerItfType}); 206 207 Component component = genericFactory.newFcInstance(taskType, 209 "threadPoolPrimitive", new ThreadPoolTask()); 210 211 if (taskName != null) 212 { 213 try 214 { 215 Fractal.getNameController(component).setFcName(taskName); 216 } 217 catch (NoSuchInterfaceException e) 218 { 219 } 221 } 222 223 return component; 224 } 225 } | Popular Tags |