📄 global.java
字号:
if (args.length > 0) { this.bootstrapAddress = null; // clear cached address // shutdownHttpServer(); Should be done as well if address changes? } try { property.addArgs2Props(args); initId(); try { // since JKD 1.4: URL url = initLogManager(args); if (url != null) log.info("Configuring JDK 1.4 logging with configuration '" + url.toString() + "'"); } catch (XmlBlasterException e) { System.err.println("Configuring JDK 1.4 logging output failed: " + e.toString()); } return property.wantsHelp() ? 1 : 0; } catch (XmlBlasterException e) { errorText = ME + " ERROR: " + e.toString(); System.err.println(errorText); // Log probably not initialized yet. return -1; } } /** * Allows you to query if user wants help. * @return true If '-help' or '-?' was passed to us */ public final boolean wantsHelp() { return property.wantsHelp(); } /** * @return If not null there was an error during construction / initialization */ public String getErrorText() { return this.errorText; } /** * @return 1 Show usage, 0 OK */ public int init(java.applet.Applet applet) { property.setApplet(applet); return property.wantsHelp() ? 1 : 0; } /** * The unique name of this instance. * @return Can be null during startup */ public ContextNode getContextNode() { return this.contextNode; } /** * The unique name of this instance. * @param contextNode The new node id */ public void setContextNode(ContextNode contextNode) { this.contextNode = contextNode; } /** * Helper for the time being to be used on client side by * services like SmtpClient. * Is filled by XmlBlasterAccess with for example "/node/heron/client/joe/session/1" * @return */ public ContextNode getScopeContextNode() { if (this.scopeContextNode == null) return getContextNode(); return this.scopeContextNode; } public void setScopeContextNode(ContextNode contextNode) { this.scopeContextNode = contextNode; } /** * Check where we are, on client or on server side? * engine.Global overwrites this * @return false As we are util.Global and running client side */ public boolean isServerSide() { return false; } /** * @return null on client side */ public NodeId getNodeId() { return null; } /** * Access the unique local id (as a String), * on client side typically the loginName with the public sessionId, * on server side the server instance unique id. * @return "" */ public String getId() { return this.id; } /** * Same as getId() but all 'special characters' are stripped * so you can use it for file names. * @return "" */ public String getStrippedId() { return getStrippedString(getId()); } /** * Utility method to strip any string, all characters which prevent * to be used for e.g. file names are replaced. * <p> * This conversion is used for file names and for the administrative * hierarchy e.g. "/node/heron/client/joe" is OK but 'http://xy:8080' instead of 'heron' is not * </p> * @param text e.g. "http://www.xmlBlaster.org:/home\\x" * @return e.g. "http_www_xmlBlaster_org_homex" */ public static final String getStrippedString(String text) { if (text == null) return null; String strippedId = ReplaceVariable.replaceAll(text, "/", ""); // JMX does not like commas, but we can't introduce this change in 1.0.5 // as the persistent queue names would change and this is not backward compatible //strippedId = ReplaceVariable.replaceAll(strippedId, ",", "_"); strippedId = ReplaceVariable.replaceAll(strippedId, " ", "_"); strippedId = ReplaceVariable.replaceAll(strippedId, ".", "_"); strippedId = ReplaceVariable.replaceAll(strippedId, ":", "_"); strippedId = ReplaceVariable.replaceAll(strippedId, "[", "_"); strippedId = ReplaceVariable.replaceAll(strippedId, "]", "_"); return ReplaceVariable.replaceAll(strippedId, "\\", ""); } /** * @see org.xmlBlaster.util.admin.extern.JmxWrapper#validateJmxValue(String) */ public final String validateJmxValue(String value) { return JmxWrapper.validateJmxValue(value); } /** * Currently set by enging.Global, used server side only. * @param a unique id */ public synchronized void setId(String id) { if (id == null) return; this.id = id; if (getStrippedId() == null) return; if (this.contextNode == null) { String instanceName = validateJmxValue(getStrippedId()); this.contextNode = new ContextNode(ContextNode.CLUSTER_MARKER_TAG, instanceName, ContextNode.ROOT_NODE); } else { this.contextNode.setInstanceName(getStrippedId()); } } /** * Is coded in derived engine.Global */ public String getLogPrefixDashed() { return ""; } /** * Is coded in derived engine.Global */ public String getLogPrefix() { return ""; } /** * Global access to the default 'global' instance. * If you have parameters (e.g. from the main() mehtod) you should * initialize Global first before using instance(): * <pre> * public static void main(String[] args) { * new Global(args); * ... * } * * //later you can get this initialized instance with: * Global glob = Global.instance(); * ... * </pre> * <p> * Note that you should avoid to use Global.instance() and preferably * use the global which describes your current context, e.g. the specific * client connection like xmlBlasterAccess.getGlobal(). * Use global.getClone(String[]) to create a new Global instance. * </p> */ public static Global instance() { if (firstInstance == null) { synchronized (Global.class) { if (firstInstance == null) new Global(); } } //System.out.println("Accessing Global.instance()"); //Thread.currentThread().dumpStack(); return firstInstance; } /** * Get a cloned instance. * <p> * Calls clone() and sets the given args thereafter. * </p> * <p> * This is the preferred way to create a new and independent * Global instance for example for another client connection. * </p> * <p> * Note that Global.instance() will return the original instance * even if called on the cloned object (it's a static variable). * You should avoid to use Global.instance() * </p> * * @param args Additional configuration parameters */ public final Global getClone(String[] args) { Global g = (Global)clone(); if (args != null && args.length > 0) g.init(args); return g; } /** * Get a deep clone (everything is independent from the origin). * <p /> * The properties and log channels and ContextNode are copied with a deep copy * manipulating these will not affect the original Global.<br /> * All other attributes are initialized as on startup. */ protected Object clone() { Global g = new Global(Property.propsToArgs(this.property.getProperties()), false, false); if (this.contextNode != null) { g.setContextNode(new ContextNode(this.contextNode.getClassName(), this.contextNode.getInstanceName(), this.contextNode.getParent())); } if (isServerSide()) { g.addObjectEntry(Constants.OBJECT_ENTRY_ServerScope, this); } else { Object obj = getObjectEntry(Constants.OBJECT_ENTRY_ServerScope); if (obj != null) g.addObjectEntry(Constants.OBJECT_ENTRY_ServerScope, obj); } return g; } /** * Access the environment properties, is never null. */ public final Property getProperty() { return (this.property == null) ? new Property() : this.property; } /** * @return the checkpointPlugin */ public I_Checkpoint getCheckpointPlugin() { return this.checkpointPlugin; } /** * @param checkpointPlugin the checkpointPlugin to set */ public void setCheckpointPlugin(I_Checkpoint checkpointPlugin) { this.checkpointPlugin = checkpointPlugin; } /** * Return a factory parsing key XML strings from publish() and update() messages. */ public final I_MsgKeyFactory getMsgKeyFactory() { if (this.msgKeyFactory == null) { synchronized (this) { if (this.msgKeyFactory == null) { this.msgKeyFactory = new MsgKeySaxFactory(this); } } } return this.msgKeyFactory; } /** * Return a factory parsing key XML strings from subscribe() and other query invocations. */ public final I_QueryKeyFactory getQueryKeyFactory() { if (this.queryKeyFactory == null) { synchronized (this) { if (this.queryKeyFactory == null) { this.queryKeyFactory = new QueryKeySaxFactory(this); } } } return this.queryKeyFactory; } /** * Return a factory parsing QoS XML strings from connect() and connect-return messages. */ public final I_ConnectQosFactory getConnectQosFactory() { if (this.connectQosFactory == null) { synchronized (this) { if (this.connectQosFactory == null) { this.connectQosFactory = new ConnectQosSaxFactory(this); } } } return this.connectQosFactory; } /** * Return a factory parsing QoS XML strings from disconnect() requests. */ public final I_DisconnectQosFactory getDisconnectQosFactory() { if (this.disconnectQosFactory == null) { synchronized (this) { if (this.disconnectQosFactory == null) { this.disconnectQosFactory = new DisconnectQosSaxFactory(this); } } } return this.disconnectQosFactory; } /** * Return a factory parsing QoS XML strings from publish() and update() messages. */ public final I_MsgQosFactory getMsgQosFactory() { if (this.msgQosFactory == null) { synchronized (this) { if (this.msgQosFactory == null) { this.msgQosFactory = new MsgQosSaxFactory(this); } } } return this.msgQosFactory; } /** * Return a factory parsing QoS XML strings from publish() and update() messages. */ public final I_QueryQosFactory getQueryQosFactory() { if (this.queryQosFactory == null) { synchronized (this) { if (this.queryQosFactory == null) { this.queryQosFactory = new QueryQosSaxFactory(this); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -