84 lines
2.6 KiB
Java
84 lines
2.6 KiB
Java
package com.google.firebase.components;
|
|
|
|
import com.google.android.gms.common.internal.Preconditions;
|
|
import com.google.firebase.events.Event;
|
|
import com.google.firebase.events.EventHandler;
|
|
import com.google.firebase.events.Publisher;
|
|
import com.google.firebase.events.Subscriber;
|
|
import java.util.ArrayDeque;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Queue;
|
|
import java.util.Set;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.Executor;
|
|
|
|
/* compiled from: com.google.firebase:firebase-common@@16.0.2 */
|
|
/* loaded from: classes.dex */
|
|
class zzh implements Publisher, Subscriber {
|
|
private final Map<Class<?>, ConcurrentHashMap<EventHandler<Object>, Executor>> a = new HashMap();
|
|
private Queue<Event<?>> b = new ArrayDeque();
|
|
private final Executor c;
|
|
|
|
zzh(Executor executor) {
|
|
this.c = executor;
|
|
}
|
|
|
|
private synchronized Set<Map.Entry<EventHandler<Object>, Executor>> b(Event<?> event) {
|
|
ConcurrentHashMap<EventHandler<Object>, Executor> concurrentHashMap = this.a.get(event.b());
|
|
if (concurrentHashMap == null) {
|
|
return Collections.emptySet();
|
|
}
|
|
return concurrentHashMap.entrySet();
|
|
}
|
|
|
|
public void a(Event<?> event) {
|
|
Preconditions.a(event);
|
|
synchronized (this) {
|
|
if (this.b != null) {
|
|
this.b.add(event);
|
|
return;
|
|
}
|
|
for (Map.Entry<EventHandler<Object>, Executor> entry : b(event)) {
|
|
entry.getValue().execute(zzi.a(entry, event));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.google.firebase.events.Subscriber
|
|
public synchronized <T> void a(Class<T> cls, Executor executor, EventHandler<? super T> eventHandler) {
|
|
Preconditions.a(cls);
|
|
Preconditions.a(eventHandler);
|
|
Preconditions.a(executor);
|
|
if (!this.a.containsKey(cls)) {
|
|
this.a.put(cls, new ConcurrentHashMap<>());
|
|
}
|
|
this.a.get(cls).put(eventHandler, executor);
|
|
}
|
|
|
|
@Override // com.google.firebase.events.Subscriber
|
|
public <T> void a(Class<T> cls, EventHandler<? super T> eventHandler) {
|
|
a(cls, this.c, eventHandler);
|
|
}
|
|
|
|
final void a() {
|
|
Queue<Event<?>> queue;
|
|
synchronized (this) {
|
|
if (this.b != null) {
|
|
queue = this.b;
|
|
this.b = null;
|
|
} else {
|
|
queue = null;
|
|
}
|
|
}
|
|
if (queue != null) {
|
|
Iterator<Event<?>> it = queue.iterator();
|
|
while (it.hasNext()) {
|
|
a(it.next());
|
|
}
|
|
}
|
|
}
|
|
}
|