1 25 package org.objectweb.joram.client.jms; 26 27 import java.net.ConnectException ; 28 import java.util.Vector ; 29 import java.util.Hashtable ; 30 import java.util.List ; 31 import java.util.Properties ; 32 33 import javax.jms.JMSException ; 34 import javax.naming.NamingException ; 35 36 import org.objectweb.joram.client.jms.admin.AdminException; 37 import org.objectweb.joram.client.jms.admin.AdminModule; 38 39 import org.objectweb.joram.shared.admin.*; 40 41 import org.objectweb.util.monolog.api.BasicLevel; 42 import org.objectweb.joram.shared.JoramTracing; 43 44 import fr.dyade.aaa.util.management.MXWrapper; 45 46 52 public class Topic extends Destination implements javax.jms.Topic , TopicMBean { 53 private final static String TOPIC_TYPE = "topic"; 54 55 public static boolean isTopic(String type) { 56 return Destination.isAssignableTo(type, TOPIC_TYPE); 57 } 58 59 public Topic() { 61 super(TOPIC_TYPE); 62 } 63 64 public Topic(String name) { 65 super(name, TOPIC_TYPE); 66 } 67 68 protected Topic(String name, String type) { 69 super(name, type); 70 } 71 72 78 public String getTopicName() throws JMSException { 79 return getName(); 80 } 81 82 99 public static Topic create(int serverId, 100 String name, 101 String className, 102 Properties prop) 103 throws ConnectException , AdminException { 104 Topic topic = new Topic(); 105 doCreate(serverId, name, className, prop, topic, TOPIC_TYPE); 106 107 StringBuffer buff = new StringBuffer (); 108 buff.append("type=").append(TOPIC_TYPE); 109 buff.append(",name=").append(name); 110 try { 111 MXWrapper.registerMBean(topic, "joramClient", buff.toString()); 112 } catch (Exception e) { 113 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 114 JoramTracing.dbgClient.log(BasicLevel.DEBUG, "registerMBean", e); 115 } 116 return topic; 117 } 118 119 132 public static Topic create(int serverId, 133 String className, 134 Properties prop) 135 throws ConnectException , AdminException { 136 return create(serverId, null, className, prop); 137 } 138 139 152 public static Topic create(int serverId, Properties prop) 153 throws ConnectException , AdminException { 154 return create(serverId, "org.objectweb.joram.mom.dest.Topic", prop); 155 } 156 157 172 public static Topic create(int serverId, String name) 173 throws ConnectException , AdminException { 174 return create(serverId, name, "org.objectweb.joram.mom.dest.Topic", null); 175 } 176 177 190 public static Topic create(String name) 191 throws ConnectException , AdminException { 192 return create(AdminModule.getLocalServerId(), 193 name, 194 "org.objectweb.joram.mom.dest.Topic", 195 null); 196 } 197 198 209 public static Topic create(int serverId) 210 throws ConnectException , AdminException { 211 return create(serverId, null, "org.objectweb.joram.mom.dest.Topic", null); 212 } 213 214 222 public static Topic create() throws ConnectException , AdminException { 223 return create(AdminModule.getLocalServerId()); 224 } 225 226 235 public Topic getHierarchicalFather() throws ConnectException , AdminException 236 { 237 Monitor_GetFather request = new Monitor_GetFather(agentId); 238 Monitor_GetFatherRep reply = 239 (Monitor_GetFatherRep) AdminModule.doRequest(request); 240 241 if (reply.getFatherId() == null) 242 return null; 243 else 244 return new Topic(reply.getFatherId()); 245 } 246 247 256 public List getClusterFellows() throws ConnectException , AdminException 257 { 258 Monitor_GetCluster request = new Monitor_GetCluster(agentId); 259 Monitor_GetClusterRep reply = 260 (Monitor_GetClusterRep) AdminModule.doRequest(request); 261 262 Vector topics = reply.getTopics(); 263 Vector list = new Vector (); 264 for (int i = 0; i < topics.size(); i++) 265 list.add(new Topic((String ) topics.get(i))); 266 return list; 267 } 268 269 279 public int getSubscriptions() throws ConnectException , AdminException 280 { 281 Monitor_GetSubscriptions request = new Monitor_GetSubscriptions(agentId); 282 Monitor_GetNumberRep reply = 283 (Monitor_GetNumberRep) AdminModule.doRequest(request); 284 return reply.getNumber(); 285 } 286 287 public String [] getSubscriberIds() 288 throws AdminException, ConnectException { 289 GetSubscriberIdsRep reply = 290 (GetSubscriberIdsRep)AdminModule.doRequest( 291 new GetSubscriberIds(agentId)); 292 return reply.getSubscriberIds(); 293 } 294 295 308 public void addClusteredTopic(Topic addedTopic) 309 throws ConnectException , AdminException 310 { 311 AdminModule.doRequest( 312 new SetCluster(agentId, 313 addedTopic.getName())); 314 } 315 316 325 public void removeFromCluster() 326 throws ConnectException , AdminException 327 { 328 AdminModule.doRequest(new UnsetCluster(agentId)); 329 } 330 331 343 public void setParent(Topic parent) 344 throws ConnectException , AdminException { 345 if (parent == null) 346 unsetParent(); 347 AdminModule.doRequest( 348 new SetFather(parent.getName(), agentId)); 349 } 350 351 360 public void unsetParent() 361 throws ConnectException , AdminException { 362 AdminModule.doRequest(new UnsetFather(agentId)); 363 } 364 } 365 | Popular Tags |