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 Summary
Fields Modifier and Type Field Description protected FileconfigBasePath where context descriptors should be deployed.protected StringdeployDirDeployment directory.protected HashMap<String,FileMessageFactory>fileFactoriesprotected HosthostThe associated host.protected intmaxValidTimeThe maximum valid time(in seconds) for FileMessageFactory.protected MBeanServermBeanServerMBean server.protected ObjectNameonameThe associated deployer ObjectName.protected intprocessDeployFrequencyFrequency of the Farm watchDir check.protected booleanstartedprotected StringtempDirTemporary directory.protected StringwatchDirWatch directory.protected booleanwatchEnabledprotected WarWatcherwatcher-
Fields inherited from class org.apache.catalina.ha.ClusterListener
cluster
-
-
Constructor Summary
Constructors Constructor Description FarmWarDeployer()
-
Method Summary
All 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(String name)Deprecated.Unused.voidbackgroundProcess()Call watcher to check for deploy changesprotected voidcheck(String name)Check a context for deployment operations.protected booleancopy(File from, File to)Copy a file to the specified temp directory.booleanequals(Object listener)voidfileModified(File newWar)Modification from watchDir war detected!voidfileRemoved(File removeWar)War remove from watchDirStringgetDeployDir()FilegetDeployDirFile()FileMessageFactorygetFactory(FileMessage msg)Create factory for all transported war filesintgetMaxValidTime()intgetProcessDeployFrequency()StringgetTempDir()FilegetTempDirFile()StringgetWatchDir()FilegetWatchDirFile()booleangetWatchEnabled()inthashCode()voidinstall(String contextName, 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(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(String contextName)Invoke the remove method on the deployer.voidremove(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(String name)Mark a context as no longer being serviced.voidsetDeployDir(String deployDir)voidsetMaxValidTime(int maxValidTime)voidsetProcessDeployFrequency(int processExpiresFrequency)Set the watcher checks frequency.voidsetTempDir(String tempDir)voidsetWatchDir(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(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 org.apache.catalina.ha.ClusterListener
accept, getCluster, messageReceived, setCluster
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.catalina.tribes.ChannelListener
accept, messageReceived
-
Methods inherited from interface org.apache.catalina.ha.ClusterDeployer
getCluster, setCluster
-
-
-
-
Field Detail
-
started
protected boolean started
-
fileFactories
protected final HashMap<String,FileMessageFactory> fileFactories
-
deployDir
protected String deployDir
Deployment directory.
-
tempDir
protected String tempDir
Temporary directory.
-
watchDir
protected String watchDir
Watch directory.
-
watchEnabled
protected boolean watchEnabled
-
watcher
protected WarWatcher watcher
-
processDeployFrequency
protected 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).
-
configBase
protected File configBase
Path where context descriptors should be deployed.
-
host
protected Host host
The associated host.
-
mBeanServer
protected MBeanServer mBeanServer
MBean server.
-
oname
protected ObjectName oname
The associated deployer ObjectName.
-
maxValidTime
protected int maxValidTime
The maximum valid time(in seconds) for FileMessageFactory.
-
-
Method Detail
-
start
public void start() throws ExceptionDescription 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
public void stop() throws LifecycleExceptionDescription copied from interface:ClusterDeployerStops the cluster deployer, the owning container will invoke this- Specified by:
stopin interfaceClusterDeployer- Throws:
LifecycleException- Error stopping cluster deployer
-
messageReceived
public 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 classClusterListener- Parameters:
msg- ClusterMessage - the message received from the cluster
-
getFactory
public FileMessageFactory getFactory(FileMessage msg) throws FileNotFoundException, IOException
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
public void removeFactory(FileMessage msg)
Remove file (war) from messages- Parameters:
msg- The file
-
accept
public 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 classClusterListener- 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.
-
install
public void install(String contextName, File webapp) throws IOException
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
public void remove(String contextName, boolean undeploy) throws IOException
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
public void fileModified(File newWar)
Modification from watchDir war detected!- Specified by:
fileModifiedin interfaceFileChangeListener- See Also:
FileChangeListener.fileModified(File)
-
fileRemoved
public void fileRemoved(File removeWar)
War remove from watchDir- Specified by:
fileRemovedin interfaceFileChangeListener- See Also:
FileChangeListener.fileRemoved(File)
-
remove
protected void remove(String contextName) throws Exception
Invoke the remove method on the deployer.- Parameters:
contextName- The context to remove- Throws:
Exception- If an error occurs removing the context
-
undeployDir
protected void undeployDir(File dir)
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:
ClusterDeployer.backgroundProcess()
-
check
protected void check(String name) throws Exception
Check a context for deployment operations.- Parameters:
name- The context name- Throws:
Exception- Error invoking the deployer
-
isServiced
@Deprecated protected boolean isServiced(String name) throws Exception
Deprecated.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:
Exception- Error invoking the deployer
-
addServiced
@Deprecated protected void addServiced(String name) throws Exception
Deprecated.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:
Exception- Error invoking the deployer
-
tryAddServiced
protected boolean tryAddServiced(String name) throws Exception
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
protected void removeServiced(String name) throws Exception
Mark a context as no longer being serviced.- Parameters:
name- The context name- Throws:
Exception- Error invoking the deployer
-
equals
public boolean equals(Object listener)
- Specified by:
equalsin interfaceChannelListener- Overrides:
equalsin classObject- Parameters:
listener- Object- Returns:
- boolean
- See Also:
Object.equals(Object)
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceChannelListener- Overrides:
hashCodein classObject- Returns:
- int
- See Also:
Object.hashCode()
-
getDeployDir
public String getDeployDir()
-
getDeployDirFile
public File getDeployDirFile()
-
setDeployDir
public void setDeployDir(String deployDir)
-
getTempDir
public String getTempDir()
-
getTempDirFile
public File getTempDirFile()
-
setTempDir
public void setTempDir(String tempDir)
-
getWatchDir
public String getWatchDir()
-
getWatchDirFile
public File getWatchDirFile()
-
setWatchDir
public void setWatchDir(String watchDir)
-
isWatchEnabled
public boolean isWatchEnabled()
-
getWatchEnabled
public boolean getWatchEnabled()
-
setWatchEnabled
public void setWatchEnabled(boolean watchEnabled)
-
getProcessDeployFrequency
public int getProcessDeployFrequency()
- 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()
-
setMaxValidTime
public void setMaxValidTime(int maxValidTime)
-
copy
protected boolean copy(File from, File to)
Copy a file to the specified temp directory.- Parameters:
from- copy from tempto- to host appBase directory- Returns:
- true, copy successful
-
removeInvalidFileFactories
protected void removeInvalidFileFactories()
-
-