net.java.dev.vcc.api
Class Command<RESULT>

java.lang.Object
  extended by net.java.dev.vcc.api.Command<RESULT>
Type Parameters:
RESULT - the type of result from this command. If the command does not return a result per-se, but can either succeed or fail, then the result type should be Success and failure will be indicated by throwing an exception.
All Implemented Interfaces:
java.util.concurrent.Future<RESULT>
Direct Known Subclasses:
Clone, Delete, PauseComputer, RestartComputer, StartComputer, StopComputer, SuspendComputer, TakeSnapshot

public abstract class Command<RESULT>
extends java.lang.Object
implements java.util.concurrent.Future<RESULT>

Represents an operation to be performed. All instances of this class must comply with the JavaBeans specification with the following modification: Setters will throw an IllegalStateException if the command has been submitted, i.e. a setFoo method would look like this

 public void setFoo(Foo foo) {
     checkNotSubmitted();
     this.foo = foo;
 }
 

When a Command subclass is being extended, any new parameters should have default values which ensure that older clients which are unaware of the new parameters will still achieve the same behaviour.


Constructor Summary
Command()
           
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
          
protected  void checkNotSubmitted()
          Throws an IllegalStateException if this command has been submitted.
protected  void checkSubmitted()
          Throws an IllegalStateException if this command has not been submitted.
 RESULT get()
          
 RESULT get(long timeout, java.util.concurrent.TimeUnit unit)
          
 boolean isCancelled()
          
 boolean isDone()
          
 boolean isSubmitted()
          Returns true if the command has been submitted.
 void setSubmitted(java.util.concurrent.Future<RESULT> delegate)
          This method is called by an SPI when the command has been submitted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Command

public Command()
Method Detail

checkNotSubmitted

protected final void checkNotSubmitted()
Throws an IllegalStateException if this command has been submitted.

Throws:
java.lang.IllegalStateException - if this command has been submitted.

checkSubmitted

protected final void checkSubmitted()
Throws an IllegalStateException if this command has not been submitted.

Throws:
java.lang.IllegalStateException - if this command has not been submitted.

setSubmitted

public final void setSubmitted(java.util.concurrent.Future<RESULT> delegate)
This method is called by an SPI when the command has been submitted.

Parameters:
delegate - The future representing the command.

cancel

public final boolean cancel(boolean mayInterruptIfRunning)

Specified by:
cancel in interface java.util.concurrent.Future<RESULT>

isSubmitted

public final boolean isSubmitted()
Returns true if the command has been submitted.

Returns:
true if the command has been submitted.

isCancelled

public final boolean isCancelled()

Specified by:
isCancelled in interface java.util.concurrent.Future<RESULT>

isDone

public final boolean isDone()

Specified by:
isDone in interface java.util.concurrent.Future<RESULT>

get

public final RESULT get()
                 throws java.lang.InterruptedException,
                        java.util.concurrent.ExecutionException

Specified by:
get in interface java.util.concurrent.Future<RESULT>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException

get

public final RESULT get(long timeout,
                        java.util.concurrent.TimeUnit unit)
                 throws java.lang.InterruptedException,
                        java.util.concurrent.ExecutionException,
                        java.util.concurrent.TimeoutException

Specified by:
get in interface java.util.concurrent.Future<RESULT>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException


Copyright © 2009. All Rights Reserved.