1 23 24 package helloworld; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import org.objectweb.dream.control.activity.Util; 30 import org.objectweb.dream.control.activity.task.Task; 31 import org.objectweb.dream.control.activity.task.TaskController; 32 import org.objectweb.dream.control.activity.task.thread.ThreadPoolController; 33 import org.objectweb.fractal.api.Component; 34 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 35 import org.objectweb.fractal.julia.control.lifecycle.ChainedIllegalLifeCycleException; 36 37 40 public class PoolClientImpl extends AbstractClientImpl 41 { 42 43 Task task = new ClientTask("Hello World task"); 44 45 49 52 protected void beforeFirstStart(Component componentItf) 53 throws IllegalLifeCycleException 54 { 55 try 56 { 57 Map m = new HashMap (); 58 m.put("thread", "pool"); 59 m.put("threadPool.capacity", new Integer (2)); 60 Util.addTask(componentItf, task, m); 61 } 62 catch (Exception e) 63 { 64 throw new IllegalLifeCycleException("Can't add task"); 65 } 66 } 67 68 71 public void startFc() throws IllegalLifeCycleException 72 { 73 super.startFc(); 74 try 76 { 77 TaskController tc = (TaskController) weaveableC 78 .getFcInterface("task-controller"); 79 ThreadPoolController threadPoolController = (ThreadPoolController) tc 80 .getTaskControl(task); 81 threadPoolController.addThreads(2); 82 } 83 catch (Exception e) 84 { 85 throw new ChainedIllegalLifeCycleException(e, null, 86 "An error occurs while retreiving task control interface"); 87 } 88 } 89 } | Popular Tags |