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.IOPushException; 31 import org.objectweb.dream.InterruptedPushException; 32 import org.objectweb.dream.Push; 33 import org.objectweb.dream.PushException; 34 import org.objectweb.dream.message.Message; 35 import org.objectweb.dream.message.manager.MessageManager; 36 import org.objectweb.dream.protocol.Process; 37 import org.objectweb.dream.protocol.utobcast.message.UTOBcastChunk; 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 51 public class REPImpl extends AbstractComponent implements Push 52 { 53 54 58 62 public static final String PENDING_MESSAGES_IN_ITF_NAME = "pending-messages-in"; 63 64 65 protected Push pendingMessagesInItf; 66 67 68 protected Push outPushItf; 69 70 71 protected ProcessMembership processMembershipItf; 72 73 74 protected BackupElection backupElectionItf; 75 76 77 protected MessageManager messageManagerItf; 78 79 Object lock = new Object (); 80 81 85 88 public REPImpl() 89 { 90 } 91 92 96 100 public void push(Message message, Map context) throws PushException 101 { 102 if (logger.isLoggable(BasicLevel.DEBUG)) 103 { 104 logger.log(BasicLevel.DEBUG, "Received REP message " + message); 105 } 106 if (logger.isLoggable(BasicLevel.DEBUG)) 110 { 111 logger.log(BasicLevel.DEBUG, "Add REP message " + message 112 + " to PendingMessages"); 113 } 114 messageManagerItf.duplicateMessage(message, false); 115 pendingMessagesInItf.push(message, null); 116 117 Process [] processes = processMembershipItf.getOtherProcesses(); 121 UTOBcastChunk chunk = (UTOBcastChunk) message 122 .getChunk(UTOBcastChunk.DEFAULT_NAME); 123 chunk.setUTOBcastMessageType(UTOBcastChunk.UTO); 124 for (int i = 0; i < processes.length; i++) 125 { 126 chunk.setProcessTo(processes[i]); 130 if (logger.isLoggable(BasicLevel.DEBUG)) 131 { 132 logger.log(BasicLevel.DEBUG, "Send UTO message " + message 133 + " to process " + processes[i]); 134 } 135 try 136 { 137 messageManagerItf.duplicateMessage(message, false); 138 outPushItf.push(message, null); 139 } 140 catch (InterruptedPushException e) 141 { 142 throw e; 144 } 145 catch (IOPushException e) 146 { 147 processMembershipItf.removeProcess(processes[i]); 149 } 150 } 151 152 chunk.setUTOBcastMessageType(UTOBcastChunk.ACK); 156 157 try 158 { 159 Process leader = processMembershipItf.getLeader(); 160 if (logger.isLoggable(BasicLevel.DEBUG)) 161 { 162 logger.log(BasicLevel.DEBUG, "Send ACK message " + message 163 + " to process " + leader); 164 } 165 chunk.setProcessTo(leader); 166 } 167 catch (InterruptedException e1) 168 { 169 throw new InterruptedPushException(e1); 170 } 171 try 172 { 173 outPushItf.push(message, null); 175 } 176 catch (IOPushException e) 177 { 178 e.printStackTrace(); 181 } 182 183 } 184 185 189 193 public void bindFc(String clientItfName, Object serverItf) 194 throws NoSuchInterfaceException, IllegalBindingException, 195 IllegalLifeCycleException 196 { 197 super.bindFc(clientItfName, serverItf); 198 if (clientItfName.equals(PENDING_MESSAGES_IN_ITF_NAME)) 199 { 200 pendingMessagesInItf = (Push) serverItf; 201 } 202 else if (clientItfName.equals(Push.OUT_PUSH_ITF_NAME)) 203 { 204 outPushItf = (Push) serverItf; 205 } 206 else if (clientItfName.equals(ProcessMembership.ITF_NAME)) 207 { 208 processMembershipItf = (ProcessMembership) serverItf; 209 } 210 else if (clientItfName.equals(BackupElection.ITF_NAME)) 211 { 212 backupElectionItf = (BackupElection) serverItf; 213 } 214 else if (clientItfName.equals(MessageManager.ITF_NAME)) 215 { 216 messageManagerItf = (MessageManager) serverItf; 217 } 218 219 } 220 221 224 public String [] listFc() 225 { 226 return new String []{PENDING_MESSAGES_IN_ITF_NAME, Push.OUT_PUSH_ITF_NAME, 227 ProcessMembership.ITF_NAME, BackupElection.ITF_NAME, 228 MessageManager.ITF_NAME}; 229 } 230 231 }
| Popular Tags
|