1 24 25 package pushwithreturn; 26 27 import java.util.Map ; 28 29 import org.objectweb.dream.AbstractComponent; 30 import org.objectweb.dream.InterruptedPushException; 31 import org.objectweb.dream.Push; 32 import org.objectweb.dream.PushException; 33 import org.objectweb.dream.message.MessageTypeImpl; 34 import org.objectweb.dream.message.Message; 35 import org.objectweb.dream.message.MessageType; 36 import org.objectweb.dream.message.manager.MessageManager; 37 import org.objectweb.fractal.api.NoSuchInterfaceException; 38 import org.objectweb.fractal.api.control.IllegalBindingException; 39 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 40 import org.objectweb.util.monolog.api.BasicLevel; 41 42 45 public class ConsumerImpl extends AbstractComponent implements Push 46 { 47 48 Push outPushItf; 49 MessageManager messageManagerItf; 50 MessageType msgType = new MessageTypeImpl(TestChunk.DEFAULT_NAME, 51 TestChunk.TYPE); 52 53 57 61 public void push(Message message, Map context) throws PushException 62 { 63 logger.log(BasicLevel.INFO, "Consumer receives message " + message); 64 65 TestChunk chunk = (TestChunk) message.getChunk(TestChunk.DEFAULT_NAME); 66 chunk.setMessage("Return message"); 67 68 try 69 { 70 Thread.sleep(2000); 71 } 72 catch (InterruptedException e) 73 { 74 throw new InterruptedPushException(e); 75 } 76 77 logger.log(BasicLevel.INFO, "Consumer sends return message"); 78 79 outPushItf.push(message, null); 80 } 81 82 86 90 public synchronized void bindFc(String clientItfName, Object serverItf) 91 throws NoSuchInterfaceException, IllegalBindingException, 92 IllegalLifeCycleException 93 { 94 super.bindFc(clientItfName, serverItf); 95 if (clientItfName.equals(Push.OUT_PUSH_ITF_NAME)) 96 { 97 outPushItf = (Push) serverItf; 98 } 99 else if (clientItfName.equals(MessageManager.ITF_NAME)) 100 { 101 messageManagerItf = (MessageManager) serverItf; 102 } 103 } 104 105 108 public String [] listFc() 109 { 110 return new String []{Push.OUT_PUSH_ITF_NAME, MessageManager.ITF_NAME}; 111 } 112 113 } | Popular Tags |