| 1 | package com.hammurapi.eventbus; |
| 2 | |
| 3 | import java.io.Serializable; |
| 4 | import java.util.logging.Level; |
| 5 | import java.util.logging.Logger; |
| 6 | |
| 7 | import com.hammurapi.eventbus.AbstractEventBus.Handle; |
| 8 | |
| 9 | class HandlerTask<E,P extends Comparable<P>,C,K, H extends EventBus.Handle<E,P,C>, S extends EventStore<E,P,C,H,S>> implements Runnable, Serializable { |
| 10 | private static final Logger logger = Logger.getLogger(HandlerTask.class.getName()); |
| 11 | |
| 12 | private Handle<E,P,C,K> handle; |
| 13 | private EventHandlerWrapper<E, P, C, K, H, S> handler; |
| 14 | |
| 15 | private InferenceContext<E,P,C,K,H,S> inferenceContext; |
| 16 | |
| 17 | HandlerTask( |
| 18 | Handle<E,P,C,K> handle, |
| 19 | EventHandlerWrapper<E, P, C, K, H, S> handler, |
| 20 | InferenceContext<E,P,C,K,H,S> inferenceContext) { |
| 21 | this.handle = handle; |
| 22 | this.handler = handler; |
| 23 | this.inferenceContext = inferenceContext; |
| 24 | } |
| 25 | |
| 26 | @SuppressWarnings("unchecked") |
| 27 | @Override |
| 28 | public void run() { |
| 29 | try { |
| 30 | handler.post(null, inferenceContext, handle); |
| 31 | } catch (Exception e) { |
| 32 | logger.log(Level.SEVERE, "Exception during event handling: "+e, e); |
| 33 | if (inferenceContext.getBus().getExceptionHandler()!=null) { |
| 34 | inferenceContext.getBus().getExceptionHandler().handleException(e); |
| 35 | } |
| 36 | if (inferenceContext.getRootHandle()!=null) { |
| 37 | inferenceContext.getRootHandle().handleException(e); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | } |
| 43 | |