⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adminmgr.java

📁 实现了Jms的服务器源码,支持多种适配器,DB,FTP,支持多种数据库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * Redistribution and use of this software and associated documentation
 * ("Software"), with or without modification, are permitted provided
 * that the following conditions are met:
 *
 * 1. Redistributions of source code must retain copyright
 *    statements and notices.  Redistributions must also contain a
 *    copy of this document.
 *
 * 2. Redistributions in binary form must reproduce the
 *    above copyright notice, this list of conditions and the
 *    following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. The name "Exolab" must not be used to endorse or promote
 *    products derived from this Software without prior written
 *    permission of Exoffice Technologies.  For written permission,
 *    please contact info@exolab.org.
 *
 * 4. Products derived from this Software may not be called "Exolab"
 *    nor may "Exolab" appear in their names without prior written
 *    permission of Exoffice Technologies. Exolab is a registered
 *    trademark of Exoffice Technologies.
 *
 * 5. Due credit should be given to the Exolab Project
 *    (http://www.exolab.org/).
 *
 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Copyright 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
 *
 * $Id: AdminMgr.java,v 1.4 2003/08/24 07:09:29 tanderson Exp $
 *
 * Date         Author  Changes
 */


package org.exolab.jms.tools.admin;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

import org.apache.log4j.xml.DOMConfigurator;
import org.apache.oro.text.regex.*;

import org.exolab.jms.config.AdminConfiguration;
import org.exolab.jms.config.Configuration;
import org.exolab.jms.config.ConfigurationManager;
import org.exolab.jms.util.CommandLine;


/**
 * This class is the Gui controller for the JMS administration. It
 * displays data as a hierarchical set of tree nodes.
 *
 * <P>The Root is all the contactable JMS servers, idealy there can be several
 * of these all on different ports, with one common admin port they all listen
 * to. A user selects a JMSServer then connects via the menu item. This
 * allows the admin GUI to connect to the server via the main port and begin
 * displaying all its Queue/Topics and registered consumers.
 *
 * If there are no queue/topics for a consumer the node will be empty.
 * Selecting a consumer allows a user to see what its details are, i.e
 * last message received and acked, whether the consumer is currently
 * active/deactive paused etc.
 *
 * <P>The Gui can also be used to add/remove queue/topics and consumer
 * registrations.
 *
 * Reliable Topics are read only, since they cannot be persisted, they simply
 * display a snapshot at the time of connection.
 *
 * <P>For the moment this is not truly dynamic, that is a refresh needs to be
 * activated on the Gui to cause an update (other than changes made
 * through the Gui istelf).
 *
 * @version     $Revision: 1.4 $ $Date: 2003/08/24 07:09:29 $
 * @author      <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
 */
public class AdminMgr extends JFrame {

    // Gui Declarations
    private JMenuBar _menuBar;
    private JMenu _file;
    private JMenuItem _exit;
    private JMenu _actions;
    private JMenu _connections;
    private JMenuItem _refresh;
    private JMenuItem _online;
    private JMenuItem _offline;
    private JMenuItem _disconnect;
    private JSeparator _separator;
    private JMenuItem _startup;
    private JMenuItem _shutdown;
    private JScrollPane _jmsServers;
    private JTree _serverProperties;
    private JTextField _messageArea;
    private JComboBox _jmsCombo;

    // If this Admin object is connected to any OpenJMS
    private boolean _connected = false;

    /**
     * The server start command
     */
    private static String _serverStart = null;

    /**
     * The server configuration file path
     */
    private static String _serverConfig = null;

    // redirect stream to local console.
    private StreamRedirect _output = null;

    /**
     * The default constructor performs all gui creations.
     *
     */
    public AdminMgr() {
        this("");
    }

    public AdminMgr(String title) {
        initComponents(title);
        pack();
    }

    /** This method is called from within the constructor to
     * initialize the form. All the GUI objects are created, and callbacks
     * registered.
     */
    private void initComponents(String title) {
        _menuBar = new JMenuBar();
        _file = new JMenu();
        _exit = new JMenuItem();
        _actions = new JMenu();
        _connections = new JMenu();
        _refresh = new JMenuItem();
        _online = new JMenuItem();
        _offline = new JMenuItem();
        _disconnect = new JMenuItem();
        _separator = new JSeparator();
        _startup = new JMenuItem();
        _shutdown = new JMenuItem();
        _jmsServers = new JScrollPane();
        _jmsCombo = new JComboBox();
        _serverProperties = new JTree();
        setTitle("OpenJMS Administrator: " + title);
        DefaultTreeModel serverModel =
            OpenJMSServer.createServerList(_serverProperties);
        _serverProperties.setModel(serverModel);
        AdminInfo info = new AdminInfo();
        _serverProperties.setCellRenderer(info);

        _messageArea = new JTextField();
        _file.setText("File");
        _exit.setToolTipText("Exit administration");
        _exit.setText("Exit");
        _exit.setMnemonic('x');

        _serverProperties.setRootVisible(false);
        _serverProperties.setShowsRootHandles(true);
        _serverProperties.putClientProperty("JTree.lineStyle", "Angled");
        _serverProperties.setCellEditor(new OpenJMSEditor(_serverProperties,
            _jmsCombo));
        _serverProperties.setEditable(false);
        setupCallbacks();
        _file.add(_exit);
        _file.setMnemonic('F');
        _menuBar.add(_file);
        _actions.setText("Actions");
        _actions.setMnemonic('A');
        _connections.setText("Connections");
        _connections.setMnemonic('C');
        _refresh.setToolTipText("Refresh the display");
        _online.setToolTipText("Connect to a running OpenJMS Server");
        _offline.setToolTipText("Connect directly to an OpenJMS database");
        _refresh.setText("Refresh");
        _refresh.setMnemonic('R');
        _actions.add(_refresh);

        _online.setText("Online");
        _online.setMnemonic('O');
        _offline.setText("Offline");
        _offline.setMnemonic('f');
        _connections.add(_online);
        _connections.add(_offline);
        _actions.add(_connections);
        _disconnect.setToolTipText
            ("Disconnect from any connected OpenJMS Servers");
        _disconnect.setText("Disconnect");
        _disconnect.setMnemonic('D');
        _actions.add(_disconnect);

        _actions.add(_separator);
        _startup.setToolTipText("Start the OpenJMS server");
        _startup.setText("Start OpenJMS");
        _startup.setMnemonic('S');
        _shutdown.setToolTipText("Shutdown the connected OpenJMS server");
        _shutdown.setText("Shutdown OpenJMS");
        _shutdown.setMnemonic('h');
        _actions.add(_startup);
        _actions.add(_shutdown);
        _menuBar.add(_actions);

        _jmsServers.setViewportView(_serverProperties);


        getContentPane().add(_jmsServers, BorderLayout.CENTER);

        _messageArea.setToolTipText("Message Area");
        _messageArea.setEditable(false);
        _messageArea.setForeground(java.awt.Color.red);
        _messageArea.setText("Not Connected");
        _messageArea.setHorizontalAlignment(SwingConstants.CENTER);


        getContentPane().add(_messageArea, BorderLayout.SOUTH);
        setJMenuBar(_menuBar);
        _startup.setEnabled(true);
        _shutdown.setEnabled(false);
        _refresh.setEnabled(false);
        _disconnect.setEnabled(false);
    }

    /**
     * The exit method for the application, when the user shutdowns the form.
     *
     * @param evt The event that triggered this action.
     *
     */
    private void exitAdmin(ActionEvent evt) {
        System.exit(0);
    }

    /**
     * Exit the Application when a user selects File->Exit from the menu
     *
     * @param evt The window event that triggered this call.
     *
     */
    private void exitForm(WindowEvent evt) {
        System.exit(0);
    }

    /**
     * Refresh the display, and repaint all items.
     *
     * @param evt The event that triggered this operation.
     *
     */
    private void refresh(ActionEvent evt) {
        if (AbstractAdminConnection.instance() instanceof OnlineConnection) {
            setConnected(false, null);
            setConnected(true, "Connected - Online Mode");
            _startup.setEnabled(false);
            _shutdown.setEnabled(true);

        } else {
            ((OpenJMSServer) (_serverProperties.getModel().getRoot()
                )).refresh();
        }
    }

    /**
     * Start the OpenJMSServer.
     *
     */
    private void startup(ActionEvent evt) {

        try {
            String args[] = getStartCommand();

            System.out.print("running ");
            for (int i = 0, j = args.length; i < j; i++) {
                System.out.print(args[i] + " ");
            }
            System.out.println();

            if (_output != null) {
                // Stop the old redirect if any.
                _output.interrupt();
            }
            Process proc = Runtime.getRuntime().exec(args);
            // Redirect output
            _output = new StreamRedirect(proc.getInputStream());
            // kick it off
            _output.start();
        } catch (Exception err) {
            JOptionPane.showMessageDialog
                (this, "Failed to Startup OpenJMSServer:\n" + err
                + "\nCheck config file",
                    "OpenJMSServer Startup", JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * When a user wishes to connect to all known OpenJMSServers.
     * Attempt to create an RMI connection to the OpenJMSServer. If the server
     * is not running, this will fail. The user can start the server through
     * the start server command, and attempt to re-connect, or use the offline
     * method below.
     *
     * @param evt The event that triggered this operation.
     *
     */
    private void onlineConnect(ActionEvent evt) {
        try {
            // if online.
            new OnlineConnection(this);
            _startup.setEnabled(false);
            _shutdown.setEnabled(true);
            setConnected(true, "Connected - Online Mode");
        } catch (Exception err) {
            JOptionPane.showMessageDialog
                (this, err.getMessage(), "Online Connection Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }


    /**
     * Connect to the database in offline mode. This action causes
     * the file chooser to be displayed, and the user must select an existing
     * database, or enter a new name to create a new database.
     *
     * All databases are suffixed with a ".db".
     *
     * @param evt The event that triggered this operation.
     *
     */
    private void offlineConnect(ActionEvent evt) {
        try {
            // if online.
            new OfflineConnection(this);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -