deploycontroller.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 844 行 · 第 1/2 页
JAVA
844 行
{ return _lifecycle.isInit(); } /** * Returns true if the instance has been idle for longer than its timeout. * * @return true if idle */ public boolean isActiveIdle() { DeployInstance instance = getDeployInstance(); if (! _lifecycle.isActive()) return false; else if (instance == null) return false; else return instance.isDeployIdle(); } /** * Return true if the instance is in the error state. * * @return true for the error state. */ public boolean isError() { if (_lifecycle.isError()) return true; DeployInstance instance = getDeployInstance(); return (instance != null && instance.getConfigException() != null); } /** * Returns true if there's currently an error. */ public boolean isErrorNow() { if (_lifecycle.isError()) return true; DeployInstance instance = getDeployInstance(); return (instance != null && instance.getConfigException() != null); } /** * Returns true if the entry is modified. */ public boolean isModified() { DeployInstance instance = getDeployInstance(); return instance == null || instance.isModified(); } /** * Log the reason for modification */ public boolean logModified(Logger log) { DeployInstance instance = getDeployInstance(); if (instance != null) { Thread thread = Thread.currentThread(); ClassLoader loader = thread.getContextClassLoader(); try { thread.setContextClassLoader(instance.getClassLoader()); return instance.logModified(log); } finally { thread.setContextClassLoader(loader); } } else return false; } /** * Returns true if the entry is modified. */ public boolean isModifiedNow() { DeployInstance instance = getDeployInstance(); return instance == null || instance.isModifiedNow(); } /** * Returns the current instance. */ public final I getDeployInstance() { synchronized (this) { if (_deployInstance == null) { Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(_parentLoader); _deployInstance = instantiateDeployInstance(); } finally { thread.setContextClassLoader(oldLoader); } } return _deployInstance; } } /** * Redeploys the entry if it's modified. */ public void startOnInit() { if (! _lifecycle.isAfterInit()) throw new IllegalStateException(L.l("startOnInit must be called after init (in '{0}')", _lifecycle.getStateName())); _strategy.startOnInit(this); } /** * Force an instance start from an admin command. */ public final void start() { _strategy.start(this); } public Throwable getConfigException() { return null; } /** * Stops the controller from an admin command. */ public final void stop() { _strategy.stop(this); } /** * Force an instance restart from an admin command. */ public final void restart() { _strategy.stop(this); _strategy.start(this); } /** * Update the controller from an admin command. */ public final void update() { _strategy.update(this); } /** * Returns the instance for a top-level request * @return the request object or null for none. */ public I request() { if (_lifecycle.isDestroyed()) return null; else if (_strategy != null) return _strategy.request(this); else return null; } /** * Returns the instance for a subrequest. * * @return the request object or null for none. */ public I subrequest() { if (_lifecycle.isDestroyed()) return null; else if (_strategy != null) return _strategy.subrequest(this); else return null; } /** * Restarts the instance * * @return the new instance */ I restartImpl() { if (! _lifecycle.isStopped() && ! _lifecycle.isInit()) stopImpl(); return startImpl(); } /** * Starts the entry. */ protected I startImpl() { assert(_lifecycle.isAfterInit()); if (DynamicClassLoader.isModified(_parentLoader)) { _deployInstance = null; return null; } I deployInstance = getDeployInstance(); Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); ClassLoader loader = null; boolean isStarting = false; try { loader = deployInstance.getClassLoader(); thread.setContextClassLoader(loader); isStarting = _lifecycle.toStarting(); if (! isStarting) return deployInstance; expandArchive(); addManifestClassPath(); configureInstance(deployInstance); deployInstance.start(); _startTime = Alarm.getCurrentTime(); } catch (ConfigException e) { _lifecycle.toError(); if (deployInstance != null) deployInstance.setConfigException(e); else { log.severe(e.toString()); log.log(Level.FINEST, e.toString(), e); } } catch (Throwable e) { _lifecycle.toError(); if (deployInstance != null) deployInstance.setConfigException(e); else log.log(Level.SEVERE, e.toString(), e); } finally { if (isStarting) _lifecycle.toActive(); // server/ if (loader instanceof DynamicClassLoader) ((DynamicClassLoader) loader).clearModified(); if (_alarm != null) _alarm.queue(_redeployCheckInterval); // XXX: strategy-controlled thread.setContextClassLoader(oldLoader); } return deployInstance; } /** * Deploys the entry, e.g. archive expansion. */ protected void expandArchive() throws Exception { } /** * Stops the current instance, putting it in the lazy state. */ void stopLazyImpl() { if (_lifecycle.isInit()) return; stopImpl(); _lifecycle.toPostInit(); } /** * Stops the current instance. */ void stopImpl() { Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); DeployInstance oldInstance = _deployInstance; boolean isStopping = false; if (oldInstance != null) thread.setContextClassLoader(oldInstance.getClassLoader()); try { isStopping = _lifecycle.toStopping(); if (! isStopping) return; synchronized (this) { oldInstance = _deployInstance; _deployInstance = null; } if (oldInstance != null) { oldInstance.destroy(); } } finally { if (isStopping) _lifecycle.toStop(); thread.setContextClassLoader(oldLoader); } return; } /** * Creates an instance. */ abstract protected I instantiateDeployInstance(); /** * Adds any manifest Class-Path */ protected void addManifestClassPath() throws IOException { } /** * Configuration of the instance */ protected void configureInstance(I deployInstance) throws Throwable { } /** * Handles the redeploy check alarm. */ public void handleAlarm(Alarm alarm) { try { _strategy.alarm(this); } finally { if (! _lifecycle.isDestroyed()) alarm.queue(_redeployCheckInterval); } } /** * Returns true if the entry is destroyed. */ public boolean isDestroyed() { return _lifecycle.isDestroyed(); } /** * Destroys the entry. */ protected boolean destroy() { if (_lifecycle.isAfterInit()) stop(); if (! _lifecycle.toDestroy()) return false; Alarm alarm = _alarm; _alarm = null; if (alarm != null) { alarm.dequeue(); } return true; } /** * Returns the appropriate log for debugging. */ protected Logger getLog() { return log; } /** * Returns the entry's debug name. */ public String toString() { String className = getClass().getName(); int p = className.lastIndexOf('.'); return className.substring(p + 1) + "[" + getId() + "]"; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?