com.sun.sgs.impl.util
Class KernelCallable<R>

java.lang.Object
  extended by com.sun.sgs.impl.util.AbstractKernelRunnable
      extended by com.sun.sgs.impl.util.KernelCallable<R>
Type Parameters:
R - the type of the result (the return value of the call method)
All Implemented Interfaces:
KernelRunnable, Callable<R>

public abstract class KernelCallable<R>
extends AbstractKernelRunnable
implements Callable<R>

An abstract utility class to run a transactional task that returns a value. A subclass of this class must implement the abstract call method which is invoked in a transaction.

Here's an example of running a KernelCallable that returns a boolean value:

 boolean result = KernelCallable.call(
        new KernelCallable<Boolean>("MyKernelCallable") {
            public Boolean call() {
                return ...;
            }
        },
        txnScheduler, taskOwner);
 


Constructor Summary
KernelCallable(String name)
          Constructs an instance with the specified name.
 
Method Summary
static
<R> R
call(KernelCallable<R> callable, TransactionScheduler txnScheduler, Identity taskOwner)
          Runs the specified callable (by invoking its call method) in a transaction using the specified txnScheduler and taskOwner and returns the result.
 void run()
          Runs this KernelRunnable.
 
Methods inherited from class com.sun.sgs.impl.util.AbstractKernelRunnable
getBaseTaskType, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.Callable
call
 

Constructor Detail

KernelCallable

public KernelCallable(String name)
Constructs an instance with the specified name.

Parameters:
name - a descriptive name (or null) for use in the toString method
Method Detail

run

public void run()
         throws Exception
Runs this KernelRunnable. If this is run by a Scheduler that support re-try logic, and if an Exception is thrown that implements ExceptionRetryStatus then the Scheduler will consult the shouldRetry method of the Exception to see if this task should be re-run.

This implementation invokes the call method of this instance and sets the result.

Specified by:
run in interface KernelRunnable
Throws:
IllegalStateException - if this task has already been successfully run via an invocation of the call method
Exception - if any error occurs

call

public static <R> R call(KernelCallable<R> callable,
                         TransactionScheduler txnScheduler,
                         Identity taskOwner)
              throws Exception
Runs the specified callable (by invoking its call method) in a transaction using the specified txnScheduler and taskOwner and returns the result. The specified callable can only be used once.

Type Parameters:
R - the return type of the KernelCallable
Parameters:
callable - a callable to invoke
txnScheduler - a transaction scheduler
taskOwner - an identity for the task's owner
Returns:
the result of executing the callable
Throws:
Exception - if running the specified callable throws an Exception

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved