1 46 51 package org.mr.kernel.services.queues; 52 53 import java.io.IOException ; 54 55 import org.mr.MantaAgent; 56 import org.mr.MantaAgentConstants; 57 import org.mr.core.protocol.RecipientAddress; 58 import org.mr.core.util.byteable.Byteable; 59 import org.mr.core.util.byteable.ByteableInputStream; 60 import org.mr.core.util.byteable.ByteableOutputStream; 61 import org.mr.core.util.byteable.ByteableRegistry; 62 import org.mr.kernel.services.MantaService; 63 import org.mr.kernel.services.ServiceActor; 64 65 73 public class QueueMaster extends ServiceActor implements RecipientAddress{ 74 private long validUntil; 75 76 80 public QueueMaster(String agentName, String serviceName) { 81 super(agentName, MantaAgent.getInstance().getDomainName(), serviceName, MantaService.SERVICE_TYPE_QUEUE); 82 } 83 84 public QueueMaster(String agentName, String domainName, String serviceName) { 85 super(agentName, domainName, serviceName, MantaService.SERVICE_TYPE_QUEUE); 86 } 87 88 91 public byte getType() { 92 return ServiceActor.COORDINATOR; 93 } 94 95 private final static String byteableName = "QM"; 96 97 100 public String getByteableName() { 101 102 return byteableName; 103 } 104 105 106 109 public void toBytes(ByteableOutputStream out) throws IOException { 110 out.writeASCIIString(getAgentName()); 111 out.writeUTF(getServiceName()); 112 out.writeByte(MantaService.SERVICE_TYPE_QUEUE); 113 out.writeUTF(getId()); 114 115 } 116 117 120 public Byteable createInstance(ByteableInputStream in) throws IOException { 121 QueueMaster result = null; 122 String agentName = in.readASCIIString(); 123 String serviceName = in.readUTF(); 124 in.readByte(); String id = in.readUTF(); 126 result = new QueueMaster(agentName,serviceName); 127 result.id = id; 128 129 return result; 130 } 131 132 135 public void registerToByteableRegistry() { 136 ByteableRegistry.registerByteableFactory(getByteableName() , this); 137 138 } 139 140 public static void register(){ 141 QueueMaster instance = new QueueMaster("","",""); 142 instance.registerToByteableRegistry(); 143 } 144 145 public long getValidUntil() { 146 return validUntil; 147 } 148 149 public void setValidUntil(long validUntil) { 150 this.validUntil = validUntil; 151 } 152 153 public byte getAcknowledgeMode() { 154 return MantaAgentConstants.CLIENT_ACK; 155 } 156 } 157 | Popular Tags |