/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.github.benmanes.caffeine.cache.Cache
 *  com.github.benmanes.caffeine.cache.Caffeine
 */
package com.l7tech.server.http;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.l7tech.server.ServerConfig;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

public class HttpStatePoolManager
implements PropertyChangeListener {
    private static final long a = 10000L;
    private static final long b;
    private ServerConfig c;
    private Cache<HttpStateCacheKey, Object> d;
    private static final String[] e;

    public HttpStatePoolManager(ServerConfig serverConfig) {
        this.c = serverConfig;
        this.d = this.a();
    }

    private Cache<HttpStateCacheKey, Object> a() {
        String[] stringArray = e;
        return Caffeine.newBuilder().maximumSize(this.c.getLongProperty(stringArray[0], 10000L)).expireAfterWrite(this.c.getTimeUnitProperty(stringArray[1], b), TimeUnit.MILLISECONDS).build();
    }

    public Object getFromStateCache(HttpStateCacheKey httpStateCacheKey) {
        return this.d.getIfPresent((Object)httpStateCacheKey);
    }

    public void putToStateCacheIfAbsent(HttpStateCacheKey httpStateCacheKey, Object object) {
        if (this.d.getIfPresent((Object)httpStateCacheKey) == null) {
            this.d.put((Object)httpStateCacheKey, object);
        }
    }

    @Override
    public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
        Cache<HttpStateCacheKey, Object> cache = this.d;
        this.d = this.a();
        cache.invalidateAll();
    }

    public long getCacheSize() {
        return this.d.estimatedSize();
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "JFf|f\u0017JL\\Za|\u0000YV]Fg`\u000ebB]Gg|4lB]KX}\btp@Tm*JFf|f\u0017JL\\Za|\u0000YV]Fg`\u000ebB]Gg|4lB]KX}\btw@Cm}\u0012l";
        int n3 = "JFf|f\u0017JL\\Za|\u0000YV]Fg`\u000ebB]Gg|4lB]KX}\btp@Tm*JFf|f\u0017JL\\Za|\u0000YV]Fg`\u000ebB]Gg|4lB]KX}\btw@Cm}\u0012l".length();
        int n4 = 39;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = HttpStatePoolManager.a(10, HttpStatePoolManager.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                e = stringArray;
                b = TimeUnit.MINUTES.toMillis(1L);
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x12);
        }
        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 -> 41;
                    case 1 -> 35;
                    case 2 -> 36;
                    case 3 -> 2;
                    case 4 -> 24;
                    case 5 -> 109;
                    default -> 18;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }

    public static class HttpStateCacheKey {
        private final int a;
        private final String b;
        private final byte[] c;

        public HttpStateCacheKey(int n2, String string, byte[] byArray) {
            this.a = n2;
            this.b = string;
            this.c = byArray;
        }

        public boolean equals(Object object) {
            if (this == object) {
                return true;
            }
            if (object == null || this.getClass() != object.getClass()) {
                return false;
            }
            HttpStateCacheKey httpStateCacheKey = (HttpStateCacheKey)object;
            if (this.a != httpStateCacheKey.a) {
                return false;
            }
            if (!this.b.equals(httpStateCacheKey.b)) {
                return false;
            }
            return Arrays.equals(this.c, httpStateCacheKey.c);
        }

        public int hashCode() {
            int n2 = this.a;
            n2 = 31 * n2 + this.b.hashCode();
            n2 = 31 * n2 + Arrays.hashCode(this.c);
            return n2;
        }
    }
}

