1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| package org.jboss.cache.pojo.notification; |
24 |
| |
25 |
| import java.util.LinkedList; |
26 |
| import java.util.Queue; |
27 |
| |
28 |
| import net.jcip.annotations.NotThreadSafe; |
29 |
| |
30 |
| import org.jboss.cache.pojo.notification.annotation.Attached; |
31 |
| import org.jboss.cache.pojo.notification.annotation.Detached; |
32 |
| import org.jboss.cache.pojo.notification.annotation.FieldModified; |
33 |
| import org.jboss.cache.pojo.notification.annotation.ListModified; |
34 |
| import org.jboss.cache.pojo.notification.annotation.MapModified; |
35 |
| import org.jboss.cache.pojo.notification.annotation.PojoCacheListener; |
36 |
| import org.jboss.cache.pojo.notification.annotation.SetModified; |
37 |
| import org.jboss.cache.pojo.notification.event.Event; |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| @PojoCacheListener |
47 |
| @NotThreadSafe |
48 |
| public class Listener |
49 |
| { |
50 |
| private Queue<Event> events = new LinkedList<Event>(); |
51 |
| |
52 |
165
| @SuppressWarnings("unchecked")
|
53 |
| public <T extends Event> T take(Class<T> t) |
54 |
| { |
55 |
165
| Event notification = events.remove();
|
56 |
165
| if (!t.isInstance(notification))
|
57 |
0
| throw new IllegalStateException("Expected notification type: " + t.getSimpleName() + " but was: " + notification.getClass().getSimpleName());
|
58 |
| |
59 |
165
| return (T) notification;
|
60 |
| } |
61 |
| |
62 |
0
| public void clear()
|
63 |
| { |
64 |
0
| events.clear();
|
65 |
| } |
66 |
| |
67 |
165
| @Attached
|
68 |
| @Detached |
69 |
| @FieldModified |
70 |
| @ListModified |
71 |
| @SetModified |
72 |
| @MapModified |
73 |
| public void handle(Event event) |
74 |
| { |
75 |
165
| events.offer(event);
|
76 |
| } |
77 |
| } |