/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.mina.util.ExceptionMonitor
 */
package com.l7tech.server.log.syslog.impl;

import com.l7tech.server.log.syslog.ManagedSyslog;
import com.l7tech.server.log.syslog.SyslogConfig;
import com.l7tech.server.log.syslog.SyslogSeverity;
import com.l7tech.server.log.syslog.impl.b;
import com.l7tech.server.log.syslog.impl.e;
import com.l7tech.server.log.syslog.impl.f;
import com.l7tech.server.log.syslog.impl.i;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.mina.util.ExceptionMonitor;

public class MinaManagedSyslog
extends ManagedSyslog {
    private static final Logger d;
    private ReentrantLock e = new ReentrantLock();
    private List<e> f;
    private final BlockingQueue<f> g;
    private final b h;
    private boolean i = false;
    private ExecutorService j = Executors.newSingleThreadExecutor();
    private SyslogConfig k;
    private static final String[] l;

    public MinaManagedSyslog(SyslogConfig syslogConfig) {
        this.k = syslogConfig;
        this.g = new LinkedBlockingQueue<f>(this.k.getQueueSize());
        this.f = new ArrayList<e>(this.k.getDropSize());
        this.h = new b(this.k, this.g);
    }

    MinaManagedSyslog(SyslogConfig syslogConfig, b b10) {
        this.k = syslogConfig;
        this.g = new LinkedBlockingQueue<f>(this.k.getQueueSize());
        this.f = new ArrayList<e>(this.k.getDropSize());
        this.h = b10;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public void log(ManagedSyslog.SyslogFormat syslogFormat, int n2, SyslogSeverity syslogSeverity, String string, String string2, long l2, long l3, String string3) {
        if (!this.h.b()) {
            return;
        }
        f f2 = this.a(syslogFormat, n2, syslogSeverity, string, string2, l2, l3, string3);
        if (!this.g.offer(f2)) {
            try {
                this.e.lock();
                if (!this.g.offer(f2)) {
                    this.g.drainTo(this.f, this.k.getDropSize());
                    this.f.clear();
                    this.g.add(f2);
                    d.log(Level.WARNING, l[0], new Object[]{this.k.getQueueSize(), this.k.getDropSize(), this.g.remainingCapacity()});
                }
            }
            finally {
                this.e.unlock();
            }
        }
    }

    int d() {
        return this.g.size();
    }

    @Override
    public void close() {
        this.g.clear();
        this.h.a();
        this.j.shutdownNow();
    }

    @Override
    protected void init() {
        if (!this.i) {
            this.i = true;
            this.h.a(this.getSyslogConnectionListener());
            this.j.execute(this.h);
            d.log(Level.INFO, l[1], this.k.getQueueSize());
        }
    }

    private f a(ManagedSyslog.SyslogFormat syslogFormat, int n2, SyslogSeverity syslogSeverity, String string, String string2, long l2, long l3, String string3) {
        return new f(syslogFormat, n2, syslogSeverity.getSeverity(), string, string2, l2, l3, string3);
    }

    static /* synthetic */ String access$000(ManagedSyslog.SyslogFormat syslogFormat, int n2, int n3, int n4, String string, String string2, long l2, long l3, String string3) {
        return MinaManagedSyslog.formatMessage(syslogFormat, n2, n3, n4, string, string2, l2, l3, string3);
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "7yV\u0011;/\u0019\teV\u000e5/\\DqP\u0018!-\u0019\rs\u0005\u001b!$UD(^M)a\u0015DdW\u0012$8\\\u0000 ^L)hV\bd@\u000e hT\u0001sV\u001c3-JJ k\u0018#hJ\u001dsI\u00123hT\u0001sV\u001c3-\u0019\u0015u@\b1hK\u0001mD\u0014:!W\u0003 F\u001c$)Z\rt\\]=;\u0019\u001f2XS,-nL\t=)U\rz@]'1J\boB]9-J\u0017aB\u0018t9L\u0001u@]'!C\u0001 Q\u0012t3\t\u0019.";
        int n3 = "7yV\u0011;/\u0019\teV\u000e5/\\DqP\u0018!-\u0019\rs\u0005\u001b!$UD(^M)a\u0015DdW\u0012$8\\\u0000 ^L)hV\bd@\u000e hT\u0001sV\u001c3-JJ k\u0018#hJ\u001dsI\u00123hT\u0001sV\u001c3-\u0019\u0015u@\b1hK\u0001mD\u0014:!W\u0003 F\u001c$)Z\rt\\]=;\u0019\u001f2XS,-nL\t=)U\rz@]'1J\boB]9-J\u0017aB\u0018t9L\u0001u@]'!C\u0001 Q\u0012t3\t\u0019.".length();
        int n4 = 116;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = MinaManagedSyslog.b(124, MinaManagedSyslog.b(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                l = stringArray;
                d = Logger.getLogger(MinaManagedSyslog.class.getName());
                ExceptionMonitor.setInstance((ExceptionMonitor)new i());
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x45);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 24;
                    case 1 -> 124;
                    case 2 -> 89;
                    case 3 -> 1;
                    case 4 -> 40;
                    case 5 -> 52;
                    default -> 69;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

