1 24 25 package org.objectweb.dream.protocol.utobcast; 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.Message; 34 import org.objectweb.dream.protocol.utobcast.message.UTOBcastChunk; 35 import org.objectweb.fractal.api.NoSuchInterfaceException; 36 import org.objectweb.fractal.api.control.IllegalBindingException; 37 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 40 46 public class DeliveredMessageRouterImpl extends AbstractComponent 47 implements 48 Push 49 { 50 51 55 56 Push localMessageItf; 57 Push remoteMessageItf; 58 ProcessMembership processMembershipItf; 59 60 short myProcessId; 61 boolean configured = false; 62 63 static final String LOCAL_MESSAGE_ITF_NAME = "local-message"; 64 static final String REMOTE_MESSAGE_ITF_NAME = "remote-message"; 65 66 70 73 public DeliveredMessageRouterImpl() 74 { 75 } 76 77 81 85 public void push(Message message, Map context) throws PushException 86 { 87 if (!configured) 88 { 89 try 90 { 91 configure(); 92 } 93 catch (InterruptedException e) 94 { 95 throw new InterruptedPushException(e); 96 } 97 } 98 UTOBcastChunk chunk = (UTOBcastChunk) message 99 .getChunk(UTOBcastChunk.DEFAULT_NAME); 100 101 if (chunk.getProcessFrom().getId() == myProcessId) 102 { 103 if (logger.isLoggable(BasicLevel.DEBUG)) 104 { 105 logger.log(BasicLevel.DEBUG, "Deliver a local message " + message); 106 } 107 localMessageItf.push(message, context); 108 } 109 else 110 { 111 if (logger.isLoggable(BasicLevel.DEBUG)) 112 { 113 logger.log(BasicLevel.DEBUG, "Deliver a remote message " + message); 114 } 115 remoteMessageItf.push(message, context); 116 } 117 } 118 119 123 void configure() throws InterruptedException 124 { 125 myProcessId = processMembershipItf.getMyself().getId(); 126 configured = true; 127 } 128 129 133 137 public void bindFc(String clientItfName, Object serverItf) 138 throws NoSuchInterfaceException, IllegalBindingException, 139 IllegalLifeCycleException 140 { 141 super.bindFc(clientItfName, serverItf); 142 if (clientItfName.equals(LOCAL_MESSAGE_ITF_NAME)) 143 { 144 localMessageItf = (Push) serverItf; 145 } 146 else if (clientItfName.equals(REMOTE_MESSAGE_ITF_NAME)) 147 { 148 remoteMessageItf = (Push) serverItf; 149 } 150 else if (clientItfName.equals(ProcessMembership.ITF_NAME)) 151 { 152 processMembershipItf = (ProcessMembership) serverItf; 153 } 154 155 } 156 157 160 public String [] listFc() 161 { 162 return new String []{LOCAL_MESSAGE_ITF_NAME, REMOTE_MESSAGE_ITF_NAME, 163 ProcessMembership.ITF_NAME}; 164 } 165 166 } | Popular Tags |