1 46 package org.mr.core.protocol; 47 48 import java.io.IOException ; 49 import java.util.HashMap ; 50 51 import org.mr.MantaAgentConstants; 52 import org.mr.core.util.byteable.Byteable; 53 import org.mr.core.util.byteable.ByteableInputStream; 54 import org.mr.core.util.byteable.ByteableOutputStream; 55 import org.mr.core.util.byteable.ByteableRegistry; 56 57 64 public class DeadEndRecipient implements RecipientAddress { 65 private String agentName; 66 private String domain; 67 private static HashMap deadEndRecipientMap = new HashMap (); 68 69 70 private DeadEndRecipient(){}; 71 72 private DeadEndRecipient(String agentName , String domain){ 73 this.agentName = agentName; 74 this.domain = domain; 75 } 76 77 public static DeadEndRecipient createDeadEndRecipient(String agentName , String domain){ 78 String globalName = agentName+domain; 79 DeadEndRecipient result = (DeadEndRecipient) deadEndRecipientMap.get(globalName); 80 if(result == null){ 81 result = new DeadEndRecipient(agentName , domain); 82 deadEndRecipientMap.put(globalName , result); 83 } 84 85 return result; 86 } 87 88 public byte getAcknowledgeMode() { 89 return MantaAgentConstants.NO_ACK; 90 } 91 92 public String getAgentName() { 93 94 return agentName; 95 } 96 97 public String getDomainName() { 98 return domain; 99 } 100 101 public String getByteableName() { 102 103 return "DERecip"; 104 } 105 106 public void toBytes(ByteableOutputStream out) throws IOException { 107 out.writeASCIIString(agentName); 108 out.writeASCIIString(domain); 109 } 110 111 public Byteable createInstance(ByteableInputStream in) throws IOException { 112 String agentName = in.readASCIIString(); 113 String domain = in.readASCIIString(); 114 return createDeadEndRecipient(agentName ,domain ); 115 } 116 117 120 public void registerToByteableRegistry() { 121 ByteableRegistry.registerByteableFactory(getByteableName() , this); 122 123 } 124 125 public static void register(){ 126 DeadEndRecipient instance = new DeadEndRecipient(); 127 instance.registerToByteableRegistry(); 128 } 129 130 public String getId() { 131 return agentName; 132 } 133 134 public String toString() { 135 return "DeadEnd:" + agentName; 136 } 137 } 138 | Popular Tags |