net.sf.asyncobjects.util
Class Serialized<T>

java.lang.Object
  extended by net.sf.asyncobjects.util.Serialized<T>
Type Parameters:
T - Value type
All Implemented Interfaces:
ExplicitSharing

public abstract class Serialized<T>
extends Object
implements ExplicitSharing

This class respresents action serialized over request queue. The class is basically an asynchronous version of Java's "synchronized" statement. The request queue ensures that instaces of this class are executed in FIFO order. It is used like the following:

 class Test {
        RequestQueue queue = new RequestQueue();
 
        public Object method1() {
                return new Serialized(queue) {
                        protected Object run() {
                                // do actions of method 1
                                return promiseOrValue;
                        }
                }.start();
        }
 
        public Object method2() {
                return new Serialized(queue) {
                        protected Object run() {
                                // do actions of method 2
                                return promiseOrValue;
                        }
                }.start();
        }
 }
 

In the example above, only one method invocation could be active at the same time even if actions will spawn several turns.


Constructor Summary
Serialized(RequestQueue queue)
          A constructor from queue
 
Method Summary
 Promise<T> promise()
          Return a promise for action execution.
protected abstract  Promise<? extends T> run()
          Action that should be queue on request queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Serialized

public Serialized(RequestQueue queue)
A constructor from queue

Parameters:
queue - a request queue
Method Detail

run

protected abstract Promise<? extends T> run()
                                     throws Throwable
Action that should be queue on request queue

Returns:
result of operation
Throws:
Throwable - if there is a problem during running action

promise

public final Promise<T> promise()
Return a promise for action execution.

Returns:
result of action or promise for it.


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