Top Description Inners Fields Constructors Methods
org.mortbay.jetty.deployer

public Class ContextDeployer

extends AbstractLifeCycle
Class Inheritance
Imports
java.io.File, .FilenameFilter, .IOException, java.util.HashMap, .Map, org.mortbay.component.AbstractLifeCycle, org.mortbay.jetty.Server, org.mortbay.jetty.handler.ContextHandler, .ContextHandlerCollection, org.mortbay.log.Log, org.mortbay.resource.Resource, org.mortbay.util.Scanner, org.mortbay.xml.XmlConfiguration

Context Deployer This deployer scans a designated directory by setConfigurationDir(String) for the appearance/disappearance or changes to xml configuration files. The scan is performed at startup and at an optional hot deployment frequency specified by setScanInterval(int). By default, the scanning is NOT recursive, but can be made so by setRecursive(boolean). Each configuration file is in XmlConfiguration format and represents the configuration of a instance of ContextHandler (or a subclass specified by the XML Configure element). The xml should configure the context and the instance is deployed to the ContextHandlerCollection specified by setContexts(Server). Similarly, when one of these existing files is removed, the corresponding context is undeployed; when one of these files is changed, the corresponding context is undeployed, the (changed) xml config file reapplied to it, and then (re)deployed. Note that the context itself is NOT copied into the hot deploy directory. The webapp directory or war file can exist anywhere. It is the xml config file that points to it's location and deploys it from there. It means, for example, that you can keep a "read-only" copy of your webapp somewhere, and apply different configurations to it simply by dropping different xml configuration files into the configuration directory.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class

Field Summary

Modifier and TypeField and Description
private ConfigurationManager
private Resource
private ContextHandlerCollection
private Map<K, V>
private boolean
private int
private Scanner
private ContextDeployer.ScannerListener
public static final String
Inherited from org.mortbay.component.AbstractLifeCycle:
_listeners

Constructor Summary

AccessConstructor and Description
public
ContextDeployer()

Constructor

Method Summary

Modifier and TypeMethod and Description
private ContextHandler
createContext(String
the config file found in the hot deploy directory
filename
)

Create a WebAppContext for the webapp being hot deployed, then apply the xml config file to it to configure it.

private void
deploy(String filename)

protected void
doStart()

Overrides org.mortbay.component.AbstractLifeCycle.doStart.

Start the hot deployer looking for webapps to deploy/undeploy
protected void
doStop()

Overrides org.mortbay.component.AbstractLifeCycle.doStop.

Stop the hot deployer.
public Resource
public ConfigurationManager
public ContextHandlerCollection

Returns:

the ContextHandlerColletion to which to deploy the contexts
getContexts
()

public String
public boolean
public int
public boolean
private void
redeploy(String filename)

public void
public void
public void
public void
public void
setContexts(ContextHandlerCollection
the ContextHandlerColletion to which to deploy the contexts
contexts
)

Associate with a ContextHandlerCollection.

public void
setDirectory(String directory)

public void
setRecursive(boolean recursive)

public void
setScanInterval(int
The period in second between scans for changed configuration files. A zero or negative interval disables hot deployment
seconds
)

private void
undeploy(String filename)

Inherited from org.mortbay.component.AbstractLifeCycle:
addLifeCycleListenerisFailedisRunningisStartedisStartingisStoppedisStoppingremoveLifeCycleListenerstartstop

Field Detail

_configMgrback to summary
private ConfigurationManager _configMgr
_configurationDirback to summary
private Resource _configurationDir
_contextsback to summary
private ContextHandlerCollection _contexts
_currentDeploymentsback to summary
private Map<K, V> _currentDeployments
_recursiveback to summary
private boolean _recursive
_scanIntervalback to summary
private int _scanInterval
_scannerback to summary
private Scanner _scanner
_scannerListenerback to summary
private ContextDeployer.ScannerListener _scannerListener
NAMEback to summary
public static final String NAME

Constructor Detail

ContextDeployerback to summary
public ContextDeployer() throws Exception

Constructor

Method Detail

createContextback to summary
private ContextHandler createContext(String filename) throws Exception

Create a WebAppContext for the webapp being hot deployed, then apply the xml config file to it to configure it.

Parameters
filename:String

the config file found in the hot deploy directory

deployback to summary
private void deploy(String filename) throws Exception
doStartback to summary
protected void doStart() throws Exception

Overrides org.mortbay.component.AbstractLifeCycle.doStart.

Start the hot deployer looking for webapps to deploy/undeploy

See Also
org.mortbay.component.AbstractLifeCycle#doStart()
doStopback to summary
protected void doStop() throws Exception

Overrides org.mortbay.component.AbstractLifeCycle.doStop.

Stop the hot deployer.

See Also
org.mortbay.component.AbstractLifeCycle#doStop()
getConfigurationDirback to summary
public Resource getConfigurationDir()
getConfigurationManagerback to summary
public ConfigurationManager getConfigurationManager()
getContextsback to summary
public ContextHandlerCollection getContexts()
Returns:ContextHandlerCollection

the ContextHandlerColletion to which to deploy the contexts

getDirectoryback to summary
public String getDirectory()
getRecursiveback to summary
public boolean getRecursive()
getScanIntervalback to summary
public int getScanInterval()
isRecursiveback to summary
public boolean isRecursive()
redeployback to summary
private void redeploy(String filename) throws Exception
setConfigurationDirback to summary
public void setConfigurationDir(String dir) throws Exception
setConfigurationDirback to summary
public void setConfigurationDir(File file) throws Exception
setConfigurationDirback to summary
public void setConfigurationDir(Resource resource)
setConfigurationManagerback to summary
public void setConfigurationManager(ConfigurationManager configMgr)
setContextsback to summary
public void setContexts(ContextHandlerCollection contexts)

Associate with a ContextHandlerCollection.

Parameters
contexts:ContextHandlerCollection

the ContextHandlerColletion to which to deploy the contexts

setDirectoryback to summary
public void setDirectory(String directory) throws Exception
setRecursiveback to summary
public void setRecursive(boolean recursive)
setScanIntervalback to summary
public void setScanInterval(int seconds)
Parameters
seconds:int

The period in second between scans for changed configuration files. A zero or negative interval disables hot deployment

undeployback to summary
private void undeploy(String filename) throws Exception
org.mortbay.jetty.deployer back to summary

protected Class ContextDeployer.ScannerListener

extends Object
implements DiscreteListener
Class Inheritance
All Implemented Interfaces
org.mortbay.util.Scanner.DiscreteListener, org.mortbay.util.Scanner.Listener

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
fileAdded(String filename)

Implements org.mortbay.util.Scanner.DiscreteListener.fileAdded.

Handle a new deployment
public void
fileChanged(String filename)

Implements org.mortbay.util.Scanner.DiscreteListener.fileChanged.

Handle a change to an existing deployment.
public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Constructor Detail

ScannerListenerback to summary
protected ScannerListener()

Method Detail

fileAddedback to summary
public void fileAdded(String filename) throws Exception

Implements org.mortbay.util.Scanner.DiscreteListener.fileAdded.

Handle a new deployment

See Also
org.mortbay.util.Scanner.FileAddedListener#fileAdded(java.lang.String)
fileChangedback to summary
public void fileChanged(String filename) throws Exception

Implements org.mortbay.util.Scanner.DiscreteListener.fileChanged.

Handle a change to an existing deployment. Undeploy then redeploy.

See Also
org.mortbay.util.Scanner.FileChangedListener#fileChanged(java.lang.String)
fileRemovedback to summary
public void fileRemoved(String filename) throws Exception

Implements org.mortbay.util.Scanner.DiscreteListener.fileRemoved.

Handle an undeploy.

See Also
org.mortbay.util.Scanner.FileRemovedListener#fileRemoved(java.lang.String)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.