Package org.codehaus.cargo.container.spi
Class AbstractLocalContainer
- java.lang.Object
-
- org.codehaus.cargo.util.log.LoggedObject
-
- org.codehaus.cargo.container.spi.AbstractContainer
-
- org.codehaus.cargo.container.spi.AbstractLocalContainer
-
- All Implemented Interfaces:
Container,RunnableContainer,LocalContainer,Loggable
- Direct Known Subclasses:
AbstractEmbeddedLocalContainer,AbstractInstalledLocalContainer
public abstract class AbstractLocalContainer extends AbstractContainer implements LocalContainer
Default container implementation that all local container implementations must extend.
-
-
Constructor Summary
Constructors Constructor Description AbstractLocalContainer(LocalConfiguration configuration)Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidexecutePostStartTasks()Some containers may require some extra steps after startup.protected voidforceStopInternal()Some containers may not fully stop and need to be forcibly stopped.LocalConfigurationgetConfiguration()FileHandlergetFileHandler()StringgetOutput()StategetState()longgetTimeout()booleanisAppend()voidrestart()Restarts the container.voidsetAppend(boolean isAppend)Sets whether output of the container should be appended to an existing file, or the existing file should be truncated.voidsetConfiguration(LocalConfiguration configuration)voidsetFileHandler(FileHandler fileHandler)voidsetOutput(String output)protected voidsetState(State state)voidsetTimeout(long timeout)voidstart()Starts the container.protected abstract voidstartInternal()Installed and Embedded containers do not have the same signature for theirdoStartmethod.voidstop()Stops the container.protected abstract voidstopInternal()Installed and Embedded containers do not have the same signature for theirdoStopmethod.protected voidverify()Verify required properties have been set before executing any action.protected voidwaitForCompletion(boolean waitForStarting)Ping the WAR CPC to verify if the container is started or stopped.protected voidwaitForPortShutdown(int port, long deadline)Waits for the shutdown of the specified server port.protected voidwaitForStarting(ContainerMonitor monitor)Use container monitor to verify if the container is started.-
Methods inherited from class org.codehaus.cargo.util.log.LoggedObject
getLogger, setLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.codehaus.cargo.container.Container
getCapability, getId, getName, getType
-
-
-
-
Constructor Detail
-
AbstractLocalContainer
public AbstractLocalContainer(LocalConfiguration configuration)
Default constructor.- Parameters:
configuration- the configuration to associate to this container. It can be changed later on by callingsetConfiguration(LocalConfiguration)
-
-
Method Detail
-
setOutput
public void setOutput(String output)
- Specified by:
setOutputin interfaceRunnableContainer- 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:
setAppendin interfaceRunnableContainer- Parameters:
isAppend- Whether output should be appended to or not
-
getOutput
public String getOutput()
- Specified by:
getOutputin interfaceRunnableContainer- 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:
isAppendin interfaceRunnableContainer- 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 ExceptionInstalled and Embedded containers do not have the same signature for theirdoStartmethod. Thus we need to abstract it.- Throws:
Exception- if any error is raised during the container start
-
stopInternal
protected abstract void stopInternal() throws ExceptionInstalled and Embedded containers do not have the same signature for theirdoStopmethod. 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 ExceptionSome 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:
startin interfaceRunnableContainer
-
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:
stopin interfaceRunnableContainer
-
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:
restartin interfaceRunnableContainer
-
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 InterruptedExceptionPing the WAR CPC to verify if the container is started or stopped.- Parameters:
waitForStarting- iftruethen wait for container start, iffalsewait for container stop- Throws:
InterruptedException- if the thread sleep is interrupted
-
waitForPortShutdown
protected void waitForPortShutdown(int port, long deadline) throws InterruptedExceptionWaits 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.
-
setConfiguration
public void setConfiguration(LocalConfiguration configuration)
- Specified by:
setConfigurationin interfaceLocalContainer- Parameters:
configuration- the local configuration implementation to use
-
getConfiguration
public LocalConfiguration getConfiguration()
- Specified by:
getConfigurationin interfaceLocalContainer- Returns:
- the local configuration to use
- See Also:
LocalContainer.setConfiguration(LocalConfiguration)
-
setTimeout
public void setTimeout(long timeout)
- Specified by:
setTimeoutin interfaceRunnableContainer- Parameters:
timeout- the timeout (in ms) after which we consider the container cannot be started or stopped.
-
getTimeout
public long getTimeout()
- Specified by:
getTimeoutin interfaceRunnableContainer- Returns:
- the timeout (in ms) after which we consider the container cannot be started or or stopped.
-
getState
public State getState()
-
setState
protected void setState(State state)
- Parameters:
state- the container current state
-
getFileHandler
public FileHandler getFileHandler()
- Specified by:
getFileHandlerin interfaceLocalContainer- Returns:
- the Cargo file utility class
-
setFileHandler
public void setFileHandler(FileHandler fileHandler)
- Specified by:
setFileHandlerin interfaceLocalContainer- 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.
-
-