EMMA Coverage Report (generated Thu Jan 20 11:39:44 EST 2011)
[all classes][com.hammurapi.eventbus.local]

COVERAGE SUMMARY FOR SOURCE FILE [LocalEventDispatchContextImpl.java]

nameclass, %method, %block, %line, %
LocalEventDispatchContextImpl.java100% (1/1)80%  (8/10)84%  (161/191)86%  (32/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LocalEventDispatchContextImpl100% (1/1)80%  (8/10)84%  (161/191)86%  (32/37)
getEventStore (): EventStore 0%   (0/1)0%   (0/6)0%   (0/1)
removeHandler (): void 0%   (0/1)0%   (0/12)0%   (0/2)
update (Object): void 100% (1/1)82%  (31/38)83%  (5/6)
consume (int): void 100% (1/1)84%  (26/31)80%  (4/5)
<static initializer> 100% (1/1)100% (5/5)100% (2/2)
LocalEventDispatchContextImpl (InferenceContext, EventHandler, Long, Abstract... 100% (1/1)100% (21/21)100% (8/8)
consume (Object): void 100% (1/1)100% (19/19)100% (4/4)
getMode (): EventHandlerBase$Mode 100% (1/1)100% (3/3)100% (1/1)
post (Object, Predicate []): void 100% (1/1)100% (20/20)100% (3/3)
update (MasterHandle): void 100% (1/1)100% (36/36)100% (5/5)

1package com.hammurapi.eventbus.local;
2 
3import java.util.Queue;
4 
5import com.hammurapi.eventbus.AbstractEventBus;
6import com.hammurapi.eventbus.AbstractEventBus.Handle;
7import com.hammurapi.eventbus.EventDispatchContext;
8import com.hammurapi.eventbus.EventHandler;
9import com.hammurapi.eventbus.EventHandlerBase.Mode;
10import com.hammurapi.eventbus.EventStore;
11import com.hammurapi.eventbus.InferenceCommand;
12import com.hammurapi.eventbus.InferenceContext;
13import com.hammurapi.eventbus.InferencePolicy;
14import com.hammurapi.eventbus.PostCommand;
15import com.hammurapi.eventbus.RemoveCommand;
16import com.hammurapi.extract.Predicate;
17 
18class LocalEventDispatchContextImpl<E, P extends Comparable<P>, C, S extends EventStore<E, P, C, AbstractEventBus.Handle<E, P, C, Long>, S>> implements EventDispatchContext<E, P, C, AbstractEventBus.Handle<E,P,C,Long>, S> {
19        
20        static ThreadLocal<LocalEventDispatchContextImpl<?, ?, ?, ?>> threadContext = new ThreadLocal<LocalEventDispatchContextImpl<?,?,?,?>>();
21        
22        private Handle<E,P,C,Long>[] handles;
23        private Long registrationKey;
24        private E[] events;
25        private EventHandler<E, P, C, AbstractEventBus.Handle<E,P,C,Long>, S> eventHandler;
26 
27        private Mode mode;
28 
29        private InferenceContext<E, P, C, Long, Handle<E, P, C, Long>, S> inferenceContext;
30 
31        public LocalEventDispatchContextImpl(
32                        InferenceContext<E, P, C, Long, AbstractEventBus.Handle<E,P,C,Long>, S> inferenceContext,
33                        EventHandler<E, P, C, AbstractEventBus.Handle<E,P,C,Long>, S> eventHandler,
34                        Long registrationKey,
35                        Handle<E,P,C,Long>[] handles,
36                        E[] events, 
37                        Mode mode) {
38                this.inferenceContext = inferenceContext;
39                this.handles = handles;
40                this.registrationKey = registrationKey;
41                this.events = events;
42                this.eventHandler = eventHandler;
43                this.mode = mode;
44        }
45 
46        @Override
47        public void consume(int index) {
48                if (!eventHandler.consumes()) {
49                        throw new IllegalStateException("This handler's declared that it doesn't consume events");
50                }
51                InferenceCommand<E, P, C, Long, Handle<E, P, C, Long>, S> consumeCommand = new RemoveCommand<E, P, C, Long, Handle<E, P, C, Long>, S>(handles[index], registrationKey, eventHandler, inferenceContext, false, handles);
52                inferenceContext.postInferenceCommand(consumeCommand);
53        }
54 
55        @Override
56        public void consume(E event) {
57                for (int i=0; i<events.length; ++i) {
58                        if (event==events[i]) {                                
59                                consume(i);
60                        }
61                }
62        }
63 
64        @Override
65        public void post(E event, Predicate<E, S>... validators) {                
66                InferenceCommand<E, P, C, Long, Handle<E, P, C, Long>, S> postCommand = new PostCommand<E, P, C, Long, Handle<E, P, C, Long>, S>(event, false, registrationKey, eventHandler, handles, inferenceContext, validators);
67                inferenceContext.postInferenceCommand(postCommand);
68        }
69        
70        @Override
71        public void removeHandler() {
72                inferenceContext.getBus().removeHandlers(registrationKey);
73        }
74 
75        @Override
76        public void update(E event) {
77                for (int i=0; i<events.length; ++i) {                        
78                        if (event==events[i]) {
79                                if (handles[i] instanceof FacadeHandle) {
80                                        update(((FacadeHandle<E,P,C,S>) handles[i]).getMaster());
81                                } else {
82                                        update((MasterHandle<E, P, C, S>) handles[i]);
83                                }
84                        }
85                }
86        }
87        
88        void update(MasterHandle<E, P, C, S> handle) {
89                InferenceCommand<E, P, C, Long, Handle<E, P, C, Long>, S> removeCommand = new RemoveCommand<E, P, C, Long, Handle<E, P, C, Long>, S>(handle, registrationKey, eventHandler, inferenceContext, true, handles);
90                inferenceContext.postInferenceCommand(removeCommand);
91                
92                InferenceCommand<E, P, C, Long, Handle<E, P, C, Long>, S> postCommand = new PostCommand<E, P, C, Long, Handle<E, P, C, Long>, S>(handle, registrationKey, eventHandler, handles, inferenceContext);
93                inferenceContext.postInferenceCommand(postCommand);
94        }
95 
96        @Override
97        public S getEventStore() {
98                return (S) ((LocalEventBusBase) inferenceContext.getBus()).unmodifiableStore;
99        }
100 
101        @Override
102        public Mode getMode() {
103                return mode;
104        }
105        
106}

[all classes][com.hammurapi.eventbus.local]
EMMA 2.0.5312 EclEmma Fix 2 (C) Vladimir Roubtsov