KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > tools > admin > AdminMgr


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: AdminMgr.java,v 1.1 2004/11/26 01:51:15 tanderson Exp $
44  *
45  * Date Author Changes
46  */

47
48
49 package org.exolab.jms.tools.admin;
50
51 import java.awt.BorderLayout JavaDoc;
52 import java.awt.Dimension JavaDoc;
53 import java.awt.Toolkit JavaDoc;
54 import java.awt.event.ActionEvent JavaDoc;
55 import java.awt.event.ActionListener JavaDoc;
56 import java.awt.event.MouseAdapter JavaDoc;
57 import java.awt.event.MouseEvent JavaDoc;
58 import java.awt.event.WindowAdapter JavaDoc;
59 import java.awt.event.WindowEvent JavaDoc;
60 import java.io.BufferedReader JavaDoc;
61 import java.io.IOException JavaDoc;
62 import java.io.InputStream JavaDoc;
63 import java.io.InputStreamReader JavaDoc;
64 import java.io.PrintStream JavaDoc;
65 import java.util.ArrayList JavaDoc;
66
67 import javax.swing.JComboBox JavaDoc;
68 import javax.swing.JFrame JavaDoc;
69 import javax.swing.JMenu JavaDoc;
70 import javax.swing.JMenuBar JavaDoc;
71 import javax.swing.JMenuItem JavaDoc;
72 import javax.swing.JOptionPane JavaDoc;
73 import javax.swing.JScrollPane JavaDoc;
74 import javax.swing.JSeparator JavaDoc;
75 import javax.swing.JTextField JavaDoc;
76 import javax.swing.JTree JavaDoc;
77 import javax.swing.SwingConstants JavaDoc;
78 import javax.swing.SwingUtilities JavaDoc;
79 import javax.swing.event.TreeExpansionEvent JavaDoc;
80 import javax.swing.event.TreeExpansionListener JavaDoc;
81 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
82 import javax.swing.tree.DefaultTreeModel JavaDoc;
83 import javax.swing.tree.TreePath JavaDoc;
84
85 import org.apache.log4j.xml.DOMConfigurator;
86 import org.apache.oro.text.regex.*;
87
88 import org.exolab.jms.config.AdminConfiguration;
89 import org.exolab.jms.config.Configuration;
90 import org.exolab.jms.config.ConfigurationManager;
91 import org.exolab.jms.util.CommandLine;
92
93
94 /**
95  * This class is the Gui controller for the JMS administration. It
96  * displays data as a hierarchical set of tree nodes.
97  *
98  * <P>The Root is all the contactable JMS servers, idealy there can be several
99  * of these all on different ports, with one common admin port they all listen
100  * to. A user selects a JMSServer then connects via the menu item. This
101  * allows the admin GUI to connect to the server via the main port and begin
102  * displaying all its Queue/Topics and registered consumers.
103  *
104  * If there are no queue/topics for a consumer the node will be empty.
105  * Selecting a consumer allows a user to see what its details are, i.e
106  * last message received and acked, whether the consumer is currently
107  * active/deactive paused etc.
108  *
109  * <P>The Gui can also be used to add/remove queue/topics and consumer
110  * registrations.
111  *
112  * Reliable Topics are read only, since they cannot be persisted, they simply
113  * display a snapshot at the time of connection.
114  *
115  * <P>For the moment this is not truly dynamic, that is a refresh needs to be
116  * activated on the Gui to cause an update (other than changes made
117  * through the Gui istelf).
118  *
119  * @version $Revision: 1.1 $ $Date: 2004/11/26 01:51:15 $
120  * @author <a HREF="mailto:mourikis@exolab.org">Jim Mourikis</a>
121  */

122 public class AdminMgr extends JFrame JavaDoc {
123
124     // Gui Declarations
125
private JMenuBar JavaDoc _menuBar;
126     private JMenu JavaDoc _file;
127     private JMenuItem JavaDoc _exit;
128     private JMenu JavaDoc _actions;
129     private JMenu JavaDoc _connections;
130     private JMenuItem JavaDoc _refresh;
131     private JMenuItem JavaDoc _online;
132     private JMenuItem JavaDoc _offline;
133     private JMenuItem JavaDoc _disconnect;
134     private JSeparator JavaDoc _separator;
135     private JMenuItem JavaDoc _startup;
136     private JMenuItem JavaDoc _shutdown;
137     private JScrollPane JavaDoc _jmsServers;
138     private JTree JavaDoc _serverProperties;
139     private JTextField JavaDoc _messageArea;
140     private JComboBox JavaDoc _jmsCombo;
141
142     // If this Admin object is connected to any OpenJMS
143
private boolean _connected = false;
144
145     /**
146      * The server start command
147      */

148     private static String JavaDoc _serverStart = null;
149
150     /**
151      * The server configuration file path
152      */

153     private static String JavaDoc _serverConfig = null;
154
155     // redirect stream to local console.
156
private StreamRedirect _output = null;
157
158     /**
159      * The default constructor performs all gui creations.
160      *
161      */

162     public AdminMgr() {
163         this("");
164     }
165
166     public AdminMgr(String JavaDoc title) {
167         initComponents(title);
168         pack();
169     }
170
171     /** This method is called from within the constructor to
172      * initialize the form. All the GUI objects are created, and callbacks
173      * registered.
174      */

175     private void initComponents(String JavaDoc title) {
176         _menuBar = new JMenuBar JavaDoc();
177         _file = new JMenu JavaDoc();
178         _exit = new JMenuItem JavaDoc();
179         _actions = new JMenu JavaDoc();
180         _connections = new JMenu JavaDoc();
181         _refresh = new JMenuItem JavaDoc();
182         _online = new JMenuItem JavaDoc();
183         _offline = new JMenuItem JavaDoc();
184         _disconnect = new JMenuItem JavaDoc();
185         _separator = new JSeparator JavaDoc();
186         _startup = new JMenuItem JavaDoc();
187         _shutdown = new JMenuItem JavaDoc();
188         _jmsServers = new JScrollPane JavaDoc();
189         _jmsCombo = new JComboBox JavaDoc();
190         _serverProperties = new JTree JavaDoc();
191         setTitle("OpenJMS Administrator: " + title);
192         DefaultTreeModel JavaDoc serverModel =
193             OpenJMSServer.createServerList(_serverProperties);
194         _serverProperties.setModel(serverModel);
195         AdminInfo info = new AdminInfo();
196         _serverProperties.setCellRenderer(info);
197
198         _messageArea = new JTextField JavaDoc();
199         _file.setText("File");
200         _exit.setToolTipText("Exit administration");
201         _exit.setText("Exit");
202         _exit.setMnemonic('x');
203
204         _serverProperties.setRootVisible(false);
205         _serverProperties.setShowsRootHandles(true);
206         _serverProperties.putClientProperty("JTree.lineStyle", "Angled");
207         _serverProperties.setCellEditor(new OpenJMSEditor(_serverProperties,
208             _jmsCombo));
209         _serverProperties.setEditable(false);
210         setupCallbacks();
211         _file.add(_exit);
212         _file.setMnemonic('F');
213         _menuBar.add(_file);
214         _actions.setText("Actions");
215         _actions.setMnemonic('A');
216         _connections.setText("Connections");
217         _connections.setMnemonic('C');
218         _refresh.setToolTipText("Refresh the display");
219         _online.setToolTipText("Connect to a running OpenJMS Server");
220         _offline.setToolTipText("Connect directly to an OpenJMS database");
221         _refresh.setText("Refresh");
222         _refresh.setMnemonic('R');
223         _actions.add(_refresh);
224
225         _online.setText("Online");
226         _online.setMnemonic('O');
227         _offline.setText("Offline");
228         _offline.setMnemonic('f');
229         _connections.add(_online);
230         _connections.add(_offline);
231         _actions.add(_connections);
232         _disconnect.setToolTipText
233             ("Disconnect from any connected OpenJMS Servers");
234         _disconnect.setText("Disconnect");
235         _disconnect.setMnemonic('D');
236         _actions.add(_disconnect);
237
238         _actions.add(_separator);
239         _startup.setToolTipText("Start the OpenJMS server");
240         _startup.setText("Start OpenJMS");
241         _startup.setMnemonic('S');
242         _shutdown.setToolTipText("Shutdown the connected OpenJMS server");
243         _shutdown.setText("Shutdown OpenJMS");
244         _shutdown.setMnemonic('h');
245         _actions.add(_startup);
246         _actions.add(_shutdown);
247         _menuBar.add(_actions);
248
249         _jmsServers.setViewportView(_serverProperties);
250
251
252         getContentPane().add(_jmsServers, BorderLayout.CENTER);
253
254         _messageArea.setToolTipText("Message Area");
255         _messageArea.setEditable(false);
256         _messageArea.setForeground(java.awt.Color.red);
257         _messageArea.setText("Not Connected");
258         _messageArea.setHorizontalAlignment(SwingConstants.CENTER);
259
260
261         getContentPane().add(_messageArea, BorderLayout.SOUTH);
262         setJMenuBar(_menuBar);
263         _startup.setEnabled(true);
264         _shutdown.setEnabled(false);
265         _refresh.setEnabled(false);
266         _disconnect.setEnabled(false);
267     }
268
269     /**
270      * The exit method for the application, when the user shutdowns the form.
271      *
272      * @param evt The event that triggered this action.
273      *
274      */

275     private void exitAdmin(ActionEvent JavaDoc evt) {
276         System.exit(0);
277     }
278
279     /**
280      * Exit the Application when a user selects File->Exit from the menu
281      *
282      * @param evt The window event that triggered this call.
283      *
284      */

285     private void exitForm(WindowEvent JavaDoc evt) {
286         System.exit(0);
287     }
288
289     /**
290      * Refresh the display, and repaint all items.
291      *
292      * @param evt The event that triggered this operation.
293      *
294      */

295     private void refresh(ActionEvent JavaDoc evt) {
296         if (AbstractAdminConnection.instance() instanceof OnlineConnection) {
297             setConnected(false, null);
298             setConnected(true, "Connected - Online Mode");
299             _startup.setEnabled(false);
300             _shutdown.setEnabled(true);
301
302         } else {
303             ((OpenJMSServer) (_serverProperties.getModel().getRoot()
304                 )).refresh();
305         }
306     }
307
308     /**
309      * Start the OpenJMSServer.
310      *
311      */

312     private void startup(ActionEvent JavaDoc evt) {
313
314         try {
315             String JavaDoc args[] = getStartCommand();
316
317             System.out.print("running ");
318             for (int i = 0, j = args.length; i < j; i++) {
319                 System.out.print(args[i] + " ");
320             }
321             System.out.println();
322
323             if (_output != null) {
324                 // Stop the old redirect if any.
325
_output.interrupt();
326             }
327             Process JavaDoc proc = Runtime.getRuntime().exec(args);
328             // Redirect output
329
_output = new StreamRedirect(proc.getInputStream());
330             // kick it off
331
_output.start();
332         } catch (Exception JavaDoc err) {
333             JOptionPane.showMessageDialog
334                 (this, "Failed to Startup OpenJMSServer:\n" + err
335                 + "\nCheck config file",
336                     "OpenJMSServer Startup", JOptionPane.ERROR_MESSAGE);
337         }
338     }
339
340     /**
341      * When a user wishes to connect to all known OpenJMSServers.
342      * Attempt to create an RMI connection to the OpenJMSServer. If the server
343      * is not running, this will fail. The user can start the server through
344      * the start server command, and attempt to re-connect, or use the offline
345      * method below.
346      *
347      * @param evt The event that triggered this operation.
348      *
349      */

350     private void onlineConnect(ActionEvent JavaDoc evt) {
351         try {
352             // if online.
353
new OnlineConnection(this);
354             _startup.setEnabled(false);
355             _shutdown.setEnabled(true);
356             setConnected(true, "Connected - Online Mode");
357         } catch (Exception JavaDoc err) {
358             JOptionPane.showMessageDialog
359                 (this, err.getMessage(), "Online Connection Error",
360                     JOptionPane.ERROR_MESSAGE);
361         }
362     }
363
364
365     /**
366      * Connect to the database in offline mode. This action causes
367      * the file chooser to be displayed, and the user must select an existing
368      * database, or enter a new name to create a new database.
369      *
370      * All databases are suffixed with a ".db".
371      *
372      * @param evt The event that triggered this operation.
373      *
374      */

375     private void offlineConnect(ActionEvent JavaDoc evt) {
376         try {
377             // if online.
378
new OfflineConnection(this);
379             _startup.setEnabled(false);
380             _shutdown.setEnabled(false);
381             setConnected(true, "Connected - OFFLine Mode");
382         } catch (Exception JavaDoc err) {
383             JOptionPane.showMessageDialog
384                 (this, err.getMessage(), "Database Error",
385                     JOptionPane.ERROR_MESSAGE);
386         }
387     }
388
389     /**
390      * Disconnect from a connected OpenJMSServer. Close the database, set the
391      * connected flag to false, stop displaying the OpenJMS folder.
392      *
393      * @param evt The event that triggered this operation.
394      *
395      */

396     private void disconnect(ActionEvent JavaDoc evt) {
397         try {
398             AbstractAdminConnection.instance().close();
399             setConnected(false, null);
400         } catch (Exception JavaDoc e) {
401             JOptionPane.showMessageDialog
402                 (this, e.getMessage(), "Database Close Error",
403                     JOptionPane.ERROR_MESSAGE);
404         }
405     }
406
407     /**
408      * A conveniance routine to open/close all database connections,
409      * and fix up the display.
410      *
411      * <P>When connecting, show the root object, get any persistent queue/topic
412      * names currently in the db, and display them.
413      * Turn off the connection menu, enable the disconnection and shutdown
414      * and the context menus. Set the message area text to connected.
415      *
416      * <P>When disconnecting, turn off the root, destroy all Gui objects
417      * close the db connection, turn off all context sensitive menus,
418      * disable disconnection menu and enable connection. Set the message
419      * text to disconnected.
420      *
421      * @param c a flag inidication if this is a connection or disconnection.
422      *
423      */

424     private void setConnected(boolean c, String JavaDoc st) {
425         if (c) {
426             _serverProperties.setRootVisible(true);
427             ((OpenJMSServer)
428                 (_serverProperties.getModel().getRoot())).displayConnections();
429             _connections.setEnabled(false);
430             _refresh.setEnabled(true);
431             // _shutdown.setEnabled(true);
432
_disconnect.setEnabled(true);
433             // _startup.setEnabled(false);
434
_messageArea.setForeground(java.awt.Color.green.darker().darker());
435             _messageArea.setText(st);
436             _connected = true;
437         } else {
438             _serverProperties.setRootVisible(false);
439             OpenJMSServer root =
440                 (OpenJMSServer) _serverProperties.getModel().getRoot();
441             root.removeAllChildren();
442             DefaultTreeModel JavaDoc model =
443                 (DefaultTreeModel JavaDoc) _serverProperties.getModel();
444             model.nodeStructureChanged((DefaultMutableTreeNode JavaDoc) root);
445             _connections.setEnabled(true);
446             _startup.setEnabled(true);
447             _shutdown.setEnabled(false);
448             _refresh.setEnabled(false);
449             _disconnect.setEnabled(false);
450             _messageArea.setForeground(java.awt.Color.red);
451             _messageArea.setText("Not Connected");
452             _connected = false;
453         }
454     }
455
456     /**
457      * Set up all Action menu callbacks, and mouse events for the tree and its
458      * nodes. Check all mose 2 key presses on a node, select the node,
459      * then call the nodes appropriate display methos to display its
460      * specific popup menus.
461      *
462      * <P>When first connected, all queue/topics displayed are not expaned.
463      * This is just a performance saver, since their could potentially
464      * be hundreds of objects. A callback is set up, so that when a queue/topic
465      * is expanded, it is lokked up only then to determine what consumers
466      * are registered with it.
467      */

468     private void setupCallbacks() {
469
470         addWindowListener(new WindowAdapter JavaDoc() {
471
472             public void windowClosing(WindowEvent JavaDoc evt) {
473                 exitForm(evt);
474             }
475         }
476         );
477
478
479         _serverProperties.addMouseListener(new MouseAdapter JavaDoc() {
480
481             public void mousePressed(MouseEvent JavaDoc e) {
482                 if (!_connected) {
483                     return;
484                 }
485
486                 if (SwingUtilities.isRightMouseButton(e)) {
487                     int selRow = _serverProperties.getRowForLocation
488                         (e.getX(), e.getY());
489
490                     _serverProperties.setSelectionRow(selRow);
491                     Object JavaDoc loc =
492                         _serverProperties.getLastSelectedPathComponent();
493                     if (loc instanceof OpenJMSNode) {
494                         OpenJMSNode node = (OpenJMSNode) loc;
495                         node.displayCommands
496                             (_serverProperties.getRowBounds(selRow));
497                     } else if (loc instanceof OpenJMSServer) {
498                         ((OpenJMSServer) loc).displayCommands
499                             (_serverProperties.getRowBounds(selRow));
500                     }
501                 }
502             }
503         }
504         );
505
506         _serverProperties.addTreeExpansionListener(new TreeExpansionListener JavaDoc() {
507
508             public void treeCollapsed(TreeExpansionEvent JavaDoc e) {
509                 // todo Anything.....
510
}
511
512             public void treeExpanded(TreeExpansionEvent JavaDoc e) {
513                 TreePath JavaDoc path = e.getPath();
514                 Object JavaDoc loc = path.getLastPathComponent();
515                 if (loc instanceof OpenJMSNode) {
516                     OpenJMSNode node = (OpenJMSNode) loc;
517                     node.update();
518                 }
519             }
520         }
521         );
522
523         /**
524          _serverProperties.addTreeSelectionListener(new TreeSelectionListener()
525          {
526          public void valueChanged(TreeSelectionEvent e)
527          {
528          TreePath path = e.getPath();
529          Object loc = path.getLastPathComponent();
530          if (loc instanceof OpenJMSNode)
531          {
532          OpenJMSNode node = (OpenJMSNode)loc;
533          System.out.println(node);
534          }
535          }
536          }
537          );
538
539          **/

540         _exit.addActionListener(new ActionListener JavaDoc() {
541
542             public void actionPerformed(ActionEvent JavaDoc evt) {
543                 exitAdmin(evt);
544             }
545         }
546         );
547
548
549         _refresh.addActionListener(new ActionListener JavaDoc() {
550
551             public void actionPerformed(ActionEvent JavaDoc evt) {
552                 refresh(evt);
553             }
554         }
555         );
556
557
558         _online.addActionListener(new ActionListener JavaDoc() {
559
560             public void actionPerformed(ActionEvent JavaDoc evt) {
561                 onlineConnect(evt);
562             }
563         }
564         );
565
566         _offline.addActionListener(new ActionListener JavaDoc() {
567
568             public void actionPerformed(ActionEvent JavaDoc evt) {
569                 offlineConnect(evt);
570             }
571         }
572         );
573
574         _disconnect.addActionListener(new ActionListener JavaDoc() {
575
576             public void actionPerformed(ActionEvent JavaDoc evt) {
577                 disconnect(evt);
578             }
579         }
580         );
581
582         _startup.addActionListener(new ActionListener JavaDoc() {
583
584             public void actionPerformed(ActionEvent JavaDoc evt) {
585                 startup(evt);
586             }
587         }
588         );
589
590         _shutdown.addActionListener(new ActionListener JavaDoc() {
591
592             public void actionPerformed(ActionEvent JavaDoc evt) {
593                 try {
594                     AbstractAdminConnection.instance().stopServer();
595                     setConnected(false, null);
596                 } catch (NullPointerException JavaDoc err) {
597                     JOptionPane.showMessageDialog
598                         (_file, "Must connect with online mode \nto "
599                         + "shutdown server", "Shutdown Error",
600                             JOptionPane.ERROR_MESSAGE);
601                 }
602             }
603         }
604         );
605     }
606
607     /**
608      * The main entry point for this admin gui.
609      * The main form and any support dialogs are created.
610      * An initial size is given, and the gui placed in the middle of the screen
611      *
612      * @param args the command line arguments
613      *
614      */

615     public static void main(String JavaDoc args[]) {
616         try {
617             CommandLine cmdline = new CommandLine(args);
618
619             boolean helpSet = cmdline.exists("help");
620             boolean configSet = cmdline.exists("config");
621             boolean stopServer = cmdline.exists("stopServer");
622             String JavaDoc username = cmdline.value("u");
623             String JavaDoc password = cmdline.value("p");
624
625             if (helpSet) {
626                 usage();
627             } else if (!configSet && !stopServer && args.length != 0) {
628                 // invalid argument specified
629
usage();
630             } else {
631                 String JavaDoc configFile = cmdline.value("config");
632                 if (configFile == null) {
633                     String JavaDoc home = getOpenJMSHome();
634                     configFile = home + "/config/openjms.xml";
635                 }
636                 ConfigurationManager.setConfig(configFile);
637                 Configuration config = ConfigurationManager.getConfig();
638                 String JavaDoc path = config.getLoggerConfiguration().getFile();
639                 if (path != null) {
640                     DOMConfigurator.configure(path);
641                 }
642                 AdminConfiguration adminConfig = null;
643
644                 adminConfig = config.getAdminConfiguration();
645                 _serverStart = adminConfig.getScript();
646                 _serverConfig = adminConfig.getConfig();
647                 if (_serverConfig == null) {
648                     _serverConfig = configFile;
649                 }
650
651                 if (stopServer) {
652                     // this is a special mode that will just attempt
653
// a connection to the server and stop it. No GUI
654

655                     new OnlineConnection(username, password);
656                     AbstractAdminConnection.instance().stopServer();
657                 } else {
658                     AdminMgr admin = new AdminMgr(configFile);
659                     QueryDialog.create(admin);
660                     CreateQueueDialog.create(admin);
661                     CreateTopicDialog.create(admin);
662                     CreateLogonDialog.create(admin);
663                     CreateUserDialog.create(admin);
664                     ChangePasswordDialog.create(admin);
665                     Dimension JavaDoc screen = Toolkit.getDefaultToolkit().getScreenSize();
666                     // About center of screen
667
admin.setLocation(screen.width / 2 - 150, screen.height / 2 - 150);
668                     admin.setSize(300, 300);
669                     admin.invalidate();
670                     admin.show();
671                 }
672             }
673         } catch (Exception JavaDoc err) {
674             err.printStackTrace();
675             System.err.println("Failed to initialize AdminMgr.\nExiting....");
676         }
677     }
678
679     /**
680      * Print out information on running this sevice
681      */

682     static protected void usage() {
683         PrintStream JavaDoc out = System.out;
684
685         out.println("\n\n");
686         out.println("=====================================================");
687         out.println("Usage information for " + AdminMgr.class.getName());
688         out.println("=====================================================");
689         out.println("\n" + AdminMgr.class.getName());
690         out.println(" [-help | -config <xml config file>]\n");
691         out.println("\t-help displays this screen\n");
692         out.println("\t-config file name of xml-based config file\n");
693     }
694
695     /**
696      * A simple class to re-direct the output stream from JMS to the local
697      * console
698      */

699     class StreamRedirect extends Thread JavaDoc {
700
701         InputStream JavaDoc is_;
702
703         StreamRedirect(InputStream JavaDoc is) {
704             is_ = is;
705         }
706
707         public void run() {
708             try {
709                 InputStreamReader JavaDoc isr = new InputStreamReader JavaDoc(is_);
710                 BufferedReader JavaDoc br = new BufferedReader JavaDoc(isr);
711                 String JavaDoc line = null;
712                 while ((line = br.readLine()) != null) {
713                     System.out.println(line);
714                 }
715             } catch (IOException JavaDoc ioe) {
716                 ioe.printStackTrace();
717             }
718         }
719     }
720
721     private String JavaDoc[] getStartCommand() throws Exception JavaDoc {
722         ArrayList JavaDoc args = new ArrayList JavaDoc();
723
724         if (_serverStart != null) {
725             Perl5Compiler compiler = new Perl5Compiler();
726             Pattern pattern = compiler.compile("'.*'|[^\\s]*");
727             Perl5Matcher matcher = new Perl5Matcher();
728             PatternMatcherInput input = new PatternMatcherInput(_serverStart);
729
730             while (matcher.contains(input, pattern)) {
731                 String JavaDoc arg = matcher.getMatch().toString();
732                 if (arg.startsWith("'") && arg.endsWith("'")) {
733                     arg = arg.substring(1, arg.length() - 1);
734                 }
735                 args.add(arg);
736             }
737         }
738
739         args.add("-config");
740         args.add(_serverConfig);
741
742         return (String JavaDoc[]) args.toArray(new String JavaDoc[0]);
743     }
744
745     /**
746      * Returns the value of the openjms.home environment variable
747      */

748     private static String JavaDoc getOpenJMSHome() {
749         return System.getProperty("openjms.home",
750             System.getProperty("user.dir"));
751     }
752
753 } //-- AdminMgr
754

755
Popular Tags