webappcontroller.java

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

JAVA
727
字号
  @Override  protected void initEnd()  {    super.initEnd();  }  /**   * Returns the admin.   */  public WebAppAdmin getAdmin()  {    return _admin;  }  /**   * Returns true if the controller matches.   */  @Override  public boolean isNameMatch(String url)  {    if (CauchoSystem.isCaseInsensitive())      return url.equalsIgnoreCase(_contextPath);    else      return url.equals(_contextPath);  }  /**   * Merges two entries.   */  protected WebAppController merge(WebAppController newController)  {    if (getConfig() != null && getConfig().getURLRegexp() != null)      return newController;    else if (newController.getConfig() != null	     && newController.getConfig().getURLRegexp() != null)      return this;    else {      Thread thread = Thread.currentThread();      ClassLoader oldLoader = thread.getContextClassLoader();      try {	thread.setContextClassLoader(getParentClassLoader());	//  The contextPath comes from current web-app	WebAppController mergedController	  = new WebAppController(getContextPath(),				 getContextPath(),				 getRootDirectory(),				 _container);	// server/1h1{2,3}	// This controller overrides configuration from the new controller	mergedController.mergeController(this);	mergedController.mergeController(newController);	return mergedController;      } finally {	thread.setContextClassLoader(oldLoader);      }    }  }  /**   * Returns the var.   */  public Var getVar()  {    return new Var();  }  /**   * Returns the webApp object.   */  @Override  public boolean destroy()  {    if (! super.destroy())      return false;    if (_container != null)      _container.removeWebApp(this);    return true;  }  /**   * Any extra steps needed to deploy the webApp.   */  protected void protectedWebApp()    throws Exception  {    Path root = getRootDirectory();    // XXX: need to re-add to control.    root.lookup("WEB-INF").chmod(0750);    root.lookup("META-INF").chmod(0750);  }  /**   * Adding any dependencies.   */  protected void addDependencies()    throws Exception  {  }  /**   * Adds a dependent file.   */  public void addDepend(Path path)  {    _dependPathList.add(path);  }  /**   * Initialize the controller.   */  @Override  protected void initBegin()  {    getVariableMap().put("app-dir", getRootDirectory());    super.initBegin();  }  @Override  protected void fillInitList(ArrayList<DeployConfig> initList)  {    if (_container != null) {      for (WebAppConfig config : _container.getWebAppDefaultList()) {	if (config.getPrologue() != null)	  initList.add(config.getPrologue());      }            for (WebAppConfig config : _container.getWebAppDefaultList())	initList.add(config);    }    super.fillInitList(initList);  }  /**   * Instantiate the webApp.   */  protected WebApp instantiateDeployInstance()  {    return new Application(this);  }  /**   * Creates the webApp.   */  @Override  protected void configureInstanceVariables(WebApp app)    throws Throwable  {    WebBeansContainer webBeans = WebBeansContainer.create();    webBeans.addSingleton(app, getContextPath(), Standard.class);    webBeans.addSingleton(getVar(), "webApp", Standard.class);    webBeans.addSingleton(getVar(), "app", Standard.class);    for (Map.Entry<String,Object> entry : getVariableMap().entrySet()) {      webBeans.addSingleton(entry.getValue(), entry.getKey(), Standard.class);    }        app.setRegexp(_regexpValues);    app.setDynamicDeploy(isDynamicDeploy());    if (_oldWebAppController != null	&& Alarm.getCurrentTime() < _oldWebAppExpireTime) {      app.setOldWebApp(_oldWebAppController.request(),		       _oldWebAppExpireTime);    }    super.configureInstanceVariables(app);  }    @Override  protected void extendJMXContext(Map<String,String> context)  {    context.put("WebApp", getMBeanId());  }  protected Path calculateRootDirectory()    throws ELException  {    Path appDir = null;    if (appDir == null && getConfig() != null) {      String path = getConfig().getRootDirectory();      if (path != null)        appDir = PathBuilder.lookupPath(path);    }    if (appDir == null && _container != null)      appDir = _container.getDocumentDirectory().lookup("./" + _contextPath);    if (appDir == null && getDeployInstance() != null)      appDir = getDeployInstance().getAppDir();    return appDir;  }  /**   * Override to prevent removing of special files.   */  @Override  protected void removeExpandFile(Path path, String relPath)    throws IOException  {    if (relPath.equals("./WEB-INF/resin-web.xml"))      return;    super.removeExpandFile(path, relPath);  }  public long getLifetimeConnectionCount()  {    synchronized (_statisticsLock) {      return _lifetimeConnectionCount;    }  }  public long getLifetimeConnectionTime()  {    synchronized (_statisticsLock) {      return _lifetimeConnectionTime;    }  }  public long getLifetimeReadBytes()  {    synchronized (_statisticsLock) {      return _lifetimeReadBytes;    }  }  public long getLifetimeWriteBytes()  {    synchronized (_statisticsLock) {      return _lifetimeWriteBytes;    }  }  public long getLifetimeClientDisconnectCount()  {    synchronized (_statisticsLock) {      return _lifetimeClientDisconnectCount;    }  }  /**   * Update statistics with the results of one request.   *   * @param milliseconds the number of millesconds for the request   * @param readBytes the number of bytes read   * @param writeBytes the number of bytes written   * @param isClientDisconnect true if the request ended with a client DisconnectException   */  public void updateStatistics(long milliseconds,                               int readBytes,                               int writeBytes,                               boolean isClientDisconnect)  {    synchronized (_statisticsLock) {      _lifetimeConnectionCount++;      _lifetimeConnectionTime += milliseconds;      _lifetimeReadBytes += readBytes;      _lifetimeWriteBytes += writeBytes;      if (isClientDisconnect)        _lifetimeClientDisconnectCount++;    }  }  @Override  protected Logger getLog()  {    return log;  }    /**   * Returns a printable view.   */  @Override  public String toString()  {    if (com.caucho.util.Alarm.isTest())      return "WebAppController" +  "[" + getId() + "]";    else      return "WebAppController$" + System.identityHashCode(this) + "[" + getId() + "]";  }  /**   * EL variables for the app.   */  public class Var {    public String getUrl()    {      return WebAppController.this.getURL();    }    public String getId()    {      String id = WebAppController.this.getId();      if (id != null)        return id;      else        return WebAppController.this.getContextPath();    }    public String getName()    {      if (getWarName() != null)        return getWarName();      else        return getId();    }    public Path getAppDir()    {      return WebAppController.this.getRootDirectory();    }    public Path getDocDir()    {      return WebAppController.this.getRootDirectory();    }    public Path getRoot()    {      return WebAppController.this.getRootDirectory();    }    public Path getRootDir()    {      return WebAppController.this.getRootDirectory();    }    public String getContextPath()    {      return WebAppController.this.getContextPath();    }    public ArrayList<String> getRegexp()    {      return _regexpValues;    }    public String getVersion()    {      return _version;    }    @Override    public String toString()    {      return "WebApp[" + getURL() + "]";    }  }}

⌨️ 快捷键说明

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