1 46 47 package org.mr.indexing.messages; 48 49 import java.io.IOException ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.Set ; 53 54 import org.mr.core.util.byteable.Byteable; 55 import org.mr.core.util.byteable.ByteableInputStream; 56 import org.mr.core.util.byteable.ByteableList; 57 import org.mr.core.util.byteable.ByteableMap; 58 import org.mr.core.util.byteable.ByteableOutputStream; 59 import org.mr.core.util.byteable.ByteableRegistry; 60 import org.mr.kernel.services.ServiceActor; 61 62 71 public class ServiceParticipationChanged implements Byteable { 72 private final static String typeString = "ServiceParticipationChanged"; 73 74 public final static String CONSUMER = "consumer"; 75 public final static String PRODUCER = "producer"; 76 public final static String COORDINATOR = "coordinator"; 77 public final static String TOPIC = "topic"; 78 public final static String QUEUE = "queue"; 79 80 private String domainName; 81 private String serviceName; 82 private String serviceType; 83 private byte operation; 86 private ByteableMap transports; 88 89 public String getDomainName() { 90 return this.domainName; 91 } 92 93 public String getServiceName() { 94 return this.serviceName; 95 } 96 97 public String getServiceType() { 98 return this.serviceType; 99 } 100 101 105 public byte getOperation() { 106 return this.operation; 107 } 108 109 public Set getActors() { 110 return this.transports.getUnderlineMap().keySet(); 111 } 112 113 public List getTransports(ServiceActor agent) { 114 return (List ) this.transports.get(agent); 115 } 116 117 public void setDomainName(String domainName) { 118 this.domainName = domainName; 119 } 120 121 public void setServiceName(String serviceName) { 122 this.serviceName = serviceName; 123 } 124 125 public void setServiceType(String serviceType) { 126 this.serviceType = serviceType; 127 } 128 129 133 public void setOperation(byte operation) { 134 this.operation = operation; 135 } 136 137 141 public void setTransports(ServiceActor agent, List transports) { 142 if (this.transports == null) { 143 this.transports = new ByteableMap(); 144 } 145 this.transports.put(agent, transports == null ? null : 146 new ByteableList(transports)); 147 } 148 149 public void setTransports(ByteableMap transports) { 150 this.transports = transports; 151 } 152 153 public String getByteableName() { 154 return "org.mr.indexing.messages.ServiceParticipationChanged"; 155 } 156 157 public void toBytes(ByteableOutputStream out) throws IOException { 158 out.writeASCIIString(this.domainName); 159 out.writeASCIIString(this.serviceName); 160 out.writeASCIIString(this.serviceType); 161 out.writeByte(this.operation); 164 out.writeByteable(this.transports); 166 } 167 168 public Byteable createInstance(ByteableInputStream in) throws IOException { 169 ServiceParticipationChanged result = new ServiceParticipationChanged(); 170 result.setDomainName(in.readASCIIString()); 171 result.setServiceName(in.readASCIIString()); 172 result.setServiceType(in.readASCIIString()); 173 result.setOperation(in.readByte()); 176 result.setTransports((ByteableMap) in.readByteable()); 177 return result; 178 } 179 180 public void registerToByteableRegistry() { 181 ByteableRegistry.registerByteableFactory(getByteableName(), this); 182 } 183 184 public static void register() { 185 ServiceParticipationChanged instance = 186 new ServiceParticipationChanged(); 187 instance.registerToByteableRegistry(); 188 } 189 190 public String toString() { 191 if (serviceName == null) { 192 return "MWB:SPC (null)"; 193 } else { 194 return "MWB:SPC op " + operation + " " + 195 serviceName + " " + transports.getUnderlineMap().size() + 196 " actors"; 197 } 198 } 199 200 public String detailedToString() { 201 if (serviceName == null) { 202 return "MWB:SPC (null)"; 203 } else { 204 StringBuffer ret = new StringBuffer (); 205 ret.append("MWB:SPC op ").append(operation). 206 append(" ").append(serviceName); 207 Iterator i = transports.getUnderlineMap().keySet().iterator(); 208 while (i.hasNext()) { 209 ret.append(" ").append(i.next()); 210 } 211 return ret.toString(); 212 } 213 } 214 215 public static final String getTypeString() { 216 return typeString; 217 } 218 } | Popular Tags |