package io.grpc.internal; import com.google.common.base.Preconditions; import io.grpc.ChannelLogger; import io.grpc.InternalChannelz; import io.grpc.InternalLogId; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public final class ChannelTracer { static final Logger logger = Logger.getLogger(ChannelLogger.class.getName()); private final long channelCreationTimeNanos; private final Collection events; private int eventsLogged; private final Object lock = new Object(); private final InternalLogId logId; static /* synthetic */ int access$008(ChannelTracer channelTracer) { int i = channelTracer.eventsLogged; channelTracer.eventsLogged = i + 1; return i; } /* JADX INFO: Access modifiers changed from: package-private */ public ChannelTracer(InternalLogId internalLogId, int i, long j, String str) { Preconditions.checkNotNull(str, "description"); this.logId = (InternalLogId) Preconditions.checkNotNull(internalLogId, "logId"); this.events = i > 0 ? new ArrayDeque(this, i) { // from class: io.grpc.internal.ChannelTracer.1 final ChannelTracer this$0; final int val$maxEvents; { this.this$0 = this; this.val$maxEvents = i; } @Override // java.util.ArrayDeque, java.util.AbstractCollection, java.util.Collection, java.util.Deque, java.util.Queue public boolean add(InternalChannelz.ChannelTrace.Event event) { if (size() == this.val$maxEvents) { removeFirst(); } ChannelTracer.access$008(this.this$0); return super.add((AnonymousClass1) event); } } : null; this.channelCreationTimeNanos = j; InternalChannelz.ChannelTrace.Event.Builder builder = new InternalChannelz.ChannelTrace.Event.Builder(); StringBuilder sb = new StringBuilder(); sb.append(str); sb.append(" created"); reportEvent(builder.setDescription(sb.toString()).setSeverity(InternalChannelz.ChannelTrace.Event.Severity.CT_INFO).setTimestampNanos(j).build()); } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: io.grpc.internal.ChannelTracer$2, reason: invalid class name */ /* loaded from: classes6.dex */ public static /* synthetic */ class AnonymousClass2 { static final int[] $SwitchMap$io$grpc$InternalChannelz$ChannelTrace$Event$Severity; static { int[] iArr = new int[InternalChannelz.ChannelTrace.Event.Severity.values().length]; $SwitchMap$io$grpc$InternalChannelz$ChannelTrace$Event$Severity = iArr; try { iArr[InternalChannelz.ChannelTrace.Event.Severity.CT_ERROR.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { $SwitchMap$io$grpc$InternalChannelz$ChannelTrace$Event$Severity[InternalChannelz.ChannelTrace.Event.Severity.CT_WARNING.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } } } /* JADX INFO: Access modifiers changed from: package-private */ public final void reportEvent(InternalChannelz.ChannelTrace.Event event) { Level level; int i = AnonymousClass2.$SwitchMap$io$grpc$InternalChannelz$ChannelTrace$Event$Severity[event.severity.ordinal()]; if (i == 1) { level = Level.FINE; } else if (i == 2) { level = Level.FINER; } else { level = Level.FINEST; } traceOnly(event); logOnly(this.logId, level, event.description); } /* JADX INFO: Access modifiers changed from: package-private */ public final boolean isTraceEnabled() { boolean z; synchronized (this.lock) { z = this.events != null; } return z; } /* JADX INFO: Access modifiers changed from: package-private */ public final void traceOnly(InternalChannelz.ChannelTrace.Event event) { synchronized (this.lock) { Collection collection = this.events; if (collection != null) { collection.add(event); } } } /* JADX INFO: Access modifiers changed from: package-private */ public static void logOnly(InternalLogId internalLogId, Level level, String str) { Logger logger2 = logger; if (logger2.isLoggable(level)) { StringBuilder sb = new StringBuilder("["); sb.append(internalLogId); sb.append("] "); sb.append(str); LogRecord logRecord = new LogRecord(level, sb.toString()); logRecord.setLoggerName(logger2.getName()); logRecord.setSourceClassName(logger2.getName()); logRecord.setSourceMethodName("log"); logger2.log(logRecord); } } /* JADX INFO: Access modifiers changed from: package-private */ public final void updateBuilder(InternalChannelz.ChannelStats.Builder builder) { synchronized (this.lock) { if (this.events == null) { return; } builder.setChannelTrace(new InternalChannelz.ChannelTrace.Builder().setNumEventsLogged(this.eventsLogged).setCreationTimeNanos(this.channelCreationTimeNanos).setEvents(new ArrayList(this.events)).build()); } } /* JADX INFO: Access modifiers changed from: package-private */ public final InternalLogId getLogId() { return this.logId; } }