|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.cayenne.event.EventBridge
public abstract class EventBridge
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.
Field Summary | |
---|---|
protected EventManager |
eventManager
|
protected java.lang.Object |
externalEventSource
|
protected java.lang.String |
externalSubject
|
protected java.util.Collection |
localSubjects
|
protected int |
mode
|
static int |
RECEIVE_EXTERNAL
|
static int |
RECEIVE_LOCAL
|
static int |
RECEIVE_LOCAL_EXTERNAL
|
static java.lang.String |
VM_ID
Deprecated. unused since 1.2 |
static java.lang.String |
VM_ID_PROPERRTY
Deprecated. unused since 1.2 |
Constructor Summary | |
---|---|
EventBridge(java.util.Collection localSubjects,
java.lang.String externalSubject)
Creates an EventBridge with multiple local subjects and a single external subject. |
|
EventBridge(EventSubject localSubject,
java.lang.String externalSubject)
Creates an EventBridge with a single local subject. |
Method Summary | |
---|---|
static java.lang.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. |
java.lang.Object |
getExternalEventSource()
Returns an object used as a source of local events posted in response to remote events. |
java.lang.String |
getExternalSubject()
Returns a String subject used to post distributed events. |
EventSubject |
getLocalSubject()
Deprecated. since 1.2 EventBridge supports multiple local subjects, so use 'getLocalSubjects()' instead. This method returns the first subject from the subject array for backwards compatibility. |
java.util.Collection |
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. |
void |
onLocalEvent(CayenneEvent event)
Deprecated. Unused since 1.2, as event dispatch is done via internal listeners. |
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,
java.lang.Object localEventSource)
Starts EventBridge in the specified mode and locally listening to a specified event source. |
void |
startup(EventManager eventManager,
int mode,
java.lang.Object localEventSource,
java.lang.Object remoteEventSource)
Starts EventBridge in the specified mode. |
protected abstract void |
startupExternal()
Starts an external interface of the EventBridge. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String VM_ID
public static final java.lang.String VM_ID_PROPERRTY
public static final int RECEIVE_LOCAL
public static final int RECEIVE_EXTERNAL
public static final int RECEIVE_LOCAL_EXTERNAL
protected java.lang.String externalSubject
protected java.util.Collection localSubjects
protected EventManager eventManager
protected int mode
protected java.lang.Object externalEventSource
Constructor Detail |
---|
public EventBridge(EventSubject localSubject, java.lang.String externalSubject)
public EventBridge(java.util.Collection localSubjects, java.lang.String externalSubject)
Method Detail |
---|
public static java.lang.String convertToExternalSubject(EventSubject localSubject)
public java.lang.String getExternalSubject()
public boolean isRunning()
public EventSubject getLocalSubject()
public java.util.Collection getLocalSubjects()
public EventManager getEventManager()
public java.lang.Object getExternalEventSource()
public boolean receivesLocalEvents()
public boolean receivesExternalEvents()
public void startup(EventManager eventManager, int mode) throws java.lang.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.
java.lang.Exception
public void startup(EventManager eventManager, int mode, java.lang.Object localEventSource) throws java.lang.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.
java.lang.Exception
public void startup(EventManager eventManager, int mode, java.lang.Object localEventSource, java.lang.Object remoteEventSource) throws java.lang.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.
java.lang.Exception
protected abstract void startupExternal() throws java.lang.Exception
java.lang.Exception
public void shutdown() throws java.lang.Exception
java.lang.Exception
protected abstract void shutdownExternal() throws java.lang.Exception
java.lang.Exception
protected void onExternalEvent(CayenneEvent event)
public void onLocalEvent(CayenneEvent event) throws java.lang.Exception
java.lang.Exception
protected abstract void sendExternalEvent(CayenneEvent localEvent) throws java.lang.Exception
java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |