1 46 50 package org.mr.kernel.services; 51 52 import java.io.IOException ; 53 54 import org.mr.MantaAgent; 55 import org.mr.MantaException; 56 import org.mr.core.protocol.RecipientAddress; 57 import org.mr.core.util.byteable.Byteable; 58 import org.mr.core.util.byteable.ByteableInputStream; 59 import org.mr.core.util.byteable.ByteableOutputStream; 60 import org.mr.core.util.byteable.ByteableRegistry; 61 62 71 public class ServiceConsumer extends ServiceActor implements RecipientAddress{ 73 private String selectorStatment; 74 private boolean durable = false; 75 private byte acknowledgeMode; 76 77 78 88 public ServiceConsumer(String agentName, String domainName, String serviceName, byte serviceType, byte acknowledgeMode ) { 89 super(agentName, domainName, serviceName, serviceType); 90 this.acknowledgeMode = acknowledgeMode; 91 durable = false; 92 } 93 94 105 public ServiceConsumer(String agentName, String domainName, String serviceName, byte serviceType, byte acknowledgeMode,String durableRecipientId ) { 106 super(agentName, domainName, serviceName, serviceType); 107 this.acknowledgeMode = acknowledgeMode; 108 durable = true; 109 this.id = durableRecipientId; 110 } 111 112 127 128 131 public byte getType() { 132 return CONSUMER; 133 } 134 135 136 137 140 public String getSelectorStatment() { 141 return selectorStatment; 142 } 143 144 148 public void setSelectorStatment(String selectorStatment) { 149 this.selectorStatment = selectorStatment; 150 } 151 152 153 156 public boolean isDurable() { 157 return durable; 158 } 159 160 163 public void setDurable(boolean durable) { 164 this.durable = durable; 165 } 166 167 private final static String byteableName = "SConsumer"; 168 171 public final String getByteableName() { 172 173 return byteableName; 174 } 175 176 180 public void toBytes(ByteableOutputStream out) throws IOException { 181 out.writeASCIIString(getAgentName()); 182 out.writeUTF(getServiceName()); 183 out.writeByte(getServiceType()); 184 out.writeByte(getAcknowledgeMode()); 185 out.writeUTF(getId()); 186 if(selectorStatment != null) 187 out.writeUTF(selectorStatment); 188 else 189 out.writeUTF(""); 190 out.writeBoolean(durable); 191 } 192 193 197 public Byteable createInstance(ByteableInputStream in) throws IOException { 198 ServiceConsumer result = null; 199 String agentName = in.readASCIIString(); 200 String serviceName = in.readUTF(); 201 byte serviceType = in.readByte(); 202 byte ackMode = in.readByte(); 203 String id = in.readUTF(); 204 String selectorStatment = in.readUTF(); 205 boolean durable = in.readBoolean(); 206 214 215 if(result == null){ 216 result = new ServiceConsumer(agentName,MantaAgent.getInstance().getDomainName(), serviceName, serviceType,ackMode); 217 result.id = id; 218 result.selectorStatment = selectorStatment; 219 result.durable = durable; 220 } 221 return result; 222 } 223 224 228 public void registerToByteableRegistry() { 229 ByteableRegistry.registerByteableFactory(getByteableName() , this); 230 } 231 236 public static void register(){ 237 ServiceConsumer instance = new ServiceConsumer(null, null, null, (byte)0, (byte)0); 238 instance.registerToByteableRegistry(); 239 } 240 241 public String toString(){ 244 StringBuffer buff = new StringBuffer (); 245 buff.append(super.toString()); 246 buff.append(" durability="); 247 buff.append(durable); 248 buff.append(" selector="); 249 buff.append(selectorStatment); 250 buff.append(" }"); 251 return buff.toString(); 252 } 253 public byte getAcknowledgeMode() { 254 return acknowledgeMode; 255 } 256 } 257 | Popular Tags |