/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.LicenseManager
 *  com.l7tech.gateway.common.audit.AuditDetailEvent
 *  com.l7tech.gateway.common.transport.jms.JmsConnection
 *  com.l7tech.gateway.common.transport.jms.JmsEndpoint
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.JmsEndpointHeader
 *  org.springframework.context.ApplicationEvent
 */
package com.l7tech.server.transport.jms2;

import com.l7tech.gateway.common.LicenseManager;
import com.l7tech.gateway.common.audit.AuditDetailEvent;
import com.l7tech.gateway.common.transport.jms.JmsConnection;
import com.l7tech.gateway.common.transport.jms.JmsEndpoint;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.JmsEndpointHeader;
import com.l7tech.server.LifecycleBean;
import com.l7tech.server.LifecycleException;
import com.l7tech.server.event.FaultProcessed;
import com.l7tech.server.event.MessageProcessed;
import com.l7tech.server.event.system.ReadyForMessages;
import com.l7tech.server.transport.jms.JmsConnectionManager;
import com.l7tech.server.transport.jms.JmsEndpointManager;
import com.l7tech.server.transport.jms.JmsPropertyMapper;
import com.l7tech.server.transport.jms2.JmsEndpointConfig;
import com.l7tech.server.transport.jms2.JmsEndpointListener;
import com.l7tech.server.transport.jms2.JmsEndpointListenerFactory;
import com.l7tech.server.transport.jms2.j;
import com.l7tech.server.transport.jms2.k;
import com.l7tech.server.util.ThreadPoolBean;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.context.ApplicationEvent;

public class JmsBootProcess
extends LifecycleBean
implements PropertyChangeListener {
    private static final Logger h;
    private final ThreadPoolBean i;
    private final JmsConnectionManager j;
    private final JmsEndpointManager k;
    private final JmsPropertyMapper l;
    private final Object m;
    private final JmsEndpointListenerFactory n;
    private Set<JmsEndpointListener> o;
    private final Timer p;
    private boolean q;
    private volatile boolean r;
    private j s;
    private k t;
    private static final String[] u;

    public JmsBootProcess(ThreadPoolBean threadPoolBean, LicenseManager licenseManager, JmsConnectionManager jmsConnectionManager, JmsEndpointManager jmsEndpointManager, JmsPropertyMapper jmsPropertyMapper, JmsEndpointListenerFactory jmsEndpointListenerFactory, Timer timer) {
        String[] stringArray = u;
        super(stringArray[3], h, stringArray[9], licenseManager);
        this.m = new Object();
        this.o = new HashSet<JmsEndpointListener>();
        this.q = false;
        this.r = false;
        this.i = threadPoolBean;
        this.j = jmsConnectionManager;
        this.k = jmsEndpointManager;
        this.l = jmsPropertyMapper;
        this.n = jmsEndpointListenerFactory;
        this.p = timer == null ? new Timer(stringArray[8], true) : timer;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
        Object object = this.m;
        synchronized (object) {
            for (JmsEndpointListener jmsEndpointListener : this.o) {
                jmsEndpointListener.propertyChange(propertyChangeEvent);
            }
        }
    }

    @Override
    protected void init() {
        try {
            if (this.i == null) {
                throw new IllegalStateException(u[19]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw JmsBootProcess.a(illegalStateException);
        }
        try {
            if (this.j == null) {
                throw new IllegalStateException(u[13]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw JmsBootProcess.a(illegalStateException);
        }
        try {
            if (this.k == null) {
                throw new IllegalStateException(u[0]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw JmsBootProcess.a(illegalStateException);
        }
        try {
            if (this.n == null) {
                throw new IllegalStateException(u[2]);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw JmsBootProcess.a(illegalStateException);
        }
    }

    @Override
    protected void doStart() throws LifecycleException {
        try {
            if (!this.isStarted()) {
                this.b();
            }
        }
        catch (LifecycleException lifecycleException) {
            throw JmsBootProcess.a(lifecycleException);
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Could not resolve type clashes
     * Loose catch block
     */
    private void a() throws LifecycleException {
        Object object = this.m;
        synchronized (object) {
            if (!this.q) {
                try {
                    this.q = true;
                    String[] stringArray = u;
                    h.info(stringArray[6]);
                    Collection collection = this.j.findAll();
                    ArrayList<Goid> arrayList = new ArrayList<Goid>();
                    for (JmsConnection jmsConnection : collection) {
                        JmsEndpoint[] jmsEndpointArray;
                        for (JmsEndpoint jmsEndpoint : jmsEndpointArray = this.k.findEndpointsForConnection(jmsConnection.getGoid())) {
                            block16: {
                                if (!jmsEndpoint.isMessageSource()) continue;
                                try {
                                    if (jmsEndpoint.isDisabled()) {
                                        continue;
                                    }
                                    break block16;
                                    catch (LifecycleException lifecycleException) {
                                        throw JmsBootProcess.a(lifecycleException);
                                    }
                                }
                                catch (LifecycleException lifecycleException) {
                                    throw JmsBootProcess.a(lifecycleException);
                                }
                            }
                            JmsEndpointConfig jmsEndpointConfig = new JmsEndpointConfig(jmsConnection, jmsEndpoint, this.l, this.getApplicationContext());
                            jmsEndpointConfig.setEvictOnExpired(false);
                            JmsEndpointListener jmsEndpointListener = this.n.createListener(jmsEndpointConfig);
                            try {
                                jmsEndpointListener.start();
                                this.o.add(jmsEndpointListener);
                            }
                            catch (LifecycleException lifecycleException) {
                                stringArray = u;
                                h.log(Level.WARNING, stringArray[11] + String.valueOf(jmsEndpoint) + stringArray[5], lifecycleException);
                                arrayList.add(jmsEndpoint.getGoid());
                            }
                        }
                    }
                    this.s = new j(this, this.j);
                    this.t = new k(this, this.k);
                    for (JmsConnection jmsConnection : arrayList) {
                        this.t.markObjectAsStale((Goid)jmsConnection);
                    }
                }
                catch (FindException findException) {
                    String[] stringArray = u;
                    String string = stringArray[18];
                    h.log(Level.SEVERE, string, findException);
                    throw new LifecycleException(string, findException);
                }
                this.p.schedule((TimerTask)this.s, this.s.getFrequency() * 2L, this.s.getFrequency());
                this.p.schedule((TimerTask)this.t, this.t.getFrequency() * 2L, this.t.getFrequency());
                h.info(u[10]);
            }
        }
    }

    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        try {
            if (this.a(applicationEvent)) {
                return;
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw JmsBootProcess.a(illegalStateException);
        }
        try {
            super.onApplicationEvent(applicationEvent);
            if (applicationEvent instanceof ReadyForMessages) {
                this.r = true;
                this.b();
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw JmsBootProcess.a(illegalStateException);
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    protected void doStop() {
        Object object = this.m;
        synchronized (object) {
            if (this.s != null) {
                this.s.cancel();
            }
            try {
                if (this.t != null) {
                    this.t.cancel();
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw JmsBootProcess.a(illegalStateException);
            }
            for (JmsEndpointListener jmsEndpointListener : this.o) {
                String[] stringArray = u;
                h.info(stringArray[17] + jmsEndpointListener.toString() + "'");
                jmsEndpointListener.stop();
            }
            for (JmsEndpointListener jmsEndpointListener : this.o) {
                h.info(u[12] + jmsEndpointListener.toString() + "'");
                jmsEndpointListener.ensureStopped();
            }
            this.o.clear();
            this.i.shutdown();
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Loose catch block
     */
    private void b() {
        block11: {
            block12: {
                boolean bl2;
                Object object = this.m;
                synchronized (object) {
                    bl2 = this.q;
                }
                if (bl2) break block11;
                try {
                    block13: {
                        if (this.r) break block12;
                        break block13;
                        catch (LifecycleException lifecycleException) {
                            throw JmsBootProcess.a(lifecycleException);
                        }
                    }
                    h.info(u[16]);
                    break block11;
                }
                catch (LifecycleException lifecycleException) {
                    throw JmsBootProcess.a(lifecycleException);
                }
            }
            try {
                if (!this.isLicensed()) break block11;
                this.i.start();
                this.a();
                break block11;
            }
            catch (IllegalStateException illegalStateException) {
                throw JmsBootProcess.a(illegalStateException);
            }
            {
                catch (LifecycleException lifecycleException) {
                    h.log(Level.SEVERE, u[15], lifecycleException);
                }
            }
        }
    }

    private boolean a(ApplicationEvent applicationEvent) {
        boolean bl2;
        block8: {
            block7: {
                try {
                    block6: {
                        try {
                            try {
                                if (applicationEvent instanceof AuditDetailEvent || applicationEvent instanceof MessageProcessed) break block6;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw JmsBootProcess.a(illegalStateException);
                            }
                            if (!(applicationEvent instanceof FaultProcessed)) break block7;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw JmsBootProcess.a(illegalStateException);
                        }
                    }
                    bl2 = true;
                    break block8;
                }
                catch (IllegalStateException illegalStateException) {
                    throw JmsBootProcess.a(illegalStateException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private void a(Goid goid) {
        Object object = this.m;
        synchronized (object) {
            Iterator<JmsEndpointListener> iterator = this.o.iterator();
            while (iterator.hasNext()) {
                JmsEndpointListener jmsEndpointListener = iterator.next();
                if (!jmsEndpointListener.getJmsConnectionGoid().equals((Object)goid)) continue;
                jmsEndpointListener.stop();
                iterator.remove();
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private void a(JmsConnection jmsConnection) {
        Object object = this.m;
        synchronized (object) {
            Goid goid = jmsConnection.getGoid();
            try {
                JmsEndpointHeader[] jmsEndpointHeaderArray;
                for (JmsEndpointHeader jmsEndpointHeader : jmsEndpointHeaderArray = this.k.findEndpointHeadersForConnection(goid)) {
                    JmsEndpoint jmsEndpoint = (JmsEndpoint)this.k.findByPrimaryKey(jmsEndpointHeader.getGoid());
                    this.t.notifyUpdate(jmsEndpoint.getGoid(), jmsEndpoint.getVersion());
                    this.a(jmsEndpoint, false);
                }
            }
            catch (FindException findException) {
                h.log(Level.SEVERE, u[7], findException);
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private void b(Goid goid) {
        Object object = this.m;
        synchronized (object) {
            Iterator<JmsEndpointListener> iterator = this.o.iterator();
            while (iterator.hasNext()) {
                JmsEndpointListener jmsEndpointListener = iterator.next();
                if (!jmsEndpointListener.getJmsEndpointGoid().equals((Object)goid)) continue;
                jmsEndpointListener.stop();
                iterator.remove();
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private void a(JmsEndpoint jmsEndpoint, boolean bl2) {
        block15: {
            try {
                this.b(jmsEndpoint.getGoid());
                if (!jmsEndpoint.isMessageSource() || jmsEndpoint.isDisabled()) break block15;
            }
            catch (LifecycleException lifecycleException) {
                throw JmsBootProcess.a(lifecycleException);
            }
            JmsEndpointListener jmsEndpointListener = null;
            try {
                JmsConnection jmsConnection = (JmsConnection)this.j.findByPrimaryKey(jmsEndpoint.getConnectionGoid());
                try {
                    if (bl2) {
                        this.s.notifyUpdate(jmsConnection.getGoid(), jmsConnection.getVersion());
                    }
                }
                catch (LifecycleException lifecycleException) {
                    throw JmsBootProcess.a(lifecycleException);
                }
                JmsEndpointConfig jmsEndpointConfig = new JmsEndpointConfig(jmsConnection, jmsEndpoint, this.l, this.getApplicationContext());
                jmsEndpointConfig.setEvictOnExpired(false);
                jmsEndpointListener = this.n.createListener(jmsEndpointConfig);
                jmsEndpointListener.start();
                Object object = this.m;
                synchronized (object) {
                    this.o.add(jmsEndpointListener);
                }
            }
            catch (LifecycleException lifecycleException) {
                String[] stringArray = u;
                h.warning(stringArray[14] + String.valueOf(jmsEndpointListener) + stringArray[4] + lifecycleException.toString());
                Object object = this.m;
                synchronized (object) {
                    if (this.t != null) {
                        this.t.markObjectAsStale(jmsEndpoint.getGoid());
                    }
                }
            }
            catch (FindException findException) {
                h.log(Level.SEVERE, u[1] + String.valueOf(jmsEndpoint), findException);
            }
        }
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[20];
                var3_1 = 0;
                var2_2 = "\u0018vmM:'a\tUhS4)j\u000f8`Nu<j\fm`O0*!&>w|Q1 (\t8oT;*/\u001ewgS0-{\u0014wg\u001d3!}]}gY%!f\u0013l)'\u0017uzx;*\u007f\u0012qgI\u0019'|\t}gX'\bn\u001elfO,nf\u000e8{X$;f\u000f}m\u0013\u00107UZ\u001d\u0017!`\t8YO:-j\u000ek\u0018F8~T9\"/\tjp\u001d4)n\u0014v)Q4:j\u000f\")\u001aS8)j<\"c]jlI'7/\r}{T:*f\u001eyeQ,\r7UZ\u001d&:n\u000fl`S2`4>y|Z=:/\u0018`jX%:f\u0012v)[< k\u0014vn\u001d0 k\rw`S!=/\u001bw{\u001d4nl\u0012vgX6:f\u0012v(\u00127UZ\u001d6!a\u001bqn\u001d'+i\u000f}zU\u0017\u000e}{K<-jGRdN\u0018+|\u000eynX\u001c \u007f\bl\f7UZ\u001d&:n\u000fllY{%>w|Q1 (\t8zI4<{]t`N!+a\u0018j)[:</\u0018vmM:'a\t8\"*y`I< h]~fOu\u0004B.8{X6+f\u000b}{\u001d!!/\u000elfMui\u001e\u001ewgS0-{\u0014wgp4 n\u001a}{\u001d<=/\u000f}xH<<j\u00196&8`jX%:f\u0012v)J='c\u00188`S<:f\u001ct`G< h]jl^0'y\u0018j)$(vh_9+/\tw)N!/}\t8Cp\u0006nJ\u0013|yR< {1qzI0 j\u000fP)pl\u001d\u001f\u0003\\]k|_&7|\t}d\u001d\"'c\u00118gR!n|\ty{Iu;a\tqe\u001d!&j]\u007fhI09n\u00048`Nu<j\u001c|p\u001d!!/\rjf^0=|]ulN&/h\u0018k'\u0017.lfM%'a\u001a8Cp\u0006n}\u0018{lT#+}]?";
                var4_3 = "\u0018vmM:'a\tUhS4)j\u000f8`Nu<j\fm`O0*!&>w|Q1 (\t8oT;*/\u001ewgS0-{\u0014wg\u001d3!}]}gY%!f\u0013l)'\u0017uzx;*\u007f\u0012qgI\u0019'|\t}gX'\bn\u001elfO,nf\u000e8{X$;f\u000f}m\u0013\u00107UZ\u001d\u0017!`\t8YO:-j\u000ek\u0018F8~T9\"/\tjp\u001d4)n\u0014v)Q4:j\u000f\")\u001aS8)j<\"c]jlI'7/\r}{T:*f\u001eyeQ,\r7UZ\u001d&:n\u000fl`S2`4>y|Z=:/\u0018`jX%:f\u0012v)[< k\u0014vn\u001d0 k\rw`S!=/\u001bw{\u001d4nl\u0012vgX6:f\u0012v(\u00127UZ\u001d6!a\u001bqn\u001d'+i\u000f}zU\u0017\u000e}{K<-jGRdN\u0018+|\u000eynX\u001c \u007f\bl\f7UZ\u001d&:n\u000fllY{%>w|Q1 (\t8zI4<{]t`N!+a\u0018j)[:</\u0018vmM:'a\t8\"*y`I< h]~fOu\u0004B.8{X6+f\u000b}{\u001d!!/\u000elfMui\u001e\u001ewgS0-{\u0014wgp4 n\u001a}{\u001d<=/\u000f}xH<<j\u00196&8`jX%:f\u0012v)J='c\u00188`S<:f\u001ct`G< h]jl^0'y\u0018j)$(vh_9+/\tw)N!/}\t8Cp\u0006nJ\u0013|yR< {1qzI0 j\u000fP)pl\u001d\u001f\u0003\\]k|_&7|\t}d\u001d\"'c\u00118gR!n|\ty{Iu;a\tqe\u001d!&j]\u007fhI09n\u00048`Nu<j\u001c|p\u001d!!/\rjf^0=|]ulN&/h\u0018k'\u0017.lfM%'a\u001a8Cp\u0006n}\u0018{lT#+}]?".length();
                var1_4 = 28;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = JmsBootProcess.b(v0, JmsBootProcess.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u0003JAl\f\u001d\u00154\u0005Gt\t\u0001F`oySH\u0000G\"VMs\u001c\u0016_a\u0005\u0014J% \u0012&PZc\u001c\u001a].DXi\u001c\n\u00127LXlH\u0011W`A]s\t\u0011^%A\u001a\u001b4MFe\t\u0017b/JXB\r\u0012\\`LG \u001a\u0016C5LFe\f]";
                    var4_3 = "\u0003JAl\f\u001d\u00154\u0005Gt\t\u0001F`oySH\u0000G\"VMs\u001c\u0016_a\u0005\u0014J% \u0012&PZc\u001c\u001a].DXi\u001c\n\u00127LXlH\u0011W`A]s\t\u0011^%A\u001a\u001b4MFe\t\u0017b/JXB\r\u0012\\`LG \u001a\u0016C5LFe\f]".length();
                    var1_4 = 66;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 70;
                        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++] = JmsBootProcess.b(v0, JmsBootProcess.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;
            }
        }
        JmsBootProcess.u = var5;
        JmsBootProcess.h = Logger.getLogger(JmsBootProcess.class.getName());
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x74);
        }
        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 -> 6;
                    case 1 -> 99;
                    case 2 -> 114;
                    case 3 -> 70;
                    case 4 -> 46;
                    case 5 -> 53;
                    default -> 116;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

