org.otfeed.support
Class CommandRunner

java.lang.Object
  extended by org.otfeed.support.CommandRunner

public class CommandRunner
extends java.lang.Object

Class that runs a list of commands, then waits for the completion. Sometimes useful in scripts.


Constructor Summary
CommandRunner()
          Creates new CommandRunner.
CommandRunner(IConnectionFactory cf, java.util.List<ICommand> commands)
          Creates new CommandRunner from a given connection factory, with the given list of commands.
 
Method Summary
 java.util.List<ICommand> getCommandList()
          List of commands to execute.
 IConnectionFactory getConnectionFactory()
          Connection factory to use.
 IConnectionStateListener getConnectionStateListener()
          Listener that watches connection-level events.
 void runCommands()
          Main method: connects to the server and executes all commands.
 void runCommands(long timeout)
          Main method: connects to the server and executes all commands.
 void setCommandList(java.util.List<ICommand> val)
          Sets list of commands.
 void setConnectionFactory(IConnectionFactory val)
          Sets the connection factory.
 void setConnectionStateListener(IConnectionStateListener val)
          Sets connection state listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandRunner

public CommandRunner()
Creates new CommandRunner.


CommandRunner

public CommandRunner(IConnectionFactory cf,
                     java.util.List<ICommand> commands)
Creates new CommandRunner from a given connection factory, with the given list of commands.

Parameters:
cf - connection factory.
commands - list of commands.
Method Detail

getConnectionFactory

public IConnectionFactory getConnectionFactory()
Connection factory to use.

Returns:
connection factory.

setConnectionFactory

public void setConnectionFactory(IConnectionFactory val)
Sets the connection factory.

Parameters:
val - connection factory.

getCommandList

public java.util.List<ICommand> getCommandList()
List of commands to execute. If empty, the runner will just do connect, login, and disconnect.

Returns:
lsit of commands.

setCommandList

public void setCommandList(java.util.List<ICommand> val)
Sets list of commands.

Parameters:
val - list of commands.

getConnectionStateListener

public IConnectionStateListener getConnectionStateListener()
Listener that watches connection-level events. Defaul is an instance of SimpleConnectionStateListener, which will print the events to the System.err.

Returns:
connection state listener.

setConnectionStateListener

public void setConnectionStateListener(IConnectionStateListener val)
Sets connection state listener.

Parameters:
val - connection state listener.

runCommands

public void runCommands()
                 throws java.lang.Exception
Main method: connects to the server and executes all commands. Blocks untill the processing is finished.

Throws:
java.lang.Exception - is something is not configured correctly, or something goes extremely wrong at the runtime.

runCommands

public void runCommands(long timeout)
                 throws java.lang.Exception
Main method: connects to the server and executes all commands. Blocks for the given timeout value waiting for the requests to complete. If timeout expires, the connection is shutdown, all pending requests are aborted with error.

Parameters:
timeout - how long to wait for the request to complete (in milliseconds).
Throws:
java.lang.Exception - if something is not configured correctly, or something goes extremely wrong at the runtime.


Copyright © 2007 Mike Kroutikov. All Rights Reserved.