Errai 3.0.1-SNAPSHOT

org.jboss.errai.ioc.client.container.async
Class AsyncBeanQuery

java.lang.Object
  extended by org.jboss.errai.ioc.client.container.async.AsyncBeanQuery

public class AsyncBeanQuery
extends Object

An AsyncBeanQuery is used for querying more than one bean at a time, and then orchestrating a unit of work to happen only after all of the beans in the query have been successfully loaded.

For instance, you may need to load two or more beans dynamically from the bean manager in order to accomplish some task. Instead of chaining a series of callbacks, which can become difficult to understand and maintain, you can instead construct a query for the set of beans you need.

Example:


 AsyncBeanQuery beanQuery = new AsyncBeanQuery();
 final AsyncBeanFuture beanAFuture = beanQuery.load(BeanA.class);
 final AsyncBeanFuture beanBFuture = beanQuery.load(BeanB.class);
 

beanQuery.query(new Runnable() { public void run() { BeanA beanA = beanAFuture.get(); BeanB beanB = beanBFuture.get(); // do some work. } });

In the above example, the Runnable passed to query(Runnable) will be executed only after all the beans requested with the previous load(AsyncBeanDef) calls have been satisfied.

Since:
3.0
Author:
Mike Brock

Constructor Summary
AsyncBeanQuery()
           
 
Method Summary
 void cancelQuery()
          Cancels the query if it has not yet returned.
<T> AsyncBeanFuture<T>
load(AsyncBeanDef<T> beanDef)
          Requests that the bean described by the specified AsyncBeanDef is loaded.
<T> AsyncBeanFuture<T>
load(Class<T> type)
          Requests that the specified bean of the specified is loaded.
<T> AsyncBeanFuture<T>
load(Class<T> type, Annotation... qualifiers)
          Requests that the specified bean of the specified and is loaded.
<T> AsyncBeanFuture<T>
loadNew(AsyncBeanDef<T> beanDef)
          Requests that a new instance of the bean described by the specified AsyncBeanDef is loaded.
<T> AsyncBeanFuture<T>
loadNew(Class<T> type)
          Requests that a new instance specified bean of the specified is loaded.
<T> AsyncBeanFuture<T>
loadNew(Class<T> type, Annotation... qualifiers)
          Requests that a new instance of specified bean of the specified and is loaded.
 void query(Runnable finishCallback)
          Initiates the constructed query based on load(AsyncBeanDef) and loadNew(AsyncBeanDef) calls made prior to calling this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncBeanQuery

public AsyncBeanQuery()
Method Detail

load

public <T> AsyncBeanFuture<T> load(Class<T> type)
Requests that the specified bean of the specified is loaded.

Type Parameters:
T - the type of bean to be loaded.
Parameters:
type - the type of the bean to be loaded. See: AsyncBeanManagerImpl.lookupBean(Class, java.lang.annotation.Annotation...)
Returns:
an AsyncBeanFuture which will house the instance of the bean once it is loaded.

load

public <T> AsyncBeanFuture<T> load(Class<T> type,
                                   Annotation... qualifiers)
Requests that the specified bean of the specified and is loaded.

Type Parameters:
T - the type of bean to be loaded.
Parameters:
type - the type of the bean to be loaded. See: AsyncBeanManagerImpl.lookupBean(Class, java.lang.annotation.Annotation...)
qualifiers - the qualifiers for the bean to be loaded.
Returns:
an AsyncBeanFuture which will house the instance of the bean once it is loaded.

load

public <T> AsyncBeanFuture<T> load(AsyncBeanDef<T> beanDef)
Requests that the bean described by the specified AsyncBeanDef is loaded.

Type Parameters:
T - the type of bean to be loaded.
Parameters:
beanDef - the AsyncBeanDef describing the bean to be loaded.
Returns:
an AsyncBeanFuture which will house the instance of the bean once it is loaded.

loadNew

public <T> AsyncBeanFuture<T> loadNew(Class<T> type)
Requests that a new instance specified bean of the specified is loaded.

Type Parameters:
T - the type of bean to be loaded.
Parameters:
type - the type of the bean to be loaded. See: AsyncBeanManagerImpl.lookupBean(Class, java.lang.annotation.Annotation...)
Returns:
an AsyncBeanFuture which will house the instance of the bean once it is loaded.

loadNew

public <T> AsyncBeanFuture<T> loadNew(Class<T> type,
                                      Annotation... qualifiers)
Requests that a new instance of specified bean of the specified and is loaded.

Type Parameters:
T - the type of bean to be loaded.
Parameters:
type - the type of the bean to be loaded. See: AsyncBeanManagerImpl.lookupBean(Class, java.lang.annotation.Annotation...)
qualifiers - the qualifiers for the bean to be loaded.
Returns:
an AsyncBeanFuture which will house the instance of the bean once it is loaded.

loadNew

public <T> AsyncBeanFuture<T> loadNew(AsyncBeanDef<T> beanDef)
Requests that a new instance of the bean described by the specified AsyncBeanDef is loaded.

Type Parameters:
T - the type of bean to be loaded.
Parameters:
beanDef - the AsyncBeanDef describing the bean to be loaded.
Returns:
an AsyncBeanFuture which will house the instance of the bean once it is loaded.

query

public void query(Runnable finishCallback)
Initiates the constructed query based on load(AsyncBeanDef) and loadNew(AsyncBeanDef) calls made prior to calling this method. The specified Runnable is invoked only after all the requested beans have been successfully loaded.

Parameters:
finishCallback - the Runnable to be invoked once all of the request beans have been loaded.

cancelQuery

public void cancelQuery()
Cancels the query if it has not yet returned. Already loaded beans are destroyed.


Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.