public abstract class EventBridge extends Object implements EventListener
An object that passes events between a local EventManager and some other event dispatch mechanism. The most common example is sending local events to remote JVMs and receiving remote events dispatched by those VMs. EventBridge makes possible to connect a network of regular EventManagers in a single "virtual" distributed EventManager.
EventBridge encapsulates a transport agreed upon by all paries (such as JMS) and maintains an array of "local" subjects to communicate with local EventManager, and a single "remote" subject - to use for "external" communications that are transport-specific.
Subclasses that require special setup to listen for external events should implement
startupExternal()
method accordingly.
This class is an example of "bridge" design pattern, hence the name.
Modifier and Type | Field and Description |
---|---|
protected EventManager |
eventManager |
protected Object |
externalEventSource |
protected String |
externalSubject |
protected Collection<EventSubject> |
localSubjects |
protected int |
mode |
static int |
RECEIVE_EXTERNAL |
static int |
RECEIVE_LOCAL |
static int |
RECEIVE_LOCAL_EXTERNAL |
Constructor and Description |
---|
EventBridge(Collection<EventSubject> localSubjects,
String externalSubject)
Creates an EventBridge with multiple local subjects and a single external subject.
|
EventBridge(EventSubject localSubject,
String externalSubject)
Creates an EventBridge with a single local subject.
|
Modifier and Type | Method and Description |
---|---|
static String |
convertToExternalSubject(EventSubject localSubject)
A utility method that performs consistent translation from an EventSubject to a
String that can be used by external transport as subject for distributed
communications.
|
EventManager |
getEventManager()
Returns local EventManager used by the bridge.
|
Object |
getExternalEventSource()
Returns an object used as a source of local events posted in response to remote
events.
|
String |
getExternalSubject()
Returns a String subject used to post distributed events.
|
Collection<EventSubject> |
getLocalSubjects()
Returns a Collection of local EventSubjects.
|
boolean |
isRunning()
Returns true if this bridge is active.
|
protected void |
onExternalEvent(CayenneEvent event)
Helper method intended to be called explicitly by subclasses to asynchronously post
an event obtained from a remote source.
|
boolean |
receivesExternalEvents()
Returns true if the bridge is configured to receive external events.
|
boolean |
receivesLocalEvents()
Returns true if the bridge is configured to receive local events from its internal
EventManager.
|
protected abstract void |
sendExternalEvent(CayenneEvent localEvent)
Sends a Cayenne event over the transport supported by this bridge.
|
void |
shutdown()
Stops listening for events on both local and external interfaces.
|
protected abstract void |
shutdownExternal()
Shuts down the external interface of the EventBridge, cleaning up and releasing any
resources used to communicate external events.
|
void |
startup(EventManager eventManager,
int mode)
Starts EventBridge in the specified mode and locally listening to all event sources
that post on a preconfigured subject.
|
void |
startup(EventManager eventManager,
int mode,
Object localEventSource)
Starts EventBridge in the specified mode and locally listening to a specified event
source.
|
void |
startup(EventManager eventManager,
int mode,
Object localEventSource,
Object remoteEventSource)
Starts EventBridge in the specified mode.
|
protected abstract void |
startupExternal()
Starts an external interface of the EventBridge.
|
public static final int RECEIVE_LOCAL
public static final int RECEIVE_EXTERNAL
public static final int RECEIVE_LOCAL_EXTERNAL
protected String externalSubject
protected Collection<EventSubject> localSubjects
protected EventManager eventManager
protected int mode
protected Object externalEventSource
public EventBridge(EventSubject localSubject, String externalSubject)
public EventBridge(Collection<EventSubject> localSubjects, String externalSubject)
public static String convertToExternalSubject(EventSubject localSubject)
public String getExternalSubject()
public boolean isRunning()
public Collection<EventSubject> getLocalSubjects()
public EventManager getEventManager()
public Object getExternalEventSource()
public boolean receivesLocalEvents()
public boolean receivesExternalEvents()
public void startup(EventManager eventManager, int mode) throws Exception
eventManager
- EventManager used to send and receive local events.mode
- One of the possible modes of operation - RECEIVE_EXTERNAL,
RECEIVE_LOCAL, RECEIVE_LOCAL_EXTERNAL.Exception
public void startup(EventManager eventManager, int mode, Object localEventSource) throws Exception
eventManager
- EventManager used to send and receive local events.mode
- One of the possible modes of operation - RECEIVE_EXTERNAL,
RECEIVE_LOCAL, RECEIVE_LOCAL_EXTERNAL.localEventSource
- If not null, only events originating from localEventSource
object will be processed by this bridge.Exception
public void startup(EventManager eventManager, int mode, Object localEventSource, Object remoteEventSource) throws Exception
eventManager
- EventManager used to send and receive local events.mode
- One of the possible modes of operation - RECEIVE_EXTERNAL,
RECEIVE_LOCAL, RECEIVE_LOCAL_EXTERNAL.localEventSource
- If not null, only events originating from localEventSource
object will be processed by this bridge.remoteEventSource
- If not null, remoteEventSource object will be used as
standby source of local events posted by this EventBridge in response to
remote events.Exception
protected abstract void startupExternal() throws Exception
Exception
public void shutdown() throws Exception
Exception
protected abstract void shutdownExternal() throws Exception
Exception
protected void onExternalEvent(CayenneEvent event)
protected abstract void sendExternalEvent(CayenneEvent localEvent) throws Exception
Exception
Copyright © 2001–2019 Apache Cayenne. All rights reserved.