1 46 package org.mr.api.jms; 47 48 import javax.jms.Destination ; 49 import javax.jms.JMSException ; 50 import javax.jms.Topic ; 51 52 import org.mr.MantaAgent; 53 import org.mr.MantaAgentConstants; 54 import org.mr.core.configuration.ConfigManager; 55 import org.mr.core.util.byteable.Byteable; 56 import org.mr.core.util.byteable.ByteableInputStream; 57 import org.mr.core.util.byteable.ByteableOutputStream; 58 import org.mr.core.util.byteable.ByteableRegistry; 59 import org.mr.kernel.services.topics.VirtualTopicManager; 60 61 import java.io.IOException ; 62 import java.io.Serializable ; 63 64 94 public class MantaTopic extends MantaDestination implements Serializable , Topic , Destination { 95 96 97 102 public MantaTopic(String name) throws JMSException { 103 setName(name); 104 } 106 110 public MantaTopic() { 111 this.destinationName = " "; 112 } 113 114 public void setName(String name) throws JMSException { 115 if(MantaAgent.isStarted()){ 116 MantaAgent.getInstance().getSingletonRepository() 117 .getVirtualTopicManager().validateTopicName(name); 118 } 119 120 this.destinationName = name; 121 } 122 123 124 128 public String toString() { 129 return this.destinationName; 130 } 132 135 public String getTopicName() { 136 return this.destinationName; 137 } 138 139 140 public static final String BYTEABLENAME = "MantaTopic"; 141 public String getByteableName() { 142 143 return BYTEABLENAME; 144 } 145 146 147 public void toBytes(ByteableOutputStream out) throws IOException { 148 149 out.writeUTF(this.destinationName); 150 151 } 152 153 public Byteable createInstance(ByteableInputStream in) throws IOException { 154 155 MantaTopic mt; 156 try { 157 mt = new MantaTopic(in.readUTF()); 158 } catch (JMSException e) { 159 throw new IOException ("Can't create topic: "+e.getMessage()); 160 } 161 return mt; 162 } 163 164 public void registerToByteableRegistry() { 165 ByteableRegistry.registerByteableFactory(getByteableName() , this); 166 167 } 168 169 public static void register() throws JMSException { 170 MantaTopic instance = new MantaTopic(); 171 instance.registerToByteableRegistry(); 172 } 173 174 175 176 } | Popular Tags |