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

COVERAGE SUMMARY FOR SOURCE FILE [FacadeHandle.java]

nameclass, %method, %block, %line, %
FacadeHandle.java100% (1/1)50%  (11/22)65%  (146/224)56%  (28.9/52)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FacadeHandle100% (1/1)50%  (11/22)65%  (146/224)56%  (28.9/52)
addDerivation (Long, EventHandler, AbstractEventBus$Handle []): void 0%   (0/1)0%   (0/7)0%   (0/2)
getDerivations (): Collection 0%   (0/1)0%   (0/4)0%   (0/1)
handleException (Exception): void 0%   (0/1)0%   (0/5)0%   (0/2)
isDerivedFrom (Object): boolean 0%   (0/1)0%   (0/5)0%   (0/1)
isDirectPost (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
join (): void 0%   (0/1)0%   (0/4)0%   (0/2)
join (long): boolean 0%   (0/1)0%   (0/5)0%   (0/1)
remove (): void 0%   (0/1)0%   (0/7)0%   (0/3)
setDirectPost (): void 0%   (0/1)0%   (0/4)0%   (0/2)
setStoreHandle (Store$Handle): void 0%   (0/1)0%   (0/5)0%   (0/1)
update (): void 0%   (0/1)0%   (0/4)0%   (0/2)
FacadeHandle (MasterHandle, LocalHandle$HandleStrength): void 100% (1/1)66%  (29/44)75%  (9/12)
invalidateFacade (InferenceContext): void 100% (1/1)82%  (28/34)78%  (7/9)
$SWITCH_TABLE$com$hammurapi$store$local$LocalHandle$HandleStrength (): int [] 100% (1/1)91%  (31/34)91%  (0.9/1)
addDerivative (Derivation): void 100% (1/1)100% (6/6)100% (2/2)
addRemoveListener (RemoveListener): void 100% (1/1)100% (5/5)100% (2/2)
getEvent (): Object 100% (1/1)100% (4/4)100% (1/1)
getId (): Long 100% (1/1)100% (4/4)100% (1/1)
getMaster (): MasterHandle 100% (1/1)100% (3/3)100% (1/1)
isValid (): boolean 100% (1/1)100% (11/11)100% (1/1)
remove (boolean, InferenceContext): void 100% (1/1)100% (9/9)100% (3/3)
toString (): String 100% (1/1)100% (16/16)100% (1/1)

1package com.hammurapi.eventbus.local;
2 
3import java.lang.ref.Reference;
4import java.lang.ref.SoftReference;
5import java.lang.ref.WeakReference;
6import java.util.Collection;
7import java.util.concurrent.ConcurrentLinkedQueue;
8 
9import com.hammurapi.eventbus.AbstractEventBus;
10import com.hammurapi.eventbus.AbstractEventBus.Handle;
11import com.hammurapi.eventbus.Derivation;
12import com.hammurapi.eventbus.EventHandler;
13import com.hammurapi.eventbus.EventStore;
14import com.hammurapi.eventbus.InferenceContext;
15import com.hammurapi.eventbus.local.LocalEventBusBase.LocalHandle;
16import com.hammurapi.store.Store;
17import com.hammurapi.store.local.LocalHandle.HandleStrength;
18 
19/**
20 * Facade handles are used by event joiners and derivations. When master handle is invalidated, it sends notifications to facades and they get invalidated.
21 * @author Pavel Vlasov
22 *
23 * @param <E>
24 * @param <P>
25 * @param <C>
26 * @param <S>
27 */
28class FacadeHandle<E, P extends Comparable<P>, C, S extends EventStore<E, P, C, AbstractEventBus.Handle<E, P, C, Long>, S>> implements LocalHandle<E,P,C,S> {
29        private MasterHandle<E,P,C,S> master;
30        private E event; // Never read - just to create strong reference.
31        private Reference<E> eventRef;
32        private Collection<Derivation<E,P,C>> derivatives = new ConcurrentLinkedQueue<Derivation<E,P,C>>();
33        private long masterId;
34        
35        public FacadeHandle(MasterHandle<E,P,C,S> master, HandleStrength handleStrength) {
36                this.master = master;
37                this.masterId = master.getId();
38                master.addFacade(this);
39                switch (handleStrength) {
40                case STRONG:
41                        event = master.getEvent();
42                        break;
43                case SOFT:
44                        eventRef = new SoftReference<E>(master.getEvent());
45                        break;
46                case WEAK:
47                        eventRef = new WeakReference<E>(master.getEvent());
48                        break;
49                }
50        }
51 
52        void addDerivative(Derivation<E,P,C> derivative) {
53                derivatives.add(derivative);
54        }
55 
56        public Long getId() {
57                return masterId;
58        }
59 
60        public Collection<Derivation<E,P,C>> getDerivations() {
61                return master.getDerivations();
62        }
63 
64        public E getEvent() {
65                return master.getEvent();
66        }
67        
68        @Override
69        public void remove() {
70                if (master!=null) {
71                        master.remove();
72                }
73        }
74 
75        public void remove(boolean forUpdate, InferenceContext<E,P,C,Long,AbstractEventBus.Handle<E,P,C,Long>,S> inferenceContext) {
76                if (master!=null) {
77                        master.remove(forUpdate, inferenceContext);
78                }
79        }
80        
81        public boolean isDerivedFrom(E event) {
82                return master.isDerivedFrom(event);
83        }
84 
85        public boolean isValid() {
86                return master!=null && master.isValid();
87        }
88 
89//        public void setEvent(E event) {
90//                master.setEvent(event);
91//        }
92 
93        public void update() {
94                master.update();
95        }
96        
97        public MasterHandle<E,P,C,S> getMaster() {
98                return master;
99        }
100        
101        /**
102         * Invoked by master.
103         */
104        void invalidateFacade(InferenceContext<E,P,C,Long,AbstractEventBus.Handle<E,P,C,Long>,S> inferenceContext) {
105                event = null;
106                if (eventRef!=null) {
107                        eventRef.clear();
108                        eventRef = null;
109                }
110                master = null;
111 
112                for (Derivation<E,P,C> derivative: derivatives) {
113                        derivative.invalidate(inferenceContext);
114                }
115                derivatives.clear();
116        }
117 
118        @Override
119        public void join() throws InterruptedException {
120                master.join();                
121        }
122 
123        @Override
124        public boolean join(long timeout) throws InterruptedException {
125                return master.join(timeout);
126        }
127        
128        @Override
129        public <H extends AbstractEventBus.Handle<E,P,C,Long>, S extends EventStore<E, P, C, H, S>> void setStoreHandle(Store.Handle<H, E, S> storeHandle) {
130                throw new UnsupportedOperationException("This operation shall not be invoked for FacadeHandle");                
131        }
132 
133        @Override
134        public String toString() {
135                return "FacadeHandle [getId()="+getId()+", master=" + master + "]";
136        }
137 
138        @Override
139        public void handleException(Exception e) {
140                master.handleException(e);
141        }
142 
143        @Override
144        public boolean isDirectPost() {
145                return master.isDirectPost();
146        }
147 
148        @Override
149        public void setDirectPost() {
150                master.setDirectPost();
151        }
152 
153        @Override
154        public void addDerivation(Long handlerId, EventHandler<E, P, C, ?, ?> handler, Handle<E, P, C, Long>[] inputs) {
155                master.addDerivation(handlerId, handler, inputs);
156                
157        }
158 
159        @Override
160        public void addRemoveListener(RemoveListener<E, P, C, S> removeListener) {
161                master.addRemoveListener(removeListener);
162        }
163        
164}
165 

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