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.util.byteable.Byteable; 57 import org.mr.core.util.byteable.ByteableInputStream; 58 import org.mr.core.util.byteable.ByteableOutputStream; 59 import org.mr.core.util.byteable.ByteableRegistry; 60 61 70 public class ServiceProducer extends ServiceActor{ 79 public ServiceProducer(String agentName, String serviceName , byte serviceType) { 80 super(agentName, MantaAgent.getInstance().getDomainName(), serviceName ,serviceType ); 81 82 } 83 84 public ServiceProducer(String agentName, String domainName, String serviceName , byte serviceType) { 85 super(agentName, domainName, serviceName ,serviceType ); 86 } 87 88 91 public byte getType() { 92 return super.PRODUCER; 93 } 94 95 102 public static ServiceProducer createNew(MantaService service){ 103 if(service == null) 104 throw new IllegalArgumentException ("service is null" ); 105 106 String myAgentName = MantaAgent.getInstance().getAgentName(); 107 ServiceProducer result = new ServiceProducer(myAgentName ,service.getServiceName() , service.getServiceType()); 108 return result; 109 } 110 111 private final static String byteableName = "SProducer"; 112 113 116 public String getByteableName() { 117 118 return byteableName; 119 } 120 121 124 public void toBytes(ByteableOutputStream out) throws IOException { 125 out.writeASCIIString(getAgentName()); 126 out.writeUTF(getServiceName()); 127 out.writeByte(getServiceType()); 128 out.writeUTF(getId()); 129 130 } 131 132 135 public Byteable createInstance(ByteableInputStream in) throws IOException { 136 ServiceProducer result = null; 137 String agentName = in.readASCIIString(); 138 String serviceName = in.readUTF(); 139 byte serviceType = in.readByte(); 140 String id = in.readUTF(); 141 if(MantaAgent.started && MantaAgent.getInstance().containsService(serviceName)){ 142 MantaService localService = MantaAgent.getInstance().getService(serviceName,serviceType); 143 if(localService != null){ 144 result =(ServiceProducer) localService.getActor(id); 145 } 146 } 147 if(result == null){ 148 result = new ServiceProducer(agentName,serviceName ,serviceType); 149 result.id = id; 150 } 151 return result; 152 } 153 154 157 public void registerToByteableRegistry() { 158 ByteableRegistry.registerByteableFactory(getByteableName() , this); 159 } 160 161 165 public static void register(){ 166 ServiceProducer instance = new ServiceProducer(null , null, null, (byte)0); 167 instance.registerToByteableRegistry(); 168 } 169 } 170 | Popular Tags |