1 24 25 package org.objectweb.dream.control.activity.task.thread; 26 27 import org.objectweb.dream.AbstractComponent; 28 import org.objectweb.dream.control.activity.scheduler.Scheduler; 29 import org.objectweb.dream.control.activity.scheduler.StoppedSchedulerException; 30 import org.objectweb.dream.control.activity.task.Task; 31 import org.objectweb.fractal.api.NoSuchInterfaceException; 32 import org.objectweb.fractal.api.control.IllegalBindingException; 33 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 34 import org.objectweb.util.monolog.api.BasicLevel; 35 36 39 public abstract class AbstractThreadTask extends AbstractComponent 40 implements 41 Task 42 { 43 44 45 protected Scheduler scheduler = null; 46 47 53 protected abstract boolean isExecuting(); 54 55 61 protected abstract void setExecuting(boolean b); 62 63 67 70 public Object execute(Object hints) throws InterruptedException 71 { 72 try 73 { 74 while (isExecuting()) 75 { 76 logger.log(BasicLevel.DEBUG, "Call to schedule"); 77 if (((Integer ) scheduler.schedule(null)).intValue() == -1) 78 { 79 setExecuting(false); 80 } 81 } 82 } 83 catch (StoppedSchedulerException e1) 84 { 85 logger.log(BasicLevel.DEBUG, "Scheduler stopped"); 86 } 87 catch (InterruptedException e) 88 { 89 logger.log(BasicLevel.DEBUG, "Interrupted"); 90 } 91 catch (Throwable e) 92 { 93 logger.log(BasicLevel.ERROR, "Exception catched", e); 94 } 95 logger.log(BasicLevel.DEBUG, "End of the execute method"); 96 return null; 97 } 98 99 103 107 public synchronized void bindFc(String clientItfName, Object serverItf) 108 throws NoSuchInterfaceException, IllegalBindingException, 109 IllegalLifeCycleException 110 { 111 super.bindFc(clientItfName, serverItf); 112 if (clientItfName.equals(Scheduler.ITF_NAME)) 113 { 114 scheduler = (Scheduler) serverItf; 115 } 116 } 117 118 121 public synchronized void unbindFc(String clientItfName) 122 throws NoSuchInterfaceException, IllegalBindingException, 123 IllegalLifeCycleException 124 { 125 super.unbindFc(clientItfName); 126 if (clientItfName.equals(Scheduler.ITF_NAME)) 127 { 128 scheduler = null; 129 } 130 } 131 132 135 public synchronized String [] listFc() 136 { 137 return new String []{Scheduler.ITF_NAME}; 138 } 139 140 } | Popular Tags |