Errai 3.0.1-SNAPSHOT

org.jboss.errai.common.client.api.extension
Class InitVotes

java.lang.Object
  extended by org.jboss.errai.common.client.api.extension.InitVotes

public final class InitVotes
extends Object

The InitVotes class provides the central algorithm around which disparate services within the Errai Framework can elect to prevent initialization and be notified when initialization occurs. This is required internally to ensure that services such as RPC proxies have been properly bound prior to any remote calls being made. This API also makes it possible for user-defined services and extensions to Errai to participate in the startup contract.

Author:
Mike Brock

Method Summary
static void registerInitFailureListener(InitFailureListener failureListener)
          Registers an InitFailureListener to monitor for initialization failures of the framework or its components.
static void registerOneTimeDependencyCallback(Class clazz, Runnable runnable)
           
static void registerOneTimeInitCallback(Runnable runnable)
          Registers a one-time callback task to be executed once initialization occurs.
static void registerOneTimePreInitCallback(Runnable runnable)
           
static void registerPersistentDependencyCallback(Class clazz, Runnable runnable)
           
static void registerPersistentInitCallback(Runnable runnable)
          Registers a callback task to be executed once initialization occurs.
static void registerPersistentPreInitCallback(Runnable runnable)
           
static void reset()
          Resets the state, clearing all current waiting votes and disarming the startup process.
static void setTimeoutMillis(int millis)
          Specifies the number of milliseconds that will be permitted to transpire until dependencies are assumed to have failed to satisfy, and thus an error is rendered to the browser console.
static void startInitPolling()
           
static void voteFor(Class<?> clazz)
          Votes for initialization and removes a lock on the initialization of framework services.
static void waitFor(Class<?> clazz)
          Declares a startup dependency on the specified class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

reset

public static void reset()
Resets the state, clearing all current waiting votes and disarming the startup process. Calling reset() does not however clear out any initialization callbacks registered with registerPersistentInitCallback(Runnable).


setTimeoutMillis

public static void setTimeoutMillis(int millis)
Specifies the number of milliseconds that will be permitted to transpire until dependencies are assumed to have failed to satisfy, and thus an error is rendered to the browser console. The default value is 5000 milliseconds.

Parameters:
millis - milliseconds.

waitFor

public static void waitFor(Class<?> clazz)
Declares a startup dependency on the specified class. By doing so, initialization of the framework services will be blocked until a voteFor(Class) is called with the same Class reference passed to this method.

If no dependencies have previously been declared, then the first caller to invoke this method arms and begins the startup process. This starts the timer window (see setTimeoutMillis(int)) for which all components being waited on are expected to report back that they're ready.

Parameters:
clazz - a class reference.
See Also:
voteFor(Class)

voteFor

public static void voteFor(Class<?> clazz)
Votes for initialization and removes a lock on the initialization of framework services. If the initialization process has been armed and this vote releases the final dependency, the initialization process will be triggered, calling all the registered initialization callbacks. See: registerPersistentInitCallback(Runnable)

Parameters:
clazz - a class reference

registerPersistentDependencyCallback

public static void registerPersistentDependencyCallback(Class clazz,
                                                        Runnable runnable)

registerOneTimeDependencyCallback

public static void registerOneTimeDependencyCallback(Class clazz,
                                                     Runnable runnable)

registerPersistentPreInitCallback

public static void registerPersistentPreInitCallback(Runnable runnable)

registerOneTimePreInitCallback

public static void registerOneTimePreInitCallback(Runnable runnable)

registerPersistentInitCallback

public static void registerPersistentInitCallback(Runnable runnable)
Registers a callback task to be executed once initialization occurs. Callbacks registered with this method will be persistent across multiple initializations, and will not be cleared out even if reset() is called. If this is not desirable, see: registerOneTimeInitCallback(java.lang.Runnable);

As of Errai 3.0, the callback list is de-duped based on instance to simplify initialization code in modules. You can now safely re-add a Runnable in initialization code as long as it is always guaranteed to be the same instance.*

Parameters:
runnable - a callback to execute

registerOneTimeInitCallback

public static void registerOneTimeInitCallback(Runnable runnable)
Registers a one-time callback task to be executed once initialization occurs. Unlike callbacks registered with registerPersistentInitCallback(Runnable) Callback(Runnable)}, callbacks registered with this method will only be executed once and will never be used again if framework services are re-initialized.

Parameters:
runnable - a callback to execute

registerInitFailureListener

public static void registerInitFailureListener(InitFailureListener failureListener)
Registers an InitFailureListener to monitor for initialization failures of the framework or its components.

Parameters:
failureListener - the instance of the InitFailureListener to be registered.

startInitPolling

public static void startInitPolling()

Errai 3.0.1-SNAPSHOT

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