QScript  2.1.2
Expression and algorithm evaluator
 All Classes Namespaces Functions Variables Pages
List of all members
org.qscript.eventsonfire.Events Class Reference

Inherits Runnable.

static< PRODUCER_TYPE >
PRODUCER_TYPE 
bind (PRODUCER_TYPE producer, Object...consumers) throws IllegalArgumentException
 
static< PRODUCER_TYPE >
PRODUCER_TYPE 
unbind (PRODUCER_TYPE producer, Object...consumers) throws IllegalArgumentException
 
static< PRODUCER_TYPE >
PRODUCER_TYPE 
fire (PRODUCER_TYPE producer, Object event, String...tags) throws IllegalArgumentException
 
static void disable ()
 
static boolean isDisabled ()
 
static void enable () throws IllegalStateException
 
static void registerStrategy (EventHandlerStrategy strategy)
 
static ExecutorService getExecutorService ()
 
static void setExecutorService (ExecutorService executorService)
 
static ErrorHandler getErrorHandler ()
 
static void setErrorHandler (ErrorHandler errorHandler) throws IllegalArgumentException
 
void run ()
 

Detailed Description

The most important class for events-on-fire.

For a detailed usage description see Usage on Google Project Hosting.

All references to producers and consumers in this class are weak, unless otherwise noted. Any producer or consumer will get garbage collected, if there is no reference to it outside this class. All checks will be made on identity instead of equality.

See Also
Usage on Google Project Hosting
Author
Manfred Hantschel

Member Function Documentation

static <PRODUCER_TYPE> PRODUCER_TYPE org.qscript.eventsonfire.Events.bind ( PRODUCER_TYPE  producer,
Object...  consumers 
) throws IllegalArgumentException
static

Binds the specified consumer / listener to the specified instance of class of a producer. The producer may either be an instance or a class reference.

  • In case of an instance, the consumer / listener is notified, if the specified producer fires the event (producers are compared by identity rather than equality).
  • In case of a class reference, the consumer / listener is notified, if a producer, that fires the event, is an instance of the specified class (e.g. if the specified producer is a Object.class reference, then the consumer get notified by all events it can handle).

The consumer must contain at least one } public void handleEvent(* event) method, otherwise an exception is thrown. Both, the producer and the consumer must have references outside of the Events class. All references within the Events class are weak, so the objects and the binding gets garbage collected if not referenced. Does nothing if the objects are already bonded. producer the instance or class of a producer, mandatory consumers one or more consumers / listeners, mandatory the producer IllegalArgumentException if the producer or the consumers are null or one of the consumer cannot handle events

static void org.qscript.eventsonfire.Events.disable ( )
static

Disables events from the current thread.

Make sure to call the enable method by using a finally block! Multiple calls to disable, increase a counter and it is necessary to call enable as often as you have called disable.

static void org.qscript.eventsonfire.Events.enable ( ) throws IllegalStateException
static

Enables events from the current thread.

It is wise to place call to this method within a finally block. Multiple calls to disable, increase a counter and it is necessary to call enable as often as you have called disable.

Exceptions
IllegalStateExceptionif events from the current thread are not disabled
static <PRODUCER_TYPE> PRODUCER_TYPE org.qscript.eventsonfire.Events.fire ( PRODUCER_TYPE  producer,
Object  event,
String...  tags 
) throws IllegalArgumentException
static

Fires the specified event from the specified instance of a producer. Notifies all consumers that are either directly bonded to the producer or that are bonded to the class, any sub-class or any interface of the producer.

Calls the appropriate } public void handleEvent(* event) method of all consumers. Does nothing, if events are disabled for the current thread. Does nothing, if there are no consumers bonded to the producer.

Parameters
producerthe producer, mandatory
eventthe event, mandatory
tags,optional,canbe checked against tags in annotations
Exceptions
IllegalArgumentExceptionif the producer or the event is null

static ErrorHandler org.qscript.eventsonfire.Events.getErrorHandler ( )
static

Returns the error handler, the DefaultErrorHandler if not specified.

Returns
the error handler, never null
static ExecutorService org.qscript.eventsonfire.Events.getExecutorService ( )
static

Returns the executor service for event handler that are executed using pooled threads. The default value is a fixed thread pool using a maximum of 4 threads.

Returns
the executor service
static boolean org.qscript.eventsonfire.Events.isDisabled ( )
static

Returns true if events from the current thread are disabled.

Returns
true if disabled
static void org.qscript.eventsonfire.Events.registerStrategy ( EventHandlerStrategy  strategy)
static

Registers a strategy for event handlers. The strategy decides for a method of a consumer, whether it is capable of handling events or not. By default there exist strategies for following annotations: EventHandler, PooledEventHandler and SwingEventHandler.

Parameters
strategythe strategy, never null
void org.qscript.eventsonfire.Events.run ( )

Worker for pending actions. There is no need to call this method.

See Also
java.lang.Runnable::run()
static void org.qscript.eventsonfire.Events.setErrorHandler ( ErrorHandler  errorHandler) throws IllegalArgumentException
static

Sets the error handler.

Parameters
errorHandlerthe error handler, mandatory
Exceptions
IllegalArgumentExceptionif the error handler is null
static void org.qscript.eventsonfire.Events.setExecutorService ( ExecutorService  executorService)
static

Sets the executor service for event handlers that are executed using pooled threads.

Parameters
executorServicethe executor service, mandatory
Exceptions
IllegalArgumentExceptionif the executor service is null
static <PRODUCER_TYPE> PRODUCER_TYPE org.qscript.eventsonfire.Events.unbind ( PRODUCER_TYPE  producer,
Object...  consumers 
) throws IllegalArgumentException
static

Unbinds the specified consumer from the specified instance or class of a producer. The producer may either be an instance or a class reference.

  • In case of an instance, the consumer / listener unbonded from the specified producer (producers are compared by identity rather than equality).
  • In case of a class reference, the consumer / listener unbonded from any producer that is an instance of the specified class (e.g. if the specified producer is a Object.class reference, then the consumer get unbonded from all producers).

Does nothing if the objects are not bonded.

Parameters
producerthe instance or class of a producer, mandatory
consumersone or more consumers / listeners, mandatory
Returns
the producer
Exceptions
IllegalArgumentExceptionif the producer or the consumers are null

The documentation for this class was generated from the following file: