org.apache.catalina.cluster.deploy
Class FarmWarDeployer

java.lang.Object
  extended byorg.apache.catalina.cluster.deploy.FarmWarDeployer
All Implemented Interfaces:
ClusterDeployer, FileChangeListener, MessageListener

public class FarmWarDeployer
extends java.lang.Object
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: 790340 $
Author:
Filip Hanik, Peter Rossbach

Field Summary
protected  java.io.File appBase
          The host appBase.
protected  CatalinaCluster cluster
           
protected  java.io.File configBase
          Path where context descriptors should be deployed.
protected  java.lang.String deployDir
           
protected  java.util.HashMap fileFactories
           
protected  Host host
          The associated host.
static org.apache.commons.logging.Log log
           
protected  javax.management.MBeanServer mBeanServer
          MBean server.
protected  javax.management.ObjectName oname
          The associated deployer ObjectName.
protected  int processDeployFrequency
          Frequency of the Farm watchDir check.
protected  boolean started
           
protected  java.lang.String tempDir
           
protected  java.lang.String watchDir
           
protected  boolean watchEnabled
           
protected  WarWatcher watcher
           
 
Constructor Summary
FarmWarDeployer()
           
 
Method Summary
 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
protected  void addServiced(java.lang.String name)
          Invoke the check method on the deployer.
 void backgroundProcess()
          call from container Background Process
protected  void check(java.lang.String name)
          Invoke the check method on the deployer.
 void cleanDeployDir()
           
protected  boolean copy(java.io.File from, java.io.File to)
          Copy a file to the specified temp directory.
 boolean equals(java.lang.Object listener)
           
 void fileModified(java.io.File newWar)
           
 void fileRemoved(java.io.File removeWar)
           
protected  java.io.File getAppBase()
          Return a File object representing the "application root" directory for our associated Host.
 CatalinaCluster getCluster()
          Returns the cluster the cluster deployer is associated with
protected  java.lang.String getConfigFile(java.lang.String path)
          Given a context path, get the config file name.
protected  java.lang.String getContextName(java.io.File war)
          Create a context path from war
 java.lang.String getDeployDir()
           
protected  java.lang.String getDocBase(java.lang.String path)
          Given a context path, get the config file name.
 FileMessageFactory getFactory(FileMessage msg)
          create factory for all transported war files
 java.lang.String getInfo()
          Return descriptive information about this deployer implementation and the corresponding version number, in the format <description>/<version>.
 int getProcessDeployFrequency()
          Return the frequency of watcher checks.
 java.lang.String getTempDir()
           
 java.lang.String getWatchDir()
           
 boolean getWatchEnabled()
           
 int hashCode()
           
 void install(java.lang.String contextPath, java.net.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  boolean isServiced(java.lang.String name)
          Invoke the check method on the deployer.
 boolean isWatchEnabled()
           
 void messageReceived(ClusterMessage msg)
          Callback from the cluster, when a message is received, The cluster will broadcast it invoking the messageReceived on the receiver.
protected  void remove(java.lang.String path)
          Invoke the remove method on the deployer.
 void remove(java.lang.String contextPath, boolean undeploy)
          Remove an existing web application, attached to the specified context path.
 void removeFactory(FileMessage msg)
          Remove file (war) from messages)
protected  void removeServiced(java.lang.String name)
          Invoke the check method on the deployer.
 void setCluster(CatalinaCluster cluster)
          Associates the cluster deployer with a cluster
 void setDeployDir(java.lang.String deployDir)
           
 void setProcessDeployFrequency(int processExpiresFrequency)
          Set the watcher checks frequency.
 void setTempDir(java.lang.String tempDir)
           
 void setWatchDir(java.lang.String watchDir)
           
 void setWatchEnabled(boolean watchEnabled)
           
 void start()
          Start the cluster deployer, the owning container will invoke this
 void stop()
          Stops the cluster deployer, the owning container will invoke this
protected  void undeployDir(java.io.File dir)
          Delete the specified directory, including all of its contents and subdirectories recursively.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static org.apache.commons.logging.Log log

cluster

protected CatalinaCluster cluster

started

protected boolean started

fileFactories

protected java.util.HashMap fileFactories

deployDir

protected java.lang.String deployDir

tempDir

protected java.lang.String tempDir

watchDir

protected java.lang.String watchDir

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 backgrondProcess calls (ie, the lower the amount, the most often the checks will occur).


configBase

protected java.io.File configBase
Path where context descriptors should be deployed.


host

protected Host host
The associated host.


appBase

protected java.io.File appBase
The host appBase.


mBeanServer

protected javax.management.MBeanServer mBeanServer
MBean server.


oname

protected javax.management.ObjectName oname
The associated deployer ObjectName.

Constructor Detail

FarmWarDeployer

public FarmWarDeployer()
Method Detail

getInfo

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


start

public void start()
           throws java.lang.Exception
Description copied from interface: ClusterDeployer
Start the cluster deployer, the owning container will invoke this

Specified by:
start in interface ClusterDeployer
Throws:
java.lang.Exception - - if failure to start cluster

stop

public void stop()
          throws LifecycleException
Description copied from interface: ClusterDeployer
Stops the cluster deployer, the owning container will invoke this

Specified by:
stop in interface ClusterDeployer
Throws:
LifecycleException

cleanDeployDir

public void cleanDeployDir()

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:
messageReceived in interface MessageListener
Parameters:
msg - ClusterMessage - the message received from the cluster

getFactory

public FileMessageFactory getFactory(FileMessage msg)
                              throws java.io.FileNotFoundException,
                                     java.io.IOException
create factory for all transported war files

Parameters:
msg -
Returns:
Factory for all app message (war files)
Throws:
java.io.FileNotFoundException
java.io.IOException

removeFactory

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

Parameters:
msg -

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:
accept in interface MessageListener
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(java.lang.String contextPath,
                    java.net.URL war)
             throws java.io.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 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.

Specified by:
install in interface ClusterDeployer
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:
java.lang.IllegalArgumentException - if the specified context path is malformed (it must be "" or start with a slash)
java.lang.IllegalStateException - if the specified context path is already attached to an existing web application
java.io.IOException - if an input/output error was encountered during installation

remove

public void remove(java.lang.String contextPath,
                   boolean undeploy)
            throws java.io.IOException
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.

Specified by:
remove in interface ClusterDeployer
Parameters:
contextPath - The context path of the application to be removed
undeploy - boolean flag to remove web application from server
Throws:
java.lang.IllegalArgumentException - if the specified context path is malformed (it must be "" or start with a slash)
java.lang.IllegalArgumentException - if the specified context path does not identify a currently installed web application
java.io.IOException - if an input/output error occurs during removal

fileModified

public void fileModified(java.io.File newWar)
Specified by:
fileModified in interface FileChangeListener

fileRemoved

public void fileRemoved(java.io.File removeWar)
Specified by:
fileRemoved in interface FileChangeListener

getContextName

protected java.lang.String getContextName(java.io.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 ''

getConfigFile

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


getDocBase

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


getAppBase

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


remove

protected void remove(java.lang.String path)
               throws java.lang.Exception
Invoke the remove method on the deployer.

Throws:
java.lang.Exception

undeployDir

protected 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

backgroundProcess

public void backgroundProcess()
Description copied from interface: ClusterDeployer
call from container Background Process

Specified by:
backgroundProcess in interface ClusterDeployer

check

protected void check(java.lang.String name)
              throws java.lang.Exception
Invoke the check method on the deployer.

Throws:
java.lang.Exception

isServiced

protected boolean isServiced(java.lang.String name)
                      throws java.lang.Exception
Invoke the check method on the deployer.

Throws:
java.lang.Exception

addServiced

protected void addServiced(java.lang.String name)
                    throws java.lang.Exception
Invoke the check method on the deployer.

Throws:
java.lang.Exception

removeServiced

protected void removeServiced(java.lang.String name)
                       throws java.lang.Exception
Invoke the check method on the deployer.

Throws:
java.lang.Exception

getCluster

public CatalinaCluster getCluster()
Description copied from interface: MessageListener
Returns the cluster the cluster deployer is associated with

Specified by:
getCluster in interface MessageListener
Returns:
CatalinaCluster

setCluster

public void setCluster(CatalinaCluster cluster)
Description copied from interface: MessageListener
Associates the cluster deployer with a cluster

Specified by:
setCluster in interface MessageListener
Parameters:
cluster - CatalinaCluster

equals

public boolean equals(java.lang.Object listener)
Specified by:
equals in interface MessageListener

hashCode

public int hashCode()
Specified by:
hashCode in interface MessageListener

getDeployDir

public java.lang.String getDeployDir()

setDeployDir

public void setDeployDir(java.lang.String deployDir)

getTempDir

public java.lang.String getTempDir()

setTempDir

public void setTempDir(java.lang.String tempDir)

getWatchDir

public java.lang.String getWatchDir()

setWatchDir

public void setWatchDir(java.lang.String watchDir)

isWatchEnabled

public boolean isWatchEnabled()

getWatchEnabled

public boolean getWatchEnabled()

setWatchEnabled

public void setWatchEnabled(boolean watchEnabled)

getProcessDeployFrequency

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


setProcessDeployFrequency

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

Parameters:
processExpiresFrequency - the new manager checks frequency

copy

protected 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


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