00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.console.gui.popups;
00026
00027 import java.awt.event.ActionEvent;
00028 import java.awt.event.MouseListener;
00029
00030 import javax.swing.JMenu;
00031 import javax.swing.JMenuItem;
00032 import javax.swing.JSeparator;
00033
00034 import org.objectweb.cjdbc.common.jmx.mbeans.DataCollectorMBean;
00035 import org.objectweb.cjdbc.common.monitor.DataCollectionNames;
00036 import org.objectweb.cjdbc.console.gui.CjdbcGui;
00037 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00038 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00039 import org.objectweb.cjdbc.console.gui.objects.BackendObject;
00040 import org.objectweb.cjdbc.console.jmx.RmiJmxClient;
00041 import org.objectweb.cjdbc.console.monitoring.MonitoringConsole;
00042
00043
00044
00045
00046
00047
00048
00049 public class BackendPopUpMenu extends AbstractPopUpMenu
00050 implements
00051 MouseListener
00052 {
00053
00054 private BackendObject bo;
00055 JMenuItem backendRemove;
00056 JMenuItem backendCreate;
00057 JMenuItem backendCheckpoint;
00058 JMenuItem backendUnsetCheckpoint;
00059 JMenuItem backendEnable;
00060 JMenuItem backendDisable;
00061 JMenuItem backendRestore;
00062 JMenuItem backendBackup;
00063 JMenuItem backendTestConnection;
00064 JMenu monitor;
00065
00066
00067
00068
00069
00070
00071
00072 public BackendPopUpMenu(CjdbcGui gui, BackendObject bo)
00073 {
00074 super(gui);
00075 this.bo = bo;
00076
00077 JSeparator separator = new JSeparator();
00078
00079 backendRemove = new JMenuItem(GuiCommands.COMMAND_BACKEND_REMOVE);
00080 backendCreate = new JMenuItem(GuiCommands.COMMAND_BACKEND_CREATE_NEW);
00081 backendCheckpoint = new JMenuItem(
00082 GuiCommands.COMMAND_BACKEND_SET_CHECKPOINT);
00083 backendEnable = new JMenuItem(GuiConstants.BACKEND_STATE_ENABLED);
00084 backendDisable = new JMenuItem(GuiConstants.BACKEND_STATE_DISABLED);
00085 backendRestore = new JMenuItem(GuiConstants.BACKEND_STATE_RESTORE);
00086 backendBackup = new JMenuItem(GuiConstants.BACKEND_STATE_BACKUP);
00087 backendTestConnection = new JMenuItem(
00088 GuiCommands.COMMAND_BACKEND_TEST_CONNECTION);
00089 backendUnsetCheckpoint = new JMenuItem(
00090 GuiCommands.COMMAND_BACKEND_UNSET_CHECKPOINT);
00091
00092 this.add(backendRemove).addActionListener(this);
00093 this.add(backendCreate).addActionListener(this);
00094 this.add(backendCheckpoint).addActionListener(this);
00095 this.add(backendUnsetCheckpoint).addActionListener(this);
00096 this.add(backendTestConnection).addActionListener(this);
00097 this.add(separator);
00098 this.add(backendEnable).addActionListener(this);
00099 this.add(backendDisable).addActionListener(this);
00100 this.add(backendRestore).addActionListener(this);
00101 this.add(backendBackup).addActionListener(this);
00102 this.add(separator);
00103
00104 buildMonitorMenu();
00105 }
00106
00107 private void buildMonitorMenu()
00108 {
00109 monitor = new JMenu("Monitor");
00110 addToMonitorMenu(DataCollectionNames.BACKEND_ACTIVE_TRANSACTION);
00111 addToMonitorMenu(DataCollectionNames.BACKEND_PENDING_REQUESTS);
00112 addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_ACTIVE_CONNECTIONS);
00113 addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_READ_REQUEST);
00114 addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_REQUEST);
00115 addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_TRANSACTIONS);
00116 addToMonitorMenu(DataCollectionNames.BACKEND_TOTAL_WRITE_REQUEST);
00117 this.add(monitor);
00118 }
00119
00120 private void addToMonitorMenu(int type)
00121 {
00122 String typeName = DataCollectionNames.get(type);
00123 JMenuItem item = new JMenuItem(typeName);
00124 String action = MonitoringConsole.getBackendActionCommand(typeName, bo
00125 .getDatabase(), bo.getName());
00126 item.setActionCommand(action);
00127 monitor.add(item).addActionListener(this);
00128 }
00129
00130
00131
00132
00133
00134
00135 public final JMenuItem getBackendCheckpoint()
00136 {
00137 return backendCheckpoint;
00138 }
00139
00140
00141
00142
00143
00144
00145 public final JMenuItem getBackendCreate()
00146 {
00147 return backendCreate;
00148 }
00149
00150
00151
00152
00153
00154
00155 public final JMenuItem getBackendRemove()
00156 {
00157 return backendRemove;
00158 }
00159
00160
00161
00162
00163 public void actionPerformed(ActionEvent e)
00164 {
00165 String action = e.getActionCommand();
00166 if (action.startsWith("graph"))
00167 {
00168 RmiJmxClient controllerMBean = bo.getJmxClient();
00169 DataCollectorMBean dataCollectorMBean;
00170 try
00171 {
00172 dataCollectorMBean = controllerMBean.getDataCollectorProxy();
00173 MonitoringConsole.graph(action, dataCollectorMBean, -1, 3600, 1000, 1,
00174 null);
00175 return;
00176 }
00177 catch (Exception e1)
00178 {
00179 e1.printStackTrace();
00180 return;
00181 }
00182 }
00183
00184 if (action.equals(GuiCommands.COMMAND_BACKEND_REMOVE))
00185 {
00186 gui.publicActionRemoveBackend(bo);
00187 }
00188 else if (action.equals(GuiCommands.COMMAND_BACKEND_CREATE_NEW))
00189 {
00190 gui.publicActionNewBackendPrompt(bo);
00191 }
00192 else if (action.equals(GuiCommands.COMMAND_BACKEND_SET_CHECKPOINT))
00193 {
00194 gui.publicActionSetCheckpoint(bo);
00195 }
00196 else if (action.equals(GuiCommands.COMMAND_BACKEND_TEST_CONNECTION))
00197 {
00198 gui.publicActionTestBackendConnection(bo);
00199 }
00200 else if (action.equals(GuiCommands.COMMAND_BACKEND_UNSET_CHECKPOINT))
00201 {
00202 gui.publicActionUnSetCheckpoint(bo);
00203 }
00204 else
00205 {
00206 gui.publicActionExecuteBackendDrop(action, bo.getName());
00207 }
00208
00209 }
00210
00211
00212
00213
00214
00215
00216 public final JMenuItem getBackendBackup()
00217 {
00218 return backendBackup;
00219 }
00220
00221
00222
00223
00224
00225
00226 public final JMenuItem getBackendDisable()
00227 {
00228 return backendDisable;
00229 }
00230
00231
00232
00233
00234
00235
00236 public final JMenuItem getBackendEnable()
00237 {
00238 return backendEnable;
00239 }
00240
00241
00242
00243
00244
00245
00246 public final JMenuItem getBackendRestore()
00247 {
00248 return backendRestore;
00249 }
00250 }