1 4 package com.tc.admin.sessions; 5 6 import com.tc.admin.AdminClient; 7 import com.tc.admin.ConnectionContext; 8 import com.tc.admin.common.ComponentNode; 9 import com.tc.admin.common.XAbstractAction; 10 import com.tc.admin.dso.ClassesHelper; 11 import com.tc.management.TerracottaManagement; 12 import com.tc.management.exposed.SessionsProductMBean; 13 14 import java.awt.event.ActionEvent ; 15 import java.awt.event.KeyEvent ; 16 import java.awt.event.MouseEvent ; 17 import java.io.IOException ; 18 19 import javax.management.MBeanServerNotification ; 20 import javax.management.Notification ; 21 import javax.management.NotificationListener ; 22 import javax.management.ObjectName ; 23 import javax.swing.JPopupMenu ; 24 import javax.swing.KeyStroke ; 25 import javax.swing.tree.DefaultTreeModel ; 26 27 public class SessionsNode extends ComponentNode implements NotificationListener { 28 private ConnectionContext m_cc; 29 private JPopupMenu m_popupMenu; 30 private RefreshAction m_refreshAction; 31 32 private static final String REFRESH_ACTION = "RefreshAction"; 33 34 public SessionsNode(ConnectionContext cc, ObjectName [] beanNames) { 35 super(); 36 37 m_cc = cc; 38 39 try { 40 ObjectName mbsd = cc.queryName("JMImplementation:type=MBeanServerDelegate"); 41 42 if(mbsd != null) { 43 cc.addNotificationListener(mbsd, this); 44 } 45 } catch(Exception ioe) { 46 ioe.printStackTrace(); 47 } 48 49 for(int i = 0; i < beanNames.length; i++) { 50 try { 51 addBean(beanNames[i]); 52 } catch(IOException ioe) { 53 ioe.printStackTrace(); 54 } 55 } 56 57 setLabel("Session Statistics"); 58 59 initMenu(); 60 } 61 62 private void addBean(ObjectName name) throws IOException { 63 SessionsProductMBean bean = (SessionsProductMBean) 64 TerracottaManagement.findMBean(name, SessionsProductMBean.class, m_cc.mbsc); 65 SessionsProductNode node = new SessionsProductNode(m_cc, bean, name); 66 DefaultTreeModel model = getModel(); 67 68 if(model != null) { 69 model.insertNodeInto(node, this, getChildCount()); 70 } 71 else { 72 add(node); 73 } 74 } 75 76 public void handleNotification(Notification notification, Object handback) { 77 if(notification instanceof MBeanServerNotification ) { 78 MBeanServerNotification mbsn = (MBeanServerNotification )notification; 79 String type = notification.getType(); 80 ObjectName name = mbsn.getMBeanName(); 81 82 if(type.equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) { 83 if(SessionsHelper.getHelper().isSessionsProductMBean(name)) { 84 try { 85 addBean(name); 86 } catch(IOException ioe) { 87 ioe.printStackTrace(); 88 } 89 } 90 } 91 } 92 } 93 94 private void initMenu() { 95 m_refreshAction = new RefreshAction(); 96 97 m_popupMenu = new JPopupMenu ("SessionNode Actions"); 98 m_popupMenu.add(m_refreshAction); 99 100 addActionBinding(REFRESH_ACTION, m_refreshAction); 101 } 102 103 public JPopupMenu getPopupMenu() { 104 return m_popupMenu; 105 } 106 107 public void refresh() { 108 109 } 110 111 private class RefreshAction extends XAbstractAction { 112 private RefreshAction() { 113 super(); 114 115 setName(AdminClient.getContext().getMessage("refresh.name")); 116 setSmallIcon(ClassesHelper.getHelper().getRefreshIcon()); 117 setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true)); 118 } 119 120 public void actionPerformed(ActionEvent ae) { 121 refresh(); 122 } 123 } 124 125 public void nodeClicked(MouseEvent me) { 126 m_refreshAction.actionPerformed(null); 127 } 128 } 129 | Popular Tags |