org.keridwen.core.messaging.internal
Class DefaultSupervisor<ReturnType>

java.lang.Object
  extended by org.keridwen.core.messaging.internal.DefaultSupervisor<ReturnType>
Type Parameters:
ReturnType - the type of object returned by the command.
All Implemented Interfaces:
Controllable, Progressable, Supervisor<ReturnType>

public class DefaultSupervisor<ReturnType>
extends Object
implements Supervisor<ReturnType>

A DefaultSupervisor controls and monitors a Command.


Constructor Summary
DefaultSupervisor(Future<ReturnType> aFuture, Command<ReturnType,?> aCommand)
          Builds a command Supervisor for the given command.
 
Method Summary
 void addControllableListener(ControllableListener listener)
           
 void addProgressableListener(ProgressableListener listener)
           
 void clearControllableListener()
           
 void clearProgressableListener()
           
 ReturnType get()
          Waits if necessary for the computation to complete, and then retrieves its result.
 ReturnType get(long timeout, TimeUnit unit)
          Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
 String getCommandDescription()
          Returns the localized Command description.
 String getCommandLabel()
          Returns the localized Command name.
 int getProgress()
           
 ControllableState getState()
           
 void interrupt()
           
 boolean isDetermined()
           
 boolean isInterrupted()
           
 boolean isInterruptible()
           
 boolean isPausable()
           
 void killCommand()
           
 void pause()
           
 void removeControllableListener(ControllableListener listener)
           
 void removeProgressableListener(ProgressableListener listener)
           
 void resume()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultSupervisor

public DefaultSupervisor(Future<ReturnType> aFuture,
                         Command<ReturnType,?> aCommand)
Builds a command Supervisor for the given command.

Parameters:
aFuture - the future to control
aCommand - the command to monitor.
Method Detail

get

public final ReturnType get(long timeout,
                            TimeUnit unit)
                     throws InterruptedException,
                            ExecutionException,
                            TimeoutException
Description copied from interface: Supervisor
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Specified by:
get in interface Supervisor<ReturnType>
Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
the computed result
Throws:
InterruptedException - if the current thread was interrupted while waiting
ExecutionException - if the computation threw an exception
TimeoutException - if the wait timed out

get

public final ReturnType get()
                     throws InterruptedException,
                            ExecutionException
Description copied from interface: Supervisor
Waits if necessary for the computation to complete, and then retrieves its result.

Specified by:
get in interface Supervisor<ReturnType>
Returns:
the computed result
Throws:
InterruptedException - if the current thread was interrupted while waiting
ExecutionException - if the computation threw an exception

getProgress

public final int getProgress()
Specified by:
getProgress in interface Progressable

getState

public final ControllableState getState()
Specified by:
getState in interface Controllable
Specified by:
getState in interface Progressable

getCommandLabel

public final String getCommandLabel()
Description copied from interface: Supervisor
Returns the localized Command name.

Specified by:
getCommandLabel in interface Supervisor<ReturnType>
Returns:
the command name

getCommandDescription

public final String getCommandDescription()
Description copied from interface: Supervisor
Returns the localized Command description.

Specified by:
getCommandDescription in interface Supervisor<ReturnType>
Returns:
the command description

interrupt

public final void interrupt()
Specified by:
interrupt in interface Controllable

pause

public final void pause()
Specified by:
pause in interface Controllable

resume

public final void resume()
Specified by:
resume in interface Controllable

isInterrupted

public final boolean isInterrupted()
Specified by:
isInterrupted in interface Controllable

isInterruptible

public final boolean isInterruptible()
Specified by:
isInterruptible in interface Controllable

addProgressableListener

public final void addProgressableListener(ProgressableListener listener)
Specified by:
addProgressableListener in interface Progressable

removeProgressableListener

public final void removeProgressableListener(ProgressableListener listener)
Specified by:
removeProgressableListener in interface Progressable

isPausable

public final boolean isPausable()
Specified by:
isPausable in interface Controllable

addControllableListener

public final void addControllableListener(ControllableListener listener)
Specified by:
addControllableListener in interface Controllable

removeControllableListener

public final void removeControllableListener(ControllableListener listener)
Specified by:
removeControllableListener in interface Controllable

clearControllableListener

public final void clearControllableListener()
Specified by:
clearControllableListener in interface Controllable

isDetermined

public final boolean isDetermined()
Specified by:
isDetermined in interface Progressable

clearProgressableListener

public final void clearProgressableListener()
Specified by:
clearProgressableListener in interface Progressable

killCommand

public void killCommand()
Specified by:
killCommand in interface Supervisor<ReturnType>


Copyright © 2010-2013 Artenum. All Rights Reserved.