1 22 package org.jboss.mq.server.jmx; 23 24 import java.util.ArrayList ; 25 import java.util.HashMap ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import java.util.StringTokenizer ; 29 30 import javax.management.Attribute ; 31 import javax.management.MBeanServer ; 32 import javax.management.MalformedObjectNameException ; 33 import javax.management.ObjectName ; 34 import javax.transaction.xa.Xid ; 35 36 import org.jboss.mq.MessageStatistics; 37 import org.jboss.mq.pm.PersistenceManager; 38 import org.jboss.mq.pm.TxManager; 39 import org.jboss.mq.server.BasicQueueParameters; 40 import org.jboss.mq.server.JMSDestinationManager; 41 import org.jboss.mq.server.JMSServerInterceptor; 42 import org.jboss.mq.server.MessageCache; 43 import org.jboss.mq.server.MessageCounter; 44 import org.jboss.mq.server.Receivers; 45 import org.jboss.mq.sm.StateManager; 46 import org.jboss.mx.util.MBeanProxyExt; 47 import org.jboss.system.ServiceControllerMBean; 48 import org.jboss.system.ServiceMBeanSupport; 49 import org.jboss.util.JBossStringBuilder; 50 import org.jboss.util.threadpool.BasicThreadPool; 51 import org.jboss.util.threadpool.ThreadPool; 52 53 62 public class DestinationManager extends InterceptorMBeanSupport implements DestinationManagerMBean 63 { 64 public String jndiBindLocation = "java:/JBossMQServer"; 65 66 67 private ServiceControllerMBean serviceController; 68 69 private ObjectName mqService; 70 71 protected JMSDestinationManager jmsServer; 72 73 private ObjectName persistenceManager; 74 75 private ObjectName stateManager; 76 77 private ObjectName messageCache; 78 79 protected BasicQueueParameters tempParameters = new BasicQueueParameters(); 80 81 private ObjectName threadPool; 82 83 private ObjectName expiryDestination; 84 85 89 public int getClientCount() 90 { 91 if (jmsServer == null) 92 return 0; 93 return jmsServer.getClientCount(); 94 } 95 99 public Map getClients() 100 { 101 if (jmsServer == null) 102 return null; 103 return jmsServer.getClients(); 104 } 105 106 112 public ObjectName getPersistenceManager() 113 { 114 return persistenceManager; 115 } 116 117 123 public void setPersistenceManager(ObjectName objectName) 124 { 125 this.persistenceManager = objectName; 126 } 127 128 134 public ObjectName getStateManager() 135 { 136 return stateManager; 137 } 138 139 145 public void setStateManager(ObjectName objectName) 146 { 147 this.stateManager = objectName; 148 } 149 150 156 public ObjectName getMessageCache() 157 { 158 return messageCache; 159 } 160 161 167 public void setMessageCache(ObjectName objectName) 168 { 169 this.messageCache = objectName; 170 } 171 172 177 public int getTemporaryMaxDepth() 178 { 179 return tempParameters.maxDepth; 180 } 181 182 187 public void setTemporaryMaxDepth(int depth) 188 { 189 tempParameters.maxDepth = depth; 190 } 191 192 197 public boolean getTemporaryInMemory() 198 { 199 return tempParameters.inMemory; 200 } 201 202 207 public void setTemporaryInMemory(boolean mode) 208 { 209 tempParameters.inMemory = mode; 210 } 211 212 218 public Class getReceiversImpl() 219 { 220 return tempParameters.receiversImpl; 221 } 222 223 229 public void setReceiversImpl(Class clazz) 230 { 231 if (clazz != null && Receivers.class.isAssignableFrom(clazz) == false) 232 throw new IllegalArgumentException ("Class " + clazz.getName() + " is not a Receivers implementation"); 233 tempParameters.receiversImpl = clazz; 234 } 235 236 public int getRecoveryRetries() 237 { 238 return tempParameters.recoveryRetries; 239 } 240 241 public void setRecoveryRetries(int retries) 242 { 243 tempParameters.recoveryRetries = retries; 244 } 245 246 public ObjectName getThreadPool() 247 { 248 return this.threadPool; 249 } 250 251 public void setThreadPool(ObjectName threadPool) 252 { 253 this.threadPool = threadPool; 254 } 255 256 public ObjectName getExpiryDestination() 257 { 258 return expiryDestination; 259 } 260 261 public void setExpiryDestination(ObjectName expiryDestination) 262 { 263 this.expiryDestination = expiryDestination; 264 } 265 266 269 public void createQueue(String name) throws Exception 270 { 271 createDestination("org.jboss.mq.server.jmx.Queue", getQueueObjectName(name), null); 272 } 273 274 277 public void createTopic(String name) throws Exception 278 { 279 createDestination("org.jboss.mq.server.jmx.Topic", getTopicObjectName(name), null); 280 } 281 282 285 public void createQueue(String name, String jndiLocation) throws Exception 286 { 287 createDestination("org.jboss.mq.server.jmx.Queue", getQueueObjectName(name), jndiLocation); 288 } 289 290 293 public void createTopic(String name, String jndiLocation) throws Exception 294 { 295 createDestination("org.jboss.mq.server.jmx.Topic", getTopicObjectName(name), jndiLocation); 296 } 297 298 protected void createDestination(String type, ObjectName name, String jndiLocation) throws Exception 302 { 303 log.debug("Attempting to create destination: " + name + "; type=" + type); 304 305 server.createMBean(type, name); 306 server.setAttribute(name, new Attribute ("DestinationManager", mqService)); 307 if (jndiLocation != null) 308 server.setAttribute(name, new Attribute ("JNDIName", jndiLocation)); 309 310 ArrayList depends = new ArrayList (); 312 depends.add(serviceName); 313 314 serviceController.create(name, depends); 315 serviceController.start(name); 316 } 317 318 321 public void destroyQueue(String name) throws Exception 322 { 323 destroyDestination(getQueueObjectName(name)); 324 } 325 326 329 public void destroyTopic(String name) throws Exception 330 { 331 destroyDestination(getTopicObjectName(name)); 332 } 333 334 protected void destroyDestination(ObjectName name) throws Exception 335 { 336 if (log.isDebugEnabled()) 337 { 338 log.debug("Attempting to destroy destination: " + name); 339 } 340 341 serviceController.stop(name); 342 343 server.invoke(name, "removeAllMessages", new Object [] { 344 }, new String [] { 345 }); 346 serviceController.destroy(name); 347 serviceController.remove(name); 348 } 349 350 protected ObjectName getObjectName(MBeanServer server, ObjectName name) throws MalformedObjectNameException 351 { 352 mqService = name; 354 return mqService; 355 } 356 357 protected ObjectName getTopicObjectName(String name) throws MalformedObjectNameException 358 { 359 return new ObjectName (mqService.getDomain() + ".destination:service=Topic,name=" + name); 360 } 361 362 protected ObjectName getQueueObjectName(String name) throws MalformedObjectNameException 363 { 364 return new ObjectName (mqService.getDomain() + ".destination:service=Queue,name=" + name); 365 } 366 367 protected ServiceControllerMBean getServiceController() 368 { 369 return serviceController; 370 } 371 372 375 public JMSServerInterceptor getInterceptor() 376 { 377 return jmsServer; 378 } 379 380 383 protected void createService() throws Exception 384 { 385 super.createService(); 386 jmsServer = new JMSDestinationManager(tempParameters); 387 } 388 389 protected void startService() throws Exception 390 { 391 serviceController = 393 (ServiceControllerMBean) MBeanProxyExt.create( 394 ServiceControllerMBean.class, 395 ServiceControllerMBean.OBJECT_NAME, 396 server); 397 398 PersistenceManager pm = (PersistenceManager) server.getAttribute(persistenceManager, "Instance"); 399 jmsServer.setPersistenceManager(pm); 400 401 StateManager sm = (StateManager) server.getAttribute(stateManager, "Instance"); 402 jmsServer.setStateManager(sm); 403 404 MessageCache mc; 407 if (messageCache != null) 408 mc = (MessageCache) server.getAttribute(messageCache, "Instance"); 409 else 410 mc = pm.getMessageCacheInstance(); 411 jmsServer.setMessageCache(mc); 412 413 ThreadPool tp; 414 ThreadGroup tg; 415 if (threadPool == null) 416 { 417 tg = new ThreadGroup ("JBossMQ Server Threads"); 418 tp = new BasicThreadPool("JMSThread", tg); 419 } 420 else 421 { 422 tp = (ThreadPool) server.getAttribute(threadPool, "Instance"); 423 if (tp instanceof BasicThreadPool) 424 tg = ((BasicThreadPool)tp).getThreadGroup(); 425 else 426 tg = new ThreadGroup ("JBossMQ Server Threads"); 427 } 428 jmsServer.setThreadPool(tp); 429 jmsServer.setThreadGroup(tg); 430 431 jmsServer.startServer(); 432 433 super.startService(); 434 } 435 436 protected void stopService() 437 { 438 jmsServer.stopServer(); 439 } 440 441 protected void destroyService() throws Exception 442 { 443 super.destroyService(); 444 jmsServer = null; 445 } 446 447 455 public void setMessageCounterHistoryDayLimit( int days ) 456 { 457 if( days < -1 ) 458 days = -1; 459 460 tempParameters.messageCounterHistoryDayLimit = days; 461 462 } 463 464 470 public int getMessageCounterHistoryDayLimit() 471 { 472 return tempParameters.messageCounterHistoryDayLimit; 473 } 474 475 480 public MessageCounter[] getMessageCounter() throws Exception 481 { 482 if (jmsServer == null) 483 return null; 484 return jmsServer.getMessageCounter(); 485 } 486 487 492 public MessageStatistics[] getMessageStatistics() throws Exception 493 { 494 if (jmsServer == null) 495 return null; 496 return MessageCounter.getMessageStatistics(jmsServer.getMessageCounter()); 497 } 498 499 504 public String listMessageCounter() throws Exception 505 { 506 if (jmsServer == null) 507 return null; 508 MessageCounter[] counter = jmsServer.getMessageCounter(); 509 510 String ret = 511 "<table width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">" 512 + "<tr>" 513 + "<th>Type</th>" 514 + "<th>Name</th>" 515 + "<th>Subscription</th>" 516 + "<th>Durable</th>" 517 + "<th>Count</th>" 518 + "<th>CountDelta</th>" 519 + "<th>Depth</th>" 520 + "<th>DepthDelta</th>" 521 + "<th>Last Add</th>" 522 + "</tr>"; 523 524 String strNameLast = null; 525 String strTypeLast = null; 526 String strDestLast = null; 527 528 String destData = ""; 529 int destCount = 0; 530 531 int countTotal = 0; 532 int countDeltaTotal = 0; 533 int depthTotal = 0; 534 int depthDeltaTotal = 0; 535 536 int i = 0; 540 for (i = 0; i < counter.length; i++) 541 { 542 StringTokenizer tokens = new StringTokenizer (counter[i].getCounterAsString(), ","); 544 545 String strType = tokens.nextToken(); 546 String strName = tokens.nextToken(); 547 String strSub = tokens.nextToken(); 548 String strDurable = tokens.nextToken(); 549 550 String strDest = strType + "-" + strName; 551 552 String strCount = tokens.nextToken(); 553 String strCountDelta = tokens.nextToken(); 554 String strDepth = tokens.nextToken(); 555 String strDepthDelta = tokens.nextToken(); 556 String strDate = tokens.nextToken(); 557 558 countTotal += Integer.parseInt(strCount); 560 depthTotal += Integer.parseInt(strDepth); 561 562 countDeltaTotal += Integer.parseInt(strCountDelta); 563 depthDeltaTotal += Integer.parseInt(strDepthDelta); 564 565 if (strCountDelta.equalsIgnoreCase("0")) 566 strCountDelta = "-"; 568 if (strDepthDelta.equalsIgnoreCase("0")) 569 strDepthDelta = "-"; 571 if (strDestLast != null && strDestLast.equals(strDest)) 575 { 576 destData += "<tr bgcolor=\"#" + ((i % 2) == 0 ? "FFFFFF" : "F0F0F0") + "\">"; 578 destCount += 1; 579 } 580 else 581 { 582 if (strDestLast != null) 584 { 585 ret += "<tr bgcolor=\"#" 587 + ((i % 2) == 0 ? "FFFFFF" : "F0F0F0") 588 + "\"><td rowspan=\"" 589 + destCount 590 + "\">" 591 + strTypeLast 592 + "</td><td rowspan=\"" 593 + destCount 594 + "\">" 595 + strNameLast 596 + "</td>" 597 + destData; 598 599 destData = ""; 600 } 601 602 destCount = 1; 603 } 604 605 destData += "<td>" 607 + strSub 608 + "</td>" 609 + "<td>" 610 + strDurable 611 + "</td>" 612 + "<td>" 613 + strCount 614 + "</td>" 615 + "<td>" 616 + strCountDelta 617 + "</td>" 618 + "<td>" 619 + strDepth 620 + "</td>" 621 + "<td>" 622 + strDepthDelta 623 + "</td>" 624 + "<td>" 625 + strDate 626 + "</td>"; 627 628 strTypeLast = strType; 630 strNameLast = strName; 631 strDestLast = strDest; 632 } 633 634 if (strDestLast != null) 635 { 636 ret += "<tr bgcolor=\"#" 638 + ((i % 2) == 0 ? "FFFFFF" : "F0F0F0") 639 + "\"><td rowspan=\"" 640 + destCount 641 + "\">" 642 + strTypeLast 643 + "</td><td rowspan=\"" 644 + destCount 645 + "\">" 646 + strNameLast 647 + "</td>" 648 + destData; 649 } 650 651 ret += "<tr>" 653 + "<td><![CDATA[ ]]></td><td><![CDATA[ ]]></td>" 654 + "<td><![CDATA[ ]]></td><td><![CDATA[ ]]></td><td>" 655 + countTotal 656 + "</td><td>" 657 + (countDeltaTotal == 0 ? "-" : Integer.toString(countDeltaTotal)) 658 + "</td><td>" 659 + depthTotal 660 + "</td><td>" 661 + (depthDeltaTotal == 0 ? "-" : Integer.toString(depthDeltaTotal)) 662 + "</td><td>Total</td></tr></table>"; 663 664 return ret; 665 } 666 667 672 public void resetMessageCounter() 673 { 674 if (jmsServer == null) 675 return; 676 jmsServer.resetMessageCounter(); 677 } 678 679 public Map retrievePreparedTransactions() 680 { 681 if (jmsServer == null) 682 return null; 683 Map map = jmsServer.getPersistenceManager().getTxManager().getPreparedTransactions(); 684 HashMap result = new HashMap (); 685 for (Iterator i = map.entrySet().iterator(); i.hasNext();) 686 { 687 Map.Entry entry = (Map.Entry ) i.next(); 688 Xid xid = (Xid ) entry.getKey(); 689 TxManager.PreparedInfo info = (TxManager.PreparedInfo) entry.getValue(); 690 if (xid != null && info != null) 691 result.put(xid, Boolean.valueOf(info.isInDoubt())); 692 } 693 return result; 694 } 695 696 public String showPreparedTransactions() 697 { 698 if (jmsServer == null) 699 return null; 700 Map map = jmsServer.getPersistenceManager().getTxManager().getPreparedTransactions(); 701 JBossStringBuilder buffer = new JBossStringBuilder(); 702 buffer.append("<table width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">"); 703 buffer.append("<tr><th>Xid</th><th>In Doubt</th><th>Local TXIDs</th></tr>"); 704 for (Iterator i = map.entrySet().iterator(); i.hasNext();) 705 { 706 Map.Entry entry = (Map.Entry ) i.next(); 707 Xid xid = (Xid ) entry.getKey(); 708 TxManager.PreparedInfo info = (TxManager.PreparedInfo) entry.getValue(); 709 if (xid != null && info != null) 710 { 711 buffer.append("<tr><td>"); 712 buffer.append(xid); 713 buffer.append("</td><td>"); 714 buffer.append(info.isInDoubt()); 715 buffer.append("</td><td>"); 716 buffer.append(info.getTxids()); 717 buffer.append("</td></tr>"); 718 } 719 } 720 buffer.append("</table>"); 721 return buffer.toString(); 722 } 723 } 724 | Popular Tags |