1 24 25 package org.objectweb.cjdbc.console.gui; 26 27 import java.awt.BorderLayout ; 28 import java.awt.Color ; 29 import java.awt.Container ; 30 import java.awt.Cursor ; 31 import java.awt.Dimension ; 32 import java.awt.FlowLayout ; 33 import java.awt.GridLayout ; 34 import java.awt.dnd.DnDConstants ; 35 import java.awt.dnd.DropTarget ; 36 import java.io.BufferedReader ; 37 import java.io.BufferedWriter ; 38 import java.io.File ; 39 import java.io.FileInputStream ; 40 import java.io.FileNotFoundException ; 41 import java.io.FileReader ; 42 import java.io.FileWriter ; 43 import java.io.IOException ; 44 import java.io.PrintWriter ; 45 import java.io.StringReader ; 46 import java.text.SimpleDateFormat ; 47 import java.util.ArrayList ; 48 import java.util.Date ; 49 import java.util.Enumeration ; 50 import java.util.HashMap ; 51 import java.util.Hashtable ; 52 import java.util.Iterator ; 53 import java.util.Set ; 54 55 import javax.management.MBeanAttributeInfo ; 56 import javax.management.MBeanException ; 57 import javax.management.MBeanInfo ; 58 import javax.management.MBeanOperationInfo ; 59 import javax.management.ObjectInstance ; 60 import javax.management.ObjectName ; 61 import javax.swing.BorderFactory ; 62 import javax.swing.Icon ; 63 import javax.swing.JButton ; 64 import javax.swing.JDesktopPane ; 65 import javax.swing.JFileChooser ; 66 import javax.swing.JFrame ; 67 import javax.swing.JInternalFrame ; 68 import javax.swing.JOptionPane ; 69 import javax.swing.JPanel ; 70 import javax.swing.JScrollPane ; 71 import javax.swing.JTabbedPane ; 72 import javax.swing.JTable ; 73 import javax.swing.JTextArea ; 74 import javax.swing.JTextField ; 75 import javax.swing.JTextPane ; 76 import javax.swing.JToolTip ; 77 import javax.swing.filechooser.FileFilter ; 78 79 import org.objectweb.cjdbc.common.exceptions.CJDBCException; 80 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate; 81 import org.objectweb.cjdbc.common.i18n.GuiTranslate; 82 import org.objectweb.cjdbc.common.jmx.JmxException; 83 import org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean; 84 import org.objectweb.cjdbc.common.jmx.mbeans.DataCollectorMBean; 85 import org.objectweb.cjdbc.common.jmx.mbeans.DatabaseBackendMBean; 86 import org.objectweb.cjdbc.common.jmx.mbeans.VirtualDatabaseMBean; 87 import org.objectweb.cjdbc.common.jmx.notifications.CjdbcNotificationList; 88 import org.objectweb.cjdbc.common.shared.BackendInfo; 89 import org.objectweb.cjdbc.common.util.Constants; 90 import org.objectweb.cjdbc.common.util.Strings; 91 import org.objectweb.cjdbc.common.xml.XmlTools; 92 import org.objectweb.cjdbc.console.gui.constants.GuiCommands; 93 import org.objectweb.cjdbc.console.gui.constants.GuiConstants; 94 import org.objectweb.cjdbc.console.gui.constants.GuiIcons; 95 import org.objectweb.cjdbc.console.gui.dnd.listeners.BackendTransferListener; 96 import org.objectweb.cjdbc.console.gui.dnd.listeners.ControllerTransferListener; 97 import org.objectweb.cjdbc.console.gui.frames.GuiExceptionFrame; 98 import org.objectweb.cjdbc.console.gui.frames.GuiInputBackupFrame; 99 import org.objectweb.cjdbc.console.gui.frames.GuiNewControllerFrame; 100 import org.objectweb.cjdbc.console.gui.frames.GuiSelectCheckpointFrame; 101 import org.objectweb.cjdbc.console.gui.frames.GuiSelectShutdownFrame; 102 import org.objectweb.cjdbc.console.gui.frames.GuiVirtualDatabaseLoginFrame; 103 import org.objectweb.cjdbc.console.gui.frames.NewBackendFrame; 104 import org.objectweb.cjdbc.console.gui.frames.jmxdesktop.AttributeChangeDialog; 105 import org.objectweb.cjdbc.console.gui.frames.jmxdesktop.OperationCallDialog; 106 import org.objectweb.cjdbc.console.gui.jtools.JMultiLineToolTip; 107 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter; 108 import org.objectweb.cjdbc.console.gui.model.AttributeModel; 109 import org.objectweb.cjdbc.console.gui.model.JNewList; 110 import org.objectweb.cjdbc.console.gui.model.OperationModel; 111 import org.objectweb.cjdbc.console.gui.objects.BackendObject; 112 import org.objectweb.cjdbc.console.gui.objects.ConfigurationFileObject; 113 import org.objectweb.cjdbc.console.gui.objects.ControllerObject; 114 import org.objectweb.cjdbc.console.gui.objects.DatabaseObject; 115 import org.objectweb.cjdbc.console.gui.objects.DumpFileObject; 116 import org.objectweb.cjdbc.console.gui.objects.tooltips.BackendToolTip; 117 import org.objectweb.cjdbc.console.gui.popups.ConfigurationFilePopUpMenu; 118 import org.objectweb.cjdbc.console.gui.popups.ControllerListPopUpMenu; 119 import org.objectweb.cjdbc.console.gui.popups.ControllerPopUpMenu; 120 import org.objectweb.cjdbc.console.gui.popups.DatabasePopUpMenu; 121 import org.objectweb.cjdbc.console.gui.popups.DumpPopUpMenu; 122 import org.objectweb.cjdbc.console.gui.popups.LogEditPopUpMenu; 123 import org.objectweb.cjdbc.console.gui.session.GuiSession; 124 import org.objectweb.cjdbc.console.gui.threads.GuiLoggingThread; 125 import org.objectweb.cjdbc.console.gui.threads.GuiParsingThread; 126 import org.objectweb.cjdbc.console.gui.threads.task.BackupBackendTask; 127 import org.objectweb.cjdbc.console.gui.threads.task.RestoreBackendTask; 128 import org.objectweb.cjdbc.console.jmx.RmiJmxClient; 129 import org.objectweb.cjdbc.console.monitoring.MonitoringConsole; 130 import org.objectweb.cjdbc.console.text.ConsoleException; 131 import org.objectweb.cjdbc.console.views.CacheStatsViewer; 132 import org.objectweb.cjdbc.console.views.CacheViewer; 133 import org.objectweb.cjdbc.console.views.RecoveryLogViewer; 134 import org.objectweb.cjdbc.console.views.SQLStatViewer; 135 136 144 public class CjdbcGui extends JFrame 145 { 146 150 GuiSession guiSession; 151 152 Hashtable databaseMBeans; 153 154 Hashtable controllerMBeans; 155 156 Hashtable backendsState; 157 158 Hashtable backendList; 159 160 Hashtable databaseList; 161 162 Hashtable controllerList; 163 164 165 Hashtable jmxClients; 166 RmiJmxClient currentJmxClient; 167 String selectedController; 168 String selectedDatabase; 169 170 Object credentials = null; 171 172 JNewList mbeanList; 173 174 178 GuiLoggingThread logginThread; 179 180 184 JPanel vdbListPanel; 185 186 JPanel fileListPanel; 187 188 JPanel controllerListPanel; 189 190 194 GuiVirtualDatabaseLoginFrame loginFrame; 195 196 GuiNewControllerFrame newControllerFrame; 197 198 GuiExceptionFrame exceptionFrame; 199 200 NewBackendFrame newBackendFrame; 201 202 GuiSelectCheckpointFrame selectCheckpointFrame; 203 204 GuiSelectShutdownFrame selectShutdownFrame; 205 206 GuiInputBackupFrame inputBackupFrame; 207 208 212 BackendTransferListener backendTransferListener; 213 214 ControllerTransferListener configurationFileTransferListener; 215 216 217 CjdbcGuiListener guiActionListener; 218 219 223 224 String debugText, loggingText; 225 226 JTextArea debugTextPane, loggingTextPane; 227 228 JTextPane infoTextPane; 229 230 GuiParsingThread parsingThread; 231 232 JTextPane xmlTextPane; 233 234 JFileChooser configurationFileChooser; 235 236 JFileChooser jarFileChooser; 237 238 JFileChooser saveFileChooser; 239 240 JPanel backendPanel; 241 242 ControllerListPopUpMenu controllerListPopUpMenu; 243 244 JTabbedPane centerPane; 245 246 JScrollPane helpScroll, debugScroll, xmlScroll, 247 loggingScroll, infoScroll, logConfigScroll; 248 249 JScrollPane fileScroll; 250 251 JTextArea debugTraceTextPane; 252 253 JTextAreaWriter traceWriter; 254 255 JTextPane logConfigTextPane; 256 257 JPanel backendButtons, backendIcons; 258 259 JDesktopPane jmxPanel; 260 JScrollPane jmxScroll; 261 JScrollPane attributePane; 262 JTable attributeTable; 263 JTable operationTable; 264 JScrollPane operationPane; 265 266 JInternalFrame mbeanFrame; 267 JInternalFrame attributeFrame; 268 JInternalFrame operationFrame; 269 270 273 public CjdbcGui() 274 { 275 super(GuiTranslate.get("gui.name")); 276 new Thread (new CjdbcGuiLoader(this)).start(); 277 } 278 279 private ControllerMBean actionGetControllerBean(String controllerName) 280 { 281 if (controllerMBeans.containsKey(controllerName)) 282 { 283 currentJmxClient = (RmiJmxClient) jmxClients.get(controllerName); 284 if (currentJmxClient.isValidConnection()) 285 { 286 ControllerMBean controllerMBean = (ControllerMBean) controllerMBeans 287 .get(controllerName); 288 ((ControllerObject) controllerList.get(controllerName)) 289 .setIcon(GuiIcons.CONTROLLER_READY); 290 return controllerMBean; 291 } 292 else 293 { 294 appendDebugText("Controller :" + controllerName 295 + " cannot be accessed anymore. Trying to reconnect..."); 296 controllerMBeans.remove(controllerName); 297 return actionGetControllerBean(controllerName); 298 } 299 } 300 else 301 { 302 try 303 { 304 RmiJmxClient jmxClient = new RmiJmxClient(controllerName, credentials); 305 appendDebugText("Setting listener for controller:" + controllerName); 306 jmxClient.setNotificationListener(guiActionListener); 307 jmxClients.put(controllerName, jmxClient); 308 controllerMBeans.put(controllerName, jmxClient.getControllerProxy()); 309 if (selectedController == null 310 || controllerName.equalsIgnoreCase(selectedController)) 311 currentJmxClient = jmxClient; 312 313 appendDebugText("Connected to: " + controllerName); 314 actionStartControllerLoggingThread(controllerName); 315 316 ControllerObject co = ((ControllerObject) controllerList 317 .get(controllerName)); 318 if (co != null) 319 co.setIcon(GuiIcons.CONTROLLER_READY); 320 return jmxClient.getControllerProxy(); 321 } 322 catch (Exception e) 323 { 324 appendDebugText("Failed to connect to: " + controllerName); 325 ControllerObject co = ((ControllerObject) controllerList 326 .get(controllerName)); 327 if (co != null) 328 co.setIcon(GuiIcons.CONTROLLER_DOWN); 329 return null; 330 } 331 } 332 } 333 334 private void actionStartControllerLoggingThread(String controllerName) 335 { 336 try 337 { 338 RmiJmxClient client = (RmiJmxClient) jmxClients.get(controllerName); 339 String ip = client.getRemoteHostAddress(); 340 341 if (logginThread != null) 342 logginThread.quit(); 343 logginThread = new GuiLoggingThread(loggingTextPane, ip); 344 logginThread.start(); 345 appendDebugText("Log4j logging thread started for: <" + controllerName 346 + ">"); 347 } 348 catch (Exception e1) 349 { 350 e1.printStackTrace(); 351 appendDebugText("Could not start log4j logging thread to: <" 352 + controllerName + ">"); 353 } 354 } 355 356 private VirtualDatabaseMBean actionGetDatabaseBean(String databaseName) 357 { 358 if (databaseMBeans.containsKey(databaseName)) 359 { 360 return (VirtualDatabaseMBean) databaseMBeans.get(databaseName); 361 } 362 else 363 { 364 appendDebugText("Login to database:" + databaseName); 365 DatabaseObject dob = (DatabaseObject) databaseList.get(databaseName); 366 if (dob == null) 367 { 368 appendDebugText("Failed to retrieve " + databaseName 369 + " from internal list"); 370 return null; 371 } 372 loginFrame = new GuiVirtualDatabaseLoginFrame(this, guiActionListener, 373 databaseName, dob.getIpAdress(), dob.getPort(), guiSession); 374 loginFrame.setVisible(true); 375 return null; 376 } 377 } 378 379 private void actionLoadDatabaseList(String controllerName) 380 { 381 ControllerMBean controllerMBean = actionGetControllerBean(controllerName); 385 ArrayList databases; 386 try 387 { 388 vdbListPanel.removeAll(); 389 databases = controllerMBean.getVirtualDatabaseNames(); 390 int size = databases.size(); 391 appendDebugText("Loading virtual databases list..."); 392 for (int i = 0; i < size; i++) 393 actionLoadDatabase((String ) databases.get(i), controllerName); 394 } 395 catch (Exception e1) 396 { 397 e1.printStackTrace(); 398 appendDebugText("Cannot load virtual database list (" + e1.getMessage() 399 + ")"); 400 vdbListPanel.removeAll(); 401 } 402 paintDatabasePanel(); 403 repaint(); 404 } 405 406 void actionUnloadBackends(String controller) 407 { 408 appendDebugText("Unloading backends from controller:" + controller); 409 Enumeration enume; 410 BackendObject bo; 411 String name; 412 while ((enume = backendList.keys()).hasMoreElements()) 413 { 414 name = (String ) enume.nextElement(); 415 bo = (BackendObject) backendList.get(name); 416 bo.setVisible(false); 417 backendList.remove(name); 418 bo = null; 419 } 420 } 421 422 void paintDatabasePanel() 423 { 424 vdbListPanel.validate(); 425 vdbListPanel.repaint(); 426 validate(); 427 repaint(); 428 } 429 430 private void actionLoadDatabase(String databaseName, String controllerName) 431 { 432 DatabaseObject dob = new DatabaseObject(databaseName, controllerName, false); 436 dob.setActionCommand(GuiCommands.COMMAND_SELECT_DATABASE); 437 dob.addActionListener(guiActionListener); 438 dob.addMouseListener(new DatabasePopUpMenu(this, dob)); 439 databaseList.put(databaseName, dob); 440 VirtualDatabaseMBean virtualDatabaseMBean = actionGetDatabaseBean(databaseName); 442 if (virtualDatabaseMBean != null) 443 dob.setDistributed(virtualDatabaseMBean.isDistributed()); 444 actionAddObjectToGridLayout(vdbListPanel, dob); 445 appendDebugText("Loaded:" + databaseName + " for controller:" 446 + controllerName); 447 } 448 449 private void actionAddObjectToGridLayout(JPanel panel, JButton button) 450 { 451 GridLayout layout = (GridLayout ) panel.getLayout(); 452 int pcount = panel.getComponentCount(); 453 layout.setRows(pcount + 1); 454 panel.add(button); 455 panel.validate(); 456 panel.repaint(); 457 } 458 459 464 public void publicActionLoadBackendsList(String databaseName) 465 { 466 try 467 { 468 VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(databaseName); 469 ArrayList backends = databaseMBean.getAllBackendNames(); 471 appendDebugText("Local Backend list for controller(" 472 + currentJmxClient.getRemoteName() + ") is:" + backends); 473 for (int i = 0; i < backends.size(); i++) 474 actionLoadBackend(databaseName, (String ) backends.get(i), 475 currentJmxClient.getRemoteName(), true); 476 477 if (databaseMBean.isDistributed()) 478 { 479 databaseMBean = actionGetDatabaseBean(databaseName); 480 Hashtable map; 481 try 482 { 483 map = databaseMBean.viewGroupBackends(); 484 Enumeration enumeration = map.keys(); 485 while (enumeration.hasMoreElements()) 486 { 487 String controllerName = (String ) enumeration.nextElement(); 488 ArrayList list = (ArrayList ) map.get(controllerName); 489 for (int i = 0; i < list.size(); i++) 490 { 491 BackendInfo info = (BackendInfo) list.get(i); 492 String backendName = info.getName(); 493 actionLoadBackend(databaseName, backendName, controllerName, 494 false); 495 } 496 } 497 } 498 catch (RuntimeException e1) 499 { 500 appendDebugText( 501 "Runtime exception while loading distributed database:" 502 + databaseName, e1); 503 } 504 505 } 506 paintBackendPane(); 507 } 508 catch (Exception e) 509 { 510 appendDebugText("Could not retrieve backend list for database" 511 + databaseName, e); 512 } 513 } 514 515 523 public void actionLoadBackend(String database, String backendName, 524 String controllerName, boolean enable) 525 { 526 BackendObject backend = null; 527 if (!backendList.containsKey(backendName)) 528 { 529 appendDebugText("Loading backend:" + backendName + " from controller:" 530 + controllerName); 531 try 532 { 533 backend = new BackendObject(this, backendTransferListener, database, 534 backendName, controllerName) 535 { 536 public JToolTip createToolTip() 537 { 538 return new JMultiLineToolTip(); 539 } 540 }; 541 } 542 catch (Exception e) 543 { 544 e.printStackTrace(); 545 } 546 backend.setBorder(BorderFactory.createTitledBorder( 547 GuiConstants.LOWERED_BORDER, controllerName)); 548 backend.setControllerName(controllerName); 549 backendList.put(backendName, backend); 550 } 551 else 552 { 553 backend = (BackendObject) backendList.get(backendName); 554 backend.setBorder(BorderFactory.createTitledBorder( 555 GuiConstants.LOWERED_BORDER, controllerName)); 556 backend.setControllerName(controllerName); 557 backend.setEnabled(controllerName.equals(selectedController)); 558 appendDebugText("ReLoading backend:" + backendName); 559 } 560 561 try 562 { 563 actionSetBackendState(backendName); 564 } 565 catch (RuntimeException e) 566 { 567 appendDebugText("cannot access mbean anymore"); 568 publicActionRemoveBackendFromGui(backendName); 569 } 570 } 571 572 579 private String actionConvertState(String jmxState) 580 { 581 if (jmxState == null) 582 return null; 583 584 appendDebugText("Converting new jmx state:" + jmxState); 585 586 if (jmxState 587 .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED)) 588 return GuiConstants.BACKEND_STATE_ENABLED; 589 else if (jmxState 590 .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED_WRITE)) 591 return GuiConstants.BACKEND_STATE_ENABLED; 592 else if (jmxState 593 .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLED)) 594 return GuiConstants.BACKEND_STATE_DISABLED; 595 else if (jmxState 596 .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLING)) 597 return GuiConstants.BACKEND_STATE_DISABLED; 598 else if (jmxState 599 .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_BACKINGUP)) 600 return GuiConstants.BACKEND_STATE_BACKUP; 601 else if (jmxState 602 .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_RECOVERING)) 603 return GuiConstants.BACKEND_STATE_RESTORE; 604 else if (jmxState 605 .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_REPLAYING)) 606 return GuiConstants.BACKEND_STATE_RECOVERY; 607 else if (jmxState 608 .equalsIgnoreCase(CjdbcNotificationList.VIRTUALDATABASE_BACKEND_UNKNOWN)) 609 return GuiConstants.BACKEND_STATE_DISABLED; 610 else 611 return null; 612 } 613 614 624 public void actionChangeBackendState(BackendObject bo, String newState) 625 { 626 if (!GuiConstants.isValidBackendState(newState)) 628 return; 629 630 632 String oldState = bo.getState(); 634 JPanel oldpanel = (JPanel ) backendsState.get(oldState); 635 oldpanel.remove(bo); 636 oldpanel.validate(); 637 oldpanel.repaint(); 638 639 bo.setState(newState); 641 642 JPanel panel = (JPanel ) backendsState.get(newState); 644 panel.add(bo); 645 panel.validate(); 646 panel.repaint(); 647 } 648 649 655 public void actionSetBackendState(String backendName) 656 { 657 try 658 { 659 BackendObject bo = (BackendObject) backendList.get(backendName); 660 if (bo == null) 661 { 662 appendDebugText("Backend (" + backendName + ") cannot be found"); 663 return; 664 } 665 String controllerName = bo.getControllerName(); 666 if (controllerName == null) 667 { 668 appendDebugText("Backend (" + backendName 669 + ") has lost its controller reference."); 670 appendDebugText("Removing backend (" + backendName 671 + ") from display list."); 672 backendList.remove(backendName); 673 return; 674 } 675 if (selectedController.equals(controllerName)) 676 bo.setEnabled(true); 677 else 678 bo.setEnabled(false); 679 String state = bo.getState(); 680 appendDebugText("STATE:" + state); 681 String login = guiSession.getAuthenticatedDatabaseLogin(bo.getDatabase()); 682 String password = guiSession.getAuthenticatedDatabasePassword(bo 683 .getDatabase()); 684 RmiJmxClient client = (RmiJmxClient) jmxClients.get(controllerName); 685 DatabaseBackendMBean backend = null; 686 VirtualDatabaseMBean databaseMBean = null; 687 688 try 689 { 690 backend = client.getDatabaseBackendProxy(bo.getDatabase(), backendName, 691 login, password); 692 databaseMBean = client.getVirtualDatabaseProxy(bo.getDatabase(), login, 693 password); 694 } 695 catch (Exception e) 696 { 697 appendDebugText("Could not change state of backend:" + backendName, 698 new JmxException("MBean connection was lost")); 699 } 700 String newState = actionConvertState(backend.getState()); 701 702 actionSetBackendState(backendName, newState); 703 704 try 706 { 707 String [] data = databaseMBean.viewBackendInformation(backendName); 708 bo.setToolTipText(new BackendToolTip(data).getFormattedToolTip()); 709 } 710 catch (Exception e) 711 { 712 appendDebugText("Tool tip could not be collected for backend:" 713 + backendName); 714 } 715 } 716 catch (Exception e) 717 { 718 appendDebugText("Could not change state of backend:" + backendName, e); 719 } 720 } 721 722 728 public void actionSetBackendState(String backendName, String newState) 729 { 730 BackendObject bo = (BackendObject) backendList.get(backendName); 731 appendDebugText("Setting backend(" + backendName + "):" + bo.getName() 732 + " to state:" + newState); 733 734 String state = bo.getState(); 735 if (state == null) 736 { 737 } 739 else 740 { 741 JPanel panel = (JPanel ) backendsState.get(state); 743 panel.remove(bo); 744 panel.validate(); 745 panel.repaint(); 746 } 747 748 JPanel panel = (JPanel ) backendsState.get(newState); 750 bo.setState(newState); 751 752 panel.add(bo); 753 panel.validate(); 754 panel.repaint(); 755 756 } 757 758 761 public void paintBackendPane() 762 { 763 backendPanel.validate(); 767 backendPanel.repaint(); 768 } 769 770 void paintConfigurationPane() 771 { 772 fileScroll.setVisible(true); 776 fileListPanel.setVisible(true); 777 fileScroll.validate(); 778 fileListPanel.validate(); 779 fileScroll.repaint(); 780 } 781 782 String actionLoadXmlText(File filePath) 783 { 784 try 788 { 789 if (filePath == null || !filePath.exists()) 790 { 791 return ""; 792 } 793 StringBuffer buffer = new StringBuffer (); 794 BufferedReader reader = new BufferedReader (new FileReader (filePath)); 795 String line = ""; 796 while ((line = reader.readLine()) != null) 797 { 798 buffer.append(line + System.getProperty("line.separator")); 799 } 800 reader.close(); 801 return buffer.toString(); 802 } 803 catch (Exception e) 804 { 805 appendDebugText("Error while reading from file:" + e.getMessage()); 806 return ""; 807 } 808 } 809 810 815 public void appendDebugText(String text) 816 { 817 debugText += text + System.getProperty("line.separator"); 818 debugTextPane.setText(debugText); 819 } 820 821 827 public void appendDebugText(String text, Exception e) 828 { 829 try 830 { 831 if (GuiConstants.DEBUG_LEVEL <= GuiConstants.DEBUG_NO_EXCEPTION_WINDOW) 832 { 833 if (e instanceof MBeanException ) 834 exceptionFrame.showException(((MBeanException ) e) 835 .getTargetException()); 836 else 837 exceptionFrame.showException(e); 838 } 839 appendDebugText(text + "[Message:" + e.getMessage() + "]"); 840 traceWriter.write("---- Exception ----\n"); 841 e.printStackTrace(new PrintWriter (traceWriter)); 842 traceWriter.flush(); 843 } 844 catch (IOException e1) 845 { 846 } 848 } 849 850 853 public void publicActionAddXmlFile() 854 { 855 if (configurationFileChooser == null) 856 { 857 configurationFileChooser = new JFileChooser ("."); 858 configurationFileChooser.setFileFilter(new FileFilter () 859 { 860 863 public boolean accept(File f) 864 { 865 if (f.getAbsolutePath().endsWith(".xml") || f.isDirectory()) 866 return true; 867 else 868 return false; 869 } 870 871 874 public String getDescription() 875 { 876 return "Xml Files"; 877 } 878 }); 879 } 880 configurationFileChooser.showOpenDialog(this); 881 File selFile = configurationFileChooser.getSelectedFile(); 882 if (selFile != null) 883 { 884 appendDebugText("Selected new file:" + selFile.getAbsolutePath()); 885 guiSession.addFileToConfigurationFiles(selFile); 886 ConfigurationFileObject cfo = new ConfigurationFileObject( 887 configurationFileTransferListener, selFile); 888 ConfigurationFilePopUpMenu cfpum = new ConfigurationFilePopUpMenu(this, 889 cfo); 890 cfo.addActionListener(cfpum); 891 cfo.addMouseListener(cfpum); 892 actionAddObjectToGridLayout(fileListPanel, cfo); 893 paintConfigurationPane(); 894 } 895 } 896 897 void actionLoadXmlList() 898 { 899 if (fileListPanel != null) 900 { 901 ArrayList vfileItems = guiSession.getConfigurationFiles(); 902 int vsize = vfileItems.size(); 903 ConfigurationFileObject cfo; 904 for (int i = 0; i < vsize; i++) 905 { 906 cfo = new ConfigurationFileObject(configurationFileTransferListener, 907 (File ) vfileItems.get(i)); 908 ConfigurationFilePopUpMenu cfpum = new ConfigurationFilePopUpMenu(this, 909 cfo); 910 cfo.addActionListener(cfpum); 911 cfo.addMouseListener(cfpum); 912 fileListPanel.add(cfo); 913 actionAddObjectToGridLayout(fileListPanel, cfo); 914 } 915 } 917 } 918 919 private ArrayList actionLoadCheckpointNames(String databaseName) 920 { 921 ArrayList list = actionGetDatabaseBean(databaseName).viewCheckpointNames(); 922 for (int i = 0; i < list.size(); i++) 923 appendDebugText("Found checkpoint:" + list.get(i) + " for database:" 924 + databaseName); 925 return list; 926 } 927 928 933 public void publicActionLoadControllerList() 934 { 935 if (controllerListPanel != null) 936 { 937 controllerListPanel.removeAll(); 938 ArrayList controllerItems = guiSession.getControllerItems(); 939 int size = controllerItems.size(); 940 for (int i = 0; i < size; i++) 941 actionLoadController((String ) controllerItems.get(i)); 942 paintControllerPane(); 943 } 944 } 945 946 949 void paintControllerPane() 950 { 951 controllerListPanel.validate(); 952 controllerListPanel.repaint(); 953 } 954 955 958 public void publicActionAddControllerView() 959 { 960 newControllerFrame.setVisible(true); 961 } 962 963 969 public void publicActionDatabaseEnableAll(String databaseName) 970 { 971 try 972 { 973 actionGetDatabaseBean(databaseName).enableAllBackends(); 974 publicActionLoadBackendsList(databaseName); 975 centerPane.setSelectedComponent(backendPanel); 976 appendDebugText("Enabled All backends for :" + databaseName 977 + " was a success"); 978 } 979 catch (Exception e) 980 { 981 appendDebugText("Enabled All backends for :" + databaseName + " failed", 982 e); 983 } 984 } 985 986 991 public void actionLoadBackendActionButton(String name) 992 { appendDebugText("Loading backend action panel:" + name); 996 Color color = GuiConstants.getBackendBgColor(name); 997 998 JPanel paneContent = new JPanel (new FlowLayout ()); 999 paneContent.setBackground(color); 1000 paneContent.setName(name); 1001 paneContent.setVisible(true); 1002 1003 JButton paneLabel = new JButton (name); 1004 paneLabel.setActionCommand(name); 1005 paneLabel.setBackground(color); 1006 paneLabel.setSize(100, 50); 1007 paneLabel.setVisible(true); 1008 1009 DropTarget target1 = new DropTarget (paneLabel, DnDConstants.ACTION_MOVE, 1010 backendTransferListener); 1011 target1.setActive(true); 1012 1013 DropTarget target2 = new DropTarget (paneContent, DnDConstants.ACTION_MOVE, 1014 backendTransferListener); 1015 target2.setActive(true); 1016 1017 GridLayout iconLayout = (GridLayout ) backendIcons.getLayout(); 1018 iconLayout.setColumns(iconLayout.getColumns() + 1); 1019 GridLayout buttonsLayout = (GridLayout ) backendButtons.getLayout(); 1020 buttonsLayout.setColumns(buttonsLayout.getColumns() + 1); 1021 backendIcons.add(paneContent); 1022 backendButtons.add(paneLabel); 1023 backendsState.put(name, paneContent); 1025 } 1026 1027 1033 public void actionLoadBackendPane(boolean recoveryEnabled) 1034 { 1035 if (backendPanel == null) 1039 { 1040 backendPanel = new JPanel (new BorderLayout ()); 1041 backendPanel.setEnabled(true); 1042 backendPanel.setBackground(Color.white); 1043 backendPanel.setVisible(true); 1044 } 1045 else 1046 { 1047 backendPanel.remove(backendButtons); 1048 backendPanel.remove(backendIcons); 1049 } 1050 1051 backendButtons = new JPanel (new GridLayout (1, 0)); 1052 backendIcons = new JPanel (new GridLayout (1, 0)); 1053 backendIcons.setBackground(Color.white); 1054 backendIcons.setVisible(true); 1055 backendButtons.setVisible(true); 1056 1057 actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_ENABLED); 1058 if (recoveryEnabled) 1059 actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_RECOVERY); 1060 actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_DISABLED); 1061 if (recoveryEnabled) 1062 actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_BACKUP); 1063 if (recoveryEnabled) 1064 actionLoadBackendActionButton(GuiConstants.BACKEND_STATE_RESTORE); 1065 backendPanel.add(backendIcons, BorderLayout.CENTER); 1066 backendPanel.add(backendButtons, BorderLayout.NORTH); 1067 1068 centerPane.validate(); 1069 centerPane.repaint(); 1070 validate(); 1071 repaint(); 1072 } 1073 1074 1077 public void publicActionLoadAuthenticatedDatabase() 1078 { 1079 loginFrame.setVisible(false); 1080 try 1081 { 1082 String databaseName = loginFrame.getDatabaseName(); 1083 String login = loginFrame.getLoginBox().getText().trim(); 1084 String password = loginFrame.getPasswordBox().getText().trim(); 1085 1086 VirtualDatabaseMBean mbean = null; 1087 try 1088 { 1089 mbean = currentJmxClient.getVirtualDatabaseProxy(databaseName, login, 1090 password); 1091 if (mbean == null) 1092 throw new IOException ("MBean connection lost"); 1093 } 1094 catch (IOException ioe) 1095 { 1096 appendDebugText(ioe.getMessage()); 1097 actionUnloadBackends(currentJmxClient.getRemoteName()); 1098 return; 1099 } 1100 1101 if (!mbean.checkAdminAuthentication(login, password)) 1102 { 1103 throw new Exception ("Authentication failed"); 1104 } 1105 1106 databaseMBeans.put(databaseName, mbean); 1107 guiSession.addDatabaseToSession(databaseName, login, password); 1108 1109 String [] list = mbean.viewControllerList(); 1110 for (int i = 0; i < list.length; i++) 1111 { 1112 appendDebugText("Found controllerL" + list[i]); 1113 if (!guiSession.checkControllerInSession(list[i])) 1114 { 1115 actionLoadController(list[i]); 1116 RmiJmxClient client = (RmiJmxClient) jmxClients.get(list[i]); 1117 client.getVirtualDatabaseProxy(databaseName, login, password); 1119 paintControllerPane(); 1120 } 1121 } 1122 1123 boolean recoveryExist = mbean.hasRecoveryLog(); 1124 appendDebugText("RecoveryLog is defined for this database:" 1125 + recoveryExist); 1126 actionLoadBackendPane(recoveryExist); 1127 1128 publicActionLoadBackendsList(databaseName); 1129 actionLoadCheckpointNames(databaseName); 1130 publicActionLoadDumpList(databaseName); 1131 } 1132 catch (Exception e1) 1133 { 1134 appendDebugText("Could not connect to database", e1); 1135 } 1136 } 1137 1138 1141 public void publicActionQuit() 1142 { 1143 try 1144 { 1145 guiSession.saveSessionToFile(new File ( 1146 GuiConstants.CJDBC_DEFAULT_SESSION_FILE)); 1147 } 1148 catch (IOException e) 1149 { 1150 System.out.println("Could not save session"); 1151 } 1152 System.exit(0); 1153 } 1154 1155 1161 public void publicActionLoadDriver(String controllerName) 1162 { 1163 if (jarFileChooser == null) 1164 { 1165 jarFileChooser = new JFileChooser ("."); 1166 jarFileChooser.setFileFilter(new FileFilter () 1167 { 1168 1171 public boolean accept(File f) 1172 { 1173 if (f.getAbsolutePath().endsWith(".jar") || f.isDirectory()) 1174 return true; 1175 else 1176 return false; 1177 } 1178 1179 1182 public String getDescription() 1183 { 1184 return "Jar Files"; 1185 } 1186 }); 1187 } 1188 jarFileChooser.showOpenDialog(this); 1189 File selFile = jarFileChooser.getSelectedFile(); 1190 try 1191 { 1192 if (selFile != null) 1193 { 1194 ControllerMBean controllerMBean = actionGetControllerBean(controllerName); 1195 controllerMBean.addDriver(readDriver(selFile.getAbsolutePath())); 1196 } 1197 } 1198 catch (Exception e) 1199 { 1200 appendDebugText("Could not load driver from jar file:" 1201 + selFile.getName()); 1202 } 1203 } 1204 1205 private byte[] readDriver(String filename) throws FileNotFoundException , 1206 IOException 1207 { 1208 File file; 1209 FileInputStream fileInput = null; 1210 file = new File (filename); 1211 fileInput = new FileInputStream (file); 1212 1213 long size = file.length(); 1215 if (size > Integer.MAX_VALUE) 1216 throw new IOException (ConsoleTranslate 1217 .get("controller.command.adddriver.file.too.big")); 1218 byte[] bytes = new byte[(int) size]; 1219 int nb = fileInput.read(bytes); 1220 fileInput.close(); 1221 if (nb != size) 1222 throw new IOException (ConsoleTranslate 1223 .get("controller.command.adddriver.file.not.read")); 1224 return bytes; 1225 } 1226 1227 1232 public void publicActionRefreshLogs(String controllerName) 1233 { 1234 try 1235 { 1236 ControllerMBean controllerMBean = actionGetControllerBean(controllerName); 1237 loggingTextPane.setText(controllerMBean.generateLogReport()); 1238 appendDebugText("Re-Fetched logs for controller:" + controllerName); 1239 } 1240 catch (Exception e) 1241 { 1242 appendDebugText("Fail to fetch logs for controller:" + controllerName, e); 1243 } 1244 } 1245 1246 1249 public void publicActionCleanDebugBuffer() 1250 { 1251 debugText = ""; 1252 debugTextPane.setText(""); 1253 } 1254 1255 1259 public void publicActionSaveConfigurationFile() 1260 { 1261 try 1262 { 1263 if (saveFileChooser == null) 1264 { 1265 saveFileChooser = new JFileChooser (); 1266 saveFileChooser.showSaveDialog(this); 1267 File selected = saveFileChooser.getSelectedFile(); 1268 if (selected != null) 1269 { 1270 BufferedWriter writer = new BufferedWriter (new FileWriter (selected)); 1271 writer.write(xmlTextPane.getText()); 1272 writer.close(); 1273 } 1274 else 1275 { 1276 appendDebugText("Did not select a file was saving..."); 1277 } 1278 } 1279 } 1280 catch (Exception e) 1281 { 1282 appendDebugText("Error while writing to file:" + e.getMessage()); 1283 } 1284 } 1285 1286 1289 public void publicActionAddController() 1290 { 1291 newControllerFrame.setVisible(false); 1292 String ipAddress = newControllerFrame.getIpAddressBox().getText().trim(); 1293 String port = newControllerFrame.getPortNumber().getText().trim(); 1294 appendDebugText("Add controller with ip:" + ipAddress + " amd port:" + port); 1295 String name = ipAddress + ":" + port; 1296 if (guiSession.checkControllerInSession(name)) 1297 { 1298 String message = GuiTranslate.get("error.controller.already.in.session"); 1299 CJDBCException e = new CJDBCException(message); 1300 appendDebugText(message, e); 1301 } 1302 else 1303 { 1304 actionLoadController(name); 1305 paintControllerPane(); 1306 } 1307 } 1308 1309 1315 private void actionLoadController(String name) 1316 { 1317 guiSession.addControllerToList(name); 1318 ControllerObject co = new ControllerObject(name); 1319 co.setActionCommand(GuiCommands.COMMAND_SELECT_CONTROLLER); 1320 co.addActionListener(guiActionListener); 1321 co.addMouseListener(new ControllerPopUpMenu(this, co)); 1322 ControllerMBean controllerMBean = actionGetControllerBean(name); 1323 if (controllerMBean == null) 1324 { 1325 appendDebugText("Cannot load controller:" + name); 1326 return; 1327 } 1328 DropTarget target = new DropTarget (co, DnDConstants.ACTION_MOVE, 1329 configurationFileTransferListener); 1330 co.setDropTarget(target); 1331 appendDebugText("Loading controller:" + controllerMBean.getJmxName()); 1332 if (currentJmxClient.isValidConnection()) 1333 { 1334 co.setState(GuiConstants.CONTROLLER_STATE_UP); 1335 } 1336 else 1337 { 1338 co.setState(GuiConstants.CONTROLLER_STATE_DOWN); 1339 } 1340 actionAddObjectToGridLayout(controllerListPanel, co); 1341 controllerList.put(name, co); 1342 } 1343 1344 1349 public void publicActionSelectNewController(String connectUrl) 1350 { 1351 Enumeration enume = controllerList.keys(); 1352 String key = ""; 1353 ControllerObject controller; 1354 while (enume.hasMoreElements()) 1355 { 1356 key = (String ) enume.nextElement(); 1357 controller = (ControllerObject) controllerList.get(key); 1358 if (key.equalsIgnoreCase(connectUrl)) 1359 { 1360 controller.setBorder(GuiConstants.TITLED_BORDER); 1361 controller.setBorderPainted(true); 1362 } 1363 else 1364 controller.setBorderPainted(false); 1365 } 1366 actionGetControllerBean(connectUrl); 1367 selectedController = connectUrl; 1368 actionLoadDatabaseList(connectUrl); 1369 publicActionLoadXmlController(connectUrl); 1370 1371 if (selectedDatabase != null) 1372 publicActionLoadAuthenticatedDatabase(); 1373 1374 actionStartControllerLoggingThread(connectUrl); 1375 } 1376 1377 1382 public String getSelectedController() 1383 { 1384 return selectedController; 1385 } 1386 1387 1392 public void publicActionLoadDumpList(String databaseName) 1393 { 1394 VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(databaseName); 1395 try 1396 { 1397 File [] dumps = new File [0]; 1400 appendDebugText("Loaded dumps for virtual database:" + databaseName); 1401 JPanel dumpPane = (JPanel ) backendsState 1402 .get(GuiConstants.BACKEND_STATE_RESTORE); 1403 dumpPane.removeAll(); 1404 for (int i = 0; i < dumps.length; i++) 1405 { 1406 appendDebugText("Adding dump:" + dumps[i]); 1407 DumpFileObject dfo = new DumpFileObject(dumps[i]) 1408 { 1409 public JToolTip createToolTip() 1410 { 1411 return new JMultiLineToolTip(); 1412 } 1413 }; 1414 dfo.addMouseListener(new DumpPopUpMenu(this, databaseName, dfo)); 1415 DropTarget target = new DropTarget (dfo, DnDConstants.ACTION_MOVE, 1416 backendTransferListener); 1417 dfo.setDropTarget(target); 1418 dumpPane.add(dfo); 1419 } 1420 paintBackendPane(); 1421 } 1422 catch (Exception e) 1423 { 1424 e.printStackTrace(); 1425 appendDebugText("Failed to load dumps for virtual database:" 1426 + databaseName + " because of:" + e.getMessage()); 1427 } 1428 } 1429 1430 1436 public void publicActionLoadXmlController(String connectUrl) 1437 { 1438 try 1439 { 1440 ControllerMBean controllerMBean = actionGetControllerBean(connectUrl); 1441 xmlTextPane.setText(controllerMBean.getXml()); 1442 appendDebugText("Loaded xml configuration for controller:" + connectUrl); 1443 } 1444 catch (Exception e) 1445 { 1446 appendDebugText("Failed to get xml configuration for controller:" 1447 + connectUrl); 1448 } 1449 } 1450 1451 1456 public void publicActionSelectNewDatabase(String value) 1457 { 1458 selectedDatabase = value; 1459 try 1460 { 1461 VirtualDatabaseMBean databaseClient = actionGetDatabaseBean(value); 1462 if (databaseClient != null) 1463 { 1464 databaseClient.viewControllerList(); 1465 publicActionLoadAuthenticatedDatabase(); 1466 } 1467 Enumeration enume = databaseList.keys(); 1468 String key = ""; 1469 DatabaseObject database; 1470 while (enume.hasMoreElements()) 1471 { 1472 key = (String ) enume.nextElement(); 1473 database = (DatabaseObject) databaseList.get(key); 1474 if (key.equalsIgnoreCase(value)) 1475 { 1476 database.setBorder(GuiConstants.TITLED_BORDER); 1477 database.setBorderPainted(true); 1478 } 1479 else 1480 database.setBorderPainted(false); 1481 } 1482 } 1483 catch (Exception e) 1484 { 1485 appendDebugText("Failed to get access to database:" + value, e); 1486 } 1487 } 1488 1489 1494 public void publicActionLoadXmlDatabase(String databaseName) 1495 { 1496 try 1497 { 1498 VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(databaseName); 1499 xmlTextPane.setText(XmlTools.prettyXml(databaseMBean.getXml())); 1500 appendDebugText("Loaded xml configuration for database:" + databaseName); 1501 centerPane.setSelectedComponent(xmlScroll); 1502 } 1503 catch (Exception e) 1504 { 1505 appendDebugText("Failed to get xml configuration for database:" 1506 + databaseName, e); 1507 } 1508 } 1509 1510 1516 public void publicActionSelectNewConfigurationFile(String file) 1517 { 1518 try 1519 { 1520 xmlTextPane.setText(actionLoadXmlText(new File (file))); 1521 appendDebugText("Loaded xml configuration for file:" + file); 1522 centerPane.setSelectedComponent(xmlScroll); 1523 } 1524 catch (Exception e) 1525 { 1526 appendDebugText("Failed to load xml for file:" + file); 1527 } 1528 } 1529 1530 1536 public void publicActionShutdownDatabase(DatabaseObject dob, int shutdownLevel) 1537 { 1538 try 1539 { 1540 String databaseName = dob.getName(); 1541 VirtualDatabaseMBean vdbMBean = actionGetDatabaseBean(databaseName); 1542 vdbMBean.shutdown(shutdownLevel); 1543 controllerListPanel.remove(dob); 1544 guiSession.getDatabaseItems().remove(databaseName); 1545 String controllerName = dob.getControllerName(); 1546 actionUnloadBackends(controllerName); 1547 actionLoadDatabaseList(controllerName); 1548 } 1549 catch (Exception e) 1550 { 1551 appendDebugText("Failed to shutdown database", e); 1552 } 1553 } 1554 1555 1561 public void publicActionExecuteBackendDrop(JButton target, String backendName) 1562 { 1563 1564 String actionName = target.getActionCommand(); 1565 if (actionName.equals(GuiConstants.BACKEND_STATE_RESTORE)) 1566 publicActionRestoreBackend(backendName, ((DumpFileObject) target) 1567 .getDumpName()); 1568 else 1569 publicActionExecuteBackendDrop(actionName, backendName); 1570 } 1571 1572 private String actionDisplaySelectCheckpointFrame(String database) 1573 { 1574 VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(database); 1575 if (selectCheckpointFrame == null) 1576 { 1577 ArrayList list = databaseMBean.viewCheckpointNames(); 1578 list.add(GuiConstants.BACKEND_NO_CHECKPOINT); 1579 String [] entries = (String []) list.toArray(new String [list.size()]); 1580 selectCheckpointFrame = new GuiSelectCheckpointFrame(this, entries, 1581 guiActionListener); 1582 selectCheckpointFrame.setVisible(true); 1583 } 1584 1585 JTextField field = selectCheckpointFrame.getValueField(); 1586 selectCheckpointFrame = null; 1587 if (field == null) 1588 return null; 1589 String checkpoint = field.getText(); 1590 return checkpoint; 1591 } 1592 1593 1600 private boolean isDropInSameColumn(String actionName, String backendName) 1601 { 1602 BackendObject bob = (BackendObject) backendList.get(backendName); 1603 String state = bob.getState(); 1604 if (state.equalsIgnoreCase(actionName)) 1605 return true; 1606 else 1607 return false; 1608 } 1609 1610 1616 public void publicActionExecuteBackendDrop(String actionName, 1617 String backendName) 1618 { 1619 appendDebugText("Got drop backend action:" + actionName + " from:" 1620 + backendName); 1621 1622 BackendObject bob = (BackendObject) backendList.get(backendName); 1623 String database = bob.getDatabase(); 1624 VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(bob 1625 .getDatabase()); 1626 1627 1635 1636 if (isDropInSameColumn(actionName, backendName)) 1637 { 1638 appendDebugText("Drop action is not relevant"); 1639 return; 1640 } 1641 1642 if (actionName.equals(GuiConstants.BACKEND_STATE_ENABLED)) 1643 { 1644 try 1645 { 1646 DatabaseBackendMBean bean = bob.getMbean(); 1647 String lastcheck = bean.getLastKnownCheckpoint(); 1648 if (lastcheck != null) 1649 { 1650 actionSetBackendState(backendName, 1651 GuiConstants.BACKEND_STATE_RECOVERY); 1652 databaseMBean.enableBackendFromCheckpoint(backendName); 1653 return; 1654 } 1655 else 1656 { 1657 String checkpoint = actionDisplaySelectCheckpointFrame(database); 1658 if (checkpoint == null) 1659 { 1660 appendDebugText("Cancelling enable backend..."); 1661 return; 1662 } 1663 appendDebugText("Using checkpoint:" + checkpoint 1664 + " to enable backend:" + backendName); 1665 if (checkpoint.equals(GuiConstants.BACKEND_NO_CHECKPOINT)) 1666 databaseMBean.forceEnableBackend(backendName); 1667 else 1668 databaseMBean.enableBackendFromCheckpoint(backendName); 1669 } 1670 } 1672 catch (Exception e) 1673 { 1674 appendDebugText("Failed to enable backend", e); 1675 } 1676 } 1677 else if (actionName.equals(GuiConstants.BACKEND_STATE_DISABLED)) 1678 { 1679 try 1680 { 1681 if (!databaseMBean.hasRecoveryLog()) 1683 databaseMBean.forceDisableBackend(backendName); 1684 else 1685 { 1686 String checkpoint = generateCheckpoint(backendName); 1687 appendDebugText("Using autogenerated checkpoint:" + checkpoint 1695 + " to disable backend:" + backendName); 1696 databaseMBean.disableBackendWithCheckpoint(backendName); 1700 } 1701 actionSetBackendState(backendName); 1702 } 1703 catch (Exception e) 1704 { 1705 appendDebugText("Failed to disable backend", e); 1706 } 1707 } 1708 else if (actionName.equals(GuiConstants.BACKEND_STATE_NEW)) 1709 { 1710 appendDebugText("Creating new backend from backend:" + bob.getName()); 1711 publicActionNewBackendPrompt(bob); 1712 } 1713 else if (actionName.equals(GuiConstants.BACKEND_STATE_BACKUP)) 1714 { 1715 publicActionBackupBackendPrompt(bob); 1716 } 1717 1718 actionRefreshBackendState(bob); 1719 } 1720 1721 private void actionRefreshBackendState(BackendObject bob) 1722 { 1723 String state = bob.getState(); 1724 JPanel panel = (JPanel ) backendsState.get(state); 1725 if (panel.getParent().equals(panel)) 1726 { 1727 appendDebugText("refresh of backend:" + bob.getName() + " not needed"); 1728 } 1729 else 1730 { 1731 appendDebugText("refresh of backend:" + bob.getName() + " needed"); 1732 actionLoadBackend(bob.getDatabase(), bob.getName(), bob 1733 .getControllerName(), bob.isEnabled()); 1734 } 1736 } 1737 1738 1744 private String generateCheckpoint(String backendName) 1745 { 1746 String check = backendName + ":" 1747 + new SimpleDateFormat ("yyyy.MM.dd.HH.mm.ss").format(new Date ()); 1748 return Strings.replace(check, ":", "-"); 1749 } 1750 1751 1756 public void publicActionNewBackendPrompt(BackendObject bob) 1757 { 1758 if (newBackendFrame == null) 1759 newBackendFrame = new NewBackendFrame(bob, guiActionListener); 1760 else 1761 newBackendFrame.setBob(bob); 1762 newBackendFrame.setVisible(true); 1763 } 1764 1765 1771 public void publicActionRestoreBackend(String backendName, String dumpName) 1772 { 1773 BackendObject bob = (BackendObject) backendList.get(backendName); 1774 try 1775 { 1776 if (bob.getMbean().isReadEnabled()) 1777 { 1778 String message = "Cannot restore an enabled backend"; 1779 appendDebugText(message, new ConsoleException(message)); 1780 return; 1781 } 1782 } 1783 catch (Exception e) 1784 { 1785 appendDebugText(e.getMessage(), e); 1786 return; 1787 } 1788 appendDebugText("Restoring backend:" + backendName + " with dump name:" 1789 + dumpName); 1790 1791 VirtualDatabaseMBean database = actionGetDatabaseBean(bob.getDatabase()); 1792 new Thread (new RestoreBackendTask(this, database, bob, dumpName)).start(); 1793 } 1794 1795 1800 public void publicActionBackupBackendPrompt(BackendObject bob) 1801 { 1802 String checkpoint = actionDisplayInputBackupFrame(bob.getDatabase(), bob 1803 .getName()); 1804 if (checkpoint == null) 1805 { 1806 appendDebugText("No dump name received, cancelling action..."); 1807 return; 1808 } 1809 VirtualDatabaseMBean database = actionGetDatabaseBean(bob.getDatabase()); 1810 new Thread (new BackupBackendTask(this, database, bob, checkpoint)).start(); 1811 } 1812 1813 1820 private String actionDisplayInputBackupFrame(String database, String backend) 1821 { 1822 VirtualDatabaseMBean databaseMBean = actionGetDatabaseBean(database); 1823 if (inputBackupFrame == null) 1824 { 1825 File [] files = new File [0]; 1828 int size = files.length; 1829 String [] entries = new String [size]; 1830 for (int i = 0; i < size; i++) 1831 { 1832 entries[i] = files[i].getName(); 1833 } 1834 inputBackupFrame = new GuiInputBackupFrame(this, entries, 1835 guiActionListener); 1836 inputBackupFrame.setValue(generateCheckpoint(backend)); 1837 inputBackupFrame.setVisible(true); 1838 } 1839 1840 JTextField field = inputBackupFrame.getValueField(); 1841 inputBackupFrame = null; 1842 if (field == null) 1843 return null; 1844 String dump = field.getText(); 1845 return dump; 1846 } 1847 1848 1851 public void publicActionRefreshCursorShape() 1852 { 1853 appendDebugText("Refresh cursor for main frame"); 1854 Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); 1855 setCursor(cursor); 1856 backendPanel.setCursor(cursor); 1857 validate(); 1858 repaint(); 1859 } 1860 1861 1867 public void publicActionExecuteControllerDrop(String filePath, 1868 String controllerName) 1869 { 1870 File file = new File (filePath); 1871 try 1872 { 1873 ControllerMBean controllerMBean = actionGetControllerBean(controllerName); 1874 controllerMBean.addVirtualDatabases(actionLoadXmlText(file)); 1875 appendDebugText("Execute public action on controller drop for:" 1876 + filePath + " and:" + controllerName); 1877 actionLoadDatabaseList(controllerName); 1878 } 1879 catch (Exception e) 1880 { 1881 appendDebugText("Failed to load configuration file :" + file.getName(), e); 1882 } 1883 } 1884 1885 1891 public void publicActionDatabaseDisableAll(String databaseName) 1892 { 1893 try 1894 { 1895 actionGetDatabaseBean(databaseName).disableAllBackends(); 1896 publicActionLoadBackendsList(databaseName); 1897 centerPane.setSelectedComponent(backendPanel); 1898 appendDebugText("Disable All backends for :" + databaseName 1899 + " was a success"); 1900 } 1901 catch (Exception e) 1902 { 1903 appendDebugText("Disable All backends for :" + databaseName + " failed.", 1904 e); 1905 } 1906 } 1907 1908 1913 public void publicActionGetControllerInfo(String controllerName) 1914 { 1915 try 1916 { 1917 ControllerMBean controllerMBean = actionGetControllerBean(controllerName); 1918 infoTextPane.setText(controllerMBean.getXml()); 1919 centerPane.setSelectedComponent(infoScroll); 1920 } 1921 catch (Exception e) 1922 { 1923 appendDebugText("Failed to get info for controller:" + controllerName, e); 1924 } 1925 } 1926 1927 1932 public void publicActionShutdownController(String controllerName) 1933 { 1934 ControllerMBean controllerMBean = null; 1935 int shutdownLevel = 2; 1936 try 1937 { 1938 controllerMBean = actionGetControllerBean(controllerName); 1939 } 1940 catch (Exception e) 1941 { 1942 appendDebugText("Failed to get a proxy to shutdown the controller:" 1943 + controllerName, e); 1944 } 1945 try 1946 { 1947 if (controllerMBean != null) 1948 { 1949 ArrayList databases = controllerMBean.getVirtualDatabaseNames(); 1950 for (int i = 0; i < databases.size(); i++) 1951 { 1952 DatabaseObject dob = (DatabaseObject) databaseList.get(databases 1953 .get(i)); 1954 appendDebugText("Shutting down database:" + dob.getName() 1955 + " with level:" + shutdownLevel); 1956 publicActionShutdownDatabase(dob, shutdownLevel); 1957 } 1958 controllerMBean.shutdown(shutdownLevel); 1959 } 1960 else 1961 appendDebugText("Failed to get a proxy to shutdown the controller:" 1962 + controllerName); 1963 } 1964 catch (Exception e) 1965 { 1966 } 1968 publicActionLoadControllerList(); 1969 1970 } 1971 1972 1977 public void publicActionControllerReport(String controllerName) 1978 { 1979 try 1980 { 1981 ControllerMBean controllerMBean = actionGetControllerBean(controllerName); 1982 infoTextPane.setText(controllerMBean.generateReport()); 1983 centerPane.setSelectedComponent(infoScroll); 1984 } 1985 catch (Exception e) 1986 { 1987 appendDebugText("Failed to get info for controller:" + controllerName, e); 1988 } 1989 } 1990 1991 1997 public void publicActionDeleteDump(String databaseName, DumpFileObject dump) 1998 { 1999 boolean confirm = actionDisplayConfirmFrame(GuiTranslate 2000 .get("gui.confirm.delete.dump")); 2001 if (!confirm) 2002 { 2003 appendDebugText("Action is not confirmed, cancelling deletion"); 2004 return; 2005 } 2006 VirtualDatabaseMBean database = actionGetDatabaseBean(databaseName); 2007 2023 } 2024 2025 2031 private boolean actionDisplayConfirmFrame(String message) 2032 { 2033 int value = JOptionPane.showConfirmDialog(this, message, message, 2034 JOptionPane.YES_NO_OPTION); 2035 if (value == JOptionPane.YES_OPTION) 2036 return true; 2037 else 2038 return false; 2039 } 2040 2041 2047 public void publicActionExecuteBackendDrop(JPanel panel, String backendName) 2048 { 2049 publicActionExecuteBackendDrop(panel.getName(), backendName); 2050 } 2051 2052 2057 public void publicActionControllerLogConfiguration(String controllerName) 2058 { 2059 try 2060 { 2061 ControllerMBean controllerMBean = actionGetControllerBean(controllerName); 2062 logConfigTextPane.setText(controllerMBean.viewLogConfigurationFile()); 2063 centerPane.setSelectedComponent(logConfigScroll); 2064 logConfigTextPane.addMouseListener(new LogEditPopUpMenu(this, 2065 controllerName, logConfigTextPane)); 2066 } 2067 catch (Exception e) 2068 { 2069 appendDebugText("Failed to get log4j configuration for controller:" 2070 + controllerName, e); 2071 } 2072 } 2073 2074 2081 public void publicActionUpdateControllerLogConfiguration( 2082 String controllerName, String newContent) 2083 { 2084 try 2085 { 2086 appendDebugText("Updating log4j configuration for controller:" 2087 + controllerName); 2088 ControllerMBean controllerMBean = actionGetControllerBean(controllerName); 2089 controllerMBean.updateLogConfigurationFile(newContent); 2090 actionStartControllerLoggingThread(controllerName); 2091 } 2092 catch (Exception e) 2093 { 2094 appendDebugText("Failed to update log4j configuration for controller:" 2095 + controllerName, e); 2096 } 2097 } 2098 2099 2106 public void publicActionSetLogConfigurationDebug(String controllerName, 2107 String logConfiguration) 2108 { 2109 try 2110 { 2111 String newContent = actionReplaceInConfiguration(logConfiguration, 2112 "INFO", "DEBUG"); 2113 publicActionUpdateControllerLogConfiguration(controllerName, newContent); 2114 } 2115 catch (Exception e) 2116 { 2117 appendDebugText("Setting log configation to debug failed for controller:" 2118 + controllerName, e); 2119 } 2120 } 2121 2122 2129 public void publicActionSetLogConfigurationServer(boolean enableServer, 2130 String controllerName, String logConfiguration) 2131 { 2132 try 2133 { 2134 String msg = "Setting server configuration to " + enableServer 2135 + " for controller:" + controllerName; 2136 appendDebugText(msg); 2137 String newContent = ""; 2138 if (enableServer) 2139 { 2140 String tmp = actionReplaceInConfiguration(logConfiguration, 2142 "Console,server", "Console"); 2143 newContent = actionReplaceInConfiguration(tmp, "Console,", 2144 "Console,server,"); 2145 } 2146 else 2147 { 2148 newContent = actionReplaceInConfiguration(logConfiguration, 2149 "Console,server", "Console"); 2150 } 2151 publicActionUpdateControllerLogConfiguration(controllerName, newContent); 2152 } 2153 catch (Exception e) 2154 { 2155 appendDebugText( 2156 "Setting log configation of appender server failed for controller:" 2157 + controllerName, e); 2158 } 2159 2160 } 2161 2162 private String actionReplaceInConfiguration(String logConfiguration, 2163 String oldMode, String newMode) throws IOException 2164 { 2165 BufferedReader reader = new BufferedReader (new StringReader ( 2166 logConfiguration)); 2167 StringBuffer buffer = new StringBuffer (); 2168 String line; 2169 int index = 0; 2170 while ((line = reader.readLine()) != null) 2171 { 2172 while ((index = line.indexOf(oldMode, index + 1)) != -1) 2173 { 2174 line = line.substring(0, index) + newMode 2175 + line.substring(index + oldMode.length()); 2176 } 2177 buffer.append(line + System.getProperty("line.separator")); 2178 } 2179 logConfigTextPane.setText(buffer.toString()); 2180 return buffer.toString(); 2181 } 2182 2183 2190 public void publicActionSetLogConfigurationInfo(String controllerName, 2191 String logConfiguration) 2192 { 2193 try 2194 { 2195 String newContent = actionReplaceInConfiguration(logConfiguration, 2196 "DEBUG", "INFO"); 2197 publicActionUpdateControllerLogConfiguration(controllerName, newContent); 2198 } 2199 catch (Exception e) 2200 { 2201 appendDebugText("Setting log configation to debug failed for controller:" 2202 + controllerName, e); 2203 } 2204 2205 } 2206 2207 2212 public Hashtable getBackendList() 2213 { 2214 return backendList; 2215 } 2216 2217 2220 public void publicActioncleanLoggingPane() 2221 { 2222 loggingTextPane.setText(""); 2223 loggingTextPane.validate(); 2224 loggingTextPane.repaint(); 2225 } 2226 2227 2232 public void publicActionRemoveConfigurationFile(ConfigurationFileObject cfo) 2233 { 2234 Container container = cfo.getParent(); 2235 container.remove(cfo); 2236 System.out.println(guiSession.getConfigurationFiles().remove( 2237 new File (cfo.getFilePath()))); 2238 container.validate(); 2239 container.repaint(); 2240 } 2241 2242 2247 public void publicActionControllerRemove(String controllerName) 2248 { 2249 ControllerObject co = (ControllerObject) controllerList 2250 .remove(controllerName); 2251 if (co != null) 2252 { 2253 controllerListPanel.remove(co); 2254 controllerListPanel.validate(); 2255 controllerListPanel.repaint(); 2256 } 2257 guiSession.getControllerItems().remove(controllerName); 2258 } 2259 2260 2268 public void publicActionStartMonitor(String controllerName, 2269 boolean displayController, boolean displayVdb, boolean displayBackends) 2270 { 2271 appendDebugText("Creating monitoring console for controller:" 2272 + controllerName); 2273 try 2274 { 2275 new MonitoringConsole(controllerName, displayController 2276 ? actionGetControllerBean(controllerName) 2277 : null, displayVdb ? actionGetDatabaseBean(selectedDatabase) : null, 2278 displayBackends); 2279 } 2280 catch (Exception e) 2281 { 2282 appendDebugText("Loading of monitoring console failed for controller:" 2283 + controllerName, e); 2284 } 2285 } 2286 2287 2290 public void publicActionCreateBackendExecute() 2291 { 2292 newBackendFrame.setVisible(false); 2293 BackendObject bob = newBackendFrame.getBob(); 2294 VirtualDatabaseMBean database = actionGetDatabaseBean(bob.getDatabase()); 2295 String oldname = bob.getName(); 2296 String newname = newBackendFrame.getNewName().getText(); 2297 String url = newBackendFrame.getNewUrl().getText(); 2298 HashMap map = new HashMap (); 2299 map.put("url", url); 2300 try 2301 { 2302 database.replicateBackend(oldname, newname, map); 2303 } 2304 catch (Exception e) 2305 { 2306 appendDebugText("Failed to create new backend:" + newname, e); 2307 } 2308 } 2309 2310 2315 public void publicActionViewCache(String databaseName) 2316 { 2317 try 2318 { 2319 DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy(); 2320 CacheViewer viewer = new CacheViewer(collector 2321 .retrieveCacheData(databaseName)); 2322 viewer.display(); 2323 } 2324 catch (Exception e) 2325 { 2326 appendDebugText("Failed to collect cache data for database:" 2327 + databaseName, e); 2328 } 2329 } 2330 2331 2336 public void publicActionViewSQLStats(String databaseName) 2337 { 2338 try 2339 { 2340 DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy(); 2341 SQLStatViewer viewer = new SQLStatViewer(collector 2342 .retrieveSQLStats(databaseName)); 2343 viewer.display(); 2344 } 2345 catch (Exception e) 2346 { 2347 appendDebugText( 2348 "Failed to collect sql data for database:" + databaseName, e); 2349 } 2350 2351 } 2352 2353 2358 public void publicActionViewCacheStats(String databaseName) 2359 { 2360 try 2361 { 2362 DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy(); 2363 CacheStatsViewer viewer = new CacheStatsViewer(collector 2364 .retrieveCacheStatsData(databaseName)); 2365 viewer.display(); 2366 } 2367 catch (Exception e) 2368 { 2369 appendDebugText("Failed to collect cache stats for database:" 2370 + databaseName, e); 2371 } 2372 } 2373 2374 2379 public CjdbcGuiListener getGuiActionListener() 2380 { 2381 return guiActionListener; 2382 } 2383 2384 2389 public GuiSession getGuiSession() 2390 { 2391 return guiSession; 2392 } 2393 2394 2399 public Hashtable getJmxClients() 2400 { 2401 return jmxClients; 2402 } 2403 2404 2409 public void publicActionRemoveBackendFromGui(String backendName) 2410 { 2411 BackendObject bo = (BackendObject) backendList.remove(backendName); 2412 if (bo != null) 2413 { 2414 backendIcons.remove(bo); 2415 JPanel panel = (JPanel ) backendsState.get(bo.getState()); 2416 panel.remove(bo); 2417 paintBackendPane(); 2418 } 2419 } 2420 2421 2426 public void publicActionRemoveBackend(BackendObject bo) 2427 { 2428 boolean confirm = actionDisplayConfirmFrame(GuiTranslate.get( 2429 "gui.confirm.remove.backend", bo.getName())); 2430 if (!confirm) 2431 { 2432 appendDebugText("Cancelling backend deletion..."); 2433 return; 2434 } 2435 2436 String controllerName = bo.getControllerName(); 2437 String databaseName = bo.getDatabase(); 2438 String backendName = bo.getName(); 2439 RmiJmxClient jmxClient = (RmiJmxClient) jmxClients.get(controllerName); 2440 String user = guiSession.getAuthenticatedDatabaseLogin(databaseName); 2441 String password = guiSession.getAuthenticatedDatabasePassword(databaseName); 2442 try 2443 { 2444 VirtualDatabaseMBean mbean = jmxClient.getVirtualDatabaseProxy( 2445 databaseName, user, password); 2446 mbean.removeBackend(backendName); 2447 publicActionRemoveBackendFromGui(backendName); 2448 } 2449 catch (Exception e) 2450 { 2451 appendDebugText("Cannot remove backend:" + backendName, e); 2452 } 2453 2454 } 2455 2456 2462 public void publicActionExecuteTransfer(String backendName, 2463 String controllerName) 2464 { 2465 BackendObject bo = (BackendObject) backendList.get(backendName); 2466 String controllerNameOrigin = bo.getControllerName(); 2467 RmiJmxClient jmxClient = (RmiJmxClient) jmxClients 2468 .get(controllerNameOrigin); 2469 String databaseName = bo.getDatabase(); 2470 String user = guiSession.getAuthenticatedDatabaseLogin(databaseName); 2471 String password = guiSession.getAuthenticatedDatabasePassword(databaseName); 2472 try 2473 { 2474 VirtualDatabaseMBean mbean = jmxClient.getVirtualDatabaseProxy( 2475 databaseName, user, password); 2476 mbean.transferBackend(backendName, controllerName); 2477 bo.setControllerName(controllerName); 2478 } 2480 catch (Exception e) 2481 { 2482 appendDebugText("Cannot remove backend:" + backendName, e); 2483 } 2484 } 2485 2486 2493 public void publicActionRemoveBackendFromGui(String backendName, 2494 String controller) 2495 { 2496 BackendObject bo = (BackendObject) backendList.get(backendName); 2497 if (bo != null) 2498 { 2499 String boController = bo.getControllerName(); 2500 if (boController.equals(controller)) 2501 publicActionRemoveBackendFromGui(backendName); 2502 else 2503 { 2504 appendDebugText("Call for removing backend:" + backendName 2505 + " from controller:" + controller 2506 + " but backend is on controller:" + boController); 2507 } 2508 } 2509 2510 } 2511 2512 2518 public void publicActionDisplayShutdownFrame(DatabaseObject database) 2519 { 2520 if (selectShutdownFrame == null) 2521 { 2522 selectShutdownFrame = new GuiSelectShutdownFrame(this, guiActionListener); 2523 selectShutdownFrame.setVisible(true); 2524 } 2525 String shutdownLevel = selectShutdownFrame.getValueField().getText(); 2526 int iLevel = Constants.SHUTDOWN_SAFE; 2528 if (shutdownLevel.equals(GuiCommands.COMMAND_SHUTDOWN_SAFE)) 2529 iLevel = Constants.SHUTDOWN_SAFE; 2530 else if (shutdownLevel.equals(GuiCommands.COMMAND_SHUTDOWN_FORCE)) 2531 iLevel = Constants.SHUTDOWN_FORCE; 2532 else if (shutdownLevel.equals(GuiCommands.COMMAND_SHUTDOWN_WAIT)) 2533 iLevel = Constants.SHUTDOWN_WAIT; 2534 appendDebugText("shudown level of database:" + database.getName() + " is:" 2535 + shutdownLevel); 2536 selectShutdownFrame = null; 2537 publicActionShutdownDatabase(database, iLevel); 2538 } 2539 2540 2545 public void publicActionViewRecoveryLog(String databaseName) 2546 { 2547 try 2548 { 2549 DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy(); 2550 RecoveryLogViewer viewer = new RecoveryLogViewer(collector 2551 .retrieveRecoveryLogData(databaseName)); 2552 viewer.display(); 2553 } 2554 catch (Exception e) 2555 { 2556 appendDebugText("Failed to collect cache stats for database:" 2557 + databaseName, e); 2558 } 2559 } 2560 2561 2566 public void publicActionSetCheckpoint(BackendObject bo) 2567 { 2568 String backendName = bo.getName(); 2569 String database = bo.getDatabase(); 2570 String checkpoint = actionDisplaySelectCheckpointFrame(database); 2571 try 2572 { 2573 appendDebugText("Setting checkpoint for backend:" + backendName + ":" 2574 + checkpoint); 2575 bo.getMbean().setLastKnownCheckpoint(checkpoint); 2576 } 2577 catch (Exception e) 2578 { 2579 appendDebugText("Failed to set checkpoint for backend:" + backendName, e); 2580 } 2581 } 2582 2583 2588 public void publicActionUnSetCheckpoint(BackendObject bo) 2589 { 2590 String backendName = bo.getName(); 2591 boolean confirm = actionDisplayConfirmFrame(GuiTranslate.get( 2592 "gui.confirm.unset.backend.checkpoint", backendName)); 2593 if (!confirm) 2594 { 2595 appendDebugText("Cancelling backend null checkpoint..."); 2596 return; 2597 } 2598 try 2599 { 2600 appendDebugText("UnSetting checkpoint for backend:" + backendName); 2601 bo.getMbean().setLastKnownCheckpoint(null); 2602 } 2603 catch (Exception e) 2604 { 2605 appendDebugText("Failed to unset checkpoint for backend:" + backendName, 2606 e); 2607 } 2608 finally 2609 { 2610 actionRefreshBackendState(bo); 2611 } 2612 2613 } 2614 2615 2620 public void publicActionTestBackendConnection(BackendObject bo) 2621 { 2622 try 2623 { 2624 DatabaseBackendMBean bean = bo.getMbean(); 2625 boolean ok = bean.isJDBCConnected(); 2626 String message = "Backend " + bo.getName(); 2627 if (ok) 2628 message += " has "; 2629 else 2630 message += " does not have "; 2631 message += "JDBC Connectivity."; 2632 2633 appendDebugText("Result of JDBC Connect[" + bo.getName() + "]:" + ok); 2634 2635 Icon icon = (ok) 2636 ? GuiIcons.BACKEND_ENABLED_ICON 2637 : GuiIcons.BACKEND_DISABLED_ICON; 2638 JOptionPane.showMessageDialog(this, message, bo.getName(), 2639 JOptionPane.INFORMATION_MESSAGE, icon); 2640 } 2641 catch (Exception e) 2642 { 2643 appendDebugText( 2644 "Cannot determine if backend has still JDBC connectivity", e); 2645 } 2646 } 2647 2648 2651 public void publicActionRefreshMBeans() 2652 { 2653 Set set; 2654 if (currentJmxClient == null) 2655 { 2656 appendDebugText("Jmx Client has not been set yet"); 2657 return; 2658 } 2659 try 2660 { 2661 appendDebugText("Refreshing mbeans for jmx server:" 2662 + currentJmxClient.getRemoteName()); 2663 set = currentJmxClient.listCJDBCMBeans(); 2664 int size = set.size(); 2665 Iterator iter = set.iterator(); 2666 Object [] data = new Object [size]; 2667 for (int i = 0; i < size; i++) 2668 data[i] = ((ObjectInstance ) iter.next()).getObjectName(); 2669 mbeanList.setListData(data); 2670 mbeanList.validate(); 2671 appendDebugText("Finished Refreshing mbeans for jmx server:" 2672 + currentJmxClient.getRemoteName()); 2673 } 2674 catch (Exception e) 2675 { 2676 appendDebugText("Failed Refreshing mbeans for jmx server:" 2677 + currentJmxClient.getRemoteName()); 2678 } 2679 } 2680 2681 2686 public void publicActionTileJmxFrames(boolean vertical) 2687 { 2688 Dimension dim = jmxPanel.getSize(); 2689 double height = dim.getHeight(); 2690 double width = dim.getWidth(); 2691 if (vertical) 2692 width = width / 3; 2693 else 2694 height = height / 3; 2695 2696 Dimension newDim = new Dimension ((int) width, (int) height); 2697 attributeFrame.setSize(newDim); 2698 operationFrame.setSize(newDim); 2699 mbeanFrame.setSize(newDim); 2700 2701 int x = (int) jmxPanel.getLocation().getX(); 2702 int y = 0; 2704 mbeanFrame.setLocation(x, y); 2705 if (vertical) 2706 { 2707 mbeanFrame.setLocation(x, y); 2708 attributeFrame.setLocation((int) (x + width), y); 2709 operationFrame.setLocation((int) (x + 2 * width), y); 2710 } 2711 else 2712 { 2713 mbeanFrame.setLocation(x, y); 2714 attributeFrame.setLocation(x, (int) (y + height)); 2715 operationFrame.setLocation(x, (int) (y + 2 * height)); 2716 } 2717 2718 jmxPanel.validate(); 2719 2720 } 2721 2722 2727 public void publicActionRefreshMBeanAttributes(ObjectName mbean) 2728 { 2729 try 2730 { 2731 appendDebugText("Fetching attributes for mbean:" + mbean); 2732 MBeanInfo info = currentJmxClient.getMBeanInfo(mbean); 2733 MBeanAttributeInfo [] attrInfo = info.getAttributes(); 2734 2735 AttributeModel dataModel = new AttributeModel(attrInfo, currentJmxClient, 2736 mbean); 2737 attributeTable.setModel(dataModel); 2738 } 2739 catch (Exception e) 2740 { 2741 appendDebugText("Could not fetch attributes for mbean:" + mbean); 2742 } 2743 } 2744 2745 2750 public void publicActionRefreshMBeanMethods(ObjectName mbean) 2751 { 2752 try 2753 { 2754 appendDebugText("Fetching methods for mbean:" + mbean); 2755 MBeanInfo info = currentJmxClient.getMBeanInfo(mbean); 2756 MBeanOperationInfo [] operInfo = info.getOperations(); 2757 2758 OperationModel dataModel = new OperationModel(operInfo); 2759 operationTable.setModel(dataModel); 2760 } 2761 catch (Exception e) 2762 { 2763 appendDebugText("Could not fetch methods for mbean:" + mbean); 2764 } 2765 } 2766 2767 2772 public RmiJmxClient getCurrentJmxClient() 2773 { 2774 return currentJmxClient; 2775 } 2776 2777 2782 public void setCurrentJmxClient(RmiJmxClient currentJmxClient) 2783 { 2784 this.currentJmxClient = currentJmxClient; 2785 } 2786 2787 2793 public void getOperationCallDialog(ObjectName name, MBeanOperationInfo info) 2794 { 2795 new OperationCallDialog(this, name, info).setVisible(true); 2796 } 2797 2798 2804 public void getAttributeChangeDialog(ObjectName name, MBeanAttributeInfo info) 2805 { 2806 new AttributeChangeDialog(this, name, info).setVisible(true); 2807 } 2808 2809} | Popular Tags |