/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.service.MetricsBin
 *  org.springframework.dao.DataIntegrityViolationException
 */
package com.l7tech.server.service;

import com.l7tech.gateway.common.service.MetricsBin;
import com.l7tech.server.service.ServiceMetrics;
import com.l7tech.server.service.ServiceMetricsServicesImpl;
import java.util.logging.Level;
import org.springframework.dao.DataIntegrityViolationException;

class ae
implements Runnable {
    private final Object a;
    private boolean b;
    final ServiceMetricsServicesImpl this$0;
    private static final String[] c;

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    ae(ServiceMetricsServicesImpl serviceMetricsServicesImpl) {
        this.this$0 = serviceMetricsServicesImpl;
        Object object = this.a = new Object();
        synchronized (object) {
            this.b = false;
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public void quit() {
        Object object = this.a;
        synchronized (object) {
            this.b = true;
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Unable to fully structure code
     */
    @Override
    public void run() {
        var6_1 = ae.c;
        ServiceMetricsServicesImpl.a.info(var6_1[3]);
        while (true) lbl-1000:
        // 6 sources

        {
            var2_3 = this.a;
            synchronized (var2_3) {
                var1_2 = this.b;
            }
            try {
                if (var1_2) {
                    ** break;
                }
            }
            catch (InterruptedException v0) {
                throw ae.a(v0);
            }
            try {
                this.a();
            }
            catch (InterruptedException var2_4) {
                var4_9 = this.a;
                synchronized (var4_9) {
                    var3_7 = this.b;
                }
                try {
                    if (var3_7) ** GOTO lbl-1000
                    ServiceMetricsServicesImpl.a.info(ae.c[0]);
                    this.quit();
                }
                catch (InterruptedException v1) {
                    throw ae.a(v1);
                }
            }
            catch (DataIntegrityViolationException var2_5) {
                var6_1 = ae.c;
                ServiceMetricsServicesImpl.a.log(Level.INFO, var6_1[4]);
            }
            catch (Exception var2_6) {
                var6_1 = ae.c;
                ServiceMetricsServicesImpl.a.log(Level.WARNING, var6_1[1], var2_6);
                continue;
            }
            break;
        }
        ** GOTO lbl-1000
lbl44:
        // 1 sources

        ServiceMetricsServicesImpl.a.info(ae.c[2]);
    }

    private void a() throws InterruptedException {
        ServiceMetrics.MetricsCollectorSet metricsCollectorSet = ServiceMetricsServicesImpl.q.take();
        MetricsBin metricsBin = new MetricsBin(metricsCollectorSet.getStartTime(), this.this$0.e, 0, this.this$0.d, metricsCollectorSet.getServiceGoid());
        try {
            if (metricsCollectorSet.getServiceState() != null) {
                metricsBin.setServiceState(metricsCollectorSet.getServiceState());
            }
        }
        catch (InterruptedException interruptedException) {
            throw ae.a(interruptedException);
        }
        try {
            metricsBin.setEndTime(metricsCollectorSet.getEndTime());
            if (metricsCollectorSet.getSummaryMetrics().getNumAttemptedRequest() > 0) {
                metricsBin.setMinFrontendResponseTime(Integer.valueOf(metricsCollectorSet.getSummaryMetrics().getMinFrontendResponseTime()));
                metricsBin.setMaxFrontendResponseTime(Integer.valueOf(metricsCollectorSet.getSummaryMetrics().getMaxFrontendResponseTime()));
            }
        }
        catch (InterruptedException interruptedException) {
            throw ae.a(interruptedException);
        }
        try {
            metricsBin.setSumFrontendResponseTime(metricsCollectorSet.getSummaryMetrics().getSumFrontendResponseTime());
            if (metricsCollectorSet.getSummaryMetrics().getNumCompletedRequest() > 0) {
                metricsBin.setMinBackendResponseTime(Integer.valueOf(metricsCollectorSet.getSummaryMetrics().getMinBackendResponseTime()));
                metricsBin.setMaxBackendResponseTime(Integer.valueOf(metricsCollectorSet.getSummaryMetrics().getMaxBackendResponseTime()));
            }
        }
        catch (InterruptedException interruptedException) {
            throw ae.a(interruptedException);
        }
        try {
            metricsBin.setSumBackendResponseTime(metricsCollectorSet.getSummaryMetrics().getSumBackendResponseTime());
            metricsBin.setNumAttemptedRequest(metricsCollectorSet.getSummaryMetrics().getNumAttemptedRequest());
            metricsBin.setNumAuthorizedRequest(metricsCollectorSet.getSummaryMetrics().getNumAuthorizedRequest());
            metricsBin.setNumCompletedRequest(metricsCollectorSet.getSummaryMetrics().getNumCompletedRequest());
            if (ServiceMetricsServicesImpl.a.isLoggable(Level.FINEST)) {
                ServiceMetricsServicesImpl.a.finest(c[5] + metricsBin.toString());
            }
        }
        catch (InterruptedException interruptedException) {
            throw ae.a(interruptedException);
        }
        this.this$0.serviceMetricsManager.doFlush(metricsCollectorSet, metricsBin);
    }

    private static InterruptedException a(InterruptedException interruptedException) {
        return interruptedException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[6];
                var3_1 = 0;
                var2_2 = "\u000eO\u0016\n4\u0013q/\u000e\u0004\u0007#\u0001j/\\B\u001a#\u001bv>G\f\fv\u0016w/\u000e\u0016\u0004v\u001bl>K\u0010\u0019#\u0002vd\u0018\tA\u0017\u00072\u001c%>\u000e\u0011\n \u0017\"\u0007K\u0016\u0019?\u0011q\bG\f\u0019\u000eO\u0016\n4\u0013q/\u000e\u0004\u0007#\u0001j/\\B\u000e.\u001bv#@\u0005E\u001a\u000eO\u0016\n4\u0013q/\u000e\u0004\u0007#\u0001j/\\B\t3\u0015k$@\u000b\u00051";
                var4_3 = "\u000eO\u0016\n4\u0013q/\u000e\u0004\u0007#\u0001j/\\B\u001a#\u001bv>G\f\fv\u0016w/\u000e\u0016\u0004v\u001bl>K\u0010\u0019#\u0002vd\u0018\tA\u0017\u00072\u001c%>\u000e\u0011\n \u0017\"\u0007K\u0016\u0019?\u0011q\bG\f\u0019\u000eO\u0016\n4\u0013q/\u000e\u0004\u0007#\u0001j/\\B\u000e.\u001bv#@\u0005E\u001a\u000eO\u0016\n4\u0013q/\u000e\u0004\u0007#\u0001j/\\B\t3\u0015k$@\u000b\u00051".length();
                var1_4 = 43;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 64;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ae.a(v0, ae.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u0015V\u0012\u001e*\u000f;'X[\u0001.\u001d~sV[?*\u001fi:T\b0&\u0005;7B\u001eR;\u0004;0X\u0015\u0001;\u0019z:Y\u000fR9\u0002t?V\u000f\u001b \u0005\u0007\u0000V\r\u001b!\f;";
                    var4_3 = "\u0015V\u0012\u001e*\u000f;'X[\u0001.\u001d~sV[?*\u001fi:T\b0&\u0005;7B\u001eR;\u0004;0X\u0015\u0001;\u0019z:Y\u000fR9\u0002t?V\u000f\u001b \u0005\u0007\u0000V\r\u001b!\f;".length();
                    var1_4 = 55;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 89;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ae.a(v0, ae.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        ae.c = var5;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(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 -> 10;
                    case 1 -> 110;
                    case 2 -> 34;
                    case 3 -> 43;
                    case 4 -> 22;
                    case 5 -> 50;
                    default -> 66;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

