orc.runtime
Class Kilim

java.lang.Object
  extended by orc.runtime.Kilim

public final class Kilim
extends java.lang.Object

Utility methods for Kilim.

Author:
quark

Nested Class Summary
static class Kilim.PausableCallable<V>
          Pausable computation which returns a value.
static class Kilim.Promise<V>
          Wrap a callable in a lazy, concurrency-safe promise.
 
Field Summary
static java.lang.Object signal
          Kilim mailboxes can't accomodate null values, so this acts as a basic signal or unit value when necessary.
 
Constructor Summary
Kilim()
           
 
Method Summary
static void exit()
           
static void runPausable(Token caller, Kilim.PausableCallable<? extends java.lang.Object> thunk)
          Utility method to run a pausable computation which generates a value for a token.
static
<V> V
runThreaded(java.util.concurrent.Callable<V> thunk)
          Spawn a thread to compute a value.
static void runThreaded(java.lang.Runnable thunk)
          Spawn a thread asynchronously.
static
<V> void
runThreaded(Token caller, java.util.concurrent.Callable<V> thunk)
          Spawn a thread to compute a value for a token.
static void startEngine(int kilimThreads, int siteThreads)
          Initialize Kilim state for a new job.
static void stopEngine()
          Shutdown Kilim threads created for the current job.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

signal

public static final java.lang.Object signal
Kilim mailboxes can't accomodate null values, so this acts as a basic signal or unit value when necessary.

Constructor Detail

Kilim

public Kilim()
Method Detail

startEngine

public static void startEngine(int kilimThreads,
                               int siteThreads)
Initialize Kilim state for a new job.


stopEngine

public static void stopEngine()
Shutdown Kilim threads created for the current job.


runThreaded

public static <V> V runThreaded(java.util.concurrent.Callable<V> thunk)
                     throws kilim.Pausable,
                            java.lang.Exception
Spawn a thread to compute a value. This is a common idiom in a Kilim computation, when you need to make blocking calls.

FIXME: I ran into about 5 different weird Kilim bugs trying to write this function; the current structure is not ideal but it was the only one which worked.

Throws:
kilim.Pausable
java.lang.Exception

runThreaded

public static <V> void runThreaded(Token caller,
                                   java.util.concurrent.Callable<V> thunk)
Spawn a thread to compute a value for a token.

See Also:
runThreaded(Callable)

runThreaded

public static void runThreaded(java.lang.Runnable thunk)
                        throws kilim.Pausable
Spawn a thread asynchronously. If you want to block until the thread is complete, use runThreaded(Callable). The point of this over new Thread() { ... }.start() is that this uses a thread pool.

Parameters:
thunk -
Throws:
kilim.Pausable

runPausable

public static void runPausable(Token caller,
                               Kilim.PausableCallable<? extends java.lang.Object> thunk)
Utility method to run a pausable computation which generates a value for a token.

Parameters:
caller - token to return the value to
thunk - computation returning a value

exit

public static void exit()
                 throws kilim.Pausable
Throws:
kilim.Pausable