KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > sessions > SessionMonitorNode


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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.beans.sessions.SessionMonitorMBean;
12
13 import java.awt.event.ActionEvent JavaDoc;
14 import java.awt.event.KeyEvent JavaDoc;
15 import java.awt.event.MouseEvent JavaDoc;
16
17 import javax.management.MBeanServerNotification JavaDoc;
18 import javax.management.Notification JavaDoc;
19 import javax.management.NotificationListener JavaDoc;
20 import javax.management.ObjectName JavaDoc;
21 import javax.swing.JPopupMenu JavaDoc;
22 import javax.swing.KeyStroke JavaDoc;
23 import javax.swing.tree.DefaultTreeModel JavaDoc;
24
25 public class SessionMonitorNode extends ComponentNode implements NotificationListener JavaDoc {
26   ObjectName JavaDoc m_beanName;
27   SessionMonitorMBean m_bean;
28   private JPopupMenu JavaDoc m_popupMenu;
29   private RefreshAction m_refreshAction;
30
31   private static final String JavaDoc REFRESH_ACTION = "RefreshAction";
32   
33   public SessionMonitorNode(ConnectionContext cc, SessionMonitorMBean bean, ObjectName JavaDoc beanName) {
34     super();
35
36     try {
37       ObjectName JavaDoc mbsd = cc.queryName("JMImplementation:type=MBeanServerDelegate");
38       
39       if(mbsd != null) {
40         cc.addNotificationListener(mbsd, this);
41       }
42     } catch(Exception JavaDoc ioe) {
43       ioe.printStackTrace();
44     }
45     
46     m_beanName = beanName;
47     m_bean = bean;
48     
49     setLabel(beanName.getKeyProperty("node"));
50     setComponent(new SessionMonitorPanel(bean));
51
52     initMenu();
53   }
54
55   public void handleNotification(Notification JavaDoc notification, Object JavaDoc handback) {
56     if(notification instanceof MBeanServerNotification JavaDoc) {
57       MBeanServerNotification JavaDoc mbsn = (MBeanServerNotification JavaDoc)notification;
58       String JavaDoc type = notification.getType();
59       ObjectName JavaDoc name = mbsn.getMBeanName();
60       
61       if(type.equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
62         if(name.equals(m_beanName)) {
63           ((DefaultTreeModel JavaDoc)getModel()).removeNodeFromParent(SessionMonitorNode.this);
64         }
65       }
66     }
67   }
68   
69   private void initMenu() {
70     m_refreshAction = new RefreshAction();
71
72     m_popupMenu = new JPopupMenu JavaDoc("SessionMonitor Actions");
73     m_popupMenu.add(m_refreshAction);
74
75     addActionBinding(REFRESH_ACTION, m_refreshAction);
76   }
77
78   public JPopupMenu JavaDoc getPopupMenu() {
79     return m_popupMenu;
80   }
81
82   public void refresh() {
83     ((SessionMonitorPanel)getComponent()).refresh();
84   }
85
86   private class RefreshAction extends XAbstractAction {
87     private RefreshAction() {
88       super();
89
90       setName(AdminClient.getContext().getMessage("refresh.name"));
91       setSmallIcon(ClassesHelper.getHelper().getRefreshIcon());
92       setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true));
93     }
94
95     public void actionPerformed(ActionEvent JavaDoc ae) {
96       refresh();
97     }
98   }
99
100   public void nodeClicked(MouseEvent JavaDoc me) {
101     m_refreshAction.actionPerformed(null);
102   }
103 }
104
Popular Tags