📄 main.java
字号:
controlPanel = new MainGUI(glob, this); // the constructor sets the variable controlPanel controlPanel.run(); } else controlPanel.showWindow(); } else if (line.toLowerCase().equals("gc")) { long totalMem = Runtime.getRuntime().totalMemory(); long freeMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); System.gc(); log.info("Garbage collector has run, total/free bytes before="+totalMem+"/"+freeMem+", after="+Runtime.getRuntime().totalMemory()+"/"+(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); } else if (line.toLowerCase().startsWith("r")) { if (line.length() > 1) { String tmp = line.substring(1).trim(); int runlevel = -10; try { runlevel = Integer.parseInt(tmp.trim()); } catch(NumberFormatException e) { log.severe("Invalid run level '" + tmp + "', it should be a number."); }; try { runlevelManager.changeRunlevel(runlevel, true); } catch(XmlBlasterException e) { log.severe(e.toString()); } } else log.info("Current runlevel is " + RunlevelManager.toRunlevelStr(runlevelManager.getCurrentRunlevel()) + "=" + runlevelManager.getCurrentRunlevel() + ""); } else if (line.toLowerCase().startsWith("j")) { if (line.length() > 1) { // ObjectName = org.xmlBlaster:nodeClass=node,node="heron" // j org.xmlBlaster:nodeClass=node,node="heron"/action=getFreeMemStr // j org.xmlBlaster:nodeClass=node,node="heron"/action=usage?action=usage // java -Djmx.invoke.getters=set ... org.xmlBlaster.Main // j org.xmlBlaster:nodeClass=node,node="heron"/action=getLastWarning?action=getLastWarning // j org.xmlBlaster:nodeClass=node,node="heron"/action=getLastWarning // j org.xmlBlaster:nodeClass=node,node="avalon_mycomp_com",clientClass=client,client="heron.mycomp.com",sessionClass=session,session="1"/action=getConnectionState String tmp = line.substring(1).trim(); try { System.out.println("Invoking: " + tmp); Object obj = JmxWrapper.getInstance(this.glob).invokeCommand(tmp); if (obj instanceof String[]) { String[] str = (String[])obj; for(int i=0; i<str.length; i++) System.out.println(str[i]); } else { System.out.println(obj); } } catch(XmlBlasterException e) { log.severe(e.toString()); } } else log.info("Please pass a JMX object name to query"); } else if (line.toLowerCase().startsWith("d")) { try { String fileName = null; if (line.length() > 1) fileName = line.substring(1).trim(); if (fileName == null) { System.out.println(glob.getDump()); log.info("Dump done"); } else { FileLocator.writeFile(fileName, glob.getDump()); log.info("Dumped internal state to '" + fileName + "'"); } } catch(XmlBlasterException e) { log.severe("Sorry, dump failed: " + e.getMessage()); } catch(Throwable e) { log.severe("Sorry, dump failed: " + e.toString()); } } else if (line.toLowerCase().equals("q")) { shutdown(); if (glob == null || !glob.isEmbedded()) System.exit(0); } else // if (keyChar == '?' || Character.isLetter(keyChar) || Character.isDigit(keyChar)) keyboardUsage(); } catch (IOException e) { log.warning(e.toString()); } } } public boolean isHalted() { if( runlevelManager != null ) return runlevelManager.isHalted(); else return true; } /** * A human readable name of the listener for logging. * <p /> * Enforced by I_RunlevelListener */ public String getName() { return ME; } /** * Invoked on run level change, see RunlevelManager.RUNLEVEL_HALTED and RunlevelManager.RUNLEVEL_RUNNING * <p /> * Enforced by I_RunlevelListener * @see org.xmlBlaster.engine.runlevel.I_RunlevelListener#runlevelChange(int, int, boolean) */ public void runlevelChange(int from, int to, boolean force) throws XmlBlasterException { //if (log.isLoggable(Level.FINER)) log.call(ME, "Changing from run level=" + from + " to level=" + to + " with force=" + force); if (to == from) return; if (to > from) { // startup //if (to == RunlevelManager.RUNLEVEL_HALTED) { // log.error(ME, "DEBUG ONLY ........"); // if (glob.getNodeId() == null) // glob.setUniqueNodeIdName(createNodeId()); //} if (to == RunlevelManager.RUNLEVEL_HALTED_POST) { boolean useSignalCatcher = glob.getProperty().get("useSignalCatcher", true); if (useSignalCatcher) { try { this.signalCatcher = SignalCatcher.instance(); this.signalCatcher.register(this); this.signalCatcher.catchSignals(); } catch (Throwable e) { log.warning("Can't register signal catcher: " + e.toString()); } } // Add us as an I_XmlBlasterExceptionHandler ... if (XmlBlasterException.getExceptionHandler() == null) XmlBlasterException.setExceptionHandler(this); // see public void newException(XmlBlasterException e); } if (to == RunlevelManager.RUNLEVEL_STANDBY) { } if (to == RunlevelManager.RUNLEVEL_STANDBY_POST) { if (showUsage) { usage(); // Now we can display the complete usage of all loaded drivers shutdown(); if (!glob.isEmbedded()) System.exit(0); } } if (to == RunlevelManager.RUNLEVEL_CLEANUP) { } if (to == RunlevelManager.RUNLEVEL_RUNNING) { } if (to == RunlevelManager.RUNLEVEL_RUNNING_POST) { log.info(Global.getMemoryStatistic()); if (controlPanel == null) { if (XbFormatter.withXtermColors()) System.out.println(XbFormatter.BLACK_GREEN); final String bound = "|"; String ver = bound + " XmlBlaster cluster node <" + glob.getId() + "> v" + glob.getReleaseId() + " " + glob.getBuildTimestamp(); int width = ver.length() + 6; if (width < 48) width = 48; ReplaceVariable sh = new ReplaceVariable(); String line = sh.charChain('-', width-2); System.out.println(""); System.out.println(" "+line+" "); System.out.println(ver + sh.charChain(' ', width-ver.length()-1) + bound); boolean useKeyboard = glob.getProperty().get("useKeyboard", true); if (useKeyboard) { String help = bound + " READY - press <enter> for options"; System.out.println(help + sh.charChain(' ', width-help.length()-1) + bound); } else { String help = bound + " READY - no keyboard input available"; System.out.println(help + sh.charChain(' ', width-help.length()-1) + bound); } System.out.println(" "+line+" "); if (XbFormatter.withXtermColors()) System.out.println(XbFormatter.ESC); } else log.info("xmlBlaster is ready for requests"); } } if (to <= from) { // shutdown if (to == RunlevelManager.RUNLEVEL_RUNNING_PRE) { if (log.isLoggable(Level.FINE)) log.fine("Shutting down xmlBlaster to runlevel " + RunlevelManager.toRunlevelStr(to) + " ..."); } if (to == RunlevelManager.RUNLEVEL_HALTED_PRE) { synchronized (this) { if (this.glob != null) { this.glob.shutdown(); } } log.info("XmlBlaster halted."); } if (to == RunlevelManager.RUNLEVEL_HALTED) { synchronized (this) { if (this.signalCatcher != null) { this.signalCatcher.removeSignalCatcher(); this.signalCatcher = null; } } } } } public void newException(XmlBlasterException e) { // Typically if the DB is lost: ErrorCode.RESOURCE_DB_UNKNOWN if (this.panicErrorCodes.indexOf(e.getErrorCodeStr()) != -1) { log.severe("PANIC: Doing immediate shutdown caused by exception: " + e.getMessage()); e.printStackTrace(); log.severe(Global.getStackTraceAsString(e)); log.severe("Complete stack trace (all threads at the time of shutdown: " + ThreadLister.getAllStackTraces()); SignalCatcher sc = this.signalCatcher; if (sc != null) { sc.removeSignalCatcher(); } System.exit(1); } } /** * You will be notified when the runtime exits. * @see I_SignalListener#shutdownHook() */ public void shutdownHook() { destroy(); } /** * Keyboard input usage. */ private void keyboardUsage() { if (XbFormatter.withXtermColors()) System.out.println(XbFormatter.BLACK_LTGREEN); System.out.println(""); System.out.println("----------------------------------------------------------"); System.out.println("XmlBlaster " + ((glob != null) ? glob.getVersion() : "") + ((glob != null) ? (" build " + glob.getBuildTimestamp()) : "")); System.out.println("Following interactive keyboard input is recognized:"); System.out.println("Key:"); System.out.println(" g Popup the control panel GUI."); System.out.println(" r <run level> Change to run level (0,3,6,9)."); try { if (JmxWrapper.getInstance(this.glob).isActivated()) System.out.println(" j <JMX call> For example 'j org.xmlBlaster:nodeClass=node,node=\""+this.glob.getStrippedId()+"\"/action=getFreeMemStr'"); } catch (XmlBlasterException e) { e.printStackTrace(); } System.out.println(" d <file name> Dump internal state of xmlBlaster to file."); System.out.println(" q Quit xmlBlaster."); System.out.println("----------------------------------------------------------"); if (XbFormatter.withXtermColors()) System.out.println(XbFormatter.ESC); } /** * Command line usage. */ private void usage() { System.out.println("-----------------------" + glob.getVersion() + "-------------------------------"); System.out.println("java org.xmlBlaster.Main <options>"); System.out.println("----------------------------------------------------------"); System.out.println(" -h Show the complete usage."); System.out.println("");// try { System.out.println(glob.getProtocolManager().usage()); } catch (XmlBlasterException e) { log.warn(ME, "No usage: " + e.toString()); } // Depending on the current run level not all drivers may be visible: I_Driver[] drivers = glob.getPluginRegistry().getPluginsOfInterfaceI_Driver(); // getPluginsOfGroup("protocol"); for (int i=0; i < drivers.length; i++) System.out.println(drivers[i].usage()); System.out.println(""); System.out.println(org.xmlBlaster.engine.cluster.ClusterManager.staticUsage()); System.out.println(""); System.out.println(glob.usage()); System.out.println(""); System.out.println("Other stuff:"); System.out.println(" -xmlBlaster/acceptWrongSenderAddress/<subjectId> <subjectId> is for example 'joe' [false]"); System.out.println(" true: Allows user 'joe' to send wrong sender address in PublishQos"); System.out.println(" -xmlBlaster/sleepOnStartup Number of milli seconds to sleep before startup [0]"); System.out.println(" -useKeyboard false Switch off keyboard input, to allow xmlBlaster running in background [true]"); System.out.println(" -doBlocking false Switch off blocking, the main method is by default never returning [true]"); System.out.println(" -admin.remoteconsole.port If port > 1000 a server is started which is available with telnet [2702]"); System.out.println(" -xmlBlaster.isEmbedded If set to true no System.exit() is possible [false]"); System.out.println(" -wipeOutJdbcDB true Destroy the complete JDBC persistence store entries of prefix=XMLBLASTER (DANGER)"); System.out.println(" -xmlBlaster/jmx/HtmlAdaptor Set to true to enable JMX HTTP access on 'http://localhost:8082' [false]"); System.out.println(" -xmlBlaster/jmx/XmlBlasterAdaptor Set to true to enable JMX xmlBlaster adaptor access for swing GUI 'org.xmlBlaster.jmxgui.Main' [false]."); System.out.println(" java -Dcom.sun.management.jmxremote ... Switch on JMX support with jconsole (JDK >= 1.5)."); System.out.println(" -xmlBlaster/jmx/observeLowMemory Write a log error when 90% of the JVM memory is used (JDK >= 1.5) [true]"); System.out.println(" -xmlBlaster/jmx/memoryThresholdFactor Configure the log error memory threshhold (defaults to 90%) (JDK >= 1.5) [0.9]"); System.out.println(" -xmlBlaster/jmx/exitOnMemoryThreshold If true xmlBlaster stops if the memoryThresholdFactor is reached (JDK >= 1.5) [false]"); System.out.println("----------------------------------------------------------"); System.out.println("Example:"); System.out.println(" java org.xmlBlaster.Main -cluster false"); System.out.println(" java org.xmlBlaster.Main -cluster.node.id heron"); System.out.println(" java org.xmlBlaster.Main -propertyFile somewhere/xmlBlaster.properties -pluginsFile somewhere/plugins.xml"); System.out.println(" java org.xmlBlaster.Main -bootstrapPort 3412"); System.out.println(" java org.xmlBlaster.Main -plugin/ior/iorFile /tmp/XmlBlaster_Ref.ior"); System.out.println(" java org.xmlBlaster.Main -logging/org.xmlBlaster.engine FINE"); System.out.println(" java org.xmlBlaster.Main -logging/org.xmlBlaster.util.protocol.RequestReplyExecutor FINEST (dumps SOCKET messages)"); System.out.println(" java org.xmlBlaster.Main -plugin/xmlrpc/hostname 102.24.64.60 -plugin/xmlrpc/port 8081"); System.out.println(" java -Dcom.sun.management.jmxremote org.xmlBlaster.Main"); System.out.println(" java -Djava.util.logging.config.file=config/logging.properties org.xmlBlaster.Main"); System.out.println(" java org.xmlBlaster.Main -?"); System.out.println("See xmlBlaster.properties for more options"); System.out.println(""); } /** * Invoke: java org.xmlBlaster.Main */ public static void main( String[] args ) { new Main(args); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -