⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globalinfo.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*------------------------------------------------------------------------------Name:      GlobalInfo.javaProject:   xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileSwitch on finer logging in xmlBlaster.properties:trace[org.xmlBlaster.contrib.dbwatcher.convert.ResultSetToXmlConverter]=truetrace[org.xmlBlaster.contrib.db.DbPool]=truetrace[org.xmlBlaster.contrib.dbwatcher.detector.MD5ChangeDetector]=truetrace[org.xmlBlaster.contrib.dbwatcher.detector.AlertScheduler]=truetrace[org.xmlBlaster.contrib.dbwatcher.detector.TimestampChangeDetector]=truetrace[org.xmlBlaster.contrib.dbwatcher.plugin.GlobalInfo]=truetrace[org.xmlBlaster.contrib.dbwatcher.mom.XmlBlasterPublisher]=truetrace[org.xmlBlaster.contrib.dbwatcher.DbWatcher]=true------------------------------------------------------------------------------*/package org.xmlBlaster.contrib;import org.xmlBlaster.contrib.replication.ReplicationConverter;import org.xmlBlaster.engine.ServerScope;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.ReplaceVariable;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.admin.extern.JmxMBeanHandle;import org.xmlBlaster.util.context.ContextNode;import org.xmlBlaster.util.def.Constants;import org.xmlBlaster.util.plugin.I_Plugin;import org.xmlBlaster.util.plugin.PluginInfo;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.HashMap;import java.util.Set;import java.util.logging.Logger;import java.util.logging.Level;/** * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a> * @author <a href="mailto:xmlblast@marcelruff.info">Marcel Ruff</a> */public abstract class GlobalInfo implements I_Plugin, I_Info {   public final static String ORIGINAL_ENGINE_GLOBAL = "_originalEngineGlobal";   public final static int UNTOUCHED = 0;   public final static int UPPER_CASE = 1;   public final static int LOWER_CASE = 2;      private static Logger log = Logger.getLogger(GlobalInfo.class.getName());   protected Global global;   protected PluginInfo pluginInfo;   private Map objects = new HashMap();   private Set propsOfOwnInterest;   private InfoHelper helper;   /** My JMX registration */   private Set jmxHandleSet = new HashSet();   private ContextNode contextNode;   private boolean onServer = true;   public static String getStrippedString(String pureVal) {      String corrected = Global.getStrippedString(pureVal);      return ReplaceVariable.replaceAll(corrected, "-", "_");   }      private final static String fixCase(String val, int chCase) {      if (val == null)         return null;      if (chCase == UPPER_CASE)         return val.toUpperCase();      if (chCase == LOWER_CASE)         return val.toLowerCase();      return val;   }      /**    * Convenience to allow the usage of a name mapped to the hostname which can be used as an identifier in a database.    * Specifically used for the prefix in the replication.    * @param info can be null, in which case only system properties are changed.    */   public static String setStrippedHostname(I_Info info, int chCase) {      String hostName = System.getProperty("host.name");      if (hostName == null) {         try {            hostName = fixCase(InetAddress.getLocalHost().getHostName(), chCase);            if (hostName == null) {               log.warning("The property 'host.name' was not set and it was not possible to retrieve the default host name (will try the IP Address instead)");               hostName = fixCase(InetAddress.getLocalHost().getHostAddress(), chCase);               if (hostName == null) {                  log.warning("the property 'host.name' is not set, will not set 'stripped.host.name'");                  return null;               }               else {                  log.warning("the property 'host.name' is not set and the default is set to the IP '" + hostName + "'");               }            }            log.info("Setting 'host.name' to '" + hostName + "'");            System.setProperty("host.name", hostName);         }         catch (UnknownHostException ex) {            log.warning("Could not retrieve the local hostname (I wanted it since 'host.name' was not set)");            return null;         }      }      String strippedHostName = getStrippedString(hostName);      String oldStrippedHostName = System.getProperty("stripped.host.name");      if (oldStrippedHostName != null)         log.warning("The system property 'stripped.host.name' was already set to '" + oldStrippedHostName + "' will NOT change it to '" + strippedHostName + "'");      else {         System.setProperty("stripped.host.name", strippedHostName);         log.info("Set system property 'stripped.host.name' to '" + strippedHostName + "'");      }      if (info != null) {         oldStrippedHostName = info.get("stripped.host.name", null);         if (oldStrippedHostName != null)            log.warning("The info property 'stripped.host.name' was already set to '" + oldStrippedHostName + "' will NOT change it to '" + strippedHostName + "'");         else {            info.put("stripped.host.name", strippedHostName);            log.info("Set info property 'stripped.host.name' to '" + strippedHostName + "'");         }      }      return strippedHostName;   }      /**    * Checks in the registry if such an object exitsts and if not it    * creates one for you and intializes it.    * @param info The info object to use.    * @param pluginClassName The complete name of the plugin to load.    * @param registryName The name to search in the registry for this    * instance. The registry will be in the info object passed. If you    * specify null, the lookup is skipped.    * @return     * @throws Exception    */   public static Object loadPlugin(I_Info info, String pluginClassName, String registryName) throws Exception {      synchronized (info) {         I_ContribPlugin plugin = null;         if (pluginClassName == null || pluginClassName.length() < 1)            throw new Exception("loadPlugin: The name of the plugin has not been specified");         if (registryName != null)            plugin = (I_ContribPlugin)info.getObject(registryName);         if (plugin != null) {            log.fine(pluginClassName + " returned (was already initialized)");            return plugin;         }         ClassLoader cl = ReplicationConverter.class.getClassLoader();         plugin = (I_ContribPlugin)cl.loadClass(pluginClassName).newInstance();         plugin.init(info);         if (registryName != null)            info.putObject(registryName, plugin);         log.fine(pluginClassName + " created and initialized");         return plugin;      }   }            /**    *     */   public GlobalInfo(Set propsOfOwnInterest) {      this.propsOfOwnInterest = propsOfOwnInterest;      if (this.propsOfOwnInterest == null)         this.propsOfOwnInterest = new HashSet();      this.helper = new InfoHelper(this);   }      /**    *     */   public GlobalInfo(String[] propKeysAsString) {      this.propsOfOwnInterest = new HashSet();      if (propKeysAsString != null) {         for (int i=0; i < propKeysAsString.length; i++)            this.propsOfOwnInterest.add(propKeysAsString[i]);      }      this.helper = new InfoHelper(this);   }   /**    * Additional infos are added on top of the initial Global configuration.    *     * @param otherGlobal can not be null.    * @param additionalInfo can be null. If not null, these properties will be added on    * top of the already set in global.    */   public GlobalInfo(Global otherGlobal, I_Info additionalInfo, boolean onServer) throws XmlBlasterException {      this.onServer = onServer;      this.propsOfOwnInterest = new HashSet();      this.helper = new InfoHelper(this);      init(otherGlobal, null);      InfoHelper.fillInfoWithEntriesFromInfo(this, additionalInfo);   }      /**    * @param otherInfo    * @param additionalInfo can be null. If not null, these properties will be added on    * top of the already set in global.    * @throws XmlBlasterException    */   public GlobalInfo(GlobalInfo baseInfo, I_Info additionalInfo, boolean onServer) throws XmlBlasterException {      this(baseInfo.global, additionalInfo, onServer);   }      /**    *     * @param global The global passed by the RunLevelManager, this is not the object owned by the plugin. It is the original global.    * @param pluginInfo    * @throws XmlBlasterException    */   protected abstract void doInit(Global global, PluginInfo pluginInfo) throws XmlBlasterException;      /**    * @see org.xmlBlaster.util.plugin.I_Plugin#init(org.xmlBlaster.util.Global, org.xmlBlaster.util.plugin.PluginInfo)    */   public final void init(Global global_, PluginInfo pluginInfo) throws XmlBlasterException {      String[] additionalAttributes = null;      if (this.onServer)         additionalAttributes = global_.getNativeConnectArgs();      this.global = global_.getClone(additionalAttributes);      if (global_ instanceof ServerScope) {         this.global.addObjectEntry(ORIGINAL_ENGINE_GLOBAL, global_);         this.global.addObjectEntry(Constants.OBJECT_ENTRY_ServerScope, global_);      }      else {         this.global.addObjectEntry(Constants.OBJECT_ENTRY_ServerScope, global_.getObjectEntry(Constants.OBJECT_ENTRY_ServerScope));      }               setStrippedHostname(this, UPPER_CASE);      log.entering(this.getClass().getName(), "init");      this.pluginInfo = pluginInfo;      if (this.pluginInfo != null) {         if (log.isLoggable(Level.FINER)) {            log.finer("init: plugin paramenters: '" + this.pluginInfo.dumpPluginParameters() + "'");            log.finer("init: plugin user data  : '" + this.pluginInfo.getUserData() + "'");         }      }      // add the property 'id' if not set explicitly already ...      String id = get(ID, null);      if (id == null) {         if (this.pluginInfo != null)            put(ID, this.pluginInfo.getType());         else            log.warning("No id has been defined for this info, please add one since this could be used to find your instance: example '" + ID + "=someId'");      }      // To allow NATIVE access to xmlBlaster (there we need to take a clone!)      if (this.onServer)         putObject("org.xmlBlaster.engine.Global", this.global);            // For JMX instanceName may not contain ","      if (pluginInfo != null) {         String instanceName = pluginInfo.getType();         this.contextNode = new ContextNode(ContextNode.SERVICE_MARKER_TAG,               instanceName, this.global.getScopeContextNode());      }      doInit(global_, pluginInfo);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -