1 24 25 package org.objectweb.cjdbc.console.gui.popups; 26 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.MouseListener ; 29 30 import javax.swing.JMenu ; 31 import javax.swing.JMenuItem ; 32 import javax.swing.JSeparator ; 33 34 import org.objectweb.cjdbc.common.jmx.mbeans.DataCollectorMBean; 35 import org.objectweb.cjdbc.common.monitor.DataCollection; 36 import org.objectweb.cjdbc.common.monitor.DataCollectionNames; 37 import org.objectweb.cjdbc.console.gui.CjdbcGui; 38 import org.objectweb.cjdbc.console.gui.constants.GuiCommands; 39 import org.objectweb.cjdbc.console.gui.constants.GuiConstants; 40 import org.objectweb.cjdbc.console.gui.objects.BackendObject; 41 import org.objectweb.cjdbc.console.jmx.RmiJmxClient; 42 import org.objectweb.cjdbc.console.monitoring.MonitoringConsole; 43 44 52 public class BackendPopUpMenu extends AbstractPopUpMenu 53 implements 54 MouseListener 55 { 56 57 private BackendObject bo; 58 JMenuItem backendRemove; 59 JMenuItem backendCreate; 60 JMenuItem backendCheckpoint; 61 JMenuItem backendUnsetCheckpoint; 62 JMenuItem backendEnable; 63 JMenuItem backendDisable; 64 JMenuItem backendRestore; 65 JMenuItem backendBackup; 66 JMenuItem backendTestConnection; 67 JMenu monitor; 68 69 75 public BackendPopUpMenu(CjdbcGui gui, BackendObject bo) 76 { 77 super(gui); 78 this.bo = bo; 79 80 JSeparator separator = new JSeparator (); 81 82 backendRemove = new JMenuItem (GuiCommands.COMMAND_BACKEND_REMOVE); 83 backendCreate = new JMenuItem (GuiCommands.COMMAND_BACKEND_CREATE_NEW); 84 backendCheckpoint = new JMenuItem ( 85 GuiCommands.COMMAND_BACKEND_SET_CHECKPOINT); 86 backendEnable = new JMenuItem (GuiConstants.BACKEND_STATE_ENABLED); 87 backendDisable = new JMenuItem (GuiConstants.BACKEND_STATE_DISABLED); 88 backendRestore = new JMenuItem (GuiConstants.BACKEND_STATE_RESTORE); 89 backendBackup = new JMenuItem (GuiConstants.BACKEND_STATE_BACKUP); 90 backendTestConnection = new JMenuItem ( 91 GuiCommands.COMMAND_BACKEND_TEST_CONNECTION); 92 backendUnsetCheckpoint = new JMenuItem ( 93 GuiCommands.COMMAND_BACKEND_UNSET_CHECKPOINT); 94 95 this.add(backendRemove).addActionListener(this); 96 this.add(backendCreate).addActionListener(this); 97 this.add(backendCheckpoint).addActionListener(this); 98 this.add(backendUnsetCheckpoint).addActionListener(this); 99 this.add(backendTestConnection).addActionListener(this); 100 this.add(separator); 101 this.add(backendEnable).addActionListener(this); 102 this.add(backendDisable).addActionListener(this); 103 this.add(backendRestore).addActionListener(this); 104 this.add(backendBackup).addActionListener(this); 105 this.add(separator); 106 107 buildMonitorMenu(); 108 } 109 110 private void buildMonitorMenu() 111 { 112 monitor = new JMenu ("Monitor"); 113 addToMonitorMenu(DataCollection.BACKEND_ACTIVE_TRANSACTION); 114 addToMonitorMenu(DataCollection.BACKEND_PENDING_REQUESTS); 115 addToMonitorMenu(DataCollection.BACKEND_TOTAL_ACTIVE_CONNECTIONS); 116 addToMonitorMenu(DataCollection.BACKEND_TOTAL_READ_REQUEST); 117 addToMonitorMenu(DataCollection.BACKEND_TOTAL_REQUEST); 118 addToMonitorMenu(DataCollection.BACKEND_TOTAL_TRANSACTIONS); 119 addToMonitorMenu(DataCollection.BACKEND_TOTAL_WRITE_REQUEST); 120 this.add(monitor); 121 } 122 123 private void addToMonitorMenu(int type) 124 { 125 String typeName = DataCollectionNames.get(type); 126 JMenuItem item = new JMenuItem (typeName); 127 String action = MonitoringConsole.getBackendActionCommand(typeName, bo 128 .getDatabase(), bo.getName()); 129 item.setActionCommand(action); 130 monitor.add(item).addActionListener(this); 131 } 132 133 138 public final JMenuItem getBackendCheckpoint() 139 { 140 return backendCheckpoint; 141 } 142 143 148 public final JMenuItem getBackendCreate() 149 { 150 return backendCreate; 151 } 152 153 158 public final JMenuItem getBackendRemove() 159 { 160 return backendRemove; 161 } 162 163 166 public void actionPerformed(ActionEvent e) 167 { 168 String action = e.getActionCommand(); 169 if (action.startsWith("graph")) 170 { 171 RmiJmxClient controllerMBean = bo.getJmxClient(); 172 DataCollectorMBean dataCollectorMBean; 173 try 174 { 175 dataCollectorMBean = controllerMBean.getDataCollectorProxy(); 176 MonitoringConsole.graph(action, dataCollectorMBean, -1, 3600, 1000, 1, 177 null); 178 return; 179 } 180 catch (Exception e1) 181 { 182 e1.printStackTrace(); 183 return; 184 } 185 } 186 187 if (action.equals(GuiCommands.COMMAND_BACKEND_REMOVE)) 188 { 189 gui.publicActionRemoveBackend(bo); 190 } 191 else if (action.equals(GuiCommands.COMMAND_BACKEND_CREATE_NEW)) 192 { 193 gui.publicActionNewBackendPrompt(bo); 194 } 195 else if (action.equals(GuiCommands.COMMAND_BACKEND_SET_CHECKPOINT)) 196 { 197 gui.publicActionSetCheckpoint(bo); 198 } 199 else if (action.equals(GuiCommands.COMMAND_BACKEND_TEST_CONNECTION)) 200 { 201 gui.publicActionTestBackendConnection(bo); 202 } 203 else if (action.equals(GuiCommands.COMMAND_BACKEND_UNSET_CHECKPOINT)) 204 { 205 gui.publicActionUnSetCheckpoint(bo); 206 } 207 else 208 { 209 gui.publicActionExecuteBackendDrop(action, bo.getName()); 210 } 211 212 } 213 214 219 public final JMenuItem getBackendBackup() 220 { 221 return backendBackup; 222 } 223 224 229 public final JMenuItem getBackendDisable() 230 { 231 return backendDisable; 232 } 233 234 239 public final JMenuItem getBackendEnable() 240 { 241 return backendEnable; 242 } 243 244 249 public final JMenuItem getBackendRestore() 250 { 251 return backendRestore; 252 } 253 } | Popular Tags |