Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.event
Class EventManager

    java.lang.Object
      org.apache.cayenne.event.EventManager

    public class EventManager

extends java.lang.Object

This class acts as bridge between an Object that wants to inform others about its current state or a change thereof (Publisher) and a list of objects interested in the Subject (Listeners).

Author:
  Dirk Olmes, Holger Hoffstaette, Andrei Adamchik

Field Summary
`static int` | `DEFAULT_DISPATCH_THREAD_COUNT`
`protected java.util.List` | `eventQueue`
`protected boolean` | `singleThread`
`protected java.util.Map` | `subjects`

Constructor Summary
`EventManager()` Creates a multithreaded EventManager using default thread count.
`EventManager(int dispatchThreadCount)` Creates an EventManager starting the specified number of threads for multithreaded dispatching.

Method Summary
`void` | `addListener(java.lang.Object listener, java.lang.String methodName, java.lang.Class eventParameterClass, EventSubject subject)` Register an `EventListener` for events sent by any sender.
`void` | `addListener(java.lang.Object listener, java.lang.String methodName, java.lang.Class eventParameterClass, EventSubject subject, java.lang.Object sender)` Register an `EventListener` for events sent by a specific sender.
`protected void` | `addListener(java.lang.Object listener, java.lang.String methodName, java.lang.Class eventParameterClass, EventSubject subject, java.lang.Object sender, boolean blocking)`
`void` | `addNonBlockingListener(java.lang.Object listener, java.lang.String methodName, java.lang.Class eventParameterClass, EventSubject subject)`
`void` | `addNonBlockingListener(java.lang.Object listener, java.lang.String methodName, java.lang.Class eventParameterClass, EventSubject subject, java.lang.Object sender)`
`static EventManager` | `getDefaultManager()` Returns the shared EventManager.
`java.util.List` | `getEventQueue()` Returns a list of currently queued events.
`boolean` | `isSingleThreaded()` Returns true if this EventManager is single-threaded.
`void` | `postEvent(java.util.EventObject event, EventSubject subject)` Sends an event to all registered objects about a particular subject.
`void` | `postNonBlockingEvent(java.util.EventObject event, EventSubject subject)` Sends an event to all registered objects about a particular subject.
`boolean` | `removeAllListeners(EventSubject subject)` Removes all listeners for a given subject.
`boolean` | `removeListener(java.lang.Object listener)` Unregister the specified listener from all event subjects handled by this `EventManager` instance.
`boolean` | `removeListener(java.lang.Object listener, EventSubject subject)` Unregister the specified listener for the events about the given subject.
`boolean` | `removeListener(java.lang.Object listener, EventSubject subject, java.lang.Object sender)` Unregister the specified listener for the events about the given subject and the given sender.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_DISPATCH_THREAD_COUNT

    public static final int DEFAULT_DISPATCH_THREAD_COUNT

See Also:
  Constant Field Values

### subjects

    protected java.util.Map subjects

### eventQueue

    protected java.util.List eventQueue

### singleThread

    protected boolean singleThread

Constructor Detail

### EventManager

    public EventManager()

  Creates a multithreaded EventManager using default thread count.

### EventManager

    public EventManager(int dispatchThreadCount)

  Creates an EventManager starting the specified number of threads for multithreaded dispatching. To create a single-threaded EventManager, use thread count of zero or less.

Method Detail

### getDefaultManager

    public static EventManager getDefaultManager()

  Returns the shared EventManager. It is created on demand on the first call to this method. Cayenne internally doesn't use default EventManager. Instead Configuration EventManager is propagated to DataDomains and DataContexts.

  Returns:
    EventManager the shared EventManager instance

### isSingleThreaded

    public boolean isSingleThreaded()

  Returns true if this EventManager is single-threaded. If so it will throw an exception on any attempt to register an unblocking listener or dispatch a non-blocking event.

  Since:
    1.2

### getEventQueue

    public java.util.List getEventQueue()

  Returns a list of currently queued events. Queue is returned by copy. This method is useful for inspecting the state of the event queue at any particular moment, but doesn't allow callers to alter the queue state.

  Since:
    1.1

### addListener

    public void addListener(java.lang.Object listener,
                            java.lang.String methodName,
                            java.lang.Class eventParameterClass,
                            EventSubject subject)

  Register an `EventListener` for events sent by any sender.

  Throws:
    `java.lang.RuntimeException` - if `methodName` is not found
  See Also:
    `addListener(Object, String, Class, EventSubject, Object)`

### addNonBlockingListener

    public void addNonBlockingListener(java.lang.Object listener,
                                       java.lang.String methodName,
                                       java.lang.Class eventParameterClass,
                                       EventSubject subject)

### addListener

    public void addListener(java.lang.Object listener,
                            java.lang.String methodName,
                            java.lang.Class eventParameterClass,
                            EventSubject subject,
                            java.lang.Object sender)

  Register an `EventListener` for events sent by a specific sender.

  Parameters:
    `listener` - the object to be notified about events
    `methodName` - the name of the listener method to be invoked
    `eventParameterClass` - the class of the single event argument passed to `methodName`
    `subject` - the event subject that the listener is interested in
    `sender` - the object whose events the listener is interested in; `null` means 'any sender'.
  Throws:
    `java.lang.RuntimeException` - if `methodName` is not found

### addNonBlockingListener

    public void addNonBlockingListener(java.lang.Object listener,
                                       java.lang.String methodName,
                                       java.lang.Class eventParameterClass,
                                       EventSubject subject,
                                       java.lang.Object sender)

### addListener

    protected void addListener(java.lang.Object listener,
                               java.lang.String methodName,
                               java.lang.Class eventParameterClass,
                               EventSubject subject,
                               java.lang.Object sender,
                               boolean blocking)

### removeListener

    public boolean removeListener(java.lang.Object listener)

  Unregister the specified listener from all event subjects handled by this `EventManager` instance.

  Parameters:
    `listener` - the object to be unregistered
  Returns:
    `true` if `listener` could be removed for any existing subjects, else returns `false`.

### removeAllListeners

    public boolean removeAllListeners(EventSubject subject)

  Removes all listeners for a given subject.

### removeListener

    public boolean removeListener(java.lang.Object listener,
                                  EventSubject subject)

  Unregister the specified listener for the events about the given subject.

  Parameters:
    `listener` - the object to be unregistered
    `subject` - the subject from which the listener is to be unregistered
  Returns:
    `true` if `listener` could be removed for the given subject, else returns `false`.

### removeListener

    public boolean removeListener(java.lang.Object listener,
                                  EventSubject subject,
                                  java.lang.Object sender)

  Unregister the specified listener for the events about the given subject and the given sender.

  Parameters:
    `listener` - the object to be unregistered
    `subject` - the subject from which the listener is to be unregistered
    `sender` - the object whose events the listener was interested in; `null` means 'any sender'.
  Returns:
    `true` if `listener` could be removed for the given subject, else returns `false`.

### postEvent

    public void postEvent(java.util.EventObject event,
                          EventSubject subject)

  Sends an event to all registered objects about a particular subject. Event is sent synchronously, so the sender thread is blocked until all the listeners finish processing the event.

  Parameters:
    `event` - the event to be posted to the observers
    `subject` - the subject about which observers will be notified
  Throws:
    `java.lang.IllegalArgumentException` - if event or subject are null

### postNonBlockingEvent

    public void postNonBlockingEvent(java.util.EventObject event,
                                     EventSubject subject)

  Sends an event to all registered objects about a particular subject. Event is queued by EventManager, releasing the sender thread, and is later dispatched in a separate thread.

  Parameters:
    `event` - the event to be posted to the observers
    `subject` - the subject about which observers will be notified
  Throws:
    `java.lang.IllegalArgumentException` - if event or subject are null
  Since:
    1.1

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2006 Apache.org All Rights Reserved.