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

## com.hammurapi.eventbus
Class AbstractEventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>

Show UML class diagram

    java.lang.Object
      com.hammurapi.eventbus.AbstractEventBus<E,P,C,K,H,S>

Type Parameters:
  `E` - Event type.
  `P` - Priority type.
  `C` - Context type.
  `K` - Handler registration key.

All Implemented Interfaces:
  EventBus<E,P,C,K,H,S>

Direct Known Subclasses:
  LocalEventBusBase

    public abstract class AbstractEventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>

extends Object
implements EventBus<E,P,C,K,H,S>

Event bus dispatches events to event handlers.

Nested Class Summary
`protected class` | `AbstractEventBus.CreateMasterHandleResult`
`static interface` | `AbstractEventBus.DerivationEx<K>` Helper interface for snapshot taking.
`static interface` | `AbstractEventBus.Handle<E,P extends Comparable<P>,C,K>` Event handle.
`static interface` | `AbstractEventBus.Snapshot<E,P extends Comparable<P>,C,K,H extends EventBus.Handle<E,P,C>,S extends EventStore<E,P,C,H,S>>` Interface to output bus structure for troubleshooting.
`static interface` | `AbstractEventBus.StateSnapshot<E,P extends Comparable<P>,C,K,H extends EventBus.Handle<E,P,C>,S extends EventStore<E,P,C,H,S>>` This snapshot also outputs bus state.
`static interface` | `AbstractEventBus.StoreEntry<E,P extends Comparable<P>,C,K>` Store entry complements store handle to provide functionality of event handle.

Field Summary
`protected static Logger` | `logger`

Constructor Summary
`AbstractEventBus(Class<E> eventType, S store, InferencePolicy inferencePolicy, InferenceFilter<E,P,C,K,H,S> inferenceFilter, StatsCollector statsCollector, TimeUnit statsTimeUnit, Matcher<E,P,C,K,H,S> matcher)`

Method Summary
`K` | `addHandler(EventHandler<E,P,C,H,S> eventHandler)` Registers event handler with a predicate.
`protected abstract TrackingExecutorService` | `createExecutorService(boolean oneOff, String name)` Create a wrapper around the root executor service for task tracking purposes.
`protected abstract TrackingExecutorService` | `createExecutorService(ExecutorService master, boolean oneOff, String name)` Creates a wrapper around the master executor service for task tracking purposes.
`protected abstract InferenceContext<E,P,C,K,H,S>` | `createInferenceContext()` Creates inference context with zero chain length and no root handle.
`protected H` | `createMasterHandle(PostCommand<E,P,C,K,H,S> postCommand)` Creates and returns new master handle.
`Collection<Derivation<E,P,C>>` | `getDerivations(E event)`
`Class<E>` | `getEventType()`
`ExceptionHandler` | `getExceptionHandler()`
`protected abstract TrackingExecutorService` | `getExecutorService()` Returns "root" executor service to submit predicate evaluation and handler execution tasks to.
`InferencePolicy` | `getInferencePolicy()`
`protected abstract Lock` | `getRtcLock()`
`S` | `getStore()`
`void` | `join()`
`boolean` | `join(long timeout)`
`void` | `manageHandlers(Matcher.HandlerManager<E,P,C,K,H,S> handlerManager)` This method is used for batch live updates of bus handlers.
`protected abstract H` | `newMasterHandle(PostCommand<E,P,C,K,H,S> postCommand)` Instantiates master handle.
`protected abstract K` | `nextId()` Generates handler ID.
`H` | `post(E event, ... validators)` Posts event to the bus.
`protected H` | `processInferenceCommand(InferenceCommand<E,P,C,K,H,S> command)`
`protected abstract void` | `processRemoveCommand(RemoveCommand<E,P,C,K,H,S> command)`
`void` | `removeHandlers(Iterable<K> keys)` Removes registered handler(s).
`void` | `removeHandlers(K... keys)` Removes registered handler(s).
`void` | `reset()` Clears join collections and handle map.
`void` | `setExceptionHandler(ExceptionHandler exceptionHandler)`
`void` | `takeSnapshot(AbstractEventBus.Snapshot<E,P,C,K,H,S> snapshot)`
`protected void` | `workingMemorySnapshot(AbstractEventBus.StateSnapshot<E,P,C,K,H,S> snapshot)`

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

Methods inherited from interface com.hammurapi.eventbus.EventBus
`remove`

Field Detail

### logger

    protected static final Logger logger

Constructor Detail

### AbstractEventBus

    public AbstractEventBus(Class<E> eventType,
                            S store,
                            InferencePolicy inferencePolicy,
                            InferenceFilter<E,P,C,K,H,S> inferenceFilter,
                            StatsCollector statsCollector,
                            TimeUnit statsTimeUnit,
                            Matcher<E,P,C,K,H,S> matcher)

Method Detail

### getEventType

    public Class<E> getEventType()

  Specified by:
    `getEventType` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`

### getInferencePolicy

    public InferencePolicy getInferencePolicy()

  Specified by:
    `getInferencePolicy` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`

### newMasterHandle

    protected abstract H newMasterHandle(PostCommand<E,P,C,K,H,S> postCommand)

  Instantiates master handle.

  Parameters:
    `event` -
  Returns:

### getExecutorService

    protected abstract TrackingExecutorService getExecutorService()

  Returns "root" executor service to submit predicate evaluation and handler execution tasks to.

### createExecutorService

    protected abstract TrackingExecutorService createExecutorService(ExecutorService master,
                                                                     boolean oneOff,
                                                                     String name)

  Creates a wrapper around the master executor service for task tracking purposes.

  Parameters:
    `master` - Master executor service
  Returns:

### createExecutorService

    protected abstract TrackingExecutorService createExecutorService(boolean oneOff,
                                                                     String name)

  Create a wrapper around the root executor service for task tracking purposes.

  Returns:
    executor service or null for the synchronous mode.

### nextId

    protected abstract K nextId()

  Generates handler ID.

  Returns:

### workingMemorySnapshot

    protected void workingMemorySnapshot(AbstractEventBus.StateSnapshot<E,P,C,K,H,S> snapshot)

### takeSnapshot

    public void takeSnapshot(AbstractEventBus.Snapshot<E,P,C,K,H,S> snapshot)

### setExceptionHandler

    public void setExceptionHandler(ExceptionHandler exceptionHandler)

  Specified by:
    `setExceptionHandler` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`

### getExceptionHandler

    public ExceptionHandler getExceptionHandler()

  Specified by:
    `getExceptionHandler` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`

### addHandler

    public K addHandler(EventHandler<E,P,C,H,S> eventHandler)

  Description copied from interface: `EventBus`
  Registers event handler with a predicate.

  Specified by:
    `addHandler` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`
  Parameters:
    `eventHandler` - Event handler.
  Returns:
    Registration key object.

### removeHandlers

    public void removeHandlers(Iterable<K> keys)

  Description copied from interface: `EventBus`
  Removes registered handler(s).

  Specified by:
    `removeHandlers` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`

### removeHandlers

    public void removeHandlers(K... keys)

  Description copied from interface: `EventBus`
  Removes registered handler(s).

  Specified by:
    `removeHandlers` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`

### getRtcLock

    protected abstract Lock getRtcLock()

### post

    public H post(E event,
                  ... validators)

  Description copied from interface: `EventBus`
  Posts event to the bus.

  Specified by:
    `post` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`
  Parameters:
    `event` - Event to dispatch to handlers.
    `validators` - Predicate(s) which are checked when object is retrieved from the event store. If there is more than one predicate, predicates are connected with AND. If validator(s) evaluate to false, the object handle is considered invalid, i.e. object is considered removed from the store. Once validator(s) evaluate to false, they shall always evaluate to false. One of use of validators can be to expire object in the store, i.e. after some time validator returns false and object is cleared from the database. If validators evaluate to false at put time, object is not put to the store and put() returns null. Validators evaluation result is not cached.
  Returns:
    Event handle or null if validator(s) evaluate to false.

### processInferenceCommand

    protected H processInferenceCommand(InferenceCommand<E,P,C,K,H,S> command)

  Parameters:
    `command` - command to be processed
    `executorService` - Executor service for asynchronous processing
    `inferenceCommandsQueue` - collector of inference commands for further processing.

### processRemoveCommand

    protected abstract void processRemoveCommand(RemoveCommand<E,P,C,K,H,S> command)

### createMasterHandle

    protected H createMasterHandle(PostCommand<E,P,C,K,H,S> postCommand)

  Creates and returns new master handle. re-dispatch existing event.

  Parameters:
    `event` - Event to add to the store.
    `joinDelegate` -
    `directPost` -
    `validators` -
    `derivation` -
  Returns:
    Master handle for new event, null for existing.

### reset

    public void reset()

  Description copied from interface: `EventBus`
  Clears join collections and handle map.

  Specified by:
    `reset` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`

### getDerivations

    public Collection<Derivation<E,P,C>> getDerivations(E event)

  Specified by:
    `getDerivations` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`
  Returns:
    Derivations for the event.

### join

    public void join()
              throws InterruptedException

  Throws:
    `InterruptedException`

### join

    public boolean join(long timeout)
                 throws InterruptedException

  Throws:
    `InterruptedException`

### getStore

    public S getStore()

  Specified by:
    `getStore` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`
  Returns:
    event store.

### manageHandlers

    public void manageHandlers(Matcher.HandlerManager<E,P,C,K,H,S> handlerManager)

  Description copied from interface: `EventBus`
  This method is used for batch live updates of bus handlers. The method acquires bus write lock, then invokes bus manager's manageBus() method within a lock and then releases the lock. Therefore, event bus structure update is executed as one logical unit.

  Specified by:
    `manageHandlers` in interface `EventBus<E,P extends Comparable<P>,C,K,H extends AbstractEventBus.Handle<E,P,C,K>,S extends EventStore<E,P,C,H,S>>`

### createInferenceContext

    protected abstract InferenceContext<E,P,C,K,H,S> createInferenceContext()

  Creates inference context with zero chain length and no root handle. Inference queue is supplied with AFTER_EVENT, AFTER_ROOT_EVENT and EXCLUSIVE policies. Use this method to create initial/root inference context.

  Returns:

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