?? adminmgr.java
字號:
_startup.setEnabled(false);
_shutdown.setEnabled(false);
setConnected(true, "Connected - OFFLine Mode");
} catch (Exception err) {
JOptionPane.showMessageDialog
(this, err.getMessage(), "Database Error",
JOptionPane.ERROR_MESSAGE);
}
}
/**
* Disconnect from a connected OpenJMSServer. Close the database, set the
* connected flag to false, stop displaying the OpenJMS folder.
*
* @param evt The event that triggered this operation.
*
*/
private void disconnect(ActionEvent evt) {
try {
AbstractAdminConnection.instance().close();
setConnected(false, null);
} catch (Exception e) {
JOptionPane.showMessageDialog
(this, e.getMessage(), "Database Close Error",
JOptionPane.ERROR_MESSAGE);
}
}
/**
* A conveniance routine to open/close all database connections,
* and fix up the display.
*
* <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>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>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(evt);
}
}
);
_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(evt);
}
}
);
_refresh.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
refresh(evt);
}
}
);
_online.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
onlineConnect(evt);
}
}
);
_offline.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
offlineConnect(evt);
}
}
);
_disconnect.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
disconnect(evt);
}
}
);
_startup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
startup(evt);
}
}
);
_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";
}
ConfigurationManager.setConfig(configFile);
Configuration config = ConfigurationManager.getConfig();
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);
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"));
}
} //-- AdminMgr
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -