001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.admin.dso;
006:
007: import org.dijon.Button;
008: import org.dijon.ContainerResource;
009: import org.dijon.PopupMenu;
010:
011: import com.tc.admin.AdminClient;
012: import com.tc.admin.AdminClientContext;
013: import com.tc.admin.ConnectionContext;
014: import com.tc.admin.common.XAbstractAction;
015: import com.tc.admin.common.XContainer;
016: import com.tc.admin.common.XObjectTable;
017: import com.tc.management.beans.L2MBeanNames;
018: import com.tc.management.beans.object.ObjectManagementMonitorMBean;
019: import com.tc.objectserver.api.GCStats;
020: import com.tc.stats.DSOMBean;
021:
022: import java.awt.Frame;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.MouseAdapter;
025: import java.awt.event.MouseEvent;
026: import java.io.IOException;
027:
028: import javax.management.AttributeNotFoundException;
029: import javax.management.InstanceNotFoundException;
030: import javax.management.MBeanException;
031: import javax.management.MBeanServerInvocationHandler;
032: import javax.management.MalformedObjectNameException;
033: import javax.management.Notification;
034: import javax.management.NotificationListener;
035: import javax.management.ReflectionException;
036: import javax.swing.JOptionPane;
037:
038: public class GCStatsPanel extends XContainer implements
039: NotificationListener {
040: private ConnectionContext m_cc;
041: private XObjectTable m_table;
042: private PopupMenu m_popupMenu;
043: private ObjectManagementMonitorMBean m_objectManagementMonitor;
044:
045: public GCStatsPanel(ConnectionContext cc) throws IOException,
046: MalformedObjectNameException, InstanceNotFoundException,
047: MBeanException, ReflectionException,
048: AttributeNotFoundException {
049: super ();
050:
051: m_cc = cc;
052:
053: AdminClientContext acc = AdminClient.getContext();
054: load((ContainerResource) acc.topRes
055: .getComponent("GCStatsPanel"));
056:
057: m_table = (XObjectTable) findComponent("GCStatsTable");
058:
059: GCStatsTableModel model = new GCStatsTableModel();
060: m_table.setModel(model);
061:
062: DSOHelper helper = DSOHelper.getHelper();
063: GCStats[] gcStats = null;
064:
065: gcStats = helper.getGCStats(cc);
066: cc.addNotificationListener(helper.getDSOMBean(cc), this );
067:
068: model.setGCStats(gcStats);
069:
070: m_objectManagementMonitor = (ObjectManagementMonitorMBean) MBeanServerInvocationHandler
071: .newProxyInstance(m_cc.mbsc,
072: L2MBeanNames.OBJECT_MANAGEMENT,
073: ObjectManagementMonitorMBean.class, false);
074:
075: RunGCAction runDGCAction = new RunGCAction();
076: Button runDGCButton = (Button) findComponent("RunGCButton");
077: runDGCButton.setAction(runDGCAction);
078:
079: m_popupMenu = new PopupMenu("GC");
080: m_popupMenu.add(runDGCAction);
081: m_table.add(m_popupMenu);
082: m_table.addMouseListener(new MouseAdapter() {
083: public void mousePressed(MouseEvent e) {
084: testPopup(e);
085: }
086:
087: public void mouseReleased(MouseEvent e) {
088: testPopup(e);
089: }
090:
091: public void testPopup(MouseEvent e) {
092: if (e.isPopupTrigger()) {
093: m_popupMenu.show(m_table, e.getX(), e.getY());
094: }
095: }
096: });
097: }
098:
099: class RunGCAction extends XAbstractAction {
100: RunGCAction() {
101: super ("Run GC");
102: }
103:
104: public void actionPerformed(ActionEvent ae) {
105: runGC();
106: }
107: }
108:
109: public void handleNotification(Notification notice, Object notUsed) {
110: String type = notice.getType();
111:
112: if (DSOMBean.GC_COMPLETED.equals(type)) {
113: GCStatsTableModel model = (GCStatsTableModel) m_table
114: .getModel();
115: model.addGCStats((GCStats) notice.getSource());
116: }
117: }
118:
119: private void runGC() {
120: try {
121: m_objectManagementMonitor.runGC();
122: } catch (RuntimeException re) {
123: Frame frame = (Frame) getAncestorOfClass(Frame.class);
124: Throwable cause = re.getCause();
125: String msg = cause != null ? cause.getMessage() : re
126: .getMessage();
127: String title = frame.getTitle();
128:
129: JOptionPane.showMessageDialog(frame, msg, title,
130: JOptionPane.INFORMATION_MESSAGE);
131: }
132: }
133:
134: public void tearDown() {
135: try {
136: if (m_cc != null && m_cc.isConnected()) {
137: DSOHelper helper = DSOHelper.getHelper();
138: m_cc.removeNotificationListener(helper
139: .getDSOMBean(m_cc), this );
140: }
141: } catch (Exception e) {/**/
142: }
143:
144: super.tearDown();
145:
146: m_cc = null;
147: m_table = null;
148: }
149: }
|