1 24 package org.objectweb.joram.client.jms.admin; 25 26 import java.util.Vector ; 27 import java.util.Hashtable ; 28 import java.util.List ; 29 import java.net.ConnectException ; 30 31 import javax.naming.*; 32 33 import javax.jms.JMSException ; 34 35 import fr.dyade.aaa.util.management.MXWrapper; 36 import org.objectweb.joram.client.jms.Message; 37 import org.objectweb.joram.shared.admin.*; 38 39 import org.objectweb.joram.shared.JoramTracing; 40 import org.objectweb.util.monolog.api.BasicLevel; 41 42 46 public class User extends AdministeredObject implements UserMBean { 47 48 String name; 49 50 String proxyId; 51 52 public User() {} 54 55 61 public User(String name, String proxyId) { 62 this.name = name; 63 this.proxyId = proxyId; 64 } 65 66 67 68 public String toString() { 69 return "User[" + name + "]:" + proxyId; 70 } 71 72 73 74 public String getName() { 75 return name; 76 } 77 78 79 public boolean equals(Object o) { 80 if (! (o instanceof User)) 81 return false; 82 83 User other = (User) o; 84 85 return other.proxyId ==proxyId; 86 } 87 88 104 public static User create(String name, String password, int serverId) 105 throws ConnectException , AdminException { 106 AdminReply reply = AdminModule.doRequest( 107 new CreateUserRequest(name, password, serverId)); 108 User user = new User(name, ((CreateUserReply) reply).getProxId()); 109 try { 110 MXWrapper.registerMBean(user, 111 "joramClient", 112 "type=User,name="+name+ 113 "["+user.getProxyId()+"]"); 114 } catch (Exception e) { 115 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 116 JoramTracing.dbgClient.log(BasicLevel.DEBUG, 117 "registerMBean",e); 118 } 119 return user; 120 } 121 122 136 public static User create(String name, String password) 137 throws ConnectException , AdminException { 138 return create(name, password, AdminModule.getLocalServerId()); 139 } 140 141 153 public void update(String newName, String newPassword) 154 throws ConnectException , AdminException { 155 AdminModule.doRequest(new UpdateUser(name, proxyId, newName, newPassword)); 156 name = newName; 157 } 158 159 165 public void delete() throws ConnectException , AdminException { 166 AdminModule.doRequest(new DeleteUser(name, proxyId)); 167 try { 168 MXWrapper.unregisterMBean("joramClient", 169 "type=User,name="+name+ 170 "["+proxyId+"]"); 171 } catch (Exception e) { 172 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 173 JoramTracing.dbgClient.log(BasicLevel.DEBUG, 174 "unregisterMBean",e); 175 } 176 } 177 178 188 public void setDMQ(DeadMQueue dmq) throws ConnectException , AdminException { 189 AdminModule.doRequest(new SetUserDMQ(proxyId, dmq.getName())); 190 } 191 192 202 public void setThreshold(int thresh) throws ConnectException , AdminException { 203 AdminModule.doRequest(new SetUserThreshold(proxyId, thresh)); 204 } 205 206 214 public DeadMQueue getDMQ() throws ConnectException , AdminException { 215 Monitor_GetDMQSettings request; 216 request = new Monitor_GetDMQSettings(proxyId); 217 Monitor_GetDMQSettingsRep reply; 218 reply = (Monitor_GetDMQSettingsRep) AdminModule.doRequest(request); 219 220 if (reply.getDMQName() == null) 221 return null; 222 else 223 return new DeadMQueue(reply.getDMQName()); 224 } 225 226 234 public int getThreshold() throws ConnectException , AdminException { 235 Monitor_GetDMQSettings request; 236 request = new Monitor_GetDMQSettings(proxyId); 237 Monitor_GetDMQSettingsRep reply; 238 reply = (Monitor_GetDMQSettingsRep) AdminModule.doRequest(request); 239 240 if (reply.getThreshold() == null) 241 return -1; 242 else 243 return reply.getThreshold().intValue(); 244 } 245 246 257 public void setNbMaxMsg(String subName, int nbMaxMsg) 258 throws ConnectException , AdminException { 259 Subscription sub = getSubscription(subName); 260 AdminModule.doRequest(new SetNbMaxMsg(proxyId, nbMaxMsg, subName)); 261 } 262 263 273 public int getNbMaxMsg(String subName) 274 throws ConnectException , AdminException { 275 Subscription sub = getSubscription(subName); 276 Monitor_GetNbMaxMsg request = new Monitor_GetNbMaxMsg(proxyId, subName); 277 Monitor_GetNbMaxMsgRep reply; 278 reply = (Monitor_GetNbMaxMsgRep) AdminModule.doRequest(request); 279 return reply.getNbMaxMsg(); 280 } 281 282 295 public Subscription[] getSubscriptions() 296 throws AdminException, ConnectException { 297 GetSubscriptionsRep reply = 298 (GetSubscriptionsRep)AdminModule.doRequest( 299 new GetSubscriptions(proxyId)); 300 String [] subNames = reply.getSubNames(); 301 String [] topicIds = reply.getTopicIds(); 302 int[] messageCounts = reply.getMessageCounts(); 303 boolean[] durable = reply.getDurable(); 304 Subscription[] res = new Subscription[subNames.length]; 305 for (int i = 0; i < res.length; i++) { 306 res[i] = new Subscription(subNames[i], 307 topicIds[i], 308 messageCounts[i], 309 durable[i]); 310 } 311 return res; 312 } 313 314 315 public List getSubscriptionList() 316 throws AdminException, ConnectException { 317 Vector list = new Vector (); 318 Subscription[] sub = getSubscriptions(); 319 for (int i = 0; i < sub.length; i++) { 320 list.add(sub[i].toString()); 321 } 322 return list; 323 } 324 325 340 public Subscription getSubscription(String subName) 341 throws AdminException, ConnectException { 342 GetSubscriptionRep reply = 343 (GetSubscriptionRep)AdminModule.doRequest( 344 new GetSubscription(proxyId, subName)); 345 return new Subscription( 346 subName, 347 reply.getTopicId(), 348 reply.getMessageCount(), 349 reply.getDurable()); 350 } 351 352 public String getSubscriptionString(String subName) 353 throws AdminException, ConnectException { 354 Subscription sub = getSubscription(subName); 355 return sub.toString(); 356 } 357 358 public String [] getMessageIds(String subName) 359 throws AdminException, ConnectException { 360 GetSubscriptionMessageIdsRep reply = 361 (GetSubscriptionMessageIdsRep)AdminModule.doRequest( 362 new GetSubscriptionMessageIds(proxyId, subName)); 363 return reply.getMessageIds(); 364 } 365 366 public Message readMessage(String subName, 367 String msgId) throws AdminException, ConnectException , JMSException { 368 GetSubscriptionMessageRep reply = 369 (GetSubscriptionMessageRep) AdminModule.doRequest( 370 new GetSubscriptionMessage(proxyId, 371 subName, 372 msgId)); 373 return Message.wrapMomMessage(null, reply.getMessage()); 374 } 375 376 public void deleteMessage( 377 String subName, 378 String msgId) 379 throws AdminException, ConnectException { 380 AdminModule.doRequest( 381 new DeleteSubscriptionMessage(proxyId, 382 subName, 383 msgId)); 384 } 385 386 public void clearSubscription(String subName) 387 throws AdminException, ConnectException { 388 AdminModule.doRequest( 389 new ClearSubscription(proxyId, 390 subName)); 391 } 392 393 394 395 public String getProxyId() { 396 return proxyId; 397 } 398 399 400 public void toReference(Reference ref) throws NamingException { 401 ref.add(new StringRefAddr("user.name", name)); 402 ref.add(new StringRefAddr("user.id", proxyId)); 403 } 404 405 406 public void fromReference(Reference ref) throws NamingException { 407 name = (String ) ref.get("user.name").getContent(); 408 proxyId = (String ) ref.get("user.id").getContent(); 409 } 410 411 415 public Hashtable code() { 416 Hashtable h = new Hashtable (); 417 h.put("name",name); 418 h.put("proxyId",proxyId); 419 return h; 420 } 421 422 425 public void decode(Hashtable h) { 426 name = (String ) h.get("name"); 427 proxyId = (String ) h.get("proxyId"); 428 } 429 } 430 | Popular Tags |