01: package org.obe.spi.util;
02:
03: import org.obe.engine.WorkflowEngine;
04: import org.obe.spi.event.ApplicationEvent;
05: import org.obe.spi.service.ApplicationEventBroker;
06: import org.obe.spi.service.AsyncManager;
07:
08: import java.util.Date;
09:
10: /**
11: * Asynchronously fires an application event. The {@link #run()} method calls
12: * {@link ApplicationEventBroker#fireApplicationEvent(ApplicationEvent, String[])
13: * ApplicationEventBroker.fireApplicationEvent()}.
14: *
15: * @author Adrian Price
16: */
17: public class AsyncFireApplicationEvent implements
18: AsyncManager.AsyncRequest {
19: private final ApplicationEvent _event;
20: private final String[] _correlationKeys;
21:
22: public AsyncFireApplicationEvent(ApplicationEvent event,
23: String[] correlationKeys) {
24:
25: _event = event;
26: _correlationKeys = correlationKeys;
27: }
28:
29: public void run() {
30: // If the event is still valid, notify the listeners.
31: Date latest = _event.getExpiry();
32: if (latest == null
33: || latest.getTime() <= System.currentTimeMillis()) {
34:
35: WorkflowEngine.getEngine().getServiceManager()
36: .getApplicationEventBroker().fireApplicationEvent(
37: _event, _correlationKeys);
38: }
39: }
40: }
|