Class FarmWarDeployer
java.lang.Object
org.apache.catalina.ha.ClusterListener
org.apache.catalina.ha.deploy.FarmWarDeployer
- All Implemented Interfaces:
ClusterDeployer, FileChangeListener, ChannelListener
A farm war deployer is a class that is able to deploy/undeploy web applications in WAR from within the cluster.
Any host can act as the admin, and will have three directories- watchDir - the directory where we watch for changes
- deployDir - the directory where we install applications
- tempDir - a temporaryDirectory to store binary data when downloading a war from the cluster
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FilePath where context descriptors should be deployed.protected StringDeployment directory.protected final HashMap<String, FileMessageFactory> Map of file name to factory for in-progress file transfers.protected HostThe associated host.protected intThe maximum valid time(in seconds) for FileMessageFactory.protected MBeanServerMBean server.protected ObjectNameThe associated deployer ObjectName.protected intFrequency of the Farm watchDir check.protected booleanWhether the deployer has been started.protected StringTemporary directory.protected StringWatch directory.protected booleanWhether the watch directory feature is enabled.protected WarWatcherThe watcher for monitoring the watch directory.Fields inherited from class ClusterListener
cluster -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(ClusterMessage msg) Accept only a certain type of messages.voidCall watcher to check for deploy changesprotected voidCheck a context for deployment operations.protected booleanCopy a file to the specified temp directory.voidfileModified(File newWar) Modification from watchDir war detected.voidfileRemoved(File removeWar) War remove from watchDir.Returns the deployment directory path.Returns the deployment directory as a File object.getFactory(FileMessage msg) Create factory for all transported war filesintReturns the maximum valid time for FileMessageFactory.intReturns the frequency of watcher checks.Returns the temporary directory path.Returns the temporary directory as a File object.Returns the watch directory path.Returns the watch directory as a File object.booleanReturns whether the watch directory feature is enabled.voidInstall a new web application, whose web application archive is at the specified URL, into this container and all the other members of the cluster with the specified context name.booleanReturns whether the watch directory feature is enabled.voidCallback from the cluster, when a message is received, The cluster will broadcast it invoking the messageReceived on the receiver.protected voidInvoke the remove method on the deployer.voidRemove an existing web application, attached to the specified context name.voidremoveFactory(FileMessage msg) Remove file (war) from messagesprotected voidRemoves invalid file factories from the factory map.protected voidremoveServiced(String name) Mark a context as no longer being serviced.voidsetDeployDir(String deployDir) Sets the deployment directory path.voidsetMaxValidTime(int maxValidTime) Sets the maximum valid time for FileMessageFactory.voidsetProcessDeployFrequency(int processExpiresFrequency) Set the watcher checks frequency.voidsetTempDir(String tempDir) Sets the temporary directory path.voidsetWatchDir(String watchDir) Sets the watch directory path.voidsetWatchEnabled(boolean watchEnabled) Sets whether the watch directory feature is enabled.voidstart()Start the cluster deployer, the owning container will invoke thisvoidstop()Stops the cluster deployer, the owning container will invoke thisprotected booleantryAddServiced(String name) Attempt to mark a context as being servicedprotected voidundeployDir(File dir) Delete the specified directory, including all of its contents and subdirectories recursively.Methods inherited from class ClusterListener
accept, getCluster, messageReceived, setClusterMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelListener
accept, messageReceivedMethods inherited from interface ClusterDeployer
getCluster, setCluster
-
Field Details
-
started
protected boolean startedWhether the deployer has been started. -
fileFactories
Map of file name to factory for in-progress file transfers. -
deployDir
Deployment directory. -
tempDir
Temporary directory. -
watchDir
Watch directory. -
watchEnabled
protected boolean watchEnabledWhether the watch directory feature is enabled. -
watcher
The watcher for monitoring the watch directory. -
processDeployFrequency
protected int processDeployFrequencyFrequency of the Farm watchDir check. Cluster wide deployment will be done once for the specified amount of backgroundProcess calls (ie, the lower the amount, the most often the checks will occur). -
configBase
Path where context descriptors should be deployed. -
host
The associated host. -
mBeanServer
MBean server. -
oname
The associated deployer ObjectName. -
maxValidTime
protected int maxValidTimeThe maximum valid time(in seconds) for FileMessageFactory.
-
-
Constructor Details
-
FarmWarDeployer
public FarmWarDeployer()Creates a new FarmWarDeployer instance.
-
-
Method Details
-
start
Description copied from interface:ClusterDeployerStart the cluster deployer, the owning container will invoke this- Specified by:
startin interfaceClusterDeployer- Throws:
Exception- - if failure to start cluster
-
stop
Description copied from interface:ClusterDeployerStops the cluster deployer, the owning container will invoke this- Specified by:
stopin interfaceClusterDeployer- Throws:
LifecycleException- Error stopping cluster deployer
-
messageReceived
Callback from the cluster, when a message is received, The cluster will broadcast it invoking the messageReceived on the receiver.- Specified by:
messageReceivedin classClusterListener- Parameters:
msg- ClusterMessage - the message received from the cluster
-
getFactory
Create factory for all transported war files- Parameters:
msg- The file- Returns:
- Factory for all app message (war files)
- Throws:
FileNotFoundException- Missing file errorIOException- Other IO error
-
removeFactory
Remove file (war) from messages- Parameters:
msg- The file
-
accept
Accept only a certain type of messages.This listener accepts only FileMessage or UndeployMessage.
- Specified by:
acceptin classClusterListener- Parameters:
msg- the message- Returns:
trueto indicate that messageReceived should be invoked. Iffalseis returned, the messageReceived method will not be invoked.
-
install
Install a new web application, whose web application archive is at the specified URL, into this container and all the other members of the cluster with the specified context name.If this application is successfully installed locally, a ContainerEvent of type
INSTALL_EVENTwill be sent to all registered listeners, with the newly createdContextas an argument.- Specified by:
installin interfaceClusterDeployer- Parameters:
contextName- The context name to which this application should be installed (must be unique)webapp- A WAR file or unpacked directory structure containing the web application to be installed- Throws:
IllegalArgumentException- if the specified context name is malformedIllegalStateException- if the specified context name is already deployedIOException- if an input/output error was encountered during installation
-
remove
Remove an existing web application, attached to the specified context name. If this application is successfully removed, a ContainerEvent of typeREMOVE_EVENTwill be sent to all registered listeners, with the removedContextas an argument. Deletes the web application war file and/or directory if they exist in the Host's appBase.- Specified by:
removein interfaceClusterDeployer- Parameters:
contextName- The context name of the application to be removedundeploy- boolean flag to remove web application from server- Throws:
IllegalArgumentException- if the specified context name is malformedIllegalArgumentException- if the specified context name does not identify a currently installed web applicationIOException- if an input/output error occurs during removal
-
fileModified
Description copied from interface:FileChangeListenerModification from watchDir war detected.- Specified by:
fileModifiedin interfaceFileChangeListener- Parameters:
newWar- the modified file
-
fileRemoved
Description copied from interface:FileChangeListenerWar remove from watchDir.- Specified by:
fileRemovedin interfaceFileChangeListener- Parameters:
removeWar- the file removed
-
remove
-
undeployDir
Delete the specified directory, including all of its contents and subdirectories recursively.- Parameters:
dir- File object representing the directory to be deleted
-
backgroundProcess
public void backgroundProcess()Call watcher to check for deploy changes- Specified by:
backgroundProcessin interfaceClusterDeployer- See Also:
-
check
-
tryAddServiced
Attempt to mark a context as being serviced- Parameters:
name- The context name- Returns:
trueif the application was marked as being serviced andfalseif the application was already marked as being serviced- Throws:
Exception- Error invoking the deployer
-
removeServiced
-
getDeployDir
Returns the deployment directory path.- Returns:
- the deployment directory path
-
getDeployDirFile
Returns the deployment directory as a File object.- Returns:
- the deployment directory file
-
setDeployDir
Sets the deployment directory path.- Parameters:
deployDir- the deployment directory path
-
getTempDir
Returns the temporary directory path.- Returns:
- the temporary directory path
-
getTempDirFile
Returns the temporary directory as a File object.- Returns:
- the temporary directory file
-
setTempDir
Sets the temporary directory path.- Parameters:
tempDir- the temporary directory path
-
getWatchDir
-
getWatchDirFile
Returns the watch directory as a File object.- Returns:
- the watch directory file
-
setWatchDir
Sets the watch directory path.- Parameters:
watchDir- the watch directory path
-
isWatchEnabled
public boolean isWatchEnabled()Returns whether the watch directory feature is enabled.- Returns:
trueif watch is enabled
-
getWatchEnabled
public boolean getWatchEnabled()Returns whether the watch directory feature is enabled.- Returns:
trueif watch is enabled
-
setWatchEnabled
public void setWatchEnabled(boolean watchEnabled) Sets whether the watch directory feature is enabled.- Parameters:
watchEnabled-trueto enable watch
-
getProcessDeployFrequency
public int getProcessDeployFrequency()Returns the frequency of watcher checks.- Returns:
- the frequency of watcher checks
-
setProcessDeployFrequency
public void setProcessDeployFrequency(int processExpiresFrequency) Set the watcher checks frequency.- Parameters:
processExpiresFrequency- the new manager checks frequency
-
getMaxValidTime
public int getMaxValidTime()Returns the maximum valid time for FileMessageFactory.- Returns:
- the maximum valid time in seconds
-
setMaxValidTime
public void setMaxValidTime(int maxValidTime) Sets the maximum valid time for FileMessageFactory.- Parameters:
maxValidTime- the maximum valid time in seconds
-
copy
-
removeInvalidFileFactories
protected void removeInvalidFileFactories()Removes invalid file factories from the factory map.
-