server.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,876 行 · 第 1/3 页

JAVA
1,876
字号
/* * 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.cluster;import com.caucho.amber.manager.PersistenceEnvironmentListener;import com.caucho.bam.BamBroker;import com.caucho.bam.BamStream;import com.caucho.config.ConfigException;import com.caucho.config.SchemaBean;import com.caucho.config.program.ConfigProgram;import com.caucho.config.types.Bytes;import com.caucho.config.types.Period;import com.caucho.git.GitRepository;import com.caucho.lifecycle.Lifecycle;import com.caucho.loader.ClassLoaderListener;import com.caucho.loader.DynamicClassLoader;import com.caucho.loader.Environment;import com.caucho.loader.EnvironmentBean;import com.caucho.loader.EnvironmentClassLoader;import com.caucho.loader.EnvironmentLocal;import com.caucho.make.AlwaysModified;import com.caucho.management.server.CacheItem;import com.caucho.management.server.ServerMXBean;import com.caucho.security.PermissionManager;import com.caucho.server.admin.Management;import com.caucho.server.cache.AbstractCache;import com.caucho.server.dispatch.ErrorFilterChain;import com.caucho.server.dispatch.ExceptionFilterChain;import com.caucho.server.dispatch.Invocation;import com.caucho.server.dispatch.InvocationMatcher;import com.caucho.server.e_app.EarConfig;import com.caucho.server.host.Host;import com.caucho.server.host.HostConfig;import com.caucho.server.host.HostContainer;import com.caucho.server.host.HostController;import com.caucho.server.host.HostExpandDeployGenerator;import com.caucho.server.log.AccessLog;import com.caucho.server.port.AbstractSelectManager;import com.caucho.server.port.Port;import com.caucho.server.port.ProtocolDispatchServer;import com.caucho.server.resin.Resin;import com.caucho.server.rewrite.RewriteDispatch;import com.caucho.server.webapp.ErrorPage;import com.caucho.server.webapp.WebApp;import com.caucho.server.webapp.WebAppConfig;import com.caucho.util.Alarm;import com.caucho.util.AlarmListener;import com.caucho.util.L10N;import com.caucho.util.ThreadPool;import com.caucho.vfs.*;import javax.annotation.PostConstruct;import javax.servlet.http.HttpServletResponse;import javax.resource.spi.ResourceAdapter;import java.lang.reflect.Method;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.logging.Level;import java.util.logging.Logger;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Server extends ProtocolDispatchServer  implements EnvironmentBean, SchemaBean, AlarmListener,             ClassLoaderListener {  private static final L10N L = new L10N(Server.class);  private static final Logger log    = Logger.getLogger(Server.class.getName());  private static final long ALARM_INTERVAL = 60000;  private static final EnvironmentLocal<String> _serverIdLocal    = new EnvironmentLocal<String>("caucho.server-id");  private final ClusterServer _clusterServer;  private final Resin _resin;  private EnvironmentClassLoader _classLoader;  private Throwable _configException;  private HostContainer _hostContainer;  private String _serverHeader = "Resin/" + com.caucho.Version.VERSION;  private GitRepository _git;  private String _url = "";  private int _urlLengthMax = 8192;  private int _srunCount;  private AccessLog _accessLog;  private long _waitForActiveTime = 10000L;  private boolean _isDevelopmentModeErrorPage;  // <server> configuration compat  private int _acceptListenBacklog = 100;    private int _acceptThreadMin = 5;  private int _acceptThreadMax = 10;  private int _connectionMax = 1024 * 1024;  // default is in Port  private int _keepaliveMax = -1;    private long _keepaliveConnectionTimeMax = 10 * 60 * 1000L;    private boolean _keepaliveSelectEnable = true;  private int _keepaliveSelectMax = -1;  private long _keepaliveSelectThreadTimeout = 1000;  private Management _management;    private long _suspendTimeMax = 600000L;  private long _memoryFreeMin = 1024 * 1024;  private long _permGenFreeMin = 1024 * 1024;    private long _shutdownWaitMax = 60 * 1000;    private int _threadMax = 4096;  private int _threadExecutorTaskMax = -1;  private int _threadIdleMin = 5;  private int _threadIdleMax = 10;  // <cluster> configuration  private String _connectionErrorPage;  private ServerAdmin _admin;  private Alarm _alarm;  protected AbstractCache _cache;  private boolean _isBindPortsAtEnd = true;  private volatile boolean _isStartedPorts;  private long _startTime;  private final Lifecycle _lifecycle;  /**   * Creates a new servlet server.   */  public Server(ClusterServer clusterServer)  {    if (clusterServer == null)      throw new NullPointerException();    _clusterServer = clusterServer;    _resin = _clusterServer.getCluster().getResin();    try {      Thread thread = Thread.currentThread();      ClassLoader loader = clusterServer.getCluster().getClassLoader();      _classLoader = (EnvironmentClassLoader) loader;      Environment.addClassLoaderListener(this, _classLoader);      PermissionManager permissionManager = new PermissionManager();      PermissionManager.setPermissionManager(permissionManager);      ClassLoader oldLoader = thread.getContextClassLoader();      try {        thread.setContextClassLoader(_classLoader);		_serverIdLocal.set(_clusterServer.getId());        _hostContainer = new HostContainer();        _hostContainer.setClassLoader(_classLoader);        _hostContainer.setDispatchServer(this);	_admin = new ServerAdmin(this);	_alarm = new Alarm(this);	_clusterServer.getServerProgram().configure(this);      } finally {        thread.setContextClassLoader(oldLoader);      }    } catch (Throwable e) {      log.log(Level.WARNING, e.toString(), e);      _configException = e;    } finally {      _lifecycle = new Lifecycle(log, toString(), Level.INFO);    }  }  /**   * Returns the current server   */  public static Server getCurrent()  {    Resin resin = Resin.getCurrent();    if (resin != null)      return resin.getServer();    else      return null;  }  /**   * Returns the classLoader   */  public ClassLoader getClassLoader()  {    return _classLoader;  }  /**   * Returns the configuration exception   */  public Throwable getConfigException()  {    return _configException;  }  /**   * Returns the configuration instance.   */  public void setConfigException(Throwable exn)  {    _configException = exn;  }  /**   * Returns the resin server   */  protected Resin getResin()  {    return _resin;  }  /**   * Returns the repository   */  public GitRepository getGit()  {    return _git;  }  /**   * Returns the cluster server   */  protected ClusterServer getClusterServer()  {    return _clusterServer;  }  /**   * Returns the admin broker.   */  public BamBroker getBroker()  {    return _resin.getManagement().getAdminBroker();  }  //  // Configuration from <server>  //  /**   * Sets the socket's listen property   */  public void setAcceptListenBacklog(int backlog)  {    _acceptListenBacklog = backlog;  }  /**   * Gets the socket's listen property   */  public int getAcceptListenBacklog()  {    return _acceptListenBacklog;  }  /**   * Sets the minimum spare listen.   */  public void setAcceptThreadMin(int minSpare)    throws ConfigException  {    if (minSpare < 1)      throw new ConfigException(L.l("accept-thread-max must be at least 1."));    _acceptThreadMin = minSpare;  }  /**   * Gets the minimum spare listen.   */  public int getAcceptThreadMin()  {    return _acceptThreadMin;  }  /**   * Sets the maximum spare listen.   */  public void setAcceptThreadMax(int maxSpare)    throws ConfigException  {    if (maxSpare < 1)      throw new ConfigException(L.l("accept-thread-max must be at least 1."));    _acceptThreadMax = maxSpare;  }  /**   * Sets the maximum spare listen.   */  public int getAcceptThreadMax()  {    return _acceptThreadMax;  }  /**   * Sets the maximum connections per port   */  public void setConnectionMax(int max)  {    _connectionMax = max;  }  /**   * Returns the port-based connection max.   *   * @return the connection max.   */  public int getConnectionMax()  {    return _connectionMax;  }  /**   * Development mode error pages.   */  public boolean isDevelopmentModeErrorPage()  {    return _isDevelopmentModeErrorPage;  }  /**   * Development mode error pages.   */  public void setDevelopmentModeErrorPage(boolean isEnable)  {    _isDevelopmentModeErrorPage = isEnable;  }  /**   * Arguments on boot   */  public void addJavaExe(String args)  {  }  /**   * Arguments on boot   */  public void addJvmArg(String args)  {  }  /**   * Arguments on boot   */  public void addJvmClasspath(String args)  {  }  /**   * Arguments on boot   */  public void addWatchdogArg(String args)  {  }  /**   * Arguments on boot   */  public void addWatchdogJvmArg(String args)  {  }  /**   * Arguments on boot   */  public void addWatchdogLog(ConfigProgram args)  {  }  /**   * Arguments on boot   */  public void addWatchdogPassword(String args)  {  }  /**   * Arguments on boot   */  public void addWatchdogPort(int port)  {  }  /**   * Arguments on boot   */  public void addWatchdogAddress(String addr)  {  }  /**   * Sets the minimum free memory after a GC   */  public void setMemoryFreeMin(Bytes min)  {    _memoryFreeMin = min.getBytes();  }  /**   * Sets the minimum free memory after a GC   */  public long getMemoryFreeMin()  {    return _memoryFreeMin;  }  /**   * Sets the minimum free memory after a GC   */  public void setPermGenFreeMin(Bytes min)  {    _permGenFreeMin = min.getBytes();  }  /**   * Sets the minimum free memory after a GC   */  public long getPermGenFreeMin()  {    return _permGenFreeMin;  }  /**   * Sets the maximum keepalive   */  public void setKeepaliveMax(int max)  {    _keepaliveMax = max;  }  /**   * Returns the thread-based keepalive max.   *   * @return the keepalive max.   */  public int getKeepaliveMax()  {    return _keepaliveMax;  }  /**   * Sets the keepalive timeout   */  public void setKeepaliveTimeout(Period period)  {    _clusterServer.setKeepaliveTimeout(period);  }  /**   * Sets the keepalive timeout   */  public long getKeepaliveTimeout()  {    return _clusterServer.getKeepaliveTimeout();  }  /**   * Sets the keepalive connection timeout   */  public void setKeepaliveConnectionTimeMax(Period period)  {    _keepaliveConnectionTimeMax = period.getPeriod();  }  /**   * Sets the keepalive timeout   */  public long getKeepaliveConnectionTimeMax()  {    return _keepaliveConnectionTimeMax;  }  /**   * Sets the select-based keepalive timeout   */  public void setKeepaliveSelectEnable(boolean enable)  {    _keepaliveSelectEnable = enable;  }  /**   * Sets the select-based keepalive timeout   */  public void setKeepaliveSelectMax(int max)  {    _keepaliveSelectMax = max;  }  /**   * Gets the select-based keepalive timeout   */  public boolean isKeepaliveSelectEnable()  {    return _keepaliveSelectEnable;  }  /**   * Sets the select-based keepalive timeout   */  public void setKeepaliveSelectThreadTimeout(Period period)  {    _keepaliveSelectThreadTimeout = period.getPeriod();  }  /**   * Sets the select-based keepalive timeout   */  public long getKeepaliveSelectThreadTimeout()  {    return _keepaliveSelectThreadTimeout;  }  public Management createManagement()  {    if (_management == null && _resin != null) {      _management = _resin.createManagement();      _management.setCluster(getCluster());    }    return _management;  }  /**   * Sets the redeploy mode   */  public void setRedeployMode(String redeployMode)  {  }  /**   * Sets the max wait time for shutdown.   */  public void setShutdownWaitMax(Period waitTime)  {    _shutdownWaitMax = waitTime.getPeriod();  }  /**   * Sets the suspend timeout   */  public void setSuspendTimeMax(Period period)  {    _suspendTimeMax = period.getPeriod();  }  /**   * Sets the suspend timeout   */  public long getSuspendTimeMax()  {    return _suspendTimeMax;  }  /**   * Gets the max wait time for a shutdown.   */  public long getShutdownWaitMax()  {    return _shutdownWaitMax;  }  /**   * Sets the default read/write timeout for the request sockets.   */  public void setSocketTimeout(Period period)

⌨️ 快捷键说明

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