unico 2004/01/05 09:14:44
Modified: src/blocks/jms/java/org/apache/cocoon/components/jms
JMSEventListener.java
Log:
provide more flexibility for overiding message -> event mapping
doc improvements
some formatting
Revision Changes Path
1.6 +39 -36
cocoon-2.1/src/blocks/jms/java/org/apache/cocoon/components/jms/JMSEventListener.java
Index: JMSEventListener.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/jms/java/org/apache/cocoon/components/jms/JMSEventListener.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JMSEventListener.java 15 Nov 2003 04:21:29 -0000 1.5
+++ JMSEventListener.java 5 Jan 2004 17:14:44 -0000 1.6
@@ -67,6 +67,7 @@
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.caching.EventAware;
+import org.apache.cocoon.caching.validity.Event;
import org.apache.cocoon.caching.validity.NamedEvent;
/**
@@ -100,7 +101,23 @@
protected String connectionName = null;
protected JMSConnection connection = null;
+ /*
+ * @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+ /*
+ * @see
org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+ */
+ public void parameterize(Parameters parameters) throws
ParameterException {
+
+ this.connectionName = parameters.getParameter("connection");
+ this.serviceName = parameters.getParameter("component");
+ this.selector = parameters.getParameter("message-selector",
this.selector);
+ }
+
public void initialize() {
try {
@@ -125,16 +142,16 @@
}
}
- /*
- * @see
org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
- public void parameterize(Parameters parameters) throws
ParameterException {
-
- this.connectionName = parameters.getParameter("connection");
- this.serviceName = parameters.getParameter("component");
- this.selector = parameters.getParameter("message-selector",
this.selector);
+ public void dispose() {
+ if (this.manager != null){
+ this.manager.release(connection);
+ this.manager.release(service);
+ }
}
-
+
/*
* @see javax.jms.MessageListener#onMessage(javax.jms.Message)
*/
@@ -144,13 +161,14 @@
if (service == null) {
service = (EventAware) this.manager.lookup(this.serviceName);
}
+ Event event = this.convertMessage(message);
if (this.getLogger().isInfoEnabled())
this.getLogger().info(
"Notifying "
+ this.serviceName
+ " of "
- + this.convertMessage(message.toString()));
- service.processEvent(new
NamedEvent(this.convertMessage(message.toString())));
+ + event);
+ service.processEvent(event);
} catch (ServiceException e) {
if (this.getLogger().isErrorEnabled()) {
this.getLogger().error(
@@ -167,33 +185,18 @@
}
/**
- * Convert the message contents to a cache key. Assume that the message
contains of
- * the trigger name, a '|', and the table name. Extract the tablename
only. You might
- * want to override this method.
+ * Convert the message contents to a cache event. The default
implementation
+ * assumes that the message contains the trigger name, a '|', and a
table name.
+ * It extracts the tablename and creates a NamedEvent with it.
+ * Override this method to provide your own message to event mappings.
*
- * @param message
- * @return cache key
+ * @param message the JMS message.
+ * @return the cache event.
*/
- protected String convertMessage(String message) {
- int pos = message.indexOf('|');
- return message.substring(pos + 1);
+ protected Event convertMessage(Message message) {
+ String name = message.toString();
+ int pos = name.indexOf('|');
+ return new NamedEvent(name.substring(pos + 1));
}
-
- /*
- * @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
- }
-
- /* (non-Javadoc)
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
- public void dispose() {
- if (this.manager != null){
- this.manager.release(connection);
- this.manager.release(service);
- }
- }
}