Class 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
    Currently we only support deployment of WAR files since they are easier to send across the wire.
    Peter Rossbach
    • Field Detail

      • started

        protected boolean started
      • deployDir

        protected String deployDir
        Deployment directory.
      • tempDir

        protected String tempDir
        Temporary directory.
      • watchDir

        protected String watchDir
        Watch directory.
      • watchEnabled

        protected boolean watchEnabled
      • 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.
    • Constructor Detail

      • FarmWarDeployer

        public FarmWarDeployer()
    • Method Detail

      • start

        public void start()
                   throws Exception
        Description copied from interface: ClusterDeployer
        Start the cluster deployer, the owning container will invoke this
        Specified by:
        start in interface ClusterDeployer
        Exception - - if failure to start cluster
      • 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 class ClusterListener
        msg - ClusterMessage - the message received from the cluster
      • removeFactory

        public void removeFactory​(FileMessage msg)
        Remove file (war) from messages
        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:
        accept in class ClusterListener
        msg - ClusterMessage
        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_EVENT will be sent to all registered listeners, with the newly created Context as an argument.

        Specified by:
        install in interface ClusterDeployer
        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
        IllegalArgumentException - if the specified context name is malformed
        IllegalStateException - if the specified context name is already deployed
        IOException - 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 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
        contextName - The context name of the application to be removed
        undeploy - boolean flag to remove web application from server
        IllegalArgumentException - if the specified context name is malformed
        IllegalArgumentException - if the specified context name does not identify a currently installed web application
        IOException - if an input/output error occurs during removal
      • remove

        protected void remove​(String contextName)
                       throws Exception
        Invoke the remove method on the deployer.
        contextName - The context to remove
        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.
        dir - File object representing the directory to be deleted
      • check

        protected void check​(String name)
                      throws Exception
        Check a context for deployment operations.
        name - The context name
        Exception - Error invoking the deployer
      • isServiced

        protected boolean isServiced​(String name)
                              throws Exception
        Unused. Will be removed in Tomcat 10.1.x onwards.
        Verified if a context is being services.
        name - The context name
        true if the context is being serviced
        Exception - Error invoking the deployer
      • tryAddServiced

        protected boolean tryAddServiced​(String name)
                                  throws Exception
        Attempt to mark a context as being serviced
        name - The context name
        true if the application was marked as being serviced and false if the application was already marked as being serviced
        Exception - Error invoking the deployer
      • removeServiced

        protected void removeServiced​(String name)
                               throws Exception
        Mark a context as no longer being serviced.
        name - The context name
        Exception - Error invoking the deployer
      • 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()
        the frequency of watcher checks.
      • setProcessDeployFrequency

        public void setProcessDeployFrequency​(int processExpiresFrequency)
        Set the watcher checks frequency.
        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.
        from - copy from temp
        to - to host appBase directory
        true, copy successful
      • removeInvalidFileFactories

        protected void removeInvalidFileFactories()