/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.transport.jms.JmsConnection
 *  javax.jms.JMSException
 *  org.apache.commons.pool.PoolableObjectFactory
 *  org.apache.commons.pool.impl.GenericObjectPool
 */
package com.l7tech.server.transport.jms2;

import com.l7tech.gateway.common.transport.jms.JmsConnection;
import com.l7tech.server.transport.jms.JmsBag;
import com.l7tech.server.transport.jms.JmsConfigException;
import com.l7tech.server.transport.jms.JmsRuntimeException;
import com.l7tech.server.transport.jms2.JmsEndpointConfig;
import com.l7tech.server.transport.jms2.JmsResourceManagerConfig;
import com.l7tech.server.transport.jms2.SessionHolderBase;
import com.l7tech.server.transport.jms2.h;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.JMSException;
import javax.naming.NamingException;
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.impl.GenericObjectPool;

public class PooledSessionHolder
extends SessionHolderBase {
    private static final Logger e;
    protected final GenericObjectPool<JmsBag> pool;
    private final JmsResourceManagerConfig f;
    private static final String[] h;

    protected PooledSessionHolder(JmsEndpointConfig jmsEndpointConfig, JmsBag jmsBag, JmsResourceManagerConfig jmsResourceManagerConfig) {
        super(jmsEndpointConfig, jmsBag);
        this.f = jmsResourceManagerConfig;
        this.pool = new GenericObjectPool((PoolableObjectFactory)new h(this), this.getSessionPoolSize(), 1, this.getSessionPoolMaxWait(), this.getMaxSessionIdle());
    }

    protected int getSessionPoolSize() {
        if (this.endpointConfig.getEndpoint().isMessageSource()) {
            return -1;
        }
        return Integer.parseInt(this.endpointConfig.getConnection().properties().getProperty(JmsConnection.PROP_SESSION_POOL_SIZE, String.valueOf(this.f.getSessionPoolSize())));
    }

    protected int getMaxSessionIdle() {
        if (this.endpointConfig.getEndpoint().isMessageSource()) {
            return -1;
        }
        return Integer.parseInt(this.endpointConfig.getConnection().properties().getProperty(JmsConnection.PROP_MAX_SESSION_IDLE, String.valueOf(this.f.getSessionMaxIdle())));
    }

    protected long getSessionPoolMaxWait() {
        if (this.endpointConfig.getEndpoint().isMessageSource()) {
            return 0L;
        }
        return Long.parseLong(this.endpointConfig.getConnection().properties().getProperty(JmsConnection.PROP_SESSION_POOL_MAX_WAIT, String.valueOf(this.f.getSessionMaxWait())));
    }

    @Override
    public JmsBag borrowJmsBag() throws JmsRuntimeException, NamingException {
        this.touch();
        try {
            return (JmsBag)this.pool.borrowObject();
        }
        catch (JMSException jMSException) {
            throw new JmsRuntimeException(jMSException);
        }
        catch (NamingException namingException) {
            throw namingException;
        }
        catch (JmsConfigException jmsConfigException) {
            throw new JmsRuntimeException(jmsConfigException);
        }
        catch (Exception exception) {
            throw new JmsRuntimeException(exception);
        }
    }

    @Override
    public void returnJmsBag(JmsBag jmsBag) {
        if (jmsBag != null) {
            try {
                this.pool.returnObject((Object)jmsBag);
            }
            catch (Exception exception) {
                jmsBag.closeSession();
            }
        }
    }

    @Override
    public void close() {
        String[] stringArray = h;
        e.log(Level.FINE, stringArray[1], new Object[]{this.name, this.connectionVersion, this.endpointVersion});
        try {
            if (this.pool != null) {
                this.pool.close();
            }
        }
        catch (Exception exception) {
            e.log(Level.FINE, h[0]);
        }
        this.bag.close();
        this.referenceCount.set(0);
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "+<\u0010I,E\u001c\n=QH,OO\u001br\u0005C%\u0000_\u0011<\u001fN#TU\u0011<Q[/OP-=>\u001eX)N[^\u0018<x`CS\u0010<\u0014H4IS\u0010rYPp]\u0015Rr\u0007N2SU\u0011<QPq]\u0006\u0005`\f";
        int n3 = "+<\u0010I,E\u001c\n=QH,OO\u001br\u0005C%\u0000_\u0011<\u001fN#TU\u0011<Q[/OP-=>\u001eX)N[^\u0018<x`CS\u0010<\u0014H4IS\u0010rYPp]\u0015Rr\u0007N2SU\u0011<QPq]\u0006\u0005`\f".length();
        int n4 = 35;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = PooledSessionHolder.b(5, PooledSessionHolder.b(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                h = stringArray;
                e = Logger.getLogger(PooledSessionHolder.class.getName());
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x39);
        }
        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 -> 123;
                    case 1 -> 87;
                    case 2 -> 116;
                    case 3 -> 46;
                    case 4 -> 69;
                    case 5 -> 37;
                    default -> 57;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

