1 24 25 package org.objectweb.cjdbc.console.gui; 26 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import java.awt.event.FocusEvent ; 30 import java.awt.event.FocusListener ; 31 import java.awt.event.MouseEvent ; 32 import java.awt.event.MouseListener ; 33 import java.util.Hashtable ; 34 35 import javax.management.MBeanAttributeInfo ; 36 import javax.management.MBeanOperationInfo ; 37 import javax.management.Notification ; 38 import javax.management.NotificationListener ; 39 import javax.management.ObjectName ; 40 import javax.swing.JButton ; 41 import javax.swing.JList ; 42 import javax.swing.JTable ; 43 import javax.swing.event.ListSelectionEvent ; 44 import javax.swing.event.ListSelectionListener ; 45 46 import org.objectweb.cjdbc.common.jmx.notifications.CjdbcNotificationList; 47 import org.objectweb.cjdbc.common.jmx.notifications.JmxNotification; 48 import org.objectweb.cjdbc.console.gui.constants.GuiCommands; 49 import org.objectweb.cjdbc.console.gui.constants.GuiConstants; 50 import org.objectweb.cjdbc.console.gui.model.AttributeModel; 51 import org.objectweb.cjdbc.console.gui.model.OperationModel; 52 import org.objectweb.cjdbc.console.gui.objects.DatabaseObject; 53 54 62 public class CjdbcGuiListener 63 implements 64 MouseListener , 65 ActionListener , 66 NotificationListener , 67 FocusListener , 68 ListSelectionListener 69 { 70 private CjdbcGui gui; 71 static final int JMX_SEQUENCE_CACHE = 100; 72 private Hashtable sequences; 73 74 79 public CjdbcGuiListener(CjdbcGui gui) 80 { 81 this.gui = gui; 82 } 83 84 90 public void handleNotification(Notification notification, Object handback) 91 { 92 String xml = (String ) notification.getUserData(); 93 if (xml == null) 95 { 96 gui.appendDebugText("Got notification with null string"); 97 return; 98 } 99 try 100 { 101 JmxNotification notif = JmxNotification 102 .createNotificationFromXmlString(xml); 103 gui.appendDebugText("----- Jmx Notification -------"); 104 gui.appendDebugText(notif.toString()); 105 gui.appendDebugText("-----------------------------------"); 106 handleNotification(notif.getType(), notif); 107 } 108 catch (Exception e) 109 { 110 gui.appendDebugText("Exception while handling notification", e); 111 } 112 } 113 114 private void handleNotification(String type, JmxNotification notification) 115 { 116 if (processedSequence(notification.getSequence())) 118 { 119 gui.appendDebugText("Notification [" + notification.getSequence() 120 + "] already processed"); 121 return; 122 } 123 124 if (type.equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ADDED)) 125 { 126 String backendName = notification 127 .getDataValue(CjdbcNotificationList.DATA_NAME); 128 String databaseName = notification 129 .getDataValue(CjdbcNotificationList.DATA_DATABASE); 130 String controller = notification.getControllerJmxName(); 131 gui.actionLoadBackend(databaseName, backendName, controller, true); 132 } 133 else if (type.equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED)) 134 { 135 String backendName = notification 136 .getDataValue(CjdbcNotificationList.DATA_NAME); 137 gui.actionSetBackendState(backendName); 138 } 139 else if (type 140 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED_WRITE)) 141 { 142 String backendName = notification 143 .getDataValue(CjdbcNotificationList.DATA_NAME); 144 gui.actionSetBackendState(backendName); 145 } 146 else if (type 147 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLED)) 148 { 149 String backendName = notification 150 .getDataValue(CjdbcNotificationList.DATA_NAME); 151 gui.actionSetBackendState(backendName); 152 } 153 else if (type 154 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_RECOVERING)) 155 { 156 String backendName = notification 157 .getDataValue(CjdbcNotificationList.DATA_NAME); 158 gui.actionSetBackendState(backendName); 159 } 160 else if (type 161 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_BACKINGUP)) 162 { 163 String backendName = notification 164 .getDataValue(CjdbcNotificationList.DATA_NAME); 165 gui.actionSetBackendState(backendName); 166 } 167 else if (type 168 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLING)) 169 { 170 String backendName = notification 171 .getDataValue(CjdbcNotificationList.DATA_NAME); 172 gui.actionSetBackendState(backendName); 173 } 174 else if (type 175 .equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_REPLAYING)) 176 { 177 String backendName = notification 178 .getDataValue(CjdbcNotificationList.DATA_NAME); 179 gui.actionSetBackendState(backendName, 180 GuiConstants.BACKEND_STATE_RECOVERY); 181 gui.actionSetBackendState(backendName); 182 } 183 else if (type.equals(CjdbcNotificationList.VIRTUALDATABASE_NEW_DUMP_LIST)) 184 { 185 String databaseName = notification 186 .getDataValue(CjdbcNotificationList.DATA_DATABASE); 187 gui.publicActionLoadDumpList(databaseName); 188 } 189 else if (type.equals(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_REMOVED)) 190 { 191 String backendName = notification 192 .getDataValue(CjdbcNotificationList.DATA_NAME); 193 String controller = notification.getControllerJmxName(); 194 gui.publicActionRemoveBackendFromGui(backendName, controller); 195 } 196 else 197 { 198 gui.appendDebugText("Jmx notification type not recognized:" + type); 199 } 200 201 } 202 203 209 private boolean processedSequence(String sequence) 210 { 211 if (sequences == null) 212 { 213 sequences = new Hashtable (); 214 return false; 215 } 216 Object o = sequences.get(sequence); 217 if (o == null) 218 { 219 sequences.put(sequence, Boolean.TRUE); 220 if (sequences.size() > JMX_SEQUENCE_CACHE) 221 sequences.clear(); 222 return false; 223 } 224 else 225 return true; 226 } 227 228 231 public void mouseClicked(MouseEvent e) 232 { 233 234 if (e.getClickCount() <= 1) 235 { 236 return; 237 } 238 if (e.getSource() instanceof JTable ) 239 { 240 JTable table = (JTable ) e.getSource(); 241 if (table.getName().equals(GuiConstants.TABLE_JMX_ATTRIBUTES)) 242 { 243 int row = table.getSelectedRow(); 244 AttributeModel model = (AttributeModel) table.getModel(); 245 MBeanAttributeInfo [] info = model.getInfo(); 246 Object o = gui.mbeanList.getSelectedValue(); 247 gui.appendDebugText("Got attribute selection for mbean:" + o 248 + " and attribute is:" + info[row].getName()); 249 gui.getAttributeChangeDialog((ObjectName ) o, info[row]); 250 } 251 if (table.getName().equals(GuiConstants.TABLE_JMX_OPERATIONS)) 252 { 253 int row = table.getSelectedRow(); 254 OperationModel model = (OperationModel) table.getModel(); 255 MBeanOperationInfo [] info = model.getInfo(); 256 Object o = gui.mbeanList.getSelectedValue(); 257 gui.appendDebugText("Got operation selection for mbean:" + o 258 + " and operation is:" + info[row].getName()); 259 gui.getOperationCallDialog((ObjectName ) o, info[row]); 260 } 261 } 262 } 263 264 267 public void mousePressed(MouseEvent e) 268 { 269 270 } 271 272 275 public void mouseReleased(MouseEvent e) 276 { 277 278 } 279 280 283 public void mouseEntered(MouseEvent e) 284 { 285 286 } 287 288 291 public void mouseExited(MouseEvent e) 292 { 293 294 } 295 296 299 public void actionPerformed(ActionEvent e) 300 { 301 String action = e.getActionCommand(); 302 gui.appendDebugText("Got action:" + action); 303 if (action.equals(GuiCommands.COMMAND_QUIT)) 304 { 305 gui.publicActionQuit(); 306 } 307 else if (action.equals(GuiCommands.COMMAND_ADD_CONTROLLER)) 308 { 309 gui.publicActionAddControllerView(); 310 } 311 else if (action.equals(GuiCommands.COMMAND_SAVE_CONFIGURATION_FILE)) 312 { 313 gui.publicActionSaveConfigurationFile(); 314 } 315 if (action.equals(GuiCommands.COMMAND_CLEAN_LOGGING_PANEL)) 316 { 317 gui.publicActioncleanLoggingPane(); 318 } 319 else if (action.equals(GuiCommands.COMMAND_ADD_CONFIG_FILE)) 320 { 321 gui.publicActionAddXmlFile(); 322 } 323 else if (action.equals(GuiCommands.COMMAND_SELECT_CONTROLLER)) 324 { 325 String controllerName = ((JButton ) e.getSource()).getName(); 326 gui.appendDebugText("Changed controller selection to:" + controllerName); 327 gui.publicActionSelectNewController(controllerName); 328 } 329 else if (action.equals(GuiCommands.COMMAND_SELECT_DATABASE)) 330 { 331 DatabaseObject source = (DatabaseObject) e.getSource(); 332 String databaseName = source.getName(); 333 gui.appendDebugText("Changed database selection to:" + databaseName); 334 gui.publicActionSelectNewDatabase(databaseName); 335 } 336 else if (action.equals(GuiCommands.COMMAND_ADD_CONTROLLER_CANCEL)) 337 { 338 gui.newControllerFrame.setVisible(false); 339 } 340 else if (action.equals(GuiCommands.COMMAND_ADD_CONTROLLER_APPROVE)) 341 { 342 gui.publicActionAddController(); 343 } 344 else if (action.equals(GuiCommands.COMMAND_SAVE_CONFIGURATION_FILE)) 345 { 346 gui.publicActionSaveConfigurationFile(); 347 } 348 else if (action.equals(GuiCommands.COMMAND_CLEAN_DEBUG_BUFFER)) 349 { 350 gui.publicActionCleanDebugBuffer(); 351 } 352 else if (action.equals(GuiCommands.COMMAND_DATABASE_AUTHENTICATE)) 353 { 354 gui.publicActionLoadAuthenticatedDatabase(); 355 } 356 else if (action.equals(GuiCommands.COMMAND_CREATE_BACKEND_APPROVE)) 357 { 358 gui.publicActionCreateBackendExecute(); 359 } 360 else if (action.equals(GuiCommands.COMMAND_CREATE_BACKEND_CANCEL)) 361 { 362 gui.newBackendFrame.setVisible(false); 363 } 364 else if (action.equals(GuiCommands.COMMAND_HIDE_CHECKPOINT_FRAME)) 365 { 366 gui.selectCheckpointFrame.setVisible(false); 367 } 368 else if (action.equals(GuiCommands.COMMAND_HIDE_SHUTDOWN_FRAME)) 369 { 370 gui.selectShutdownFrame.setVisible(false); 371 } 372 else if (action.equals(GuiCommands.COMMAND_HIDE_BACKUP_FRAME)) 373 { 374 gui.inputBackupFrame.setVisible(false); 375 } 376 else if (action.equals(GuiCommands.COMMAND_MONITOR_CURRENT_CONTROLLER)) 377 { 378 gui.publicActionStartMonitor(gui.getSelectedController(), true, true, 379 true); 380 } 381 382 } 383 384 387 public void focusGained(FocusEvent e) 388 { 389 gui.publicActionTileJmxFrames(false); 390 gui.publicActionRefreshMBeans(); 391 } 392 393 396 public void focusLost(FocusEvent e) 397 { 398 399 } 400 401 404 public void valueChanged(ListSelectionEvent e) 405 { 406 JList list = (JList ) e.getSource(); 407 ObjectName name = (ObjectName ) list.getSelectedValue(); 408 gui.publicActionRefreshMBeanAttributes(name); 409 gui.publicActionRefreshMBeanMethods(name); 410 } 411 } | Popular Tags |