EventBus.java
6.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.google.common.eventbus;
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import qm;
import qn;
import qo;
@Beta
public class EventBus
{
private static final LoadingCache<Class<?>, Set<Class<?>>> a = CacheBuilder.newBuilder().weakKeys().build(new CacheLoader() {});
private final SetMultimap<Class<?>, qn> b = HashMultimap.create();
private final ReadWriteLock c = new ReentrantReadWriteLock();
private final qo d = new qm();
private final ThreadLocal<Queue<a>> e = new ThreadLocal() {};
private final ThreadLocal<Boolean> f = new ThreadLocal() {};
private SubscriberExceptionHandler g;
public EventBus()
{
this("default");
}
public EventBus(SubscriberExceptionHandler paramSubscriberExceptionHandler)
{
this.g = ((SubscriberExceptionHandler)Preconditions.checkNotNull(paramSubscriberExceptionHandler));
}
public EventBus(String paramString)
{
this(new b(paramString));
}
@VisibleForTesting
private static Set<Class<?>> a(Class<?> paramClass)
{
try
{
paramClass = (Set)a.getUnchecked(paramClass);
return paramClass;
}
catch (UncheckedExecutionException paramClass)
{
throw Throwables.propagate(paramClass.getCause());
}
}
void a(Object paramObject, qn paramqn)
{
((Queue)this.e.get()).offer(new a(paramObject, paramqn));
}
void b(Object paramObject, qn paramqn)
{
try
{
paramqn.a(paramObject);
return;
}
catch (InvocationTargetException localInvocationTargetException)
{
try
{
this.g.handleException(localInvocationTargetException.getCause(), new SubscriberExceptionContext(this, paramObject, paramqn.a, paramqn.b));
return;
}
catch (Throwable paramObject)
{
Logger.getLogger(EventBus.class.getName()).log(Level.SEVERE, String.format("Exception %s thrown while handling exception: %s", new Object[] { paramObject, localInvocationTargetException.getCause() }), (Throwable)paramObject);
}
}
}
void dispatchQueuedEvents()
{
if (((Boolean)this.f.get()).booleanValue()) {
return;
}
this.f.set(Boolean.valueOf(true));
try
{
Queue localQueue = (Queue)this.e.get();
for (;;)
{
a locala = (a)localQueue.poll();
if (locala == null) {
break;
}
b(locala.a, locala.b);
}
this.f.remove();
}
finally
{
this.f.remove();
this.e.remove();
}
this.e.remove();
}
public void post(Object paramObject)
{
Iterator localIterator = a(paramObject.getClass()).iterator();
int i = 0;
while (localIterator.hasNext())
{
Object localObject = (Class)localIterator.next();
this.c.readLock().lock();
try
{
localObject = this.b.get(localObject);
if (!((Set)localObject).isEmpty())
{
int j = 1;
localObject = ((Set)localObject).iterator();
for (;;)
{
i = j;
if (!((Iterator)localObject).hasNext()) {
break;
}
a(paramObject, (qn)((Iterator)localObject).next());
}
}
}
finally
{
this.c.readLock().unlock();
}
}
if ((i == 0) && (!(paramObject instanceof DeadEvent))) {
post(new DeadEvent(this, paramObject));
}
dispatchQueuedEvents();
}
public void register(Object paramObject)
{
paramObject = this.d.a(paramObject);
this.c.writeLock().lock();
try
{
this.b.putAll((Multimap)paramObject);
return;
}
finally
{
this.c.writeLock().unlock();
}
}
public void unregister(Object paramObject)
{
Iterator localIterator = this.d.a(paramObject).asMap().entrySet().iterator();
while (localIterator.hasNext())
{
Object localObject2 = (Map.Entry)localIterator.next();
Object localObject1 = (Class)((Map.Entry)localObject2).getKey();
localObject2 = (Collection)((Map.Entry)localObject2).getValue();
this.c.writeLock().lock();
try
{
localObject1 = this.b.get(localObject1);
if (!((Set)localObject1).containsAll((Collection)localObject2))
{
paramObject = String.valueOf(String.valueOf(paramObject));
throw new IllegalArgumentException(((String)paramObject).length() + 65 + "missing event subscriber for an annotated method. Is " + (String)paramObject + " registered?");
}
}
finally
{
this.c.writeLock().unlock();
}
((Set)localObject1).removeAll((Collection)localObject2);
this.c.writeLock().unlock();
}
}
static final class a
{
final Object a;
final qn b;
public a(Object paramObject, qn paramqn)
{
this.a = Preconditions.checkNotNull(paramObject);
this.b = ((qn)Preconditions.checkNotNull(paramqn));
}
}
static final class b
implements SubscriberExceptionHandler
{
private final Logger a;
public b(String paramString)
{
String str = String.valueOf(String.valueOf(EventBus.class.getName()));
paramString = String.valueOf(String.valueOf((String)Preconditions.checkNotNull(paramString)));
this.a = Logger.getLogger(str.length() + 1 + paramString.length() + str + "." + paramString);
}
public final void handleException(Throwable paramThrowable, SubscriberExceptionContext paramSubscriberExceptionContext)
{
Logger localLogger = this.a;
Level localLevel = Level.SEVERE;
String str = String.valueOf(String.valueOf(paramSubscriberExceptionContext.getSubscriber()));
paramSubscriberExceptionContext = String.valueOf(String.valueOf(paramSubscriberExceptionContext.getSubscriberMethod()));
localLogger.log(localLevel, str.length() + 30 + paramSubscriberExceptionContext.length() + "Could not dispatch event: " + str + " to " + paramSubscriberExceptionContext, paramThrowable.getCause());
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/eventbus/EventBus.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/