1 package com.ubermq.jms.ui.admin; 2 3 import com.ubermq.jms.server.admin.*; 4 import java.rmi.*; 5 import java.util.*; 6 import javax.swing.*; 7 import javax.swing.tree.*; 8 9 class ServerTreeNode 10 extends DefaultMutableTreeNode 11 implements AdminTreeNode 12 { 13 private MessageServerAdmin admin; 14 15 private MyStatusNode serverStatusNode; 16 private MySubscriptionsNode subscriptionsNode; 17 private MyConnectionsNode connectionsNode; 18 private MyPersistentConsumersNode consumersNode; 19 20 private static final String SERVER_STATUS = "Server Status", 21 SUBSCRIPTION_TABLE = "Subscription Table", 22 CONNECTIONS = "Connections", 23 CONSUMERS = "Persistent Subscribers"; 24 25 ServerTreeNode(MessageServerAdmin admin) 26 throws RemoteException 27 { 28 super(admin.getServerName(), true); 29 this.admin = admin; 30 31 this.serverStatusNode = new MyStatusNode(); 33 this.subscriptionsNode = new MySubscriptionsNode(); 34 this.connectionsNode = new MyConnectionsNode(); 35 this.consumersNode = new MyPersistentConsumersNode(); 36 37 add(serverStatusNode); 39 add(subscriptionsNode); 40 add(connectionsNode); 41 add(consumersNode); 42 } 43 44 MessageServerAdmin getAdmin() 45 { 46 return admin; 47 } 48 49 52 public void refresh(DefaultTreeModel treeModel) 53 throws RemoteException 54 { 55 connectionsNode.refresh(treeModel); 56 serverStatusNode.refresh(treeModel); 57 consumersNode.refresh(treeModel); 58 } 59 60 public String getDescription() 61 { 62 try 63 { 64 StringBuffer sb = new StringBuffer (); 65 sb.append("<h2>"); 66 sb.append(admin.getServerName()); 67 sb.append("</h2>"); 68 return sb.toString(); 69 } 70 catch (RemoteException e) { 71 return "Description unavailable."; 72 } 73 } 74 75 public JPopupMenu getContextMenu() 76 { 77 return null; 78 } 79 80 public ImageIcon getImageIcon() 81 { 82 return AdminViewer.serverIcon; 83 } 84 85 private class MyStatusNode 86 extends DefaultMutableTreeNode 87 implements AdminTreeNode 88 { 89 public MyStatusNode() 90 { 91 super(SERVER_STATUS, false); 92 } 93 94 public void refresh(DefaultTreeModel tm) 95 { 96 } 97 98 public String getDescription() 99 { 100 try 101 { 102 StringBuffer sb = new StringBuffer (); 103 sb.append("<i>Statistics</i>"); 104 sb.append("<pre>"); 105 sb.append(admin.getRouterStatistics().getStatisticsAsText()); 106 sb.append("</pre>"); 107 108 return sb.toString(); 109 } 110 catch (RemoteException e) { 111 return "Statistics Unavailable."; 112 } 113 } 114 115 public JPopupMenu getContextMenu() 116 { 117 return null; 118 } 119 120 public ImageIcon getImageIcon() 121 { 122 return AdminViewer.scriptIcon; 123 } 124 } 125 126 private class MyConnectionsNode 127 extends DefaultMutableTreeNode 128 implements AdminTreeNode 129 { 130 public MyConnectionsNode() 131 { 132 super(CONNECTIONS, true); 133 } 134 135 public void refresh(DefaultTreeModel treeModel) 136 throws RemoteException 137 { 138 Collection c = admin.getConnections(); 140 141 Map newTree = new HashMap(); 143 Iterator iter = c.iterator(); 144 while (iter.hasNext()) 145 { 146 ConnectionAdmin ca = (ConnectionAdmin)iter.next(); 147 newTree.put(ca.getName(), ca); 148 } 149 150 Map alreadyInTree = new HashMap(); 152 iter = ((children != null) ? children : Collections.EMPTY_LIST).iterator(); 153 while (iter.hasNext()) 154 { 155 ConnectionTreeNode ctn = (ConnectionTreeNode)iter.next(); 156 alreadyInTree.put(ctn.getAdmin().getName(), ctn); 157 } 158 159 Set insertions = new HashSet(), deletions = new HashSet(); 161 insertions.addAll(newTree.keySet()); 162 insertions.removeAll(alreadyInTree.keySet()); 163 deletions.addAll(alreadyInTree.keySet()); 164 deletions.removeAll(newTree.keySet()); 165 166 iter = deletions.iterator(); 168 while (iter.hasNext()) 169 { 170 ConnectionTreeNode ctn = (ConnectionTreeNode)alreadyInTree.get(iter.next()); 171 treeModel.removeNodeFromParent(ctn); 172 } 173 174 iter = insertions.iterator(); 176 while (iter.hasNext()) 177 { 178 ConnectionAdmin ca = (ConnectionAdmin)newTree.get(iter.next()); 179 treeModel.insertNodeInto(new ConnectionTreeNode(ca), this, 0); 180 } 181 } 182 183 public String getDescription() 184 { 185 return ""; 186 } 187 188 public JPopupMenu getContextMenu() 189 { 190 return null; 191 } 192 193 public ImageIcon getImageIcon() 194 { 195 return AdminViewer.serverIcon; 196 } 197 } 198 199 private class MySubscriptionsNode 200 extends DefaultMutableTreeNode 201 implements AdminTreeNode 202 { 203 MySubscriptionsNode() 204 { 205 super(SUBSCRIPTION_TABLE, false); 206 } 207 208 public String getDescription() 209 { 210 try 212 { 213 Map topicToConns = new HashMap(); 214 Iterator iter = admin.getConnections().iterator(); 215 while (iter.hasNext()) 216 { 217 ConnectionAdmin admin = (ConnectionAdmin)iter.next(); 218 219 Iterator i2 = admin.getSubscriptions().iterator(); 220 while(i2.hasNext()) 221 { 222 Object topic = (Object )i2.next(); 223 List l = (List)topicToConns.get(topic); 224 if (l == null) 225 { 226 l = new ArrayList(); 227 topicToConns.put(topic, l); 228 } 229 l.add(admin.getName()); 230 } 231 } 232 233 StringBuffer sb = new StringBuffer (); 235 sb.append("<table border=0 width=\"80%\">"); 236 237 iter = topicToConns.keySet().iterator(); 238 if (!iter.hasNext()) 239 sb.append("<i>No Subscriptions</i>"); 240 while (iter.hasNext()) 241 { 242 Object topic = iter.next(); 243 244 sb.append("<tr><td>"); 245 sb.append(topic); 246 sb.append("</td><td>"); 247 248 List l = (List)topicToConns.get(topic); 249 Iterator i2 = l.iterator(); 250 int i=0; 251 while(i2.hasNext()) 252 { 253 if (i++ > 0) 254 sb.append("<br>"); 255 sb.append(i2.next()); 256 } 257 sb.append("</td></tr>"); 258 } 259 sb.append("</table>"); 260 261 return sb.toString(); 262 } 263 catch (RemoteException e) { 264 return "Unavailable."; 265 } 266 } 267 268 public void refresh(DefaultTreeModel treeModel) 269 { 270 } 271 272 public JPopupMenu getContextMenu() 273 { 274 return null; 275 } 276 277 public ImageIcon getImageIcon() 278 { 279 return AdminViewer.scriptIcon; 280 } 281 } 282 283 private class MyPersistentConsumersNode 284 extends DefaultMutableTreeNode 285 implements AdminTreeNode 286 { 287 MyPersistentConsumersNode() 288 { 289 super(CONSUMERS, true); 290 } 291 292 296 public ImageIcon getImageIcon() 297 { 298 return AdminViewer.envelopeIcon; 299 } 300 301 305 public void refresh(DefaultTreeModel treeModel) throws RemoteException 306 { 307 Collection c = admin.getPersistentConsumers(); 309 310 Map newTree = new HashMap(); 312 Iterator iter = c.iterator(); 313 while (iter.hasNext()) 314 { 315 PersistentConsumerAdmin ca = (PersistentConsumerAdmin)iter.next(); 316 newTree.put(ca.getName(), ca); 317 } 318 319 Map alreadyInTree = new HashMap(); 321 iter = ((children != null) ? children : Collections.EMPTY_LIST).iterator(); 322 while (iter.hasNext()) 323 { 324 MyPersistentConsumerNode ctn = (MyPersistentConsumerNode)iter.next(); 325 alreadyInTree.put(ctn.getAdmin().getName(), ctn); 326 } 327 328 Set insertions = new HashSet(), deletions = new HashSet(); 330 insertions.addAll(newTree.keySet()); 331 insertions.removeAll(alreadyInTree.keySet()); 332 deletions.addAll(alreadyInTree.keySet()); 333 deletions.removeAll(newTree.keySet()); 334 335 iter = deletions.iterator(); 337 while (iter.hasNext()) 338 { 339 MyPersistentConsumerNode ctn = (MyPersistentConsumerNode)alreadyInTree.get(iter.next()); 340 treeModel.removeNodeFromParent(ctn); 341 } 342 343 iter = insertions.iterator(); 345 while (iter.hasNext()) 346 { 347 PersistentConsumerAdmin ca = (PersistentConsumerAdmin)newTree.get(iter.next()); 348 treeModel.insertNodeInto(new MyPersistentConsumerNode(ca), this, 0); 349 } 350 } 351 352 356 public JPopupMenu getContextMenu() 357 { 358 return null; 359 } 360 361 364 public String getDescription() 365 { 366 return ""; 367 } 368 } 369 370 private class MyPersistentConsumerNode 371 extends DefaultMutableTreeNode 372 implements AdminTreeNode 373 { 374 private PersistentConsumerAdmin pc; 375 private String description; 376 private boolean goingAway; 377 378 private ImageIcon openIcon, closedIcon; 379 380 MyPersistentConsumerNode(PersistentConsumerAdmin pc) 381 throws RemoteException 382 { 383 super(pc.getName(), false); 384 this.pc = pc; 385 this.goingAway = false; 386 387 if (pc.isQueue()) 388 { 389 this.openIcon = AdminViewer.queueIcon; 390 this.closedIcon = AdminViewer.queueIcon; 391 } 392 else 393 { 394 this.openIcon = AdminViewer.scriptIcon; 395 this.closedIcon = AdminViewer.scriptDeletedIcon; 396 } 397 398 if (pc.isQueue()) 400 this.description = "<b>Queue</b> " + pc.getName() + "<P>"; 401 else 402 this.description = "<b>Subscribed to: </b>" + pc.getSubscription() + "<P>"; 403 } 404 405 public PersistentConsumerAdmin getAdmin() 406 { 407 return pc; 408 } 409 410 414 public ImageIcon getImageIcon() 415 { 416 if (goingAway) 417 return AdminViewer.trashIcon; 418 419 try 420 { 421 return (pc.isActive() ? openIcon : closedIcon); 422 } 423 catch (RemoteException e) { 424 return AdminViewer.deleteIcon; 425 } 426 } 427 428 432 public void refresh(DefaultTreeModel treeModel) throws RemoteException 433 { 434 } 435 436 440 public JPopupMenu getContextMenu() 441 { 442 JPopupMenu pm = new JPopupMenu(); 443 pm.add(new CloseAction()); 444 return pm; 445 } 446 447 450 public String getDescription() 451 { 452 try 453 { 454 return description + pc.getDescription(); 455 } 456 catch (RemoteException e) { 457 return "Unavailable."; 458 } 459 } 460 461 462 private class CloseAction 463 extends AbstractAction 464 { 465 public CloseAction() {super("Delete", AdminViewer.trashIcon);} 466 public boolean isEnabled() 467 { 468 try 469 { 470 return !pc.isActive(); 471 } 472 catch (RemoteException e) { 473 return false; 474 } 475 } 476 public void actionPerformed(java.awt.event.ActionEvent e) 477 { 478 try 479 { 480 if (JOptionPane.showConfirmDialog(null, 481 "Deleting this consumer will permanently delete all stored messages. Are you sure you want to continue?", 482 "Delete", 483 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) 484 { 485 pc.close(); 486 goingAway = true; 487 } 488 } 489 catch (Exception x) { 490 JOptionPane.showMessageDialog(null, x.getMessage()); 491 } 492 } 493 } 494 495 } 496 497 } 498 | Popular Tags |