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;
00026
00027 import java.awt.event.ActionEvent;
00028 import java.awt.event.ActionListener;
00029 import java.awt.event.FocusEvent;
00030 import java.awt.event.FocusListener;
00031 import java.awt.event.MouseEvent;
00032 import java.awt.event.MouseListener;
00033 import java.util.Hashtable;
00034
00035 import javax.management.MBeanAttributeInfo;
00036 import javax.management.MBeanOperationInfo;
00037 import javax.management.Notification;
00038 import javax.management.NotificationListener;
00039 import javax.management.ObjectName;
00040 import javax.swing.JButton;
00041 import javax.swing.JList;
00042 import javax.swing.JTable;
00043 import javax.swing.event.ListSelectionEvent;
00044 import javax.swing.event.ListSelectionListener;
00045
00046 import org.objectweb.cjdbc.common.jmx.notifications.CjdbcNotificationList;
00047 import org.objectweb.cjdbc.common.jmx.notifications.JmxNotification;
00048 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00049 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00050 import org.objectweb.cjdbc.console.gui.model.AttributeModel;
00051 import org.objectweb.cjdbc.console.gui.model.OperationModel;
00052 import org.objectweb.cjdbc.console.gui.objects.DatabaseObject;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 public class CjdbcGuiListener
00063 implements
00064 MouseListener,
00065 ActionListener,
00066 NotificationListener,
00067 FocusListener,
00068 ListSelectionListener
00069 {
00070 private CjdbcGui gui;
00071 static final int JMX_SEQUENCE_CACHE = 100;
00072 private Hashtable sequences;
00073
00074
00075
00076
00077
00078
00079 public CjdbcGuiListener(CjdbcGui gui)
00080 {
00081 this.gui = gui;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090 public void handleNotification(Notification notification, Object handback)
00091 {
00092 String xml = (String) notification.getUserData();
00093
00094 if (xml == null)
00095 {
00096 gui.appendDebugText("Got notification with null string");
00097 return;
00098 }
00099 try
00100 {
00101 JmxNotification notif = JmxNotification
00102 .createNotificationFromXmlString(xml);
00103 gui.appendDebugText("----- Jmx Notification -------");
00104 gui.appendDebugText(notif.toString());
00105 gui.appendDebugText("-----------------------------------");
00106 handleNotification(notif.getType(), notif);
00107 }
00108 catch (Exception e)
00109 {
00110 gui.appendDebugText("Exception while handling notification", e);
00111 }
00112 }
00113
00114 private void handleNotification(String type, JmxNotification notification)
00115 {
00116
00117 if (processedSequence(notification.getSequence()))
00118 {
00119 gui.appendDebugText("Notification [" + notification.getSequence()
00120 + "] already processed");
00121 return;
00122 }
00123
00124 if (type.equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ADDED))
00125 {
00126 String backendName = notification
00127 .getDataValue(CjdbcNotificationList.DATA_NAME);
00128 String databaseName = notification
00129 .getDataValue(CjdbcNotificationList.DATA_DATABASE);
00130 String controller = notification.getControllerJmxName();
00131 gui.actionLoadBackend(databaseName, backendName, controller, true);
00132 }
00133 else if (type.equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED))
00134 {
00135 String backendName = notification
00136 .getDataValue(CjdbcNotificationList.DATA_NAME);
00137 gui.actionSetBackendState(backendName);
00138 }
00139 else if (type
00140 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED_WRITE))
00141 {
00142 String backendName = notification
00143 .getDataValue(CjdbcNotificationList.DATA_NAME);
00144 gui.actionSetBackendState(backendName);
00145 }
00146 else if (type
00147 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLED))
00148 {
00149 String backendName = notification
00150 .getDataValue(CjdbcNotificationList.DATA_NAME);
00151 gui.actionSetBackendState(backendName);
00152 }
00153 else if (type
00154 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_RECOVERING))
00155 {
00156 String backendName = notification
00157 .getDataValue(CjdbcNotificationList.DATA_NAME);
00158 gui.actionSetBackendState(backendName);
00159 }
00160 else if (type
00161 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_BACKINGUP))
00162 {
00163 String backendName = notification
00164 .getDataValue(CjdbcNotificationList.DATA_NAME);
00165 gui.actionSetBackendState(backendName);
00166 }
00167 else if (type
00168 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLING))
00169 {
00170 String backendName = notification
00171 .getDataValue(CjdbcNotificationList.DATA_NAME);
00172 gui.actionSetBackendState(backendName);
00173 }
00174 else if (type
00175 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_REPLAYING))
00176 {
00177 String backendName = notification
00178 .getDataValue(CjdbcNotificationList.DATA_NAME);
00179 gui.actionSetBackendState(backendName,
00180 GuiConstants.BACKEND_STATE_RECOVERY);
00181 gui.actionSetBackendState(backendName);
00182 }
00183 else if (type.equals(CjdbcNotificationList.VIRTUALDATABASE_NEW_DUMP_LIST))
00184 {
00185 String databaseName = notification
00186 .getDataValue(CjdbcNotificationList.DATA_DATABASE);
00187 gui.publicActionLoadDumpList(databaseName);
00188 }
00189 else if (type.equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_REMOVED))
00190 {
00191 String backendName = notification
00192 .getDataValue(CjdbcNotificationList.DATA_NAME);
00193 String controller = notification.getControllerJmxName();
00194 gui.publicActionRemoveBackendFromGui(backendName, controller);
00195 }
00196 else
00197 {
00198 gui.appendDebugText("Jmx notification type not recognized:" + type);
00199 }
00200
00201 }
00202
00203
00204
00205
00206
00207
00208
00209 private boolean processedSequence(String sequence)
00210 {
00211 if (sequences == null)
00212 {
00213 sequences = new Hashtable();
00214 return false;
00215 }
00216 Object o = sequences.get(sequence);
00217 if (o == null)
00218 {
00219 sequences.put(sequence, Boolean.TRUE);
00220 if (sequences.size() > JMX_SEQUENCE_CACHE)
00221 sequences.clear();
00222 return false;
00223 }
00224 else
00225 return true;
00226 }
00227
00228
00229
00230
00231 public void mouseClicked(MouseEvent e)
00232 {
00233
00234 if (e.getClickCount() <= 1)
00235 {
00236 return;
00237 }
00238 if (e.getSource() instanceof JTable)
00239 {
00240 JTable table = (JTable) e.getSource();
00241 if (table.getName().equals(GuiConstants.TABLE_JMX_ATTRIBUTES))
00242 {
00243 int row = table.getSelectedRow();
00244 AttributeModel model = (AttributeModel) table.getModel();
00245 MBeanAttributeInfo[] info = model.getInfo();
00246 Object o = gui.mbeanList.getSelectedValue();
00247 gui.appendDebugText("Got attribute selection for mbean:" + o
00248 + " and attribute is:" + info[row].getName());
00249 gui.getAttributeChangeDialog((ObjectName) o, info[row]);
00250 }
00251 if (table.getName().equals(GuiConstants.TABLE_JMX_OPERATIONS))
00252 {
00253 int row = table.getSelectedRow();
00254 OperationModel model = (OperationModel) table.getModel();
00255 MBeanOperationInfo[] info = model.getInfo();
00256 Object o = gui.mbeanList.getSelectedValue();
00257 gui.appendDebugText("Got operation selection for mbean:" + o
00258 + " and operation is:" + info[row].getName());
00259 gui.getOperationCallDialog((ObjectName) o, info[row]);
00260 }
00261 }
00262 }
00263
00264
00265
00266
00267 public void mousePressed(MouseEvent e)
00268 {
00269
00270 }
00271
00272
00273
00274
00275 public void mouseReleased(MouseEvent e)
00276 {
00277
00278 }
00279
00280
00281
00282
00283 public void mouseEntered(MouseEvent e)
00284 {
00285
00286 }
00287
00288
00289
00290
00291 public void mouseExited(MouseEvent e)
00292 {
00293
00294 }
00295
00296
00297
00298
00299 public void actionPerformed(ActionEvent e)
00300 {
00301 String action = e.getActionCommand();
00302 gui.appendDebugText("Got action:" + action);
00303 if (action.equals(GuiCommands.COMMAND_QUIT))
00304 {
00305 gui.publicActionQuit();
00306 }
00307 else if (action.equals(GuiCommands.COMMAND_ADD_CONTROLLER))
00308 {
00309 gui.publicActionAddControllerView();
00310 }
00311 else if (action.equals(GuiCommands.COMMAND_SAVE_CONFIGURATION_FILE))
00312 {
00313 gui.publicActionSaveConfigurationFile();
00314 }
00315 if (action.equals(GuiCommands.COMMAND_CLEAN_LOGGING_PANEL))
00316 {
00317 gui.publicActioncleanLoggingPane();
00318 }
00319 else if (action.equals(GuiCommands.COMMAND_ADD_CONFIG_FILE))
00320 {
00321 gui.publicActionAddXmlFile();
00322 }
00323 else if (action.equals(GuiCommands.COMMAND_SELECT_CONTROLLER))
00324 {
00325 String controllerName = ((JButton) e.getSource()).getName();
00326 gui.appendDebugText("Changed controller selection to:" + controllerName);
00327 gui.publicActionSelectNewController(controllerName);
00328 }
00329 else if (action.equals(GuiCommands.COMMAND_SELECT_DATABASE))
00330 {
00331 DatabaseObject source = (DatabaseObject) e.getSource();
00332 String databaseName = source.getName();
00333 gui.appendDebugText("Changed database selection to:" + databaseName);
00334 gui.publicActionSelectNewDatabase(databaseName);
00335 }
00336 else if (action.equals(GuiCommands.COMMAND_ADD_CONTROLLER_CANCEL))
00337 {
00338 gui.newControllerFrame.setVisible(false);
00339 }
00340 else if (action.equals(GuiCommands.COMMAND_ADD_CONTROLLER_APPROVE))
00341 {
00342 gui.publicActionAddController();
00343 }
00344 else if (action.equals(GuiCommands.COMMAND_SAVE_CONFIGURATION_FILE))
00345 {
00346 gui.publicActionSaveConfigurationFile();
00347 }
00348 else if (action.equals(GuiCommands.COMMAND_CLEAN_DEBUG_BUFFER))
00349 {
00350 gui.publicActionCleanDebugBuffer();
00351 }
00352 else if (action.equals(GuiCommands.COMMAND_DATABASE_AUTHENTICATE))
00353 {
00354 gui.publicActionLoadAuthenticatedDatabase();
00355 }
00356 else if (action.equals(GuiCommands.COMMAND_CREATE_BACKEND_APPROVE))
00357 {
00358 gui.publicActionCreateBackendExecute();
00359 }
00360 else if (action.equals(GuiCommands.COMMAND_CREATE_BACKEND_CANCEL))
00361 {
00362 gui.newBackendFrame.setVisible(false);
00363 }
00364 else if (action.equals(GuiCommands.COMMAND_HIDE_CHECKPOINT_FRAME))
00365 {
00366 gui.selectCheckpointFrame.setVisible(false);
00367 }
00368 else if (action.equals(GuiCommands.COMMAND_HIDE_SHUTDOWN_FRAME))
00369 {
00370 gui.selectShutdownFrame.setVisible(false);
00371 }
00372 else if (action.equals(GuiCommands.COMMAND_HIDE_BACKUP_FRAME))
00373 {
00374 gui.inputBackupFrame.setVisible(false);
00375 }
00376 else if (action.equals(GuiCommands.COMMAND_MONITOR_CURRENT_CONTROLLER))
00377 {
00378 gui.publicActionStartMonitor(gui.getSelectedController(), true, true,
00379 true);
00380 }
00381
00382 }
00383
00384
00385
00386
00387 public void focusGained(FocusEvent e)
00388 {
00389 gui.publicActionTileJmxFrames(false);
00390 gui.publicActionRefreshMBeans();
00391 }
00392
00393
00394
00395
00396 public void focusLost(FocusEvent e)
00397 {
00398
00399 }
00400
00401
00402
00403
00404 public void valueChanged(ListSelectionEvent e)
00405 {
00406 JList list = (JList) e.getSource();
00407 ObjectName name = (ObjectName) list.getSelectedValue();
00408 gui.publicActionRefreshMBeanAttributes(name);
00409 gui.publicActionRefreshMBeanMethods(name);
00410 }
00411 }