📄 global.java
字号:
/*------------------------------------------------------------------------------Name: Global.javaProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileComment: Properties for xmlBlaster------------------------------------------------------------------------------*/package org.xmlBlaster.util;import org.xmlBlaster.util.ReplaceVariable;import java.util.logging.Formatter;import java.util.logging.Handler;import java.util.logging.LogManager;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.protocol.I_CallbackDriver;import org.xmlBlaster.util.checkpoint.I_Checkpoint;import org.xmlBlaster.util.cluster.NodeId;import org.xmlBlaster.util.context.ContextNode;import org.xmlBlaster.util.qos.address.Address;import org.xmlBlaster.client.PluginLoader;import org.xmlBlaster.util.key.I_MsgKeyFactory;import org.xmlBlaster.util.key.MsgKeySaxFactory;import org.xmlBlaster.util.key.I_QueryKeyFactory;import org.xmlBlaster.util.key.QueryKeySaxFactory;import org.xmlBlaster.util.log.XbFormatter;import org.xmlBlaster.util.qos.I_ConnectQosFactory;import org.xmlBlaster.util.qos.ConnectQosSaxFactory;import org.xmlBlaster.util.qos.I_DisconnectQosFactory;import org.xmlBlaster.util.qos.DisconnectQosSaxFactory;import org.xmlBlaster.util.qos.I_MsgQosFactory;import org.xmlBlaster.util.qos.MsgQosSaxFactory;import org.xmlBlaster.util.qos.I_QueryQosFactory;import org.xmlBlaster.util.qos.QueryQosSaxFactory;import org.xmlBlaster.util.qos.I_StatusQosFactory;import org.xmlBlaster.util.qos.StatusQosQuickParseFactory;import org.xmlBlaster.util.classloader.ClassLoaderFactory;import org.xmlBlaster.util.classloader.StandaloneClassLoaderFactory;import org.xmlBlaster.util.queue.QueuePluginManager;import org.xmlBlaster.util.dispatch.plugins.DispatchPluginManager;import org.xmlBlaster.util.dispatch.DispatchManager;import org.xmlBlaster.util.dispatch.DispatchWorkerPool;import org.xmlBlaster.util.dispatch.DispatchConnectionsHandler;import org.xmlBlaster.util.queue.I_Queue;import org.xmlBlaster.util.queuemsg.MsgQueueEntry;import org.xmlBlaster.client.queuemsg.MsgQueuePublishEntry;import org.xmlBlaster.client.dispatch.ClientDispatchConnectionsHandler;import org.xmlBlaster.client.protocol.ProtocolPluginManager;import org.xmlBlaster.client.protocol.CbServerPluginManager;import org.xmlBlaster.util.http.HttpIORServer;import org.xmlBlaster.client.script.XmlScriptInterpreter;import org.xmlBlaster.util.def.Constants;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.util.queue.I_EntryFactory;import org.xmlBlaster.util.plugin.I_PluginConfig;import org.xmlBlaster.util.plugin.PluginManagerBase;import org.xmlBlaster.util.plugin.PluginRegistry;import org.xmlBlaster.util.property.Property;import org.xmlBlaster.client.queuemsg.ClientEntryFactory;import org.xmlBlaster.client.I_XmlBlasterAccess;import org.xmlBlaster.client.XmlBlasterAccess;import org.xmlBlaster.engine.ServerScope;import java.util.Iterator;import java.util.Properties;import java.util.ArrayList;import java.util.Map;import java.util.HashMap;import java.util.Collections;import java.net.MalformedURLException;import java.net.URL;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.PrintStream;import java.io.InputStream;import java.io.UnsupportedEncodingException;import java.util.Hashtable;import java.net.Socket;import javax.management.ObjectName;import javax.management.NotificationBroadcasterSupport;import javax.management.Notification;import javax.management.AttributeChangeNotification;import javax.xml.parsers.SAXParserFactory;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.FactoryConfigurationError;import javax.xml.transform.TransformerFactory;import javax.xml.transform.TransformerFactoryConfigurationError;import org.xmlBlaster.util.admin.extern.JmxMBeanHandle;import org.xmlBlaster.util.admin.extern.JmxWrapper;/** * Global variables to avoid singleton. * <p> * Each Global instance holds all configuration and helper objects for * exactly one XmlBlasterAccess client instance. It is like a local * stack for a connection. * </p> * <p> * Use one instance of this for each XmlBlasterAccess client connection to xmlBlaster. * </p> * <p> * A Global instance is still usable after a call to its shutdown() method, * it can be used again in another XmlBlasterAccess instance. * </p> * * @see org.xmlBlaster.test.classtest.GlobalTest */public class Global implements Cloneable{ private static Logger log = Logger.getLogger(Global.class.getName()); private static boolean logIsInitialized; private volatile static Global firstInstance; /** The amount of physical RAM of this machine. * Set by JmxWrappter.java, else 0 * @since JDK 1.5 */ public static long totalPhysicalMemorySize; /** Number of bytes this JVM can allocate max, the -Xmx???M setting * Set by JmxWrappter.java * (defaults to Runtime.getRuntime().maxMemory()) * @since JDK 1.5 */ public static long heapMemoryUsage = Runtime.getRuntime().maxMemory(); /** The max number of file descriptors this JVM may use * Set by JmxWrappter.java, else 0 * @since JDK 1.5 */ public static long maxFileDescriptorCount; /** Version string, please change for new releases (4 digits) */ private String versionDefault = "1.6.2"; /** This will be replaced by build.xml with the current version */ private String version = "@version@"; /** This will be replaced by build.xml with the current subversion revision number */ private String revisionNumber = "@revision.number@"; /** This will be replaced by build.xml with the build timestamp */ private String buildTimestamp = "@build.timestamp@"; /** This will be replaced by build.xml with the compiling JDK vendor */ private String buildJavaVendor = "@build.java.vendor@"; /** This will be replaced by build.xml with the compiling JDK version */ private String buildJavaVersion = "@build.java.version@"; protected String ME = "Global"; protected String ip_addr = null; protected String id = ""; private volatile String instanceId; protected volatile Property property = null; protected String errorText = null; protected ContextNode contextNode; protected ContextNode scopeContextNode; protected String cbHostname = null; protected String addressNormalized = null; /** The xmlBlaster class loader factory */ private ClassLoaderFactory classLoaderFactory = null; protected /*final*/ Map nativeCallbackDriverMap; /** Store objects in the scope of one client connection or server instance */ protected /*final*/ Map objectMap; /** Helper to synchronize objectMap access */ public final Object objectMapMonitor = new Object(); protected volatile Address bootstrapAddress; protected PluginLoader clientSecurityLoader; protected volatile QueuePluginManager queuePluginManager; protected volatile DispatchPluginManager dispatchPluginManager; protected volatile ProtocolPluginManager protocolPluginManager; protected volatile CbServerPluginManager cbServerPluginManager; private volatile HttpIORServer httpServer; // xmlBlaster publishes his AuthServer IOR protected Hashtable logChannels = new Hashtable(); protected SAXParserFactory saxFactory; protected DocumentBuilderFactory docBuilderFactory; protected TransformerFactory transformerFactory; /** Must be loaded in runlevel 0 or 1 before any access as not synchronized */ protected I_Checkpoint checkpointPlugin; protected volatile I_MsgKeyFactory msgKeyFactory; protected volatile I_QueryKeyFactory queryKeyFactory; protected volatile I_ConnectQosFactory connectQosFactory; protected volatile I_DisconnectQosFactory disconnectQosFactory; protected volatile I_MsgQosFactory msgQosFactory; protected volatile I_QueryQosFactory queryQosFactory; protected volatile I_StatusQosFactory statusQosFactory; protected volatile Timeout pingTimer; protected volatile Timeout burstModeTimer; protected volatile Timeout messageTimer; protected volatile Timeout jdbcConnectionPoolTimer; protected volatile DispatchWorkerPool dispatchWorkerPool; protected static int counter = 0; private volatile PluginManagerBase pluginManager; private volatile PluginRegistry pluginRegistry; /** The client handle to access xmlBlaster */ protected volatile I_XmlBlasterAccess xmlBlasterAccess; protected boolean isDoingShutdown = false; /** set to allow wipe out the persistence on restarts */ protected boolean wipeOutDB = false; //** the entry factory to be used */ protected I_EntryFactory entryFactory; /** JMX notification sequence number. */ protected long sequenceNumber = 1; /** * Constructs an initial Global object, * same as Global(null, true, true) */ public Global() { this(null, true, false); } /** * Constructs an initial Global object which is initialized * by your properties, * same as Global(args, true, true) */ public Global(Properties props) { this(Property.propsToArgs(props)); } /** * Constructs an initial Global object which is initialized * by your args array (usually the command line args). * Same as Global(args, true, true) */ public Global(String[] args) { this(args, true, false); } /** * Constructs an initial Global object which is initialized * by your args array (usually the command line args). * * <p>By setting loadPropFile to false it is possible to create a Global * which does not automatically search out the xmlBlaster.properties file, * which is good when you want to start xmlBlaster in an embedded environment. * <p>It is possible to later load the property file if one wants, here is one * way to do it:</p> * <pre> Property p = glob.getProperty(); Properties prop = new Properties(); FileInfo i = p.findPath("xmlBlaster.properties"); InputStream is = i.getInputStream(); prop.load(is); String[] ar = Property.propsToArgs(prop); p.addArgs2Props( ar != null ? ar : new String[0] ); </pre> <p>It is also possible to load an entire second property file or find it with some other algorithm byte using the same pattern as above, just don't use findPath, but some other code.</p> * @param args args array (usually the command line args). * @param loadPropFile if automatic loading of xmlBlaster.properties should be done. */ public Global(String[] args, boolean loadPropFile, boolean checkInstance) { counter++; if (checkInstance == true) { if (firstInstance != null) { System.out.println("######Global args constructor invoked again, try Global.instance()"); Thread.dumpStack(); } } synchronized (Global.class) { if (firstInstance == null) firstInstance = this; } initProps(args,loadPropFile); initId(); nativeCallbackDriverMap = Collections.synchronizedMap(new HashMap()); objectMap = new HashMap(); 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()); } } public static int getCounter() { return counter; } /** * @return the JmxWrapper used to manage the MBean resources */ public final JmxWrapper getJmxWrapper() throws XmlBlasterException { return JmxWrapper.getInstance(this); } /** * Check if JMX is activated. * @return true if JMX is in use */ public boolean isJmxActivated() { try { return getJmxWrapper().isActivated(); } catch (XmlBlasterException e) { return false; } } /** * Send an administrative notification. */ public void sendNotification(NotificationBroadcasterSupport source, String msg, String attributeName, String attributeType, Object oldValue, Object newValue) { // Avoid any log.warning or log.severe to prevent looping alert events if (isJmxActivated()) { Notification n = new AttributeChangeNotification(source, sequenceNumber++, System.currentTimeMillis(), msg, attributeName, attributeType, oldValue, newValue); source.sendNotification(n); } } /** * JMX support. * Start xmlBlaster with <code>java -Dcom.sun.management.jmxremote org.xmlBlaster.Main</code> * You can access xmlBlaster from 'jconsole' delivered with JDK1.5 or above. * The root node is always the cluster node id. * @param contextNode Used to retrieve a unique instance name for the given MBean * @param mbean the MBean object instance * @return The object name used to register or null on error
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -