- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
103 lines
3.4 KiB
Java
103 lines
3.4 KiB
Java
package com.google.firebase.components;
|
|
|
|
import com.amazonaws.handlers.HandlerChainFactory$$ExternalSyntheticThrowCCEIfNotNull0;
|
|
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.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;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class EventBus implements Subscriber, Publisher {
|
|
public final Executor defaultExecutor;
|
|
public final Map handlerMap = new HashMap();
|
|
public Queue pendingEvents = new ArrayDeque();
|
|
|
|
public EventBus(Executor executor) {
|
|
this.defaultExecutor = executor;
|
|
}
|
|
|
|
public void publish(final Event event) {
|
|
Preconditions.checkNotNull(event);
|
|
synchronized (this) {
|
|
try {
|
|
Queue queue = this.pendingEvents;
|
|
if (queue != null) {
|
|
queue.add(event);
|
|
return;
|
|
}
|
|
for (final Map.Entry entry : getHandlers(event)) {
|
|
((Executor) entry.getValue()).execute(new Runnable(entry, event) { // from class: com.google.firebase.components.EventBus$$ExternalSyntheticLambda0
|
|
public final /* synthetic */ Map.Entry f$0;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
EventBus.lambda$publish$0(this.f$0, null);
|
|
}
|
|
});
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static /* synthetic */ void lambda$publish$0(Map.Entry entry, Event event) {
|
|
((EventHandler) entry.getKey()).handle(event);
|
|
}
|
|
|
|
public final synchronized Set getHandlers(Event event) {
|
|
throw null;
|
|
}
|
|
|
|
@Override // com.google.firebase.events.Subscriber
|
|
public synchronized void subscribe(Class cls, Executor executor, EventHandler eventHandler) {
|
|
try {
|
|
Preconditions.checkNotNull(cls);
|
|
Preconditions.checkNotNull(eventHandler);
|
|
Preconditions.checkNotNull(executor);
|
|
if (!this.handlerMap.containsKey(cls)) {
|
|
this.handlerMap.put(cls, new ConcurrentHashMap());
|
|
}
|
|
((ConcurrentHashMap) this.handlerMap.get(cls)).put(eventHandler, executor);
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
@Override // com.google.firebase.events.Subscriber
|
|
public void subscribe(Class cls, EventHandler eventHandler) {
|
|
subscribe(cls, this.defaultExecutor, eventHandler);
|
|
}
|
|
|
|
public void enablePublishingAndFlushPending() {
|
|
Queue queue;
|
|
synchronized (this) {
|
|
try {
|
|
queue = this.pendingEvents;
|
|
if (queue != null) {
|
|
this.pendingEvents = null;
|
|
} else {
|
|
queue = null;
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
if (queue != null) {
|
|
Iterator it = queue.iterator();
|
|
while (it.hasNext()) {
|
|
HandlerChainFactory$$ExternalSyntheticThrowCCEIfNotNull0.m(it.next());
|
|
publish(null);
|
|
}
|
|
}
|
|
}
|
|
}
|