1 46 50 package org.mr.kernel.services; 51 52 53 54 import org.mr.kernel.UniqueIDGenerator; 55 import org.mr.core.net.MantaAddress; 56 57 66 public abstract class ServiceActor implements MantaAddress{ 70 public static final byte CONSUMER =1; 71 74 public static final byte PRODUCER =2; 75 78 public static final byte COORDINATOR =3; 79 80 83 private String agentName; 84 87 private String domainName; 88 91 private String serviceName; 92 93 96 private byte serviceType; 97 98 101 protected String id; 102 103 104 105 public ServiceActor(String agentName, String domainName, String serviceName , byte serviceType){ 106 this.agentName = agentName; 107 this.domainName = domainName; 108 this.serviceName = serviceName; 109 this.serviceType = serviceType; 110 StringBuffer idBuf = new StringBuffer (); 111 idBuf.append(agentName); 112 idBuf.append("@"); 113 idBuf.append(serviceName); 114 idBuf.append(serviceType); 115 idBuf.append(getType()); 116 idBuf.append(UniqueIDGenerator.getNextMessageID()); 117 this.id = idBuf.toString(); 118 } 119 120 public void setID(String id){ 121 this.id = id; 122 } 123 124 127 public abstract byte getType(); 128 129 130 133 public String getAgentName() { 134 return agentName; 135 } 136 137 140 public String getDomainName() { 141 return this.domainName; 142 } 143 144 147 public void setAgentName(String actorName) { 148 this.agentName = actorName; 149 } 150 153 public String toString(){ 154 StringBuffer buff = new StringBuffer (); 155 buff.append("ServiceActor{ service="); 156 buff.append(getServiceName()); 157 buff.append(" id="); 158 buff.append(getId()); 159 buff.append(" type="); 160 buff.append(getType()); 161 return buff.toString(); 162 } 163 164 167 public String getServiceName() { 168 return serviceName; 169 } 170 171 172 173 174 177 public String getId() { 178 179 return id; 180 } 181 182 185 public boolean equals(Object obj){ 186 if(this == obj) return true; 187 if (obj instanceof ServiceActor){ 188 ServiceActor other = (ServiceActor)obj; 189 if(other.getId().equalsIgnoreCase(this.getId())){ 190 return true; 191 } 192 193 } 194 return false; 195 } 196 197 public int hashCode(){ 198 return this.getId().toUpperCase().hashCode(); 200 } 201 202 203 public byte getServiceType() { 204 return serviceType; 205 } 206 } 207 | Popular Tags |