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 void
executePostStartTasks()
Some containers may require some extra steps after startup.protected void
forceStopInternal()
Some containers may not fully stop and need to be forcibly stopped.LocalConfiguration
getConfiguration()
FileHandler
getFileHandler()
String
getOutput()
State
getState()
long
getTimeout()
boolean
isAppend()
void
restart()
Restarts the container.void
setAppend(boolean isAppend)
Sets whether output of the container should be appended to an existing file, or the existing file should be truncated.void
setConfiguration(LocalConfiguration configuration)
void
setFileHandler(FileHandler fileHandler)
void
setOutput(String output)
protected void
setState(State state)
void
setTimeout(long timeout)
void
start()
Starts the container.protected abstract void
startInternal()
Installed and Embedded containers do not have the same signature for theirdoStart
method.void
stop()
Stops the container.protected abstract void
stopInternal()
Installed and Embedded containers do not have the same signature for theirdoStop
method.protected void
verify()
Verify required properties have been set before executing any action.protected void
waitForCompletion(boolean waitForStarting)
Ping the WAR CPC to verify if the container is started or stopped.protected void
waitForPortShutdown(int port, long deadline)
Waits for the shutdown of the specified server port.protected void
waitForStarting(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:
setOutput
in 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:
setAppend
in interfaceRunnableContainer
- Parameters:
isAppend
- Whether output should be appended to or not
-
getOutput
public String getOutput()
- Specified by:
getOutput
in 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:
isAppend
in 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 Exception
Installed and Embedded containers do not have the same signature for theirdoStart
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 theirdoStop
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 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:
stop
in 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:
restart
in 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 InterruptedException
Ping the WAR CPC to verify if the container is started or stopped.- Parameters:
waitForStarting
- iftrue
then wait for container start, iffalse
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.
-
setConfiguration
public void setConfiguration(LocalConfiguration configuration)
- Specified by:
setConfiguration
in interfaceLocalContainer
- Parameters:
configuration
- the local configuration implementation to use
-
getConfiguration
public LocalConfiguration getConfiguration()
- Specified by:
getConfiguration
in interfaceLocalContainer
- Returns:
- the local configuration to use
- See Also:
LocalContainer.setConfiguration(LocalConfiguration)
-
setTimeout
public void setTimeout(long timeout)
- Specified by:
setTimeout
in interfaceRunnableContainer
- 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 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:
getFileHandler
in interfaceLocalContainer
- Returns:
- the Cargo file utility class
-
setFileHandler
public void setFileHandler(FileHandler fileHandler)
- Specified by:
setFileHandler
in 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.
-
-