001: package org.obe.server.j2ee.service;
002:
003: import java.util.Collection;
004: import java.util.Date;
005: import java.util.Iterator;
006: import javax.ejb.CreateException;
007: import javax.ejb.FinderException;
008: import javax.ejb.RemoveException;
009: import org.apache.commons.logging.Log;
010: import org.obe.client.api.repository.RepositoryException;
011: import org.obe.client.api.repository.EventTypeMetaData;
012: import org.obe.event.AbstractApplicationEventBroker;
013: import org.obe.event.BasicApplicationEventBroker;
014: import org.obe.server.j2ee.ejb.EventSubscriptionLocal;
015: import org.obe.server.j2ee.repository.EJBLocalHelper;
016: import org.obe.server.util.ObjectUtil;
017: import org.obe.spi.event.ApplicationEvent;
018: import org.obe.spi.service.ServiceManager;
019: import org.obe.xpdl.model.misc.Duration;
020:
021: /**
022: * Provides a persistent application event broker service.
023: *
024: * @author Adrian Price
025: */
026: public class EJBApplicationEventBroker extends
027: AbstractApplicationEventBroker {
028: protected static final Log _logger = getLog(EJBApplicationEventBroker.class);
029:
030: public EJBApplicationEventBroker(ServiceManager svcMgr) {
031: super (svcMgr);
032: }
033:
034: protected String getConfigurationFileName() {
035: String filename = BasicApplicationEventBroker.class.getName();
036: return filename.substring(filename.lastIndexOf('.') + 1)
037: + ".xml";
038: }
039:
040: protected Log getLogger() {
041: return _logger;
042: }
043:
044: protected ApplicationEventSubscription createSubscription(
045: String eventType, Object[] eventKeys, String predicate,
046: Date effective, Date expiry, int count,
047: String[] correlationKeys) throws RepositoryException {
048:
049: try {
050: return EJBLocalHelper.getEventSubscriptionHome().create(
051: eventType, eventKeys, predicate, effective, expiry,
052: count, correlationKeys);
053: } catch (CreateException e) {
054: throw new RepositoryException(e);
055: }
056: }
057:
058: protected TemporalEventSubscription createSubscription(
059: String eventType, Date effective, Date expiry, int count,
060: Duration interval, String calendar, boolean recoverable,
061: String[] correlationKeys) throws RepositoryException {
062:
063: try {
064: return EJBLocalHelper.getEventSubscriptionHome().create(
065: eventType, effective, expiry, count,
066: interval == null ? null : interval.toString(),
067: calendar, recoverable, correlationKeys);
068: } catch (CreateException e) {
069: throw new RepositoryException(e);
070: }
071: }
072:
073: public void unsubscribe(String[] correlationKeys, boolean exact)
074: throws RepositoryException {
075:
076: try {
077: Collection subs = EJBLocalHelper.getEventSubscriptionHome()
078: .xfindByCorrelationKeys(correlationKeys, exact);
079: for (Iterator i = subs.iterator(); i.hasNext();) {
080: EventSubscriptionLocal sub = (EventSubscriptionLocal) i
081: .next();
082: sub.remove();
083: }
084: } catch (FinderException e) {
085: throw new RepositoryException(e);
086: } catch (RemoveException e) {
087: throw new RepositoryException(e);
088: }
089: }
090:
091: protected Collection findSubscriptions(ApplicationEvent event,
092: EventTypeMetaData metaData) throws RepositoryException {
093:
094: try {
095: Object[] keys = event.getKeys();
096: return EJBLocalHelper.getEventSubscriptionHome()
097: .xfindByEvent(
098: event.getEventType(),
099: keys,
100: ObjectUtil.hashcode(keys, metaData
101: .getInputParameterCount()));
102: } catch (FinderException e) {
103: throw new RepositoryException(e);
104: }
105: }
106:
107: protected void storeEvent(ApplicationEvent event,
108: EventTypeMetaData metaData) throws RepositoryException {
109:
110: try {
111: EJBLocalHelper.getApplicationEventHome().create(
112: event,
113: ObjectUtil.hashcode(event.getKeys(), metaData
114: .getInputParameterCount()));
115: } catch (CreateException e) {
116: throw new RepositoryException(e);
117: }
118: }
119:
120: protected Collection findStoredEvents(String eventType,
121: Object[] subscriptionKeys) throws RepositoryException {
122:
123: try {
124: return EJBLocalHelper.getApplicationEventHome()
125: .xfindByEvent(eventType, subscriptionKeys);
126: } catch (FinderException e) {
127: throw new RepositoryException(e);
128: }
129: }
130: }
|