src/org/objectweb/cjdbc/console/monitoring/MonitoringConsole.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.console.monitoring; 00026 00027 import java.awt.BorderLayout; 00028 import java.awt.Color; 00029 import java.awt.Dimension; 00030 import java.awt.Font; 00031 import java.awt.GridLayout; 00032 import java.awt.Point; 00033 import java.awt.Toolkit; 00034 import java.awt.Window; 00035 import java.awt.event.ActionEvent; 00036 import java.awt.event.ActionListener; 00037 import java.awt.event.MouseEvent; 00038 import java.awt.event.MouseListener; 00039 import java.awt.event.WindowEvent; 00040 import java.awt.event.WindowListener; 00041 import java.io.BufferedOutputStream; 00042 import java.io.File; 00043 import java.io.FileInputStream; 00044 import java.io.FileOutputStream; 00045 import java.io.IOException; 00046 import java.util.ArrayList; 00047 import java.util.Enumeration; 00048 import java.util.Hashtable; 00049 import java.util.Iterator; 00050 import java.util.PropertyResourceBundle; 00051 import java.util.StringTokenizer; 00052 import java.util.Vector; 00053 00054 import javax.management.MBeanException; 00055 import javax.swing.JButton; 00056 import javax.swing.JComboBox; 00057 import javax.swing.JComponent; 00058 import javax.swing.JFrame; 00059 import javax.swing.JLabel; 00060 import javax.swing.JMenu; 00061 import javax.swing.JMenuBar; 00062 import javax.swing.JMenuItem; 00063 import javax.swing.JPanel; 00064 import javax.swing.JScrollPane; 00065 import javax.swing.JTextField; 00066 import javax.swing.JToolBar; 00067 import javax.swing.SwingConstants; 00068 00069 import org.objectweb.cjdbc.common.i18n.MonitorTranslate; 00070 import org.objectweb.cjdbc.common.jmx.JmxException; 00071 import org.objectweb.cjdbc.common.monitor.AbstractDataCollector; 00072 import org.objectweb.cjdbc.common.monitor.DataCollection; 00073 import org.objectweb.cjdbc.common.monitor.DataCollectionNames; 00074 import org.objectweb.cjdbc.console.jmx.ControllerJmxClient; 00075 import org.objectweb.cjdbc.console.jmx.DataCollectorJmxClient; 00076 00082 public class MonitoringConsole extends JFrame 00083 implements 00084 DataCollection, 00085 MouseListener, 00086 ActionListener, 00087 WindowListener 00088 { 00089 // Window parameters 00090 private int frameWidth = 400; 00091 private int frameHeight = 700; 00092 00093 // Swing Components 00094 private JLabel label; 00095 private JScrollPane jScroll; 00096 00097 // MBean components 00098 private ControllerJmxClient controllerMBean; 00099 private DataCollectorJmxClient dataCollectorMBean; 00100 00101 // Menu components 00102 private static final String GRAPH_CONTROLLER = MonitorTranslate.get("heading.controller"); 00103 private static final String GRAPH_VIRTUAL_DATABASE = MonitorTranslate.get("heading.virtualdatabase"); 00104 private static final String GRAPH_CACHE = MonitorTranslate.get("heading.cache"); 00105 private static final String GRAPH_SCHEDULER = MonitorTranslate.get("heading.scheduler"); 00106 private static final String GRAPH_BACKENDS = MonitorTranslate.get("heading.backends"); 00107 00108 private Hashtable windows = new Hashtable(); 00109 00110 private Vector comboBoxesItems = new Vector(); 00111 private Hashtable comboBoxes = new Hashtable(); 00112 00113 // Fonts & Colors 00114 private Font boxFont = new Font("Arial", 00115 Font.PLAIN, 10); 00116 private Font labelFont = new Font("Arial", 00117 Font.BOLD, 10); 00118 private Font headerFont = new Font("Arial", 00119 Font.BOLD, 12); 00120 private Color toolBarColor = Color.white; 00121 00122 // Graph options 00123 private int graphRepeat = -1; 00124 private int graphTimeframe = 3600; 00125 private int graphFrequency = 1000; 00126 private int graphDisplayFrequency = 1; 00127 00128 // Actions 00129 private static final String COMMAND_SAVE = MonitorTranslate.get("command.save"); 00130 private static final String COMMAND_LOAD = MonitorTranslate.get("command.load"); 00131 private static final String COMMAND_CLOSE_GRAPHS = MonitorTranslate.get("command.close.all"); 00132 private static final String COMMAND_OPTIONS = MonitorTranslate.get("command.set.options"); 00133 private static final String COMMAND_CLOSE = MonitorTranslate.get("command.quit"); 00134 private static final String COMMAND_REFRESH = MonitorTranslate.get("command.refresh"); 00135 00136 private static final String OPTIONS_APPLY = "OptionsApply"; 00137 private static final String OPTIONS_CANCEL = "OptionsCancel"; 00138 00139 00140 // Combox 00141 private static final String COMBO_HIDE = MonitorTranslate.get("command.hide"); 00142 private static final String COMBO_FLOATING = MonitorTranslate.get("command.float"); 00143 00144 private boolean isLoading = false; 00145 00146 // Option window 00147 private JFrame options; 00148 private JTextField ftimeframe; 00149 private JTextField ffrequency; 00150 private JTextField frepeat; 00151 private JTextField displayBuffer; 00152 00159 public MonitoringConsole(String jmxUrl) throws JmxException 00160 { 00161 super(MonitorTranslate.get("monitor.frame.title",jmxUrl)); 00162 00163 // Get MBeans reference 00164 ControllerJmxClient controllerMBean = new ControllerJmxClient(); 00165 controllerMBean.connect(jmxUrl); 00166 this.controllerMBean = controllerMBean; 00167 dataCollectorMBean = new DataCollectorJmxClient(controllerMBean 00168 .getRemoteHostName(), controllerMBean.getRemoteHostPort(), 00169 controllerMBean.getCredentials()); 00170 00171 // Get options for combo boxes 00172 comboBoxesItems.add(COMBO_HIDE); 00173 comboBoxesItems.add(COMBO_FLOATING); 00174 00175 Toolkit toolkit; 00176 Dimension dim; 00177 int screenHeight, screenWidth; 00178 00179 // Initialize basic layout properties 00180 setForeground(Color.white); 00181 getContentPane().setLayout(new BorderLayout()); 00182 00183 // Set the frame's display to be WIDTH x HEIGHT in the middle of the screen 00184 toolkit = Toolkit.getDefaultToolkit(); 00185 dim = toolkit.getScreenSize(); 00186 screenHeight = dim.height; 00187 screenWidth = dim.width; 00188 setBounds((screenWidth - frameWidth) / 2, (screenHeight - frameHeight) / 2, 00189 frameWidth, frameHeight); 00190 00191 try 00192 { 00193 // Init Frame with dynamic content 00194 initConsole(); 00195 } 00196 catch (MBeanException e) 00197 { 00198 throw new JmxException(e.getMessage()); 00199 } 00200 00201 // Status Bar 00202 label = new JLabel("Select Graphs ..."); 00203 label.setFont(labelFont); 00204 getContentPane().add(label, BorderLayout.SOUTH); 00205 getContentPane().setBackground(toolBarColor); 00206 getContentPane().setForeground(toolBarColor); 00207 00208 // Menu Bar 00209 JMenuBar menuBar = new JMenuBar(); 00210 JMenu menu = new JMenu(MonitorTranslate.get("monitor.menu.bar")); 00211 JMenuItem item1 = new JMenuItem(COMMAND_SAVE); 00212 JMenuItem item2 = new JMenuItem(COMMAND_LOAD); 00213 JMenuItem item3 = new JMenuItem(COMMAND_CLOSE); 00214 JMenuItem item4 = new JMenuItem(COMMAND_CLOSE_GRAPHS); 00215 JMenuItem item5 = new JMenuItem(COMMAND_OPTIONS); 00216 JMenuItem item6 = new JMenuItem(COMMAND_REFRESH); 00217 item1.setBackground(toolBarColor); 00218 item2.setBackground(toolBarColor); 00219 item3.setBackground(toolBarColor); 00220 item4.setBackground(toolBarColor); 00221 item5.setBackground(toolBarColor); 00222 item6.setBackground(toolBarColor); 00223 menu.add(item1).addActionListener(this); 00224 menu.add(item2).addActionListener(this); 00225 menu.add(item4).addActionListener(this); 00226 menu.add(item5).addActionListener(this); 00227 menu.add(item6).addActionListener(this); 00228 menu.addSeparator(); 00229 menu.add(item3).addActionListener(this); 00230 menu.setVisible(true); 00231 menu.setBackground(toolBarColor); 00232 menuBar.add(menu); 00233 menuBar.setBackground(toolBarColor); 00234 this.setJMenuBar(menuBar); 00235 00236 // Prepare options window 00237 options = new JFrame(MonitorTranslate.get("options.frame.title")); 00238 options.setSize(200, 200); 00239 JPanel optionsPanel = new JPanel(); 00240 optionsPanel.setLayout(new GridLayout(5, 2)); 00241 optionsPanel.add(new JLabel(MonitorTranslate.get("options.repeat"))); 00242 frepeat = new JTextField(0); 00243 frepeat.setAlignmentX(RIGHT_ALIGNMENT); 00244 frepeat.setText(graphRepeat + ""); 00245 frepeat.addActionListener(this); 00246 optionsPanel.add(frepeat); 00247 00248 optionsPanel.add(new JLabel(MonitorTranslate.get("options.display.buffer"))); 00249 displayBuffer = new JTextField(0); 00250 displayBuffer.setText("" + graphDisplayFrequency); 00251 displayBuffer.addActionListener(this); 00252 displayBuffer.setAlignmentX(RIGHT_ALIGNMENT); 00253 optionsPanel.add(displayBuffer); 00254 00255 optionsPanel.add(new JLabel(MonitorTranslate.get("options.frequency"))); 00256 ffrequency = new JTextField(0); 00257 ffrequency.setText("" + graphFrequency); 00258 ffrequency.addActionListener(this); 00259 ffrequency.setAlignmentX(RIGHT_ALIGNMENT); 00260 optionsPanel.add(ffrequency); 00261 00262 optionsPanel.add(new JLabel(MonitorTranslate.get("options.timeframe"))); 00263 ftimeframe = new JTextField(0); 00264 ftimeframe.setText(graphTimeframe + ""); 00265 ftimeframe.addActionListener(this); 00266 ftimeframe.setAlignmentX(RIGHT_ALIGNMENT); 00267 optionsPanel.add(ftimeframe); 00268 00269 JButton optionConfirm = new JButton(MonitorTranslate.get("options.ok")); 00270 optionConfirm.setActionCommand(OPTIONS_APPLY); 00271 optionConfirm.addActionListener(this); 00272 optionsPanel.add(optionConfirm); 00273 00274 JButton optionCancel = new JButton(MonitorTranslate.get("options.cancel")); 00275 optionCancel.setActionCommand(OPTIONS_CANCEL); 00276 optionCancel.addActionListener(this); 00277 optionsPanel.add(optionCancel); 00278 00279 options.getContentPane().add(optionsPanel); 00280 options.setVisible(false); 00281 options.setDefaultCloseOperation(HIDE_ON_CLOSE); 00282 options.validate(); 00283 00284 //Put the final touches to the JFrame object 00285 validate(); 00286 setVisible(true); 00287 this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); 00288 } 00289 00290 private void initConsole() throws JmxException, MBeanException 00291 { 00292 // Get the menus with all commands 00293 this.setVisible(false); 00294 BorderLayout layout = new BorderLayout(); 00295 JPanel pane = new JPanel(layout); 00296 pane.add(initializeControllerBar(), BorderLayout.NORTH); 00297 pane.add(initializaDatabaseBar(), BorderLayout.CENTER); 00298 jScroll = new JScrollPane(); 00299 jScroll.getViewport().add(pane); 00300 getContentPane().add(jScroll, BorderLayout.CENTER); 00301 validate(); 00302 this.setVisible(true); 00303 } 00304 00305 private JLabel getHeaderLabel(String text) 00306 { 00307 JLabel label = new JLabel(text); 00308 label.setFont(headerFont); 00309 label.setAlignmentX(CENTER_ALIGNMENT); 00310 return label; 00311 } 00312 00313 private JLabel getSubHeaderLabel(String text) 00314 { 00315 JLabel label = new JLabel(text); 00316 label.setFont(labelFont); 00317 label.setAlignmentX(CENTER_ALIGNMENT); 00318 return label; 00319 } 00320 00321 private JToolBar initializeControllerBar() 00322 { 00323 JToolBar toolbar = new JToolBar(GRAPH_CONTROLLER, SwingConstants.VERTICAL); 00324 toolbar.setOrientation(SwingConstants.VERTICAL); 00325 toolbar.addMouseListener(this); 00326 toolbar.add(getHeaderLabel(GRAPH_CONTROLLER)); 00327 toolbar.add(getGraphMenuItem(CONTROLLER_USED_MEMORY, "", "")); 00328 toolbar.add(getGraphMenuItem(CONTROLLER_THREADS_NUMBER, "", "")); 00329 toolbar.add(getGraphMenuItem(CONTROLLER_WORKER_PENDING_QUEUE, "", "")); 00330 toolbar.add(getGraphMenuItem(CONTROLLER_IDLE_WORKER_THREADS, "", "")); 00331 toolbar.setVisible(true); 00332 return toolbar; 00333 } 00334 00335 private JToolBar initializeCacheBar(String vdb) 00336 { 00337 JToolBar toolbar = new JToolBar(GRAPH_CACHE, SwingConstants.VERTICAL); 00338 00339 try 00340 { 00341 if (controllerMBean.isCacheEnableForDatabase(vdb) == false) 00342 toolbar.setEnabled(false); 00343 else 00344 { 00345 toolbar.add(getSubHeaderLabel(GRAPH_CACHE + " [" + vdb + "]")); 00346 toolbar.add(getGraphMenuItem(CACHE_STATS_COUNT_HITS, vdb, "")); 00347 toolbar.add(getGraphMenuItem(CACHE_STATS_COUNT_INSERT, vdb, "")); 00348 toolbar.add(getGraphMenuItem(CACHE_STATS_COUNT_SELECT, vdb, "")); 00349 toolbar.add(getGraphMenuItem(CACHE_STATS_HITS_PERCENTAGE, vdb, "")); 00350 toolbar.add(getGraphMenuItem(CACHE_STATS_NUMBER_ENTRIES, vdb, "")); 00351 } 00352 } 00353 catch (Exception e) 00354 { 00355 toolbar.setEnabled(false); 00356 } 00357 return toolbar; 00358 } 00359 00360 private JToolBar initializeSchedulerBar(String vdb) 00361 { 00362 JToolBar toolbar = new JToolBar(GRAPH_SCHEDULER, SwingConstants.VERTICAL); 00363 toolbar.add(getSubHeaderLabel(GRAPH_SCHEDULER + " [" + vdb + "]")); 00364 toolbar.add(getGraphMenuItem(SCHEDULER_NUMBER_READ, vdb, "")); 00365 toolbar.add(getGraphMenuItem(SCHEDULER_NUMBER_REQUESTS, vdb, "")); 00366 toolbar.add(getGraphMenuItem(SCHEDULER_NUMBER_WRITES, vdb, "")); 00367 toolbar.add(getGraphMenuItem(SCHEDULER_PENDING_TRANSACTIONS, vdb, "")); 00368 toolbar.add(getGraphMenuItem(SCHEDULER_PENDING_WRITES, vdb, "")); 00369 return toolbar; 00370 } 00371 00372 private JToolBar initializaBackendBar(String vdb, String backendName) 00373 { 00374 JToolBar backendMenu = new JToolBar(GRAPH_BACKENDS, SwingConstants.VERTICAL); 00375 backendMenu.add(getSubHeaderLabel(GRAPH_BACKENDS + " [" + backendName 00376 + " on " + vdb + "]")); 00377 backendMenu.add(getGraphMenuItem(BACKEND_ACTIVE_TRANSACTION, vdb, 00378 backendName)); 00379 backendMenu 00380 .add(getGraphMenuItem(BACKEND_PENDING_REQUESTS, vdb, backendName)); 00381 backendMenu.add(getGraphMenuItem(BACKEND_TOTAL_ACTIVE_CONNECTIONS, vdb, 00382 backendName)); 00383 backendMenu.add(getGraphMenuItem(BACKEND_TOTAL_REQUEST, vdb, backendName)); 00384 backendMenu.add(getGraphMenuItem(BACKEND_TOTAL_READ_REQUEST, vdb, 00385 backendName)); 00386 backendMenu.add(getGraphMenuItem(BACKEND_TOTAL_WRITE_REQUEST, vdb, 00387 backendName)); 00388 backendMenu.add(getGraphMenuItem(BACKEND_TOTAL_TRANSACTIONS, vdb, 00389 backendName)); 00390 return backendMenu; 00391 } 00392 00393 private JToolBar initializaDatabaseBar() throws JmxException, MBeanException 00394 { 00395 JToolBar toolbar = new JToolBar(GRAPH_VIRTUAL_DATABASE, JToolBar.VERTICAL); 00396 toolbar.addMouseListener(this); 00397 00398 ArrayList dbs = controllerMBean.listVirtualDatabases(); 00399 ArrayList backends; 00400 String vdb = ""; 00401 for (int i = 0; i < dbs.size(); i++) 00402 { 00403 vdb = (String) dbs.get(i); 00404 toolbar.add(getHeaderLabel(GRAPH_VIRTUAL_DATABASE + " [" + vdb + "]")); 00405 // Virtual Database main graphs 00406 toolbar.add(getGraphMenuItem(DATABASES_ACTIVE_THREADS, vdb, "")); 00407 toolbar.add(getGraphMenuItem(DATABASES_NUMBER_OF_THREADS, vdb, "")); 00408 toolbar.add(getGraphMenuItem(DATABASES_PENDING_CONNECTIONS, vdb, "")); 00409 // Cache 00410 toolbar.add(initializeCacheBar(vdb)); 00411 // Scheduler 00412 toolbar.add(initializeSchedulerBar(vdb)); 00413 // Backends 00414 backends = controllerMBean.listBackends(vdb); 00415 for (int j = 0; j < backends.size(); j++) 00416 { 00417 String backendName = (String) backends.get(j); 00418 toolbar.add(initializaBackendBar(vdb, backendName)); 00419 } 00420 } 00421 return toolbar; 00422 } 00423 00424 private JComponent getGraphMenuItem(int type, String virtualDbName, 00425 String targetName) 00426 { 00427 String name = DataCollectionNames.get(type); 00428 JComboBox item = new JComboBox(comboBoxesItems); 00429 item.setFont(boxFont); 00430 item.setName(name); 00431 item.addActionListener(this); 00432 item.addMouseListener(this); 00433 if (virtualDbName == null) 00434 virtualDbName = ""; 00435 if (targetName == null) 00436 targetName = ""; 00437 String actionCommand = "graph " + name.toLowerCase().replace(' ', '_') 00438 + " " + virtualDbName + " " + targetName; 00439 actionCommand = actionCommand.trim(); 00440 item.setActionCommand(actionCommand); 00441 item.setVisible(true); 00442 BorderLayout layout = new BorderLayout(); 00443 JPanel panel = new JPanel(layout); 00444 JLabel label = new JLabel(name); 00445 label.setAlignmentX(CENTER_ALIGNMENT); 00446 label.setFont(labelFont); 00447 panel.add(label, BorderLayout.WEST); 00448 panel.add(item, BorderLayout.EAST); 00449 00450 comboBoxes.put(actionCommand, item); 00451 return panel; 00452 } 00453 00457 public void mouseClicked(MouseEvent e) 00458 { 00459 status(e.getComponent().getName() + " was clicked"); 00460 } 00461 00465 public void mouseEntered(MouseEvent e) 00466 { 00467 00468 } 00469 00473 public void mouseExited(MouseEvent e) 00474 { 00475 00476 } 00477 00481 public void mousePressed(MouseEvent e) 00482 { 00483 00484 } 00485 00489 public void mouseReleased(MouseEvent e) 00490 { 00491 00492 } 00493 00494 private void doSaveConfiguration() throws IOException 00495 { 00496 Iterator iter = comboBoxes.keySet().iterator(); 00497 File f = new File("monitor.properties"); 00498 BufferedOutputStream bof = new BufferedOutputStream(new FileOutputStream(f)); 00499 String temp; 00500 while (iter.hasNext()) 00501 { 00502 Object o = iter.next(); 00503 String key = o.toString().trim().replace(' ', '.'); 00504 JComboBox box = (JComboBox) comboBoxes.get(o); 00505 temp = (key + "=" + box.getSelectedItem()) 00506 + System.getProperty("line.separator"); 00507 bof.write(temp.getBytes()); 00508 } 00509 00510 Iterator iter2 = windows.keySet().iterator(); 00511 Window win; 00512 Point p; 00513 String name, winX, winY; 00514 while (iter2.hasNext()) 00515 { 00516 win = ((Window) windows.get(iter2.next())); 00517 p = win.getLocation(); 00518 name = win.getName().trim().replace(' ', '.'); 00519 winX = name + ".X=" + (int) p.getX() 00520 + System.getProperty("line.separator"); 00521 winY = name + ".Y=" + (int) p.getY() 00522 + System.getProperty("line.separator"); 00523 bof.write(winX.getBytes()); 00524 bof.write(winY.getBytes()); 00525 } 00526 bof.write(("options.repeat=" + graphRepeat + System 00527 .getProperty("line.separator")).getBytes()); 00528 bof.write(("options.timeframe=" + graphTimeframe + System 00529 .getProperty("line.separator")).getBytes()); 00530 bof.write(("options.frequency=" + graphFrequency + System 00531 .getProperty("line.separator")).getBytes()); 00532 bof.write(("options.displayfrequency=" + graphDisplayFrequency + System 00533 .getProperty("line.separator")).getBytes()); 00534 00535 bof.flush(); 00536 bof.close(); 00537 } 00538 00539 private void doLoadConfiguration() throws IOException 00540 { 00541 closeAllWindows(); 00542 isLoading = true; 00543 File f = new File("monitor.properties"); 00544 PropertyResourceBundle props = new PropertyResourceBundle( 00545 new FileInputStream(f)); 00546 Enumeration enume = props.getKeys(); 00547 String key = "", keyr = "", value = ""; 00548 JFrame frame; 00549 00550 try 00551 { 00552 graphRepeat = Integer 00553 .parseInt((String) props.getObject("options.repeat")); 00554 frepeat.setText("" + graphRepeat); 00555 graphFrequency = Integer.parseInt((String) props 00556 .getObject("options.frequency")); 00557 ffrequency.setText("" + graphFrequency); 00558 graphTimeframe = Integer.parseInt((String) props 00559 .getObject("options.timeframe")); 00560 ftimeframe.setText("" + graphTimeframe); 00561 graphDisplayFrequency = Integer.parseInt((String) props 00562 .getObject("options.displayfrequency")); 00563 displayBuffer.setText("" + graphDisplayFrequency); 00564 } 00565 catch (Exception e) 00566 { 00567 error(e.getMessage()); 00568 } 00569 00570 while (enume.hasMoreElements()) 00571 { 00572 key = (String) enume.nextElement(); 00573 value = (String) props.getObject(key); 00574 if (key.startsWith("options")) 00575 { 00576 // done 00577 } 00578 else if (key.endsWith(".X") || key.endsWith(".Y")) 00579 { 00580 // do nothing 00581 } 00582 else 00583 { 00584 if (value.equals(COMBO_FLOATING)) 00585 try 00586 { 00587 frame = graph(key); 00588 keyr = key.trim().replace('.', ' '); 00589 //System.out.println(key); 00590 JComboBox box = (JComboBox) comboBoxes.get(keyr); 00591 if (box != null) 00592 box.setSelectedItem(COMBO_FLOATING); 00593 try 00594 { 00595 int x = Integer.parseInt((String) props.getObject(key + ".X")); 00596 int y = Integer.parseInt((String) props.getObject(key + ".Y")); 00597 00598 //Window win = ((Window) windows.get(keyr)); 00599 //System.out.println(frame.getName()+"-"+x+"-"+y); 00600 frame.setLocation(x, y); 00601 //win.getComponent(0).setLocation(x, y); 00602 //win.setVisible(true); 00603 //win.validate(); 00604 } 00605 catch (Exception e) 00606 { 00607 // ignore does not exist 00608 error(e.getMessage()); 00609 } 00610 } 00611 catch (Exception e) 00612 { 00613 // cannot load ... 00614 } 00615 } 00616 } 00617 isLoading = false; 00618 } 00619 00623 public void actionPerformed(ActionEvent e) 00624 { 00625 if (isLoading) 00626 return; 00627 String actionCommand = e.getActionCommand(); 00628 status("Action:" + actionCommand); 00629 if (actionCommand.equals(COMMAND_SAVE)) 00630 { 00631 try 00632 { 00633 doSaveConfiguration(); 00634 } 00635 catch (IOException e1) 00636 { 00637 // TODO: display dialog box 00638 // Dialog d = new Dialog(this, "Saving Failed"); 00639 // d.add(new JLabel("Saving Failed because of:" + e1.getMessage())); 00640 // d.setVisible(true); 00641 // d.setSize(100,50); 00642 // d.setModal(true); 00643 //d.setDefaultCloseOperation(DISPOSE_ON_CLOSE); 00644 e1.printStackTrace(); 00645 } 00646 } 00647 else if (actionCommand.equals(COMMAND_LOAD)) 00648 { 00649 try 00650 { 00651 doLoadConfiguration(); 00652 } 00653 catch (IOException e1) 00654 { 00655 // TODO: display dialog box 00656 e1.printStackTrace(); 00657 } 00658 } 00659 else if (actionCommand.equals(OPTIONS_APPLY)) 00660 { 00661 00662 try 00663 { 00664 graphRepeat = Integer.parseInt(frepeat.getText()); 00665 graphTimeframe = Integer.parseInt(ftimeframe.getText()); 00666 graphFrequency = Integer.parseInt(ffrequency.getText()); 00667 graphDisplayFrequency = Integer.parseInt(displayBuffer.getText()); 00668 options.setVisible(false); 00669 } 00670 catch (Exception failed) 00671 { 00672 error(failed.getMessage()); 00673 } 00674 } 00675 else if (actionCommand.equals(OPTIONS_CANCEL)) 00676 { 00677 options.setVisible(false); 00678 frepeat.setText(graphRepeat + ""); 00679 ftimeframe.setText(graphTimeframe + ""); 00680 ffrequency.setText(graphFrequency + ""); 00681 } 00682 else if (actionCommand.equals(COMMAND_REFRESH)) 00683 { 00684 try 00685 { 00686 initConsole(); 00687 } 00688 catch (Exception error) 00689 { 00690 error(error.getMessage()); 00691 } 00692 } 00693 else if (actionCommand.equals(COMMAND_OPTIONS)) 00694 { 00695 options.setVisible(true); 00696 } 00697 else if (actionCommand.equals(COMMAND_CLOSE)) 00698 { 00699 closeAllWindows(); 00700 this.dispose(); 00701 } 00702 else if (actionCommand.equals(COMMAND_CLOSE_GRAPHS)) 00703 { 00704 closeAllWindows(); 00705 } 00706 Object o = e.getSource(); 00707 if (o instanceof JComboBox) 00708 { 00709 JComboBox box = (JComboBox) o; 00710 String selected = (String) box.getSelectedItem(); 00711 status(selected.toString()); 00712 try 00713 { 00714 Window win = (Window) windows.get(e.getActionCommand().trim()); 00715 if (!selected.equals(COMBO_HIDE)) 00716 { 00717 if (win == null) 00718 { 00719 graph(e.getActionCommand()); 00720 } 00721 } 00722 else 00723 { 00724 windows.remove(win.getName()); 00725 win.setVisible(false); 00726 win.dispose(); 00727 } 00728 } 00729 catch (Exception f) 00730 { 00731 error(f.getMessage()); 00732 } 00733 } 00734 00735 } 00736 00737 private void closeAllWindows() 00738 { 00739 while (true) 00740 { 00741 try 00742 { 00743 Iterator iter = windows.keySet().iterator(); 00744 while (iter.hasNext()) 00745 { 00746 Window win = ((Window) windows.get(iter.next())); 00747 JComboBox box = (JComboBox) comboBoxes.get(win.getName()); 00748 if (box != null) 00749 box.setSelectedItem(COMBO_HIDE); 00750 } 00751 break; 00752 } 00753 catch (RuntimeException e) 00754 { 00755 //concurrent modification exception 00756 continue; 00757 } 00758 } 00759 } 00760 00761 private void status(String message) 00762 { 00763 label.setBackground(Color.white); 00764 label.setText(message); 00765 } 00766 00767 private void error(String message) 00768 { 00769 label.setBackground(Color.red); 00770 label.setText(message); 00771 } 00772 00779 private JFrame graph(String command) throws JmxException, MBeanException 00780 { 00781 // Used for saving configuration 00782 command = command.replace('.', ' '); 00783 00784 StringTokenizer tokenizer = new StringTokenizer(command, " "); 00785 String token0 = tokenizer.nextToken(); 00786 if (token0.equals("graph")) 00787 { 00788 String token1 = tokenizer.nextToken(); 00789 int type = DataCollectionNames.getTypeFromCommand(token1); 00790 String token2 = (tokenizer.hasMoreTokens()) ? tokenizer.nextToken() : ""; 00791 String token3 = (tokenizer.hasMoreTokens()) ? tokenizer.nextToken() : ""; 00792 AbstractDataCollector collector = dataCollectorMBean 00793 .retrieveDataCollectorInstance(type, token3, token2); 00794 MonitoringGraph graph = new MonitoringGraph(collector, dataCollectorMBean); 00795 graph.setRepeat(graphRepeat); 00796 graph.setTimeFrame(graphTimeframe); 00797 graph.setFrequency(graphFrequency); 00798 graph.setDisplayFrequency(graphDisplayFrequency); 00799 graph.start(); 00800 graph.setText(command); 00801 // Do not do before, as frame is null before starts of thread! 00802 graph.getFrame().addWindowListener(this); 00803 graph.getFrame().setName(command.trim()); 00804 return graph.getFrame(); 00805 } 00806 else 00807 { 00808 return null; 00809 } 00810 } 00811 00815 public void windowActivated(WindowEvent e) 00816 { 00817 00818 } 00819 00823 public void windowClosed(WindowEvent e) 00824 { 00825 00826 } 00827 00831 public void windowClosing(WindowEvent e) 00832 { 00833 Window win = e.getWindow(); 00834 JComboBox box = (JComboBox) comboBoxes.get(win.getName()); 00835 windows.remove(win.getName()); 00836 if (box != null) 00837 box.setSelectedIndex(0); 00838 status(win.getName() + " is closing"); 00839 } 00840 00844 public void windowDeactivated(WindowEvent e) 00845 { 00846 00847 } 00848 00852 public void windowDeiconified(WindowEvent e) 00853 { 00854 00855 } 00856 00860 public void windowIconified(WindowEvent e) 00861 { 00862 00863 } 00864 00868 public void windowOpened(WindowEvent e) 00869 { 00870 Window win = e.getWindow(); 00871 status(win.getName() + " has opened"); 00872 windows.put(win.getName(), e.getWindow()); 00873 } 00874 }

CJDBCversion1.0.4に対してTue Oct 12 15:15:59 2004に生成されました。 doxygen 1.3.8