org.codehaus.cargo.container.spi
Class AbstractLocalContainer

java.lang.Object
  extended by org.codehaus.cargo.util.log.LoggedObject
      extended by org.codehaus.cargo.container.spi.AbstractContainer
          extended by 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.

Version:
$Id: AbstractLocalContainer.java 1866 2009-02-09 22:33:16Z adriancole $

Constructor Summary
AbstractLocalContainer(LocalConfiguration configuration)
          Default constructor.
 
Method Summary
 LocalConfiguration getConfiguration()
          
 FileHandler getFileHandler()
           
 String getOutput()
          
 State getState()
          
 long getTimeout()
          
 boolean isAppend()
          
 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 their doStart method.
 void stop()
          Stops the container.
protected abstract  void stopInternal()
          Installed and Embedded containers do not have the same signature for their doStop 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.
 
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
 
Methods inherited from interface org.codehaus.cargo.util.log.Loggable
getLogger, setLogger
 

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 calling setConfiguration(LocalConfiguration)
Method Detail

setOutput

public final 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.
See Also:
RunnableContainer.setOutput(String)

setAppend

public final 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
See Also:
RunnableContainer.setAppend(boolean)

getOutput

public final 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.
See Also:
RunnableContainer.getOutput()

isAppend

public final 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
See Also:
RunnableContainer.isAppend()

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

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
See Also:
RunnableContainer.start()

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
See Also:
RunnableContainer.stop()

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

setConfiguration

public void setConfiguration(LocalConfiguration configuration)

Specified by:
setConfiguration in interface LocalContainer
Parameters:
configuration - the local configuration implementation to use
See Also:
LocalContainer.setConfiguration(LocalConfiguration)

getConfiguration

public LocalConfiguration getConfiguration()

Specified by:
getConfiguration in interface LocalContainer
Returns:
the local configuration to use
See Also:
LocalContainer.getConfiguration()

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.
See Also:
RunnableContainer.setTimeout(long)

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.
See Also:
RunnableContainer.getTimeout()

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)
See Also:
Container.getState()

setState

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

getFileHandler

public FileHandler getFileHandler()
Specified by:
getFileHandler in interface LocalContainer
Returns:
the Cargo file utility class

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.


Copyright © 2004-2012 Codehaus. All Rights Reserved.