📄 main.java
字号:
/*------------------------------------------------------------------------------Name: Main.javaProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileComment: Main class to invoke the xmlBlaster server------------------------------------------------------------------------------*/package org.xmlBlaster;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.engine.*;import org.xmlBlaster.util.FileLocator;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.admin.extern.JmxWrapper;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.util.I_XmlBlasterExceptionHandler;import org.xmlBlaster.util.ReplaceVariable;import org.xmlBlaster.util.ThreadLister;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.SignalCatcher;import org.xmlBlaster.util.I_SignalListener;import org.xmlBlaster.util.log.XbFormatter;import org.xmlBlaster.util.property.Property;import org.xmlBlaster.protocol.I_XmlBlaster;import org.xmlBlaster.protocol.I_Authenticate;import org.xmlBlaster.engine.runlevel.RunlevelManager;import org.xmlBlaster.engine.runlevel.I_RunlevelListener;import org.xmlBlaster.protocol.I_Driver;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.IOException;/** * Main class to invoke the xmlBlaster server. * <p /> * There are many command line parameters supported * please invoke with "-?" to get a complete list of the supported parameters. * <br /> * Every parameter may be set in the xmlBlaster.property file as a system property or at the command line, * the command line is strongest, xmlBlaster.properties weakest. The leading "-" from the command line key * parameters are stripped (see Property.java). * <p /> * Examples how to start the xmlBlaster server: * <p /> * <code> java org.xmlBlaster.Main -bootstrapPort 3412</code> * <p /> * <code> java org.xmlBlaster.Main -plugin/ior/iorFile /tmp/XmlBlaster_Ref</code> * <p /> * <code> java org.xmlBlaster.Main -logging FINEST</code> * <p /> * <code> java org.xmlBlaster.Main -plugin/xmlrpc/hostname 102.24.64.60 -plugin/xmlrpc/port 8081</code> * <p /> * <code> java org.xmlBlaster.Main -?</code> * * @author <a href="mailto:xmlBlaster@marcelruff.info">Marcel Ruff</a>. * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/admin.telnet.html" target="others">admin.telnet</a> * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/util.property.html" target="others">util.property</a> */public class Main implements I_RunlevelListener, I_Main, I_SignalListener, I_XmlBlasterExceptionHandler{ private String ME = "Main"; private ServerScope glob = null; private static Logger log = Logger.getLogger(Main.class.getName()); /** Starts/stops xmlBlaster */ private RunlevelManager runlevelManager = null; private boolean showUsage = false; private boolean inShutdownProcess = false; private SignalCatcher signalCatcher; /** * Comma separate list of errorCodes which to an immediate System.exit(1); * Used by our default implementation of I_XmlBlasterExceptionHandler */ private String panicErrorCodes = ErrorCode.RESOURCE_DB_UNKNOWN.getErrorCode()+","+ErrorCode.RESOURCE_DB_UNAVAILABLE.getErrorCode(); /** * true: If instance created by control panel<br /> * false: running without GUI */ static MainGUI controlPanel = null; /** * You need to call init() after construction. * Currently used by XmlBlasterClassLoader */ public Main() { //System.out.println("Default constructor called ..."); } public Main(ServerScope glob, MainGUI controlPanel_) { controlPanel = controlPanel_; controlPanel.xmlBlasterMain = this; init(glob); } /** * Start xmlBlaster using the properties from utilGlob * without loading xmlBlaster.properties again * @param utilGlob The environment for this server instance */ public Main(Global utilGlob) { if (utilGlob instanceof ServerScope) init(utilGlob); else init(new ServerScope(Property.propsToArgs(utilGlob.getProperty().getProperties()))); } /** * Start xmlBlaster using the given properties * and load xmlBlaster.properties. * @param args The command line parameters */ public Main(String[] args) { // The setting 'java -DxmlBlaster/initClassName=mypackage.MyClass ...' allows to load an initial class instance String initClass = System.getProperty("xmlBlaster/initClassName", ""); if (initClass.length() > 0) { try { this.getClass().getClassLoader().loadClass(initClass).newInstance(); } catch (Exception e) { e.printStackTrace(); } } init(new ServerScope(args)); } public ServerScope getGlobal() { return this.glob; } /* * Start xmlBlaster using the properties from utilGlob * without loading <tt>xmlBlaster.properties</tt> again * @param utilGlob The environment for this server instance */ public void init(org.xmlBlaster.util.Global utilGlob) { org.xmlBlaster.engine.ServerScope gg = new org.xmlBlaster.engine.ServerScope(utilGlob.getProperty().getProperties(), false); utilGlob.setId(gg.getId()); // Inherit backwards the cluster node id init(gg); } /* * Start xmlBlaster using the given properties * and load <tt>xmlBlaster.properties</tt>. * @param props The environment for this server instance */ public void init(java.util.Properties props) { this.init(new org.xmlBlaster.engine.ServerScope(props, true)); } public final void init(ServerScope glob) { this.glob = glob; this.ME = "Main" + glob.getLogPrefixDashed(); //try { log.info(ME, glob.getDump()); } catch (Throwable e) { System.out.println(ME + ": " + e.toString()); e.printStackTrace(); } showUsage = glob.wantsHelp(); Thread.currentThread().setName("XmlBlaster.MainThread"); if (glob.wantsHelp()) showUsage = true; else if (glob.getErrorText() != null) { usage(); log.severe(glob.getErrorText()); if (glob.isEmbedded()) throw new IllegalArgumentException(glob.getErrorText()); else System.exit(0); } long sleepOnStartup = glob.getProperty().get("xmlBlaster/sleepOnStartup", 0L); if (sleepOnStartup > 0L) { log.info("Going to sleep as configured xmlBlaster/sleepOnStartup=" + sleepOnStartup); try { Thread.sleep(sleepOnStartup); } catch(InterruptedException e) { log.warning("Caught exception during xmlBlaster/sleepOnStartup=" + sleepOnStartup + ": " + e.toString()); } } this.panicErrorCodes = glob.getProperty().get("xmlBlaster/panicErrorCodes", this.panicErrorCodes); log.fine("Following errorCodes do an immediate exit: " + this.panicErrorCodes); int runlevel = glob.getProperty().get("runlevel", RunlevelManager.RUNLEVEL_RUNNING); try { runlevelManager = glob.getRunlevelManager(); runlevelManager.addRunlevelListener(this); runlevelManager.initPluginManagers(); runlevelManager.changeRunlevel(runlevel, false); } catch (Throwable e) { if (e instanceof XmlBlasterException) { log.severe(e.getMessage()); } else { e.printStackTrace(); log.severe(e.toString()); } if (glob.isEmbedded()) { throw new IllegalArgumentException(e.toString()); } else { log.severe("Changing runlevel to '" + RunlevelManager.toRunlevelStr(runlevel) + "' failed, good bye"); System.exit(1); } } boolean useKeyboard = glob.getProperty().get("useKeyboard", true); if (!useKeyboard) { while (true) { try { Thread.sleep(100000000L); } catch(InterruptedException e) { log.warning("Caught exception: " + e.toString()); } } /* // Exception in thread "main" java.lang.IllegalMonitorStateException: try { Thread.currentThread().wait(); } catch(InterruptedException e) { log.warn(ME, "Caught exception: " + e.toString()); } */ } // Used by testsuite to switch off blocking, this Main method is by default never returning: boolean doBlocking = glob.getProperty().get("doBlocking", true); if (doBlocking) { checkForKeyboardInput(); // orb.run(); } } /** Same as shutdown() but does additionally an engine.global.shutdown() */ public synchronized void destroy() { shutdown(); if (this.glob != null) { this.glob.shutdown(); this.glob = null; } } /** * Instructs the RunlevelManager to shut down, which causes all object adapters to shut down. * <p /> * The drivers are removed. */ public synchronized void shutdown() { if (inShutdownProcess) return; inShutdownProcess = true; int errors = 0; try { errors = runlevelManager.changeRunlevel(RunlevelManager.RUNLEVEL_HALTED, true); } catch(XmlBlasterException e) { log.severe("Problem during shutdown: " + e.toString()); } if (errors > 0) { log.warning("There were " + errors + " errors during shutdown."); } else { if (log.isLoggable(Level.FINE)) log.fine("shutdown() done"); } } /** * Access the authentication singleton. */ public I_Authenticate getAuthenticate() { return glob.getAuthenticate(); } /** * Access the xmlBlaster singleton. */ public I_XmlBlaster getXmlBlaster() { return getAuthenticate().getXmlBlaster(); } /** * Check for keyboard entries from console. * <p /> * Supported input is: * <ul> * <li>'g' to pop up the control panel GUI</li> * <li>'d' to dump the internal state of xmlBlaster</li> * <li>'q' to quit xmlBlaster</li> * </ul> * <p /> * NOTE: This method never returns, only on exit for 'q' */ private void checkForKeyboardInput() { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (true) { // orbacus needs this !!! Michele? // if (orb.work_pending()) orb.perform_work(); try { String line = in.readLine(); // Blocking in I/O if (line == null) continue; line = line.trim(); if (line.toLowerCase().equals("g")) { if (controlPanel == null) { log.info("Invoking control panel GUI ...");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -