hostcontroller.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 699 行 · 第 1/2 页

JAVA
699
字号
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT.  See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * *   Free Software Foundation, Inc. *   59 Temple Place, Suite 330 *   Boston, MA 02111-1307  USA * * @author Scott Ferguson */package com.caucho.server.host;import com.caucho.config.ConfigException;import com.caucho.config.types.PathBuilder;import com.caucho.el.EL;import com.caucho.log.Log;import com.caucho.management.server.HostMXBean;import com.caucho.server.deploy.DeployController;import com.caucho.server.deploy.DeployControllerAdmin;import com.caucho.server.deploy.EnvironmentDeployController;import com.caucho.server.e_app.EarConfig;import com.caucho.server.webapp.WebAppConfig;import com.caucho.util.L10N;import com.caucho.vfs.Depend;import com.caucho.vfs.Dependency;import com.caucho.vfs.Path;import com.caucho.vfs.Vfs;import com.caucho.webbeans.manager.*;import java.util.ArrayList;import java.util.HashMap;import java.util.Map;import java.util.logging.Level;import java.util.logging.Logger;import java.util.regex.Matcher;import java.util.regex.Pattern;import javax.webbeans.*;/** * A configuration entry for a host */public class HostController  extends EnvironmentDeployController<Host,HostConfig>{  private static final Logger log    = Logger.getLogger(HostController.class.getName());  private static final L10N L = new L10N(HostController.class);    private HostContainer _container;  // The host name is the canonical name  private String _hostName;  // The regexp name is the matching name of the regexp  private String _regexpName;  private Pattern _regexp;  private String _rootDirectoryPattern;  // Any host aliases.  private ArrayList<String> _entryHostAliases    = new ArrayList<String>();  private ArrayList<Pattern> _entryHostAliasRegexps    = new ArrayList<Pattern>();  // includes aliases from the Host, e.g. server/1f35  private ArrayList<String> _hostAliases = new ArrayList<String>();  private ArrayList<Pattern> _hostAliasRegexps = new ArrayList<Pattern>();  // The host variables.  private final Var _hostVar = new Var();  private final HostAdmin _admin = new HostAdmin(this);  private ArrayList<Dependency> _dependList = new ArrayList<Dependency>();  HostController(String id,		 HostConfig config,		 HostContainer container,		 Map<String,Object> varMap)  {    super(id, config);    setHostName(id);    if (varMap != null)      getVariableMap().putAll(varMap);        getVariableMap().put("host", _hostVar);    setContainer(container);        setRootDirectory(config.calculateRootDirectory(getVariableMap()));  }  HostController(String id, Path rootDirectory, HostContainer container)  {    super(id, rootDirectory);    addHostAlias(id);    setHostName(id);    getVariableMap().put("name", id);    getVariableMap().put("host", _hostVar);        setContainer(container);  }  public void setContainer(HostContainer container)  {    _container = container;        if (_container != null) {      for (HostConfig defaultConfig : _container.getHostDefaultList())	addConfigDefault(defaultConfig);    }  }  /**   * Returns the Resin host name.   */  public String getName()  {    String name = super.getId();        if (name != null)      return name;    else      return getHostName();  }  /**   * Returns the host's canonical name   */  public String getHostName()  {    return _hostName;  }  /**   * Sets the host's canonical name   */  public void setHostName(String name)  {    if (name != null)      name = name.trim();        if (name == null || name.equals("*"))      name = "";        name = name.toLowerCase();    _hostName = name;  }  /**   * Returns the host's canonical name   */  public void setRegexpName(String name)  {    _regexpName = name.toLowerCase();  }    /**   * Adds a host alias.   */  public void addHostAlias(String name)  {    if (name != null)      name = name.trim();        if (name == null || name.equals("*"))      name = ""; // XXX: default?        name = name.toLowerCase();    if (! _entryHostAliases.contains(name))      _entryHostAliases.add(name);    addExtHostAlias(name);  }  /**   * Adds an extension host alias, e.g. from a resin:import   */  public void addExtHostAlias(String name)  {    if (! _hostAliases.contains(name))      _hostAliases.add(name);  }  /**   * Returns the host aliases.   */  public ArrayList<String> getHostAliases()  {    return _hostAliases;  }  /**   * Adds an extension host alias, e.g. from a resin:import   */  public void addExtHostAliasRegexp(Pattern name)  {    if (! _hostAliasRegexps.contains(name))      _hostAliasRegexps.add(name);  }  /**   * Sets the regexp pattern   */  public void setRegexp(Pattern regexp)  {    _regexp = regexp;  }  /**   * Sets the root directory pattern   */  public void setRootDirectoryPattern(String rootDirectoryPattern)  {    _rootDirectoryPattern = rootDirectoryPattern;  }  /**   * Adds a dependent file.   */  public void addDepend(Path depend)  {    if (! _dependList.contains(depend))      _dependList.add(new Depend(depend));  }  /**   * Returns the host admin.   */  public HostMXBean getAdmin()  {    return _admin;  }  /**   * Returns the deploy admin.   */  protected DeployControllerAdmin getDeployAdmin()  {    return _admin;  }  /**   * Initialize the entry.   */  protected void initBegin()  {    try {      try {	if (getConfig() == null || getHostName() != null) {	}	else if (getConfig().getHostName() != null)	  setHostName(EL.evalString(getConfig().getHostName(),				    EL.getEnvironment()));      } catch (Exception e) {	log.log(Level.WARNING, e.toString(), e);      }      if (_regexpName != null && _hostName == null)	_hostName = _regexpName;      if (_hostName == null)	_hostName = "";      ArrayList<String> aliases = null;      if (getConfig() != null) {	aliases = getConfig().getHostAliases();	_entryHostAliasRegexps.addAll(getConfig().getHostAliasRegexps());	_hostAliasRegexps.addAll(getConfig().getHostAliasRegexps());      }            for (int i = 0; aliases != null && i < aliases.size(); i++) {	String alias = aliases.get(i);	alias = EL.evalString(alias, EL.getEnvironment());		addHostAlias(alias);      }    } catch (Exception e) {      log.log(Level.WARNING, e.toString(), e);    }    super.initBegin();  }  /**   * Returns the "name" property.   */  protected String getMBeanId()  {    String name = _hostName;        if (name == null)      name = "";    else if (name.indexOf(':') >= 0)      name = name.replace(':', '-');    if (name.equals(""))      return "default";    else      return name;  }  /**   * Returns true for a matching name.   */  public boolean isNameMatch(String name)  {    if (name.equals("default"))      name = "";        if (_hostName.equalsIgnoreCase(name))      return true;    for (int i = _hostAliases.size() - 1; i >= 0; i--) {      if (name.equalsIgnoreCase(_hostAliases.get(i)))	return true;    }    for (int i = _hostAliasRegexps.size() - 1; i >= 0; i--) {      Pattern alias = _hostAliasRegexps.get(i);      if (alias.matcher(name).find())	return true;

⌨️ 快捷键说明

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