📄 adminmgr.java
字号:
(this, e.getMessage(), "Database Close Error", JOptionPane.ERROR_MESSAGE); } } /** * A conveniance routine to open/close all database connections, and fix up * the display. * <p/> * <P>When connecting, show the root object, get any persistent queue/topic * names currently in the db, and display them. Turn off the connection * menu, enable the disconnection and shutdown and the context menus. Set * the message area text to connected. * <p/> * <P>When disconnecting, turn off the root, destroy all Gui objects close * the db connection, turn off all context sensitive menus, disable * disconnection menu and enable connection. Set the message text to * disconnected. * * @param c a flag inidication if this is a connection or disconnection. */ private void setConnected(boolean c, String st) { if (c) { _serverProperties.setRootVisible(true); ((OpenJMSServer) (_serverProperties.getModel().getRoot())).displayConnections(); _connections.setEnabled(false); _refresh.setEnabled(true); // _shutdown.setEnabled(true); _disconnect.setEnabled(true); // _startup.setEnabled(false); _messageArea.setForeground(java.awt.Color.green.darker().darker()); _messageArea.setText(st); _connected = true; } else { _serverProperties.setRootVisible(false); OpenJMSServer root = (OpenJMSServer) _serverProperties.getModel().getRoot(); root.removeAllChildren(); DefaultTreeModel model = (DefaultTreeModel) _serverProperties.getModel(); model.nodeStructureChanged((DefaultMutableTreeNode) root); _connections.setEnabled(true); _startup.setEnabled(true); _shutdown.setEnabled(false); _refresh.setEnabled(false); _disconnect.setEnabled(false); _messageArea.setForeground(java.awt.Color.red); _messageArea.setText("Not Connected"); _connected = false; } } /** * Set up all Action menu callbacks, and mouse events for the tree and its * nodes. Check all mose 2 key presses on a node, select the node, then call * the nodes appropriate display methos to display its specific popup * menus. * <p/> * <P>When first connected, all queue/topics displayed are not expaned. This * is just a performance saver, since their could potentially be hundreds of * objects. A callback is set up, so that when a queue/topic is expanded, it * is lokked up only then to determine what consumers are registered with * it. */ private void setupCallbacks() { addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { exitForm(); } } ); _serverProperties.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (!_connected) { return; } if (SwingUtilities.isRightMouseButton(e)) { int selRow = _serverProperties.getRowForLocation (e.getX(), e.getY()); _serverProperties.setSelectionRow(selRow); Object loc = _serverProperties.getLastSelectedPathComponent(); if (loc instanceof OpenJMSNode) { OpenJMSNode node = (OpenJMSNode) loc; node.displayCommands (_serverProperties.getRowBounds(selRow)); } else if (loc instanceof OpenJMSServer) { ((OpenJMSServer) loc).displayCommands (_serverProperties.getRowBounds(selRow)); } } } } ); _serverProperties.addTreeExpansionListener(new TreeExpansionListener() { public void treeCollapsed(TreeExpansionEvent e) { // todo Anything..... } public void treeExpanded(TreeExpansionEvent e) { TreePath path = e.getPath(); Object loc = path.getLastPathComponent(); if (loc instanceof OpenJMSNode) { OpenJMSNode node = (OpenJMSNode) loc; node.update(); } } } ); /** _serverProperties.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getPath(); Object loc = path.getLastPathComponent(); if (loc instanceof OpenJMSNode) { OpenJMSNode node = (OpenJMSNode)loc; System.out.println(node); } } } ); **/ _exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exitAdmin(); } } ); _refresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { refresh(); } } ); _online.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { onlineConnect(); } } ); _offline.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { offlineConnect(); } } ); _disconnect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { disconnect(); } } ); _startup.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { startup(); } } ); _shutdown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { AbstractAdminConnection.instance().stopServer(); setConnected(false, null); } catch (NullPointerException err) { JOptionPane.showMessageDialog (_file, "Must connect with online mode \nto " + "shutdown server", "Shutdown Error", JOptionPane.ERROR_MESSAGE); } } } ); } /** * The main entry point for this admin gui. The main form and any support * dialogs are created. An initial size is given, and the gui placed in the * middle of the screen * * @param args the command line arguments */ public static void main(String args[]) { try { CommandLine cmdline = new CommandLine(args); boolean helpSet = cmdline.exists("help"); boolean configSet = cmdline.exists("config"); boolean stopServer = cmdline.exists("stopServer"); String username = cmdline.value("u"); String password = cmdline.value("p"); if (helpSet) { usage(); } else if (!configSet && !stopServer && args.length != 0) { // invalid argument specified usage(); } else { String configFile = cmdline.value("config"); if (configFile == null) { String home = getOpenJMSHome(); configFile = home + "/config/openjms.xml"; } Configuration config = new ConfigurationLoader().load(configFile); String path = config.getLoggerConfiguration().getFile(); if (path != null) { DOMConfigurator.configure(path); } AdminConfiguration adminConfig = null; adminConfig = config.getAdminConfiguration(); _serverStart = adminConfig.getScript(); _serverConfig = adminConfig.getConfig(); if (_serverConfig == null) { _serverConfig = configFile; } if (stopServer) { // this is a special mode that will just attempt // a connection to the server and stop it. No GUI new OnlineConnection(username, password, config); AbstractAdminConnection.instance().stopServer(); } else { AdminMgr admin = new AdminMgr(configFile); QueryDialog.create(admin); CreateQueueDialog.create(admin); CreateTopicDialog.create(admin); CreateLogonDialog.create(admin); CreateUserDialog.create(admin); ChangePasswordDialog.create(admin); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); // About center of screen admin.setLocation(screen.width / 2 - 150, screen.height / 2 - 150); admin.setSize(300, 300); admin.invalidate(); admin.show(); } } } catch (Exception err) { err.printStackTrace(); System.err.println("Failed to initialize AdminMgr.\nExiting...."); } } /** * Print out information on running this sevice */ static protected void usage() { PrintStream out = System.out; out.println("\n\n"); out.println("====================================================="); out.println("Usage information for " + AdminMgr.class.getName()); out.println("====================================================="); out.println("\n" + AdminMgr.class.getName()); out.println(" [-help | -config <xml config file>]\n"); out.println("\t-help displays this screen\n"); out.println("\t-config file name of xml-based config file\n"); } /** * A simple class to re-direct the output stream from JMS to the local * console */ class StreamRedirect extends Thread { InputStream is_; StreamRedirect(InputStream is) { is_ = is; } public void run() { try { InputStreamReader isr = new InputStreamReader(is_); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } } catch (IOException ioe) { ioe.printStackTrace(); } } } private String[] getStartCommand() throws Exception { ArrayList args = new ArrayList(); if (_serverStart != null) { Perl5Compiler compiler = new Perl5Compiler(); Pattern pattern = compiler.compile("'.*'|[^\\s]*"); Perl5Matcher matcher = new Perl5Matcher(); PatternMatcherInput input = new PatternMatcherInput(_serverStart); while (matcher.contains(input, pattern)) { String arg = matcher.getMatch().toString(); if (arg.startsWith("'") && arg.endsWith("'")) { arg = arg.substring(1, arg.length() - 1); } args.add(arg); } } args.add("-config"); args.add(_serverConfig); return (String[]) args.toArray(new String[0]); } /** * Returns the value of the openjms.home environment variable */ private static String getOpenJMSHome() { return System.getProperty("openjms.home", System.getProperty("user.dir")); } /** * Display and log an error * * @param title * @param message * @param exception */ private void error(String title, String message, Exception exception) { _log.error(message, exception); JOptionPane.showMessageDialog(this, message, title, JOptionPane.ERROR_MESSAGE); }} //-- AdminMgr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -