Class AbstractLocalContainer

    • Constructor Detail

    • Method Detail

      • setOutput

        public void setOutput​(String output)
        Specified by:
        setOutput in interface RunnableContainer
        Parameters:
        output - the file to which the container's output will be logged to. Note that we're passing a String instead of a File because we want to leave the possibility of using URIs for specifying the home location.
      • setAppend

        public void setAppend​(boolean isAppend)
        Sets whether output of the container should be appended to an existing file, or the existing file should be truncated.
        Specified by:
        setAppend in interface RunnableContainer
        Parameters:
        isAppend - Whether output should be appended to or not
      • getOutput

        public String getOutput()
        Specified by:
        getOutput in interface RunnableContainer
        Returns:
        the file to which the container's output will be logged to. Note that we're returning a String instead of a File because we want to leave the possibility of using URIs for specifying the home location.
      • isAppend

        public boolean isAppend()
        Specified by:
        isAppend in interface RunnableContainer
        Returns:
        true if the output of the container should be appended to the output file or false otherwise
      • verify

        protected void verify()
        Verify required properties have been set before executing any action.
      • startInternal

        protected abstract void startInternal()
                                       throws Exception
        Installed and Embedded containers do not have the same signature for their doStart method. Thus we need to abstract it.
        Throws:
        Exception - if any error is raised during the container start
      • stopInternal

        protected abstract void stopInternal()
                                      throws Exception
        Installed and Embedded containers do not have the same signature for their doStop method. Thus we need to abstract it.
        Throws:
        Exception - if any error is raised during the container stop
      • forceStopInternal

        protected void forceStopInternal()
        Some containers may not fully stop and need to be forcibly stopped. This method should be overridden for containers that support forcibly stopping the container.
      • executePostStartTasks

        protected void executePostStartTasks()
                                      throws Exception
        Some containers may require some extra steps after startup.
        Throws:
        Exception - if any error is raised during these executions
      • start

        public final void start()
        Starts the container. It blocks until the container is fully started unless it doesn't start before the timeout period in which case an exception will be thrown.
        Specified by:
        start in interface RunnableContainer
      • stop

        public final void stop()
        Stops the container. It blocks until the container is fully stopped unless it doesn't stop before the timeout period in which case an exception will be thrown.
        Specified by:
        stop in interface RunnableContainer
      • restart

        public void restart()
        Restarts the container. It blocks until the container is fully stopped (if it not already is) and then blocks until the container is fully started unless it doesn't start before the timeout period in which case an exception will be thrown.
        Specified by:
        restart in interface RunnableContainer
      • waitForStarting

        protected void waitForStarting​(ContainerMonitor monitor)
                                throws InterruptedException
        Use container monitor to verify if the container is started.
        Parameters:
        monitor - Container monitor checking container availability.
        Throws:
        InterruptedException - if the thread sleep is interrupted.
      • waitForCompletion

        protected void waitForCompletion​(boolean waitForStarting)
                                  throws InterruptedException
        Ping the WAR CPC to verify if the container is started or stopped.
        Parameters:
        waitForStarting - if true then wait for container start, if false wait for container stop
        Throws:
        InterruptedException - if the thread sleep is interrupted
      • waitForPortShutdown

        protected void waitForPortShutdown​(int port,
                                           long deadline)
                                    throws InterruptedException
        Waits for the shutdown of the specified server port.
        Parameters:
        port - The port number.
        deadline - The deadline for the port to shutdown.
        Throws:
        InterruptedException - If the thread was interrupted while waiting for the port shutdown.
      • setTimeout

        public void setTimeout​(long timeout)
        Specified by:
        setTimeout in interface RunnableContainer
        Parameters:
        timeout - the timeout (in ms) after which we consider the container cannot be started or stopped.
      • getTimeout

        public long getTimeout()
        Specified by:
        getTimeout in interface RunnableContainer
        Returns:
        the timeout (in ms) after which we consider the container cannot be started or or stopped.
      • getState

        public State getState()
        Specified by:
        getState in interface Container
        Returns:
        the container state (Valid states are Container.STOPPED, Container.STARTED, Container.STARTING and Container.STOPPING)
      • setState

        protected void setState​(State state)
        Parameters:
        state - the container current state
      • setFileHandler

        public void setFileHandler​(FileHandler fileHandler)
        Specified by:
        setFileHandler in interface LocalContainer
        Parameters:
        fileHandler - the Cargo file utility class to use. This method is useful for unit testing with Mock objects as it can be passed a test file handler that doesn't perform any real file action.