1 24 25 package org.objectweb.dream.protocol.causality; 26 27 import java.util.Map ; 28 29 import org.objectweb.dream.AbstractComponent; 30 import org.objectweb.dream.Push; 31 import org.objectweb.dream.PushException; 32 import org.objectweb.dream.message.ChunkAlreadyExistsException; 33 import org.objectweb.dream.message.ExtensibleMessage; 34 import org.objectweb.dream.message.Message; 35 import org.objectweb.dream.message.manager.MessageManager; 36 import org.objectweb.dream.protocol.ArrowChunk; 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 OutMessageStamperImpl extends AbstractComponent 46 implements 47 Push, 48 CausalityTransformerAttributeController 49 { 50 51 private MessageManager messageManagerItf; 52 private MatrixClock matrixClockItf; 53 private Push outPushItf; 54 55 private String arrowChunkName; 56 private String causalityChunkName; 57 58 61 public void push(Message message, Map context) throws PushException 62 { 63 ArrowChunk arrowChunk = (ArrowChunk) message.getChunk(arrowChunkName); 64 65 if (arrowChunk == null) 66 { 67 logger.log(BasicLevel.ERROR, "Unable to find arrow chunk named " 68 + arrowChunkName + ". The message is dropped"); 69 return; 70 } 71 72 CausalityChunk csltChunk = (CausalityChunk) message 73 .getChunk(causalityChunkName); 74 if (csltChunk == null) 75 { 76 if (message instanceof ExtensibleMessage) 77 { 78 csltChunk = (CausalityChunk) messageManagerItf 79 .createChunk(CausalityChunk.TYPE); 80 try 81 { 82 ((ExtensibleMessage) message).addChunk(causalityChunkName, 83 CausalityChunk.TYPE, csltChunk); 84 } 85 catch (ChunkAlreadyExistsException e) 86 { 87 } 89 } 90 else 91 { 92 logger 93 .log( 94 BasicLevel.ERROR, 95 "Unable to find causality chunk in the unextensible message. The message is dropped"); 96 return; 97 } 98 } 99 Object stamp = matrixClockItf.getStamp(arrowChunk.getProcessIdFrom(), 100 arrowChunk.getProcessIdTo()); 101 csltChunk.setCausalityStamp(stamp); 102 outPushItf.push(message, context); 103 } 104 105 109 112 public String getArrowChunkName() 113 { 114 return arrowChunkName; 115 } 116 117 120 public void setArrowChunkName(String arrowChunkName) 121 { 122 this.arrowChunkName = arrowChunkName; 123 } 124 125 128 public String getCausalityChunkName() 129 { 130 return causalityChunkName; 131 } 132 133 136 public void setCausalityChunkName(String causalityChunkName) 137 { 138 this.causalityChunkName = causalityChunkName; 139 } 140 141 145 148 public String [] listFc() 149 { 150 return new String []{Push.OUT_PUSH_ITF_NAME, 151 MatrixClock.MATRIX_CLOCK_ITF_NAME, MessageManager.ITF_NAME}; 152 } 153 154 158 public synchronized void bindFc(String clientItfName, Object serverItf) 159 throws NoSuchInterfaceException, IllegalBindingException, 160 IllegalLifeCycleException 161 { 162 super.bindFc(clientItfName, serverItf); 163 if (clientItfName.equals(MatrixClock.MATRIX_CLOCK_ITF_NAME)) 164 { 165 matrixClockItf = (MatrixClock) serverItf; 166 } 167 else if (clientItfName.equals(Push.OUT_PUSH_ITF_NAME)) 168 { 169 outPushItf = (Push) serverItf; 170 } 171 else if (clientItfName.equals(MessageManager.ITF_NAME)) 172 { 173 messageManagerItf = (MessageManager) serverItf; 174 } 175 } 176 177 } | Popular Tags |