org.apache.cayenne.event
Class JMSBridge

java.lang.Object
  extended by org.apache.cayenne.event.EventBridge
      extended by org.apache.cayenne.event.JMSBridge
All Implemented Interfaces:
EventListener, MessageListener

public class JMSBridge
extends EventBridge
implements MessageListener

Implementation of EventBridge that passes and receives events via JMS (Java Messaging Service). JMSBridge uses "publish/subscribe" model for communication with external agents.

Since:
1.1
Author:
Andrus Adamchik

Field Summary
protected  TopicPublisher publisher
           
protected  TopicConnection receivedConnection
           
protected  TopicConnection sendConnection
           
protected  TopicSession sendSession
           
protected  TopicSubscriber subscriber
           
protected  String topicConnectionFactoryName
           
 
Fields inherited from class org.apache.cayenne.event.EventBridge
eventManager, externalEventSource, externalSubject, localSubjects, mode, RECEIVE_EXTERNAL, RECEIVE_LOCAL, RECEIVE_LOCAL_EXTERNAL
 
Constructor Summary
JMSBridge(Collection localSubjects, String externalSubject)
           
JMSBridge(EventSubject localSubject, String externalSubject)
           
 
Method Summary
protected  Serializable eventToMessageObject(CayenneEvent event)
          Converts CayenneEvent to a serializable object that will be sent via JMS.
 String getTopicConnectionFactoryName()
           
protected  CayenneEvent messageObjectToEvent(Serializable object)
          Converts a Serializable instance to CayenneEvent.
 void onMessage(Message message)
          JMS MessageListener implementation.
protected  void sendExternalEvent(CayenneEvent localEvent)
          Sends a Cayenne event over the transport supported by this bridge.
 void setTopicConnectionFactoryName(String name)
           
protected  void shutdownExternal()
          Closes all resources used to communicate via JMS.
protected  void startupExternal()
          Starts up JMS machinery for "publish/subscribe" model.
protected  Topic topicNotFound(Context jndiContext, NamingException ex)
          Attempts to create missing Topic.
 
Methods inherited from class org.apache.cayenne.event.EventBridge
convertToExternalSubject, getEventManager, getExternalEventSource, getExternalSubject, getLocalSubjects, isRunning, onExternalEvent, receivesExternalEvents, receivesLocalEvents, shutdown, startup, startup, startup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

topicConnectionFactoryName

protected String topicConnectionFactoryName

sendConnection

protected TopicConnection sendConnection

sendSession

protected TopicSession sendSession

receivedConnection

protected TopicConnection receivedConnection

publisher

protected TopicPublisher publisher

subscriber

protected TopicSubscriber subscriber
Constructor Detail

JMSBridge

public JMSBridge(EventSubject localSubject,
                 String externalSubject)

JMSBridge

public JMSBridge(Collection localSubjects,
                 String externalSubject)
Since:
1.2
Method Detail

onMessage

public void onMessage(Message message)
JMS MessageListener implementation. Injects received events to the EventManager local event queue.

Specified by:
onMessage in interface MessageListener

getTopicConnectionFactoryName

public String getTopicConnectionFactoryName()
Returns:
Name of javax.jms.TopicConnectionFactory accessible via JNDI.

setTopicConnectionFactoryName

public void setTopicConnectionFactoryName(String name)

startupExternal

protected void startupExternal()
                        throws Exception
Starts up JMS machinery for "publish/subscribe" model.

Specified by:
startupExternal in class EventBridge
Throws:
Exception

topicNotFound

protected Topic topicNotFound(Context jndiContext,
                              NamingException ex)
                       throws Exception
Attempts to create missing Topic. Since Topic creation is JMS-implementation specific, this task is left to subclasses. Current implementation simply rethrows the exception.

Throws:
Exception

shutdownExternal

protected void shutdownExternal()
                         throws Exception
Closes all resources used to communicate via JMS.

Specified by:
shutdownExternal in class EventBridge
Throws:
Exception

sendExternalEvent

protected void sendExternalEvent(CayenneEvent localEvent)
                          throws Exception
Description copied from class: EventBridge
Sends a Cayenne event over the transport supported by this bridge.

Specified by:
sendExternalEvent in class EventBridge
Throws:
Exception

eventToMessageObject

protected Serializable eventToMessageObject(CayenneEvent event)
                                     throws Exception
Converts CayenneEvent to a serializable object that will be sent via JMS. Default implementation simply returns the event, but subclasses can customize this behavior.

Throws:
Exception

messageObjectToEvent

protected CayenneEvent messageObjectToEvent(Serializable object)
                                     throws Exception
Converts a Serializable instance to CayenneEvent. Returns null if the object is not supported. Default implementation simply tries to cast the object to CayenneEvent, but subclasses can customize this behavior.

Throws:
Exception


Copyright © 2001-2007 Apache Cayenne. All Rights Reserved.