org.apache.catalina.ha.deploy

Class FarmWarDeployer

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 form within the cluster.

Any host can act as the admin, and will have three directories Currently we only support deployment of WAR files since they are easier to send across the wire.

Version: $Revision: 734560 $

Author: Filip Hanik Peter Rossbach

Field Summary
protected FileappBase
The host appBase.
protected CatalinaClustercluster
protected FileconfigBase
Path where context descriptors should be deployed.
protected StringdeployDir
protected HashMapfileFactories
protected Hosthost
The associated host.
static Loglog
protected MBeanServermBeanServer
MBean server.
protected ObjectNameoname
The associated deployer ObjectName.
protected intprocessDeployFrequency
Frequency of the Farm watchDir check.
protected booleanstarted
protected StringtempDir
protected StringwatchDir
protected WarWatcherwatcher
protected booleanwatchEnabled
Constructor Summary
FarmWarDeployer()
Method Summary
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 header
protected voidaddServiced(String name)
Invoke the check method on the deployer.
voidbackgroundProcess()
protected voidcheck(String name)
Invoke the check method on the deployer.
voidcleanDeployDir()
protected booleancopy(File from, File to)
Copy a file to the specified temp directory.
booleanequals(Object listener)
voidfileModified(File newWar)
voidfileRemoved(File removeWar)
protected FilegetAppBase()
Return a File object representing the "application root" directory for our associated Host.
CatalinaClustergetCluster()
protected StringgetConfigFile(String path)
Given a context path, get the config file name.
protected StringgetContextName(File war)
Create a context path from war
StringgetDeployDir()
protected StringgetDocBase(String path)
Given a context path, get the config file name.
FileMessageFactorygetFactory(FileMessage msg)
create factory for all transported war files
StringgetInfo()
Return descriptive information about this deployer implementation and the corresponding version number, in the format <description>/<version>.
intgetProcessDeployFrequency()
Return the frequency of watcher checks.
StringgetTempDir()
StringgetWatchDir()
booleangetWatchEnabled()
inthashCode()
voidinstall(String contextPath, URL war)
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 path.
protected booleanisServiced(String name)
Invoke the check method on the deployer.
booleanisWatchEnabled()
voidmessageReceived(ClusterMessage msg)
Callback from the cluster, when a message is received, The cluster will broadcast it invoking the messageReceived on the receiver.
voidremove(String contextPath, boolean undeploy)
Remove an existing web application, attached to the specified context path.
protected voidremove(String path)
Invoke the remove method on the deployer.
voidremoveFactory(FileMessage msg)
Remove file (war) from messages)
protected voidremoveServiced(String name)
Invoke the check method on the deployer.
voidsetCluster(CatalinaCluster cluster)
voidsetDeployDir(String deployDir)
voidsetProcessDeployFrequency(int processExpiresFrequency)
Set the watcher checks frequency.
voidsetTempDir(String tempDir)
voidsetWatchDir(String watchDir)
voidsetWatchEnabled(boolean watchEnabled)
voidstart()
voidstop()
protected voidundeployDir(File dir)
Delete the specified directory, including all of its contents and subdirectories recursively.

Field Detail

appBase

protected File appBase
The host appBase.

cluster

protected CatalinaCluster cluster

configBase

protected File configBase
Path where context descriptors should be deployed.

deployDir

protected String deployDir

fileFactories

protected HashMap fileFactories

host

protected Host host
The associated host.

log

public static Log log

mBeanServer

protected MBeanServer mBeanServer
MBean server.

oname

protected ObjectName oname
The associated deployer ObjectName.

processDeployFrequency

protected int processDeployFrequency
Frequency of the Farm watchDir check. Cluster wide deployment will be done once for the specified amount of backgrondProcess calls (ie, the lower the amount, the most often the checks will occur).

started

protected boolean started

tempDir

protected String tempDir

watchDir

protected String watchDir

watcher

protected WarWatcher watcher

watchEnabled

protected boolean watchEnabled

Constructor Detail

FarmWarDeployer

public FarmWarDeployer()

Method Detail

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

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.

addServiced

protected void addServiced(String name)
Invoke the check method on the deployer.

backgroundProcess

public void backgroundProcess()

check

protected void check(String name)
Invoke the check method on the deployer.

cleanDeployDir

public void cleanDeployDir()

copy

protected boolean copy(File from, File to)
Copy a file to the specified temp directory.

Parameters: from copy from temp to to host appBase directory

Returns: true, copy successful

equals

public boolean equals(Object listener)

fileModified

public void fileModified(File newWar)

fileRemoved

public void fileRemoved(File removeWar)

getAppBase

protected File getAppBase()
Return a File object representing the "application root" directory for our associated Host.

getCluster

public CatalinaCluster getCluster()

getConfigFile

protected String getConfigFile(String path)
Given a context path, get the config file name.

getContextName

protected String getContextName(File war)
Create a context path from war

Parameters: war War filename

Returns: '/filename' or if war name is ROOT.war context name is empty string ''

getDeployDir

public String getDeployDir()

getDocBase

protected String getDocBase(String path)
Given a context path, get the config file name.

getFactory

public FileMessageFactory getFactory(FileMessage msg)
create factory for all transported war files

Parameters: msg

Returns: Factory for all app message (war files)

Throws: java.io.FileNotFoundException java.io.IOException

getInfo

public String getInfo()
Return descriptive information about this deployer implementation and the corresponding version number, in the format <description>/<version>.

getProcessDeployFrequency

public int getProcessDeployFrequency()
Return the frequency of watcher checks.

getTempDir

public String getTempDir()

getWatchDir

public String getWatchDir()

getWatchEnabled

public boolean getWatchEnabled()

hashCode

public int hashCode()

install

public void install(String contextPath, URL war)
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 path. A context path of "" (the empty string) should be used for the root application for this container. Otherwise, the context path must start with a slash.

If this application is successfully installed locally, a ContainerEvent of type INSTALL_EVENT will be sent to all registered listeners, with the newly created Context as an argument.

Parameters: contextPath The context path to which this application should be installed (must be unique) war A URL of type "jar:" that points to a WAR file, or type "file:" that points to an unpacked directory structure containing the web application to be installed

Throws: IllegalArgumentException if the specified context path is malformed (it must be "" or start with a slash) IllegalStateException if the specified context path is already attached to an existing web application IOException if an input/output error was encountered during installation

isServiced

protected boolean isServiced(String name)
Invoke the check method on the deployer.

isWatchEnabled

public boolean isWatchEnabled()

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.

Parameters: msg ClusterMessage - the message received from the cluster

remove

public void remove(String contextPath, boolean undeploy)
Remove an existing web application, attached to the specified context path. If this application is successfully removed, a ContainerEvent of type REMOVE_EVENT will be sent to all registered listeners, with the removed Context as an argument. Deletes the web application war file and/or directory if they exist in the Host's appBase.

Parameters: contextPath The context path of the application to be removed undeploy boolean flag to remove web application from server

Throws: IllegalArgumentException if the specified context path is malformed (it must be "" or start with a slash) IllegalArgumentException if the specified context path does not identify a currently installed web application IOException if an input/output error occurs during removal

remove

protected void remove(String path)
Invoke the remove method on the deployer.

removeFactory

public void removeFactory(FileMessage msg)
Remove file (war) from messages)

Parameters: msg

removeServiced

protected void removeServiced(String name)
Invoke the check method on the deployer.

setCluster

public void setCluster(CatalinaCluster cluster)

setDeployDir

public void setDeployDir(String deployDir)

setProcessDeployFrequency

public void setProcessDeployFrequency(int processExpiresFrequency)
Set the watcher checks frequency.

Parameters: processExpiresFrequency the new manager checks frequency

setTempDir

public void setTempDir(String tempDir)

setWatchDir

public void setWatchDir(String watchDir)

setWatchEnabled

public void setWatchEnabled(boolean watchEnabled)

start

public void start()

stop

public void stop()

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

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.