1 24 25 package helloworld; 26 27 import org.objectweb.dream.AbstractComponent; 28 import org.objectweb.dream.Push; 29 import org.objectweb.dream.control.activity.task.AbstractTask; 30 import org.objectweb.dream.message.MessageTypeImpl; 31 import org.objectweb.dream.message.Message; 32 import org.objectweb.dream.message.MessageType; 33 import org.objectweb.dream.message.manager.MessageManager; 34 import org.objectweb.fractal.api.NoSuchInterfaceException; 35 import org.objectweb.fractal.api.control.IllegalBindingException; 36 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 37 38 39 public abstract class AbstractClientImpl extends AbstractComponent 40 { 41 42 Push outPushItf; 43 MessageManager messageManager; 44 MessageType msgType = new MessageTypeImpl(HelloWorldChunk.DEFAULT_NAME, 45 HelloWorldChunk.TYPE); 46 47 protected class ClientTask extends AbstractTask 48 { 49 50 private String message; 51 52 55 public ClientTask(String message) 56 { 57 super("client-task-" + message); 58 this.message = message; 59 } 60 61 64 public Object execute(Object hints) throws InterruptedException 65 { 66 try 67 { 68 Message msg = messageManager.createMessage(msgType); 69 HelloWorldChunk chunk = (HelloWorldChunk) msg 70 .getChunk(HelloWorldChunk.DEFAULT_NAME); 71 chunk.setMessage(message); 72 outPushItf.push(msg, null); 73 } 74 catch (Exception e) 75 { 76 e.printStackTrace(); 77 return STOP_EXECUTING; 78 } 79 Thread.sleep(1000); 80 return EXECUTE_AGAIN; 81 } 82 } 83 84 88 92 public synchronized void bindFc(String clientItfName, Object serverItf) 93 throws NoSuchInterfaceException, IllegalBindingException, 94 IllegalLifeCycleException 95 { 96 super.bindFc(clientItfName, serverItf); 97 if (clientItfName.equals(Push.OUT_PUSH_ITF_NAME)) 98 { 99 outPushItf = (Push) serverItf; 100 } 101 else if (clientItfName.equals(MessageManager.ITF_NAME)) 102 { 103 messageManager = (MessageManager) serverItf; 104 } 105 } 106 107 110 public String [] listFc() 111 { 112 return new String []{Push.OUT_PUSH_ITF_NAME, MessageManager.ITF_NAME}; 113 } 114 } | Popular Tags |