1 24 25 package activity; 26 27 import java.util.Collections ; 28 29 import org.objectweb.dream.AbstractComponent; 30 import org.objectweb.dream.InterruptedPullException; 31 import org.objectweb.dream.Pull; 32 import org.objectweb.dream.PullException; 33 import org.objectweb.dream.control.activity.Util; 34 import org.objectweb.dream.control.activity.task.AbstractTask; 35 import org.objectweb.dream.message.Message; 36 import org.objectweb.dream.message.manager.MessageManager; 37 import org.objectweb.fractal.api.Component; 38 import org.objectweb.fractal.api.NoSuchInterfaceException; 39 import org.objectweb.fractal.api.control.IllegalBindingException; 40 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 41 import org.objectweb.util.monolog.api.BasicLevel; 42 43 46 public class ClientImpl extends AbstractComponent 47 { 48 49 protected Pull inPullItf; 50 protected MessageManager messageManagerItf; 51 52 56 59 protected void beforeFirstStart(Component componentItf) 60 throws IllegalLifeCycleException 61 { 62 try 63 { 64 Util.addTask(componentItf, new PullTask(), Collections.EMPTY_MAP); 65 logger.log(BasicLevel.INFO, "task added"); 66 } 67 catch (Exception e) 68 { 69 throw new IllegalLifeCycleException("Can't add task"); 70 } 71 } 72 73 protected class PullTask extends AbstractTask 74 { 75 76 PullTask() 77 { 78 super("PullTask"); 79 } 80 81 84 public Object execute(Object hints) throws InterruptedException 85 { 86 Message message = null; 87 try 88 { 89 message = inPullItf.pull(null); 90 System.out.println("PullComponent has received a message : " + message); 91 } 92 catch (PullException e) 93 { 94 System.out.println("An exeception occurs while pulling a message : " 95 + e); 96 if (e instanceof InterruptedPullException) 97 { 98 System.out.println("The pull method has been interrupted"); 99 } 100 return STOP_EXECUTING; 101 } 102 return EXECUTE_AGAIN; 103 } 104 } 106 110 114 public void bindFc(String clientItfName, Object serverItf) 115 throws NoSuchInterfaceException, IllegalBindingException, 116 IllegalLifeCycleException 117 { 118 super.bindFc(clientItfName, serverItf); 119 if (clientItfName.equals(Pull.IN_PULL_ITF_NAME)) 120 { 121 inPullItf = (Pull) serverItf; 122 } 123 else if (clientItfName.equals(MessageManager.ITF_NAME)) 124 { 125 messageManagerItf = (MessageManager) serverItf; 126 } 127 } 128 129 132 public String [] listFc() 133 { 134 return new String []{Pull.IN_PULL_ITF_NAME, MessageManager.ITF_NAME}; 135 } 136 137 } | Popular Tags |