1 package org.apache.cocoon.caching.impl; 16 17 import javax.jms.Message ; 18 19 import org.apache.avalon.framework.parameters.ParameterException; 20 import org.apache.avalon.framework.parameters.Parameters; 21 import org.apache.avalon.framework.thread.ThreadSafe; 22 import org.apache.cocoon.caching.Cache; 23 import org.apache.cocoon.caching.EventAware; 24 import org.apache.cocoon.caching.validity.Event; 25 import org.apache.cocoon.caching.validity.NamedEvent; 26 import org.apache.cocoon.components.jms.AbstractMessageListener; 27 28 54 public class JMSEventMessageListener extends AbstractMessageListener implements ThreadSafe { 55 56 58 private static final String DEFAULT_EVENTCACHE_ROLE = Cache.ROLE + "/EventAware"; 59 private static final String EVENTCACHE_ROLE_PARAM = "eventcache-role"; 60 61 63 private String m_eventAwareRole; 64 private EventAware m_eventCache; 65 66 68 public JMSEventMessageListener() { 69 } 70 71 public void parameterize(Parameters parameters) throws ParameterException { 72 super.parameterize(parameters); 73 m_eventAwareRole = parameters.getParameter(EVENTCACHE_ROLE_PARAM, DEFAULT_EVENTCACHE_ROLE); 74 } 75 76 public void initialize() throws Exception { 77 super.initialize(); 78 m_eventCache = (EventAware) m_manager.lookup(m_eventAwareRole); 79 } 80 81 public void dispose() { 82 super.dispose(); 83 this.m_manager.release(m_eventCache); 84 } 85 86 89 public synchronized void onMessage(Message message) { 90 if (getLogger().isDebugEnabled()) { 91 getLogger().debug("Receiving message: " + message); 92 } 93 final Event[] events = eventsFromMessage(message); 94 for (int i = 0; i < events.length; i++) { 95 if (getLogger().isDebugEnabled()) { 96 getLogger().debug("Notifying " + m_eventAwareRole + " of " + events[i]); 97 } 98 m_eventCache.processEvent(events[i]); 99 } 100 } 101 102 111 protected Event[] eventsFromMessage(Message message) { 112 String name = message.toString(); 113 int pos = name.indexOf('|'); 114 return new Event[] { new NamedEvent(name.substring(pos + 1)) }; 115 } 116 117 } 118 | Popular Tags |