Errai 3.0.1-SNAPSHOT

org.jboss.errai.jpa.sync.client.local
Class ClientSyncWorker<E>

java.lang.Object
  extended by org.jboss.errai.jpa.sync.client.local.ClientSyncWorker<E>
Type Parameters:
E - The entity type this worker's named query returns.

public class ClientSyncWorker<E>
extends Object

Handles the job of keeping one JPA NamedQuery in sync between the client and server. A ClientSyncWorker has three states:

  1. Not yet started - no sync happens
  2. Running - data sync operations happen automatically
  3. Stopped - no sync happens
New instances are in the "not yet started" state. You start them with a call to #start(), and stop them with a call to stop(). Once started, a sync worker instance can be stopped but not restarted. Once stopped, a sync worker cannot be restarted.

Author:
Jonathan Fuerth , Christian Sadilek

Nested Class Summary
static interface ClientSyncWorker.QueryParamInitCallback
          A callback that provides parameters for the query used by a ClientSyncWorker.
 
Constructor Summary
ClientSyncWorker(ClientSyncManager manager, String queryName, Class<E> queryResultType, ErrorCallback<?> onError)
          Creates a new ClientSyncWorker which takes responsibility for syncing the results of the named JPA query.
 
Method Summary
 void addSyncCallback(DataSyncCallback<E> onCompletion)
          Registers the given callback to receive notifications each time a sync operation has been performed.
static
<E> ClientSyncWorker<E>
create(String queryName, Class<E> queryResultType, ErrorCallback<?> onError)
          Creates a new ClientSyncWorker which takes responsibility for syncing the results of the named JPA query.
 void start(Map<String,Object> queryParams)
          Starts this sync worker if it has not already been started or stopped.
 void start(Object beanInstance, ClientSyncWorker.QueryParamInitCallback queryParamCallback)
          Starts this sync worker if it has not already been started or stopped.
 void stop()
          Stops this sync worker if it is running.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientSyncWorker

public ClientSyncWorker(ClientSyncManager manager,
                        String queryName,
                        Class<E> queryResultType,
                        ErrorCallback<?> onError)
Creates a new ClientSyncWorker which takes responsibility for syncing the results of the named JPA query.

This constructor is primarily intended for testing. Consider using #create(String, Class, Map, ErrorCallback) instead, which obtains an instance of ClientSyncManager from the IOC Bean Manager.

Parameters:
manager - The instance of ClientSyncManager that should be used for all data sync operations.
queryName - The name of a JPA named query. Must be visible to client-side code, and if it has parameters, they must be named (not positional) parameters.
queryResultType - The result type returned by the named query.
onError - Error callback that should be invoked if any sync request encounters a data transmission error on the bus. If null, transmission errors are logged to the slf4j logger for the ClientSyncWorker class.
Method Detail

create

public static <E> ClientSyncWorker<E> create(String queryName,
                                             Class<E> queryResultType,
                                             ErrorCallback<?> onError)
Creates a new ClientSyncWorker which takes responsibility for syncing the results of the named JPA query.

Type Parameters:
E - The entity type the named query returns.
Parameters:
queryName - The name of a JPA named query. Must be visible to client-side code, and if it has parameters, they must be named (not positional) parameters.
queryResultType - The result type returned by the named query.
onError - Error callback that should be invoked if any sync request encounters a data transmission error on the bus. If null, transmission errors are logged to the slf4j logger for the ClientSyncWorker class.
Returns:
a new ClientSyncWorker instance in the "not yet started" state.

addSyncCallback

public void addSyncCallback(DataSyncCallback<E> onCompletion)
Registers the given callback to receive notifications each time a sync operation has been performed.

Parameters:
onCompletion - the callback to notify of completed sync operations. Must not be null.

start

public void start(Map<String,Object> queryParams)
Starts this sync worker if it has not already been started or stopped.

Parameters:
queryParams - Name-value pairs for all named parameters in the named query. Never null.
Throws:
IllegalStateException - if this sync worker has been stopped.

start

public void start(Object beanInstance,
                  ClientSyncWorker.QueryParamInitCallback queryParamCallback)
Starts this sync worker if it has not already been started or stopped.

Parameters:
beanInstance - The managed bean instance the observes the sync results and defines the query parameters.
queryParamCallback - A ClientSyncWorker.QueryParamInitCallback that provides the query parameters for this ClientSyncWorker's query.
Throws:
IllegalStateException - if this sync worker has been stopped.

stop

public void stop()
Stops this sync worker if it is running.

Throws:
IllegalStateException - if this sync worker has not yet been started.

Errai 3.0.1-SNAPSHOT

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