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

📄 a3cmlconfig.java

📁 一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      domainConf.addDomain(new A3CMLDomain(d0.name,d0.network));      A3CMLServer s0 = (A3CMLServer) domainConf.getServer(AgentServer.getServerId());      d0 = domainConf.getDomain(AgentServer.ADMIN_DOMAIN);      d0.addServer(s0);      for (int i = 0; i < s0.networks.size(); ) {        A3CMLNetwork network = (A3CMLNetwork) s0.networks.elementAt(i);        if (!(network.domain.equals(AgentServer.ADMIN_DOMAIN) ||               network.domain.equals(domainName))) {          s0.networks.removeElement(network);        } else          i++;      }    } catch (UnknownServerException exc) {      if (Log.logger.isLoggable(BasicLevel.DEBUG))        Log.logger.log(BasicLevel.DEBUG, "", exc);    }    return domainConf;  }  /**   * Gets configuration of agent servers by a list of domain from a Config object.    * This method fills the object graph configuration in the <code>Config</code>   * object.   *   * @param domainName  list of domain name   * @return	        the <code>Config</code> object if file exists and is   * 		        correct, null otherwise.   *   * @exception Exception   *	unspecialized exception when reading and parsing the configuration file   */  public A3CMLConfig getDomainConfig(String[] listDomainName) throws Exception {    if (Log.logger.isLoggable(BasicLevel.DEBUG))      Log.logger.log(BasicLevel.DEBUG,                     "Config.getDomainConfig(" + listDomainName + ")");    Hashtable context = new Hashtable();    A3CMLConfig domainConf = new A3CMLConfig();    Vector domainList = new Vector();    for (int i = 0; i < listDomainName.length; i++)      domainList.addElement(listDomainName[i]);        for (int n = 0; n < listDomainName.length; n++) {      String domainName = listDomainName[n];      // add domain "domainName" in domainConf.      A3CMLDomain dom = getDomain(domainName).duplicate(context);      domainConf.addDomain(dom);            // add persistent server in domainConf.      for (int i = 0; i < dom.servers.size(); i++) {        A3CMLServer server = (A3CMLServer) dom.servers.elementAt(i);        for (int j = 0; j < server.networks.size(); ) {          A3CMLNetwork network = (A3CMLNetwork) server.networks.elementAt(j);          if (!(network.domain.equals(AgentServer.ADMIN_DOMAIN) ||                network.domain.equals("transient") ||                 domainList.contains(network.domain))) {            server.networks.removeElement(network);          } else            j++;        }        domainConf.servers.put(new Short(server.sid),server);      }    }          // add global properties in domainConf.    for (Enumeration p = properties.elements(); p.hasMoreElements(); ) {      A3CMLProperty property = (A3CMLProperty) p.nextElement();      domainConf.addProperty(((A3CMLProperty) property).duplicate());    }        try {      // for Admin Domain      // add domain "ADMIN_DOMAIN" in domainConf.      A3CMLDomain d0 = getDomain(AgentServer.ADMIN_DOMAIN);      domainConf.addDomain(new A3CMLDomain(d0.name,d0.network));      A3CMLServer s0 = (A3CMLServer) domainConf.getServer(AgentServer.getServerId());      d0 = domainConf.getDomain(AgentServer.ADMIN_DOMAIN);      d0.addServer(s0);      for (int i = 0; i < s0.networks.size(); ) {        A3CMLNetwork network = (A3CMLNetwork) s0.networks.elementAt(i);        if (!(network.domain.equals(AgentServer.ADMIN_DOMAIN) ||               domainList.contains(network.domain))) {          s0.networks.removeElement(network);        } else          i++;      }    } catch (UnknownServerException exc) {      if (Log.logger.isLoggable(BasicLevel.DEBUG))        Log.logger.log(BasicLevel.DEBUG, "", exc);    }    return domainConf;  }    /**   * save configuration of agent servers (Config)   * in a serialized file.   *   * @exception IOException   * @see AgentServer.DEFAULT_SER_CFG_FILE   */  public void save() throws IOException {    if (Log.logger.isLoggable(BasicLevel.DEBUG))      Log.logger.log(BasicLevel.DEBUG, "Config.save(" + this + ")");    AgentServer.getTransaction().save(this, AgentServer.DEFAULT_SER_CFG_FILE);  }      /**   * read object from a serialized file,   * in cfgDir if null, search object in    * path used to load classes   *   * @param cfgDir        read obj in this directory   * @param cfgFileName   serialized file name   * @exception           Exception   */  public static A3CMLConfig load() throws Exception {    // Get the logging monitor from current server MonoLog.loggeritorFactory    if (Log.logger.isLoggable(BasicLevel.DEBUG))      Log.logger.log(BasicLevel.DEBUG, "Config.load()");        A3CMLConfig a3config = (A3CMLConfig) AgentServer.getTransaction().load(AgentServer.DEFAULT_SER_CFG_FILE);    if (a3config == null) {      Log.logger.log(BasicLevel.WARN,                     "Unable to find configuration file.");      throw new IOException("Unable to find configuration file .");    }        if (Log.logger.isLoggable(BasicLevel.DEBUG))      Log.logger.log(BasicLevel.DEBUG, "Config.load : a3cmlconfig = " + a3config);    return a3config;  }  /**   * Gets a <code>A3CMLConfig</code> serialialized object from file.   *   * @param path   path of serialized configuration file   * @return	   the <code>A3CMLConfig</code> object if file exists and is   * 		   correct, null otherwise.   *   * @exception Exception   *	unspecialized exception when reading and parsing the configuration file   */  public static A3CMLConfig getConfig(String path) throws Exception {    // Get the logging monitor from current server MonoLog.loggeritorFactory    if (Log.logger.isLoggable(BasicLevel.DEBUG))      Log.logger.log(BasicLevel.DEBUG, "Config.load(" + path + ")");        A3CMLConfig a3config = null;        File cfgFile = new File(path);    if (cfgFile.exists() && cfgFile.isFile()) {      if ((cfgFile.length() == 0)) {        Log.logger.log(BasicLevel.ERROR,                       " \"" + cfgFile.getPath() + "\", is empty.");        throw new IOException(" \"" + cfgFile.getPath() + "\", is empty.");      }            FileInputStream fis = null;      try {        fis = new FileInputStream(cfgFile);        ObjectInputStream ois = new ObjectInputStream(fis);        a3config = (A3CMLConfig) ois.readObject();      } catch (Exception exc) {        Log.logger.log(BasicLevel.WARN, "Can't load configuration: " + path, exc);      } finally {        if (fis != null) fis.close();      }      if (Log.logger.isLoggable(BasicLevel.DEBUG))        Log.logger.log(BasicLevel.DEBUG,                       "Config.load : a3cmlconfig = " + a3config);      return a3config;    }    //search a3config in path used to load classes.    ClassLoader classLoader = null;    InputStream is = null;    try {      classLoader = A3CMLConfig.class.getClassLoader();      if (classLoader != null) {        Log.logger.log(BasicLevel.WARN,                       "Trying to find [" + path + "] using " +                       classLoader + " class loader.");        is = classLoader.getResourceAsStream(path);      }    } catch(Throwable t) {      Log.logger.log(BasicLevel.WARN,                     "Can't find [" + path + "] using " +                     classLoader + " class loader.", t);      is = null;    }    if (is == null) {      // Last ditch attempt: get the resource from the system class path.      Log.logger.log(BasicLevel.WARN,                     "Trying to find serialized config using ClassLoader.getSystemResource().");      is = ClassLoader.getSystemResourceAsStream(path);    }    if (is != null) {      ObjectInputStream ois = new ObjectInputStream(is);      a3config = (A3CMLConfig) ois.readObject();    }    if (a3config == null) {      Log.logger.log(BasicLevel.WARN,                     "Unable to find configuration file: " + path);      throw new IOException("Unable to find configuration file: " + path);    }        if (Log.logger.isLoggable(BasicLevel.DEBUG))      Log.logger.log(BasicLevel.DEBUG, "Config.load : a3cmlconfig = " + a3config);    return a3config;  }// ### save//     Transaction transaction = AgentServer.getTransaction();//     if (transaction != null) {//       // use transaction to save this obj//       if (Log.logger.isLoggable(BasicLevel.DEBUG))//         Log.logger.log(BasicLevel.DEBUG,//                    "Config.save with AgentServer.transaction");// //     AgentServer.getTransaction().save(obj,cfgDir,cfgFileName);//     } else {//       if (Log.logger.isLoggable(BasicLevel.DEBUG))//         Log.logger.log(BasicLevel.DEBUG,//                    "Config.save without transaction");//       File file = new File(cfgDir, cfgFileName);//       File temp = new File(cfgDir, cfgFileName+"_temp");      //       if (cfgDir != null) {//         File dir = new File(cfgDir);//         if (!dir.exists()) dir.mkdir();//       }      //       if (file.exists())//         file.renameTo(temp);      //       // Save the current state of the object.//       FileOutputStream fos = null;//       try {//         fos = new FileOutputStream(file);//         ObjectOutputStream oos = new ObjectOutputStream(fos);//         oos.writeObject(obj);//         oos.flush();//         fos.getFD().sync();//         fos.close();//         fos = null;//         temp.delete();//         temp = null;//       } finally {//         if (fos != null) fos.close();//       }//     }//     if (Log.logger.isLoggable(BasicLevel.DEBUG)) {//       try {//         A3CML.toXML(this, null, "debugServers.xml");//       } catch (Exception exc) {}//     }  public String toString() {    StringBuffer strBuf = new StringBuffer();    strBuf.append("(").append(super.toString());    strBuf.append(",properties=").append(properties);    strBuf.append(",domains=").append(domains);    strBuf.append(",servers=").append(servers);    strBuf.append(",clusters=").append(clusters);    strBuf.append(")");    return strBuf.toString();  }    /* -+-+-+-                                                -+-+-+- */  /* -+-+-+- This code below is needed for historic reason. -+-+-+- */  /* -+-+-+- It is used in mediation chain in order to find -+-+-+- */  /* -+-+-+- the corresponding TcpServer services.          -+-+-+- */  /* -+-+-+- This code below is needed for historic reason. -+-+-+- */  /* -+-+-+-                                                -+-+-+- */  /**   * Gets the argument strings for a particular service running on a server   * identified by its host (searchs on all servers and associated transient).   *   * @param hostname	hostname   * @param className	the service class name   * @return		the arguments as declared in configuration file   * @exception UnknownServiceException   *	The specified service is not declared on this server.    */  public final String getServiceArgsHost(String hostname,                                         String classname) throws Exception {    for (Enumeration s = servers.elements(); s.hasMoreElements(); ) {      A3CMLServer server = (A3CMLServer) s.nextElement();      if (server.hostname.equals(hostname)) {	try {	  String args = getServiceArgs(server.sid, classname);	  return args;	} catch (Exception exc) {}      }    }    throw new UnknownServiceException("Unknown service \"" + classname +                                      "\" on host " + hostname);  }  public boolean equals(Object obj) {    if (obj == null) return false;    if (obj instanceof A3CMLConfig) {      A3CMLConfig config = (A3CMLConfig) obj;      if (domains.equals(config.domains) &&          servers.equals(config.servers) &&          properties.equals(config.properties))        return true;    }    return false;  }  /**   * reset visited and gateway fields.   */  public void reset() {    for (Enumeration s = servers.elements(); s.hasMoreElements(); ) {      A3CMLServer server = (A3CMLServer) s.nextElement();      server.visited = false;      server.gateway = (short) -1;    }    for (Enumeration d = domains.elements(); d.hasMoreElements(); ) {      A3CMLDomain domain = (A3CMLDomain) d.nextElement();      domain.gateway = (short) -1;    }  }}

⌨️ 快捷键说明

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