/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.EntityManager
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.PersistentEntity
 */
package com.l7tech.server;

import com.l7tech.objectmodel.EntityManager;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.PersistentEntity;
import java.util.ArrayList;
import java.util.Map;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

public abstract class PeriodicVersionCheck
extends TimerTask {
    private final Logger a = Logger.getLogger(this.getClass().getName());
    private EntityManager b;
    private Map<Goid, Integer> c;
    private static final long d = 4000L;
    private static final String[] h;

    public PeriodicVersionCheck(EntityManager entityManager) throws FindException {
        this.b = entityManager;
        this.c = entityManager.findVersionMap();
    }

    /*
     * Loose catch block
     */
    @Override
    public synchronized void run() {
        block31: {
            try {
                String[] stringArray;
                Integer n2;
                Integer n3;
                ArrayList<Goid> arrayList;
                ArrayList<Goid> arrayList2;
                ArrayList<Goid> arrayList3;
                Map map;
                block30: {
                    block32: {
                        try {
                            map = this.b.findVersionMap();
                        }
                        catch (FindException findException) {
                            String[] stringArray2 = h;
                            this.a.log(Level.SEVERE, stringArray2[8], findException);
                            return;
                        }
                        arrayList3 = new ArrayList<Goid>();
                        arrayList2 = new ArrayList<Goid>();
                        arrayList = new ArrayList<Goid>();
                        for (Goid goid : map.keySet()) {
                            n3 = this.c.get(goid);
                            try {
                                if (n3 == null) {
                                    this.a.fine(h[4] + String.valueOf(goid) + h[3]);
                                    arrayList3.add(goid);
                                    continue;
                                }
                            }
                            catch (FindException findException) {
                                throw PeriodicVersionCheck.a(findException);
                            }
                            n2 = (Integer)map.get(goid);
                            try {
                                if (n2.equals(n3)) continue;
                                arrayList2.add(goid);
                                this.a.fine(h[7] + String.valueOf(goid) + h[6]);
                            }
                            catch (FindException findException) {
                                throw PeriodicVersionCheck.a(findException);
                            }
                        }
                        for (Goid goid : this.c.keySet()) {
                            try {
                                if (map.get(goid) != null) continue;
                                arrayList.add(goid);
                                this.a.fine(h[7] + String.valueOf(goid) + h[1]);
                            }
                            catch (FindException findException) {
                                throw PeriodicVersionCheck.a(findException);
                            }
                        }
                        if (!arrayList3.isEmpty()) break block30;
                        if (!arrayList2.isEmpty()) break block30;
                        break block32;
                        catch (FindException findException) {
                            throw PeriodicVersionCheck.a(findException);
                        }
                    }
                    try {
                        if (!arrayList.isEmpty()) break block30;
                        break block31;
                        catch (FindException findException) {
                            throw PeriodicVersionCheck.a(findException);
                        }
                    }
                    catch (FindException findException) {
                        throw PeriodicVersionCheck.a(findException);
                    }
                }
                for (Goid goid : arrayList3) {
                    if (!this.a(goid, 0)) continue;
                    try {
                        n3 = this.b.findByPrimaryKey(goid);
                    }
                    catch (FindException findException) {
                        n3 = null;
                        stringArray = h;
                        this.a.log(Level.WARNING, stringArray[0], findException);
                    }
                    try {
                        if (n3 == null) continue;
                        this.b((PersistentEntity)n3);
                    }
                    catch (FindException findException) {
                        throw PeriodicVersionCheck.a(findException);
                    }
                }
                for (Goid goid : arrayList2) {
                    if (!this.a(goid, n3 = (Integer)map.get(goid))) continue;
                    try {
                        n2 = this.b.findByPrimaryKey(goid);
                    }
                    catch (FindException findException) {
                        n2 = null;
                        stringArray = h;
                        this.a.log(Level.WARNING, stringArray[5], findException);
                    }
                    try {
                        if (n2 == null) continue;
                        this.a((PersistentEntity)n2);
                    }
                    catch (FindException findException) {
                        throw PeriodicVersionCheck.a(findException);
                    }
                }
                for (Goid goid : arrayList) {
                    this.a(goid);
                }
            }
            catch (Exception exception) {
                this.a.log(Level.WARNING, h[2], exception);
            }
        }
    }

    public void markObjectAsStale(Goid goid) {
        this.c.remove(goid);
    }

    private void a(Goid goid) {
        this.c.remove(goid);
        this.onDelete(goid);
    }

    private boolean a(Goid goid, Integer n2) {
        boolean bl2 = this.preSave(goid, n2);
        if (!bl2) {
            this.c.put(goid, n2);
        }
        return bl2;
    }

    private void a(PersistentEntity persistentEntity) {
        this.c.put(persistentEntity.getGoid(), persistentEntity.getVersion());
        this.onUpdate(persistentEntity);
    }

    private void b(PersistentEntity persistentEntity) {
        this.c.put(persistentEntity.getGoid(), persistentEntity.getVersion());
        this.onCreate(persistentEntity);
    }

    protected abstract void onDelete(Goid var1);

    protected boolean preSave(Goid goid, int n2) {
        return true;
    }

    protected void onUpdate(PersistentEntity persistentEntity) {
    }

    protected void onCreate(PersistentEntity persistentEntity) {
    }

    protected boolean notifyUpdate(Goid goid, int n2) {
        Integer n3 = this.c.put(goid, n2);
        return n3 == null || n3 != n2;
    }

    protected boolean notifyDelete(Goid goid) {
        return this.c.remove(goid) != null;
    }

    public long getFrequency() {
        return 4000L;
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[9];
                var3_1 = 0;
                var2_2 = "<\u0015x_\u007faa\r\u0013mB+o \n[oDny5\u001c\u001f,Ujv/\u0016\u000f,Tn83\u001c\u000f~_nn$\u001d\u0012Y\u0013mE+z$\u001c\u0015,Rnt$\r\u001eh\u0018#<\t~Yy8\"\u0011\u001eo]bv&Y\riDxq.\u0017[eXmw3\u0014\u001ax_dvo\bY\u0012\u007f\u0016e}6W\u0007<\u0015x_\u007faa+<\u0015x_\u007faa\r\u0013mB+o \n[yFoy5\u001c\u001f,Ujv/\u0016\u000f,Tn83\u001c\u000f~_nn$\u001d\u0012Y\u0013mE+z$\u001c\u0015,C{| \r\u001eh\u0018";
                var4_3 = "<\u0015x_\u007faa\r\u0013mB+o \n[oDny5\u001c\u001f,Ujv/\u0016\u000f,Tn83\u001c\u000f~_nn$\u001d\u0012Y\u0013mE+z$\u001c\u0015,Rnt$\r\u001eh\u0018#<\t~Yy8\"\u0011\u001eo]bv&Y\riDxq.\u0017[eXmw3\u0014\u001ax_dvo\bY\u0012\u007f\u0016e}6W\u0007<\u0015x_\u007faa+<\u0015x_\u007faa\r\u0013mB+o \n[yFoy5\u001c\u001f,Ujv/\u0016\u000f,Tn83\u001c\u000f~_nn$\u001d\u0012Y\u0013mE+z$\u001c\u0015,C{| \r\u001eh\u0018".length();
                var1_4 = 43;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = PeriodicVersionCheck.a(v0, PeriodicVersionCheck.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u000f&KlLRRB/:MjJ\u000b\u0015/<KlVLR<-MvQD\u001c9f\u001fqPB\u0001j>ZwKB\u001d$h\\m]H\u0019j!L%K_\u001d:8Vk_\u000b\u00028-RdL^\u0000/$F";
                    var4_3 = "\u000f&KlLRRB/:MjJ\u000b\u0015/<KlVLR<-MvQD\u001c9f\u001fqPB\u0001j>ZwKB\u001d$h\\m]H\u0019j!L%K_\u001d:8Vk_\u000b\u00028-RdL^\u0000/$F".length();
                    var1_4 = 7;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 106;
                        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++] = PeriodicVersionCheck.a(v0, PeriodicVersionCheck.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;
            }
        }
        PeriodicVersionCheck.h = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x18);
        }
        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 -> 32;
                    case 1 -> 34;
                    case 2 -> 85;
                    case 3 -> 111;
                    case 4 -> 82;
                    case 5 -> 65;
                    default -> 24;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

