Package org.apache.catalina.ha.deploy
Class FarmWarDeployer
- java.lang.Object
- 
- org.apache.catalina.ha.ClusterListener
- 
- org.apache.catalina.ha.deploy.FarmWarDeployer
 
 
- 
- All Implemented Interfaces:
- ClusterDeployer,- FileChangeListener,- ChannelListener
 
 public class FarmWarDeployer extends ClusterListener implements ClusterDeployer, FileChangeListener 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
 - Author:
- Peter Rossbach
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected java.io.FileconfigBasePath where context descriptors should be deployed.protected java.lang.StringdeployDirDeployment directory.protected java.util.HashMap<java.lang.String,FileMessageFactory>fileFactoriesprotected HosthostThe associated host.protected intmaxValidTimeThe maximum valid time(in seconds) for FileMessageFactory.protected javax.management.MBeanServermBeanServerMBean server.protected javax.management.ObjectNameonameThe associated deployer ObjectName.protected intprocessDeployFrequencyFrequency of the Farm watchDir check.protected booleanstartedprotected java.lang.StringtempDirTemporary directory.protected java.lang.StringwatchDirWatch directory.protected booleanwatchEnabledprotected WarWatcherwatcher- 
Fields inherited from class org.apache.catalina.ha.ClusterListenercluster
 
- 
 - 
Constructor SummaryConstructors Constructor Description FarmWarDeployer()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaccept(ClusterMessage msg)Before the cluster invokes messageReceived the cluster will ask the receiver to accept or decline the message, In the future, when messages get big, the accept method will only take a message headerprotected voidaddServiced(java.lang.String name)Deprecated.Unused.voidbackgroundProcess()Call watcher to check for deploy changesprotected voidcheck(java.lang.String name)Check a context for deployment operations.protected booleancopy(java.io.File from, java.io.File to)Copy a file to the specified temp directory.booleanequals(java.lang.Object listener)voidfileModified(java.io.File newWar)Modification from watchDir war detected!voidfileRemoved(java.io.File removeWar)War remove from watchDirjava.lang.StringgetDeployDir()java.io.FilegetDeployDirFile()FileMessageFactorygetFactory(FileMessage msg)Create factory for all transported war filesintgetMaxValidTime()intgetProcessDeployFrequency()java.lang.StringgetTempDir()java.io.FilegetTempDirFile()java.lang.StringgetWatchDir()java.io.FilegetWatchDirFile()booleangetWatchEnabled()inthashCode()voidinstall(java.lang.String contextName, java.io.File webapp)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.protected booleanisServiced(java.lang.String name)Deprecated.Unused.booleanisWatchEnabled()voidmessageReceived(ClusterMessage msg)Callback from the cluster, when a message is received, The cluster will broadcast it invoking the messageReceived on the receiver.protected voidremove(java.lang.String contextName)Invoke the remove method on the deployer.voidremove(java.lang.String contextName, boolean undeploy)Remove an existing web application, attached to the specified context name.voidremoveFactory(FileMessage msg)Remove file (war) from messagesprotected voidremoveInvalidFileFactories()protected voidremoveServiced(java.lang.String name)Mark a context as no longer being serviced.voidsetDeployDir(java.lang.String deployDir)voidsetMaxValidTime(int maxValidTime)voidsetProcessDeployFrequency(int processExpiresFrequency)Set the watcher checks frequency.voidsetTempDir(java.lang.String tempDir)voidsetWatchDir(java.lang.String watchDir)voidsetWatchEnabled(boolean watchEnabled)voidstart()Start the cluster deployer, the owning container will invoke thisvoidstop()Stops the cluster deployer, the owning container will invoke thisprotected booleantryAddServiced(java.lang.String name)Attempt to mark a context as being servicedprotected voidundeployDir(java.io.File dir)Delete the specified directory, including all of its contents and subdirectories recursively.- 
Methods inherited from class org.apache.catalina.ha.ClusterListeneraccept, getCluster, messageReceived, setCluster
 - 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.apache.catalina.tribes.ChannelListeneraccept, messageReceived
 - 
Methods inherited from interface org.apache.catalina.ha.ClusterDeployergetCluster, setCluster
 
- 
 
- 
- 
- 
Field Detail- 
startedprotected boolean started 
 - 
fileFactoriesprotected final java.util.HashMap<java.lang.String,FileMessageFactory> fileFactories 
 - 
deployDirprotected java.lang.String deployDir Deployment directory.
 - 
tempDirprotected java.lang.String tempDir Temporary directory.
 - 
watchDirprotected java.lang.String watchDir Watch directory.
 - 
watchEnabledprotected boolean watchEnabled 
 - 
watcherprotected WarWatcher watcher 
 - 
processDeployFrequencyprotected int processDeployFrequency Frequency 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).
 - 
configBaseprotected java.io.File configBase Path where context descriptors should be deployed.
 - 
hostprotected Host host The associated host.
 - 
mBeanServerprotected javax.management.MBeanServer mBeanServer MBean server.
 - 
onameprotected javax.management.ObjectName oname The associated deployer ObjectName.
 - 
maxValidTimeprotected int maxValidTime The maximum valid time(in seconds) for FileMessageFactory.
 
- 
 - 
Method Detail- 
startpublic void start() throws java.lang.ExceptionDescription copied from interface:ClusterDeployerStart the cluster deployer, the owning container will invoke this- Specified by:
- startin interface- ClusterDeployer
- Throws:
- java.lang.Exception- - if failure to start cluster
 
 - 
stoppublic void stop() throws LifecycleExceptionDescription copied from interface:ClusterDeployerStops the cluster deployer, the owning container will invoke this- Specified by:
- stopin interface- ClusterDeployer
- Throws:
- LifecycleException- Error stopping cluster deployer
 
 - 
messageReceivedpublic void messageReceived(ClusterMessage msg) Callback from the cluster, when a message is received, The cluster will broadcast it invoking the messageReceived on the receiver.- Specified by:
- messageReceivedin class- ClusterListener
- Parameters:
- msg- ClusterMessage - the message received from the cluster
 
 - 
getFactorypublic FileMessageFactory getFactory(FileMessage msg) throws java.io.FileNotFoundException, java.io.IOException Create factory for all transported war files- Parameters:
- msg- The file
- Returns:
- Factory for all app message (war files)
- Throws:
- java.io.FileNotFoundException- Missing file error
- java.io.IOException- Other IO error
 
 - 
removeFactorypublic void removeFactory(FileMessage msg) Remove file (war) from messages- Parameters:
- msg- The file
 
 - 
acceptpublic boolean accept(ClusterMessage msg) Before the cluster invokes messageReceived the cluster will ask the receiver to accept or decline the message, In the future, when messages get big, the accept method will only take a message header- Specified by:
- acceptin class- ClusterListener
- Parameters:
- msg- ClusterMessage
- Returns:
- boolean - returns true to indicate that messageReceived should be invoked. If false is returned, the messageReceived method will not be invoked.
 
 - 
installpublic void install(java.lang.String contextName, java.io.File webapp) throws java.io.IOExceptionInstall 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 interface- ClusterDeployer
- 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:
- java.lang.IllegalArgumentException- if the specified context name is malformed
- java.lang.IllegalStateException- if the specified context name is already deployed
- java.io.IOException- if an input/output error was encountered during installation
 
 - 
removepublic void remove(java.lang.String contextName, boolean undeploy) throws java.io.IOExceptionRemove 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 interface- ClusterDeployer
- Parameters:
- contextName- The context name of the application to be removed
- undeploy- boolean flag to remove web application from server
- Throws:
- java.lang.IllegalArgumentException- if the specified context name is malformed
- java.lang.IllegalArgumentException- if the specified context name does not identify a currently installed web application
- java.io.IOException- if an input/output error occurs during removal
 
 - 
fileModifiedpublic void fileModified(java.io.File newWar) Modification from watchDir war detected!- Specified by:
- fileModifiedin interface- FileChangeListener
- See Also:
- FileChangeListener.fileModified(File)
 
 - 
fileRemovedpublic void fileRemoved(java.io.File removeWar) War remove from watchDir- Specified by:
- fileRemovedin interface- FileChangeListener
- See Also:
- FileChangeListener.fileRemoved(File)
 
 - 
removeprotected void remove(java.lang.String contextName) throws java.lang.ExceptionInvoke the remove method on the deployer.- Parameters:
- contextName- The context to remove
- Throws:
- java.lang.Exception- If an error occurs removing the context
 
 - 
undeployDirprotected void undeployDir(java.io.File dir) Delete the specified directory, including all of its contents and subdirectories recursively.- Parameters:
- dir- File object representing the directory to be deleted
 
 - 
backgroundProcesspublic void backgroundProcess() Call watcher to check for deploy changes- Specified by:
- backgroundProcessin interface- ClusterDeployer
- See Also:
- ClusterDeployer.backgroundProcess()
 
 - 
checkprotected void check(java.lang.String name) throws java.lang.ExceptionCheck a context for deployment operations.- Parameters:
- name- The context name
- Throws:
- java.lang.Exception- Error invoking the deployer
 
 - 
isServiced@Deprecated protected boolean isServiced(java.lang.String name) throws java.lang.ExceptionDeprecated.Unused. Will be removed in Tomcat 10.1.x onwards.Verified if a context is being services.- Parameters:
- name- The context name
- Returns:
- trueif the context is being serviced
- Throws:
- java.lang.Exception- Error invoking the deployer
 
 - 
addServiced@Deprecated protected void addServiced(java.lang.String name) throws java.lang.ExceptionDeprecated.Unused. Will be removed in Tomcat 10.1.x onwards. UsetryAddServiced(java.lang.String)Mark a context as being services.- Parameters:
- name- The context name
- Throws:
- java.lang.Exception- Error invoking the deployer
 
 - 
tryAddServicedprotected boolean tryAddServiced(java.lang.String name) throws java.lang.ExceptionAttempt to mark a context as being serviced- Parameters:
- name- The context name
- Returns:
- trueif the application was marked as being serviced and- falseif the application was already marked as being serviced
- Throws:
- java.lang.Exception- Error invoking the deployer
 
 - 
removeServicedprotected void removeServiced(java.lang.String name) throws java.lang.ExceptionMark a context as no longer being serviced.- Parameters:
- name- The context name
- Throws:
- java.lang.Exception- Error invoking the deployer
 
 - 
equalspublic boolean equals(java.lang.Object listener) - Specified by:
- equalsin interface- ChannelListener
- Overrides:
- equalsin class- java.lang.Object
- Parameters:
- listener- Object
- Returns:
- boolean
- See Also:
- Object.equals(Object)
 
 - 
hashCodepublic int hashCode() - Specified by:
- hashCodein interface- ChannelListener
- Overrides:
- hashCodein class- java.lang.Object
- Returns:
- int
- See Also:
- Object.hashCode()
 
 - 
getDeployDirpublic java.lang.String getDeployDir() 
 - 
getDeployDirFilepublic java.io.File getDeployDirFile() 
 - 
setDeployDirpublic void setDeployDir(java.lang.String deployDir) 
 - 
getTempDirpublic java.lang.String getTempDir() 
 - 
getTempDirFilepublic java.io.File getTempDirFile() 
 - 
setTempDirpublic void setTempDir(java.lang.String tempDir) 
 - 
getWatchDirpublic java.lang.String getWatchDir() 
 - 
getWatchDirFilepublic java.io.File getWatchDirFile() 
 - 
setWatchDirpublic void setWatchDir(java.lang.String watchDir) 
 - 
isWatchEnabledpublic boolean isWatchEnabled() 
 - 
getWatchEnabledpublic boolean getWatchEnabled() 
 - 
setWatchEnabledpublic void setWatchEnabled(boolean watchEnabled) 
 - 
getProcessDeployFrequencypublic int getProcessDeployFrequency() - Returns:
- the frequency of watcher checks.
 
 - 
setProcessDeployFrequencypublic void setProcessDeployFrequency(int processExpiresFrequency) Set the watcher checks frequency.- Parameters:
- processExpiresFrequency- the new manager checks frequency
 
 - 
getMaxValidTimepublic int getMaxValidTime() 
 - 
setMaxValidTimepublic void setMaxValidTime(int maxValidTime) 
 - 
copyprotected boolean copy(java.io.File from, java.io.File to)Copy a file to the specified temp directory.- Parameters:
- from- copy from temp
- to- to host appBase directory
- Returns:
- true, copy successful
 
 - 
removeInvalidFileFactoriesprotected void removeInvalidFileFactories() 
 
- 
 
-