net.sf.asyncobjects.util
Class AsyncProcess<R>

java.lang.Object
  extended by net.sf.asyncobjects.util.AsyncProcess<R>
Type Parameters:
R - a result type

public abstract class AsyncProcess<R>
extends Object

This utility class represents a simple asynchronous operation. It is mostly used to implement asynchronous loops. It exists to compensate problems with tail recursion implementation.

Author:
const

Nested Class Summary
protected  class AsyncProcess.ProcessWhen<I>
          A utility when variant that fails process (using failure(Throwable)) if promise is smashed or body is smashed.
 
Constructor Summary
protected AsyncProcess()
          A construct for processs
 
Method Summary
protected  void failure(Throwable problem)
          Subclasses should call this method to indicate that process failed.
protected  void onFailure(Throwable problem)
          This method is called when process completed unsuccessfully.
protected  void onSuccess(R value)
          This method is called when process completed successfully.
 Promise<R> promise()
           
protected abstract  void run()
          Process body.
protected  void success(Promise<R> value)
          Subclasses should call this method to indicate that process finished successfully.
protected  void success(R value)
          Subclasses should call this method to indicate that process finished successfully.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncProcess

protected AsyncProcess()
A construct for processs

Method Detail

run

protected abstract void run()
                     throws Throwable
Process body. This method should be implemented in subclasses

Throws:
Throwable - in case of any problem

success

protected final void success(R value)
Subclasses should call this method to indicate that process finished successfully.

Parameters:
value - a value of the process

success

protected final void success(Promise<R> value)
Subclasses should call this method to indicate that process finished successfully.

Parameters:
value - a value of the process

failure

protected final void failure(Throwable problem)
Subclasses should call this method to indicate that process failed.

Parameters:
problem - a problem associated with process

promise

public final Promise<R> promise()
Returns:
a promise for process result

onFailure

protected void onFailure(Throwable problem)
This method is called when process completed unsuccessfully. This method does not affect generic process flow.

Parameters:
problem - a problem of the process

onSuccess

protected void onSuccess(R value)
This method is called when process completed successfully. This method does not affect generic process flow.

Parameters:
value - a value of the process


Copyright © 2002-2007 Constantine Plotnikov. All Rights Reserved.