/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.cluster.ClusterProperty
 *  com.l7tech.objectmodel.FindException
 *  org.springframework.transaction.PlatformTransactionManager
 */
package com.l7tech.server.cluster;

import com.l7tech.gateway.common.cluster.ClusterProperty;
import com.l7tech.objectmodel.FindException;
import com.l7tech.server.audit.AuditContextUtils;
import com.l7tech.server.cluster.ClusterPropertyManager;
import com.l7tech.server.cluster.f;
import com.l7tech.server.cluster.h;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.transaction.PlatformTransactionManager;

public class ClusterLock
implements Lock {
    private static final Logger a;
    private static final Random b;
    private final long c = b.nextLong();
    private final ClusterPropertyManager d;
    protected final PlatformTransactionManager transactionManager;
    private final String e;
    private final long f;
    private static final String[] g;

    public ClusterLock(ClusterPropertyManager clusterPropertyManager, PlatformTransactionManager platformTransactionManager, String string) {
        this(clusterPropertyManager, platformTransactionManager, string, Long.MAX_VALUE);
    }

    public ClusterLock(ClusterPropertyManager clusterPropertyManager, PlatformTransactionManager platformTransactionManager, String string, long l2) {
        if (clusterPropertyManager == null) {
            throw new NullPointerException(g[17]);
        }
        this.d = clusterPropertyManager;
        this.transactionManager = platformTransactionManager;
        this.e = string;
        this.f = l2 * 60L * 1000L;
    }

    public String toString() {
        return this.e;
    }

    @Override
    public Condition newCondition() {
        throw new UnsupportedOperationException(g[6]);
    }

    @Override
    public void lock() {
        throw new UnsupportedOperationException(g[13]);
    }

    @Override
    public void lockInterruptibly() throws InterruptedException {
        throw new UnsupportedOperationException(g[13]);
    }

    @Override
    public boolean tryLock(long l2, TimeUnit timeUnit) throws InterruptedException {
        throw new UnsupportedOperationException(g[13]);
    }

    /*
     * Unable to fully structure code
     */
    @Override
    public boolean tryLock() {
        block27: {
            block24: {
                block26: {
                    block25: {
                        var1_1 = false;
                        var2_2 = null;
                        var3_3 = null;
                        try {
                            var2_2 = this.d.getCachedEntityByName(this.e, 0);
                        }
                        catch (FindException var4_4) {
                            try {
                                if (ClusterLock.a.isLoggable(Level.FINE)) {
                                    ClusterLock.a.log(Level.FINE, ClusterLock.g[16] + this.e + ClusterLock.g[9], var4_4);
                                }
                            }
                            catch (FindException v0) {
                                throw ClusterLock.a(v0);
                            }
                        }
                        if (var2_2 == null) {
                            var2_2 = new ClusterProperty(this.e, null);
                        } else {
                            var3_3 = h.parseString(var2_2.getValue());
                        }
                        var4_5 = System.currentTimeMillis();
                        var6_6 = -9223372036854775808L;
                        try {
                            if (var3_3 != null && var3_3.isLocked()) {
                            }
                            ** GOTO lbl30
                        }
                        catch (FindException v1) {
                            throw ClusterLock.a(v1);
                        }
                        var6_6 = var4_5 - var3_3.getLockTime();
                        try {
                            try {
                                if (var6_6 < this.f) break block24;
lbl30:
                                // 2 sources

                                if (var6_6 >= this.f) {
                                }
                                break block25;
                            }
                            catch (FindException v2) {
                                throw ClusterLock.a(v2);
                            }
                            ClusterLock.a.warning(ClusterLock.g[2] + this.e + ClusterLock.g[3] + String.valueOf(var3_3) + ClusterLock.g[5]);
                        }
                        catch (FindException v3) {
                            throw ClusterLock.a(v3);
                        }
                    }
                    var8_7 = new h(true, var4_5, this.c);
                    var2_2.setValue(var8_7.toString());
                    var1_1 = this.a(var2_2);
                    try {
                        try {
                            if (!var1_1) break block26;
                            if (ClusterLock.a.isLoggable(Level.FINE)) {
                            }
                            break block27;
                        }
                        catch (FindException v4) {
                            throw ClusterLock.a(v4);
                        }
                        ClusterLock.a.fine(this.e + ClusterLock.g[19] + this.c);
                        break block27;
                    }
                    catch (FindException v5) {
                        throw ClusterLock.a(v5);
                    }
                }
                var13_8 = ClusterLock.g;
                ClusterLock.a.warning(this.e + var13_8[14] + this.c + var13_8[8]);
                break block27;
            }
            if (ClusterLock.a.isLoggable(Level.FINE)) {
                var9_10 = var3_3.getOwnerId();
                var11_11 = this.c;
                var13_9 = ClusterLock.g;
                ClusterLock.a.fine(this.e + var13_9[11] + var11_11 + var13_9[10] + var9_10);
            }
        }
        try {
            if (ClusterLock.a.isLoggable(Level.FINE)) {
                ClusterLock.a.fine(ClusterLock.g[1] + var1_1);
            }
        }
        catch (FindException v6) {
            throw ClusterLock.a(v6);
        }
        return var1_1;
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    @Override
    public void unlock() {
        block16: {
            ClusterProperty clusterProperty;
            block15: {
                clusterProperty = null;
                h h2 = null;
                try {
                    clusterProperty = this.d.getCachedEntityByName(this.e, 0);
                }
                catch (FindException findException) {
                    String[] stringArray = g;
                    a.log(Level.WARNING, stringArray[12] + this.e + stringArray[15], findException);
                }
                if (clusterProperty == null) {
                    clusterProperty = new ClusterProperty(this.e, null);
                } else {
                    h2 = h.parseString(clusterProperty.getValue());
                }
                try {
                    block14: {
                        try {
                            try {
                                if (h2 == null || !h2.isLocked()) break block14;
                            }
                            catch (FindException findException) {
                                throw ClusterLock.a(findException);
                            }
                            if (h2.getOwnerId() == this.c) break block15;
                        }
                        catch (FindException findException) {
                            throw ClusterLock.a(findException);
                        }
                    }
                    a.warning(g[18] + this.e + g[4] + String.valueOf(h2));
                    return;
                }
                catch (FindException findException) {
                    throw ClusterLock.a(findException);
                }
            }
            h h3 = new h(false, System.currentTimeMillis(), this.c);
            try {
                try {
                    clusterProperty.setValue(h3.toString());
                    if (!this.a(clusterProperty)) break block16;
                    if (!a.isLoggable(Level.FINE)) return;
                }
                catch (FindException findException) {
                    throw ClusterLock.a(findException);
                }
                a.fine(this.e + g[7] + this.c);
                return;
            }
            catch (FindException findException) {
                throw ClusterLock.a(findException);
            }
        }
        a.warning(g[0] + this.e);
    }

    private boolean a(ClusterProperty clusterProperty) {
        boolean[] blArray = new boolean[1];
        AuditContextUtils.doAsSystem(new f(this, blArray, clusterProperty));
        return blArray[0];
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[20];
                var3_1 = 0;
                var2_2 = ")qQ'5Bl\u0002oL+,\u000bw\u000b#\u0014\u0018qZ\u0004(\u0001rD*\u0003:\"\u0016l\u001emJ& B\u001d?wB$\"Bz\u0000vP<\"\u00109\u0000l@#g\u0004v\u0019mGh!\rkL\u0003L9\u0003\u001aW#V&\"\u001ai\t`W-#B|\u0002wQ1g\u0004v\u0019mGrg\u0011L8\u0003;3\u0007x\u0000jM/g\u000ev\u000fh\r\u000f\"lWh.\u000fi\u0000fN-)\u0016|\b\rLvM$(\u0001r\tg\u0003*>B\bLEb\u0001\u000b']M\u000bLmL<g\u0004v\u0019mGf\u0015W#@=5\u0010|\u0002wO1g\rn\u0002fGh%\u001b9&L`O=4\u0016|\u001e#O'$\t9\u0019sG)3\u00079\"Lwh&\u0016m\tnS<\"\u00069\u000ez\u0003\u0017/oV;3\u0007kLoL+,B|\u0002wQ1g\u0004v\u001e#\u000f\"lWh.\u000fi\u0000fN-)\u0016|\b L`O=4\u0016|\u001e#O'$\t9\u0019sG)3\u00079\rwW-*\u0012mLaZh\u000bLmL<g\u0004v\u0019mGf\u0017/oV;3\u0007kLoL+,B|\u0002wQ1g\u0004v\u001e#2/oV;3\u0007k<qL8\"\u0010m\u0015NB&&\u0005|\u001e#S)5\u0003t\twF:g\u000fl\u001fw\u0003&(\u00169\u000ef\u0003&2\u000euB";
                var4_3 = ")qQ'5Bl\u0002oL+,\u000bw\u000b#\u0014\u0018qZ\u0004(\u0001rD*\u0003:\"\u0016l\u001emJ& B\u001d?wB$\"Bz\u0000vP<\"\u00109\u0000l@#g\u0004v\u0019mGh!\rkL\u0003L9\u0003\u001aW#V&\"\u001ai\t`W-#B|\u0002wQ1g\u0004v\u0019mGrg\u0011L8\u0003;3\u0007x\u0000jM/g\u000ev\u000fh\r\u000f\"lWh.\u000fi\u0000fN-)\u0016|\b\rLvM$(\u0001r\tg\u0003*>B\bLEb\u0001\u000b']M\u000bLmL<g\u0004v\u0019mGf\u0015W#@=5\u0010|\u0002wO1g\rn\u0002fGh%\u001b9&L`O=4\u0016|\u001e#O'$\t9\u0019sG)3\u00079\"Lwh&\u0016m\tnS<\"\u00069\u000ez\u0003\u0017/oV;3\u0007kLoL+,B|\u0002wQ1g\u0004v\u001e#\u000f\"lWh.\u000fi\u0000fN-)\u0016|\b L`O=4\u0016|\u001e#O'$\t9\u0019sG)3\u00079\rwW-*\u0012mLaZh\u000bLmL<g\u0004v\u0019mGf\u0017/oV;3\u0007kLoL+,B|\u0002wQ1g\u0004v\u001e#2/oV;3\u0007k<qL8\"\u0010m\u0015NB&&\u0005|\u001e#S)5\u0003t\twF:g\u000fl\u001fw\u0003&(\u00169\u000ef\u0003&2\u000euB".length();
                var1_4 = 16;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ClusterLock.a(v0, ClusterLock.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "2\u007fPr._q\u001frQ61_\u000bQrQ61\u001a`Q|Gu";
                    var4_3 = "2\u007fPr._q\u001frQ61_\u000bQrQ61\u001a`Q|Gu".length();
                    var1_4 = 13;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 5;
                        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++] = ClusterLock.a(v0, ClusterLock.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;
            }
        }
        ClusterLock.g = var5;
        ClusterLock.a = Logger.getLogger(ClusterLock.class.getName());
        ClusterLock.b = new Random();
    }

    private static FindException a(FindException findException) {
        return findException;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ '\u0001');
        }
        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 -> 116;
                    case 1 -> 27;
                    case 2 -> 59;
                    case 3 -> 80;
                    case 4 -> 95;
                    case 5 -> 122;
                    default -> 1;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

