/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.log.HybridDiagnosticContextMatcher
 *  com.l7tech.common.log.HybridDiagnosticContextMatcher$MatcherRules
 *  com.l7tech.gateway.common.log.GatewayDiagnosticContextKeys
 *  com.l7tech.gateway.common.log.SinkConfiguration
 */
package com.l7tech.server.log;

import com.l7tech.common.log.HybridDiagnosticContextMatcher;
import com.l7tech.gateway.common.log.GatewayDiagnosticContextKeys;
import com.l7tech.gateway.common.log.SinkConfiguration;
import com.l7tech.server.log.MessageCategory;
import com.l7tech.server.log.MessageSink;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

abstract class MessageSinkSupport
implements MessageSink {
    private final SinkConfiguration a;
    private final Set<MessageCategory> b;
    private final int c;
    private final HybridDiagnosticContextMatcher.MatcherRules d;

    @Override
    public void message(MessageCategory messageCategory, LogRecord logRecord) {
        block4: {
            try {
                try {
                    if (logRecord == null || !this.a(messageCategory, logRecord)) break block4;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw MessageSinkSupport.a(illegalArgumentException);
                }
                this.processMessage(messageCategory, logRecord);
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw MessageSinkSupport.a(illegalArgumentException);
            }
        }
    }

    @Override
    public List<Handler> getHandlers() {
        return Collections.emptyList();
    }

    MessageSinkSupport(SinkConfiguration sinkConfiguration) {
        this.a = sinkConfiguration;
        this.c = sinkConfiguration.getSeverity().toLoggingLevel().intValue();
        this.b = this.a(sinkConfiguration);
        this.d = new HybridDiagnosticContextMatcher.MatcherRules(sinkConfiguration.getFilters(), GatewayDiagnosticContextKeys.PREFIX_MATCH_PROPERTIES);
    }

    SinkConfiguration a() {
        return this.a;
    }

    int getThreshold() {
        return this.c;
    }

    boolean a(MessageCategory messageCategory) {
        boolean bl2;
        block2: {
            bl2 = false;
            try {
                if (messageCategory == null || !this.b.contains((Object)messageCategory)) break block2;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw MessageSinkSupport.a(illegalArgumentException);
            }
            bl2 = true;
        }
        return bl2;
    }

    abstract void processMessage(MessageCategory var1, LogRecord var2);

    private boolean a(MessageCategory messageCategory, LogRecord logRecord) {
        boolean bl2;
        block7: {
            block6: {
                try {
                    try {
                        try {
                            if (logRecord.getLevel().intValue() < this.getThreshold() || !this.a(messageCategory)) break block6;
                        }
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw MessageSinkSupport.a(illegalArgumentException);
                        }
                        if (!HybridDiagnosticContextMatcher.matches((HybridDiagnosticContextMatcher.MatcherRules)this.d)) break block6;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw MessageSinkSupport.a(illegalArgumentException);
                    }
                    bl2 = true;
                    break block7;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw MessageSinkSupport.a(illegalArgumentException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    private Set<MessageCategory> a(SinkConfiguration sinkConfiguration) {
        HashSet<MessageCategory> hashSet = new HashSet<MessageCategory>();
        String string = sinkConfiguration.getCategories();
        if (string != null) {
            StringTokenizer stringTokenizer = new StringTokenizer(string, ",");
            while (stringTokenizer.hasMoreTokens()) {
                String string2 = stringTokenizer.nextToken().trim();
                try {
                    hashSet.add(MessageCategory.valueOf(string2));
                }
                catch (IllegalArgumentException illegalArgumentException) {}
            }
        }
        return Collections.unmodifiableSet(hashSet);
    }

    private static IllegalArgumentException a(IllegalArgumentException illegalArgumentException) {
        return illegalArgumentException;
    }

    static class ConfigurationException
    extends Exception {
        static final long serialVersionUID = -2488045756444917897L;

        ConfigurationException(String string) {
            super(string);
        }

        ConfigurationException(String string, Throwable throwable) {
            super(string, throwable);
        }
    }
}

