/*
(non-Javadoc)
@see javax.jms.QueueConnection#createQueueSession(boolean, int)
197645
@Override
	public synchronized QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException
    {
        checkNotClosed();
        
        RemoteQueueSession session = new RemoteQueueSession(idProvider.createID(),
        		                                            this,
        		                                            transportHub.createEndpoint(),
        		                                            transacted,
        		                                            acknowledgeMode);
        registerSession(session);
        session.remoteInit();
        return session;
    }
1103762
public static BatchSession newBatchSession(KnowledgePackage knowledgePackage,int threadSize,int batchSize){
		return new BatchSessionImpl(knowledgePackage,threadSize,batchSize);
	}
1309889
@Override
    public JmsQueueConnectionFactory createQueueConnectionFactory() throws JMSException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createQueueConnectionFactory");
        JmsQueueConnectionFactory jmsqcf = null;

        // get a jca managed queue connection factory, which is used to construct
        // the jms queue connection factory.
        JmsJcaManagedQueueConnectionFactory jcamqcf = JmsJcaFactory.getInstance().createManagedQueueConnectionFactory();

        // invoke the construction of a jms queue connection factory - the jca
        // managed queue connection factory will call back into the jms api code
        // by getting a JmsRAFactoryFactory, and calling a create jms queue
        // connection factory method on it with jca connection factory and jca
        // managed queue connection factory objects as parameters (the jms qcf
        // will keep references to the jca cf and jca mqcf).
        try {
            jmsqcf = (JmsQueueConnectionFactory) jcamqcf.createConnectionFactory();
        } catch (ResourceException re) {
            // No FFDC code needed
            // d222942 review - no documentation for when a RE will be thrown, so
            // default exception ok. (A quick look at the RA suggests the exception isn't
            // ever thrown).
            // d238447 FFDC review. Comment above suggests an FFDC ok for this case.
            throw (JMSException) JmsErrorUtils.newThrowable(
                                                            JMSException.class,
                                                            "EXCEPTION_RECEIVED_CWSIA0007",
                                                            new Object[] { re, "JmsFactoryFactoryImpl.createQueueConnectionFactory (#1)" },
                                                            re,
                                                            "JmsFactoryFactoryImpl.createQueueConnectionFactory#1",
                                                            this,
                                                            tc
                            );
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "createQueueConnectionFactory", jmsqcf);
        return jmsqcf;
    }
1049566
@Override
	public final Session createSession(boolean transacted, int acknowledgeMode) throws JMSException
    {
        if (!transacted && acknowledgeMode == Session.SESSION_TRANSACTED)
            throw new FFMQException("Acknowledge mode SESSION_TRANSACTED cannot be used for an non-transacted session","INVALID_ACK_MODE");
        
        externalAccessLock.readLock().lock();
    	try
		{
	        checkNotClosed();
	        RemoteSession session = new RemoteSession(idProvider.createID(),
	        		                                  this,
	                                                  transportHub.createEndpoint(),
	                                                  transacted,
	                                                  acknowledgeMode);
	        registerSession(session);
	        session.remoteInit();
	        return session;
		}
    	finally
    	{
    		externalAccessLock.readLock().unlock();
    	}
    }
1298050
@Override
    public Queue createQueue(String queueName) throws JMSRuntimeException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createQueue", new Object[] { queueName });

        Queue queue = null;
        try {
            queue = jmsSession.createQueue(queueName);
        } catch (JMSException jmse) {
            throw (JMSRuntimeException) JmsErrorUtils.getJMS2Exception(jmse, JMSRuntimeException.class);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "createQueue", new Object[] { queue });
        }

        return queue;
    }
267991
@Override
    public ISession createSession(String id, boolean newId) {
        // assert (id!=null);
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINER)) {
            StringBuffer sb = new StringBuffer("{").append(id).append(",").append(newId).append("} ").append(appNameForLogging);
            LoggingUtil.SESSION_LOGGER_CORE.entering(methodClassName, methodNames[CREATE_SESSION], sb.toString());
        }
        MemorySession sess = null;

        // need to test on a different language
        // try creating a temporary logger with the old resource bundle, and then
        // changing the environment to French or something
        if (inProcessOfStopping) {
            throwException("SessionContext.createWhenStop");
        }
        if ((!_smc.getEnableOverflow()) && (_sessions.size() >= _smc.getInMemorySize())) {
            // if we know we're in an overflow situation, don't bother
            // creating a new session
            if (_sessionStatistics != null) {
                _sessionStatistics.incNoRoomForNewSession();
            }
            sess = overflowSession;
        }
        // We expect the second part of check below - _sessions.get(id) == null --
        // to pass unless
        // the id generator generates a dup. This really should never happen.
        // The synchronization in SessionManager.createISession will prevent
        // multiple threads
        // with the same incoming id from both getting into this code. We're no
        // longer using
        // the newId parm...it could be removed, but its now part of the IStore
        // interface.
        if ((sess == null) && (_sessions.get(id) == null)) {
            if(!_removeAttrOnInvalidate)
                sess = new MemorySession(this, id, _storeCallback);
            else{
                if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
                    LoggingUtil.SESSION_LOGGER_CORE.logp(Level.FINE, methodClassName, methodNames[CREATE_SESSION], "Create MemorySession with _removeAttrOnInvalidate -->" + _removeAttrOnInvalidate );
                }
                sess = new MemorySession(this, id, _storeCallback, _removeAttrOnInvalidate);
            }
            sess.setUserName(ANONYMOUS_USER);
            // since this was a newly created session, we need to update the
            // lastAccessTime to the create time
            sess.updateLastAccessTime(sess.getCreationTime());
            try {
                _sessions.put(id, sess);
            } catch (TooManySessionsException tmse) {
                // could catch this exception if multiple threads get past the
                // first overflow check and then attempt to do the sessions.put
                sess = overflowSession;
            }
        }

        // Returns a new session if everything is good
        // Returns an overflowSession is overflow is not allowed and we've already
        // hit the maximum number in memory
        // Returns null if there was an existing session with this key - should
        // never happen

        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_CORE.exiting(methodClassName, methodNames[CREATE_SESSION], sess);
        }
        return sess;
    }
554552
@Override
    public QueueBrowser createBrowser(Queue queue) throws JMSRuntimeException, InvalidDestinationRuntimeException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createBrowser", queue);

        QueueBrowser queueBrowser = null;
        try {
            queueBrowser = jmsSession.createBrowser(queue);
        } catch (InvalidDestinationException ide) {
            throw (InvalidDestinationRuntimeException) JmsErrorUtils.getJMS2Exception(ide, InvalidDestinationRuntimeException.class);
        } catch (JMSException jmse) {
            throw (JMSRuntimeException) JmsErrorUtils.getJMS2Exception(jmse, JMSRuntimeException.class);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "createBrowser");
        }

        return queueBrowser;
    }
201615
@Override
    public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException {
        connectionLock.readLock().lock();
        try {
            ManagedSession managedSession = new ManagedSession(
                    getConnection().createSession(transacted, acknowledgeMode),
                    transacted,
                    acknowledgeMode,
                    connectionDefinition.isJeeMode(),
                    this);
            sessions.add(managedSession);
            return managedSession;
        } finally {
            connectionLock.readLock().unlock();
        }
    }
129794
@Override
    public QueueConnectionFactory createQueueConnectionFactory(JmsJcaConnectionFactory jcaConnectionFactory, JmsJcaManagedQueueConnectionFactory jcaManagedQueueConnectionFactory) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createQueueConnectionFactory", new Object[] { jcaConnectionFactory, jcaManagedQueueConnectionFactory });
        QueueConnectionFactory qcf = new JmsQueueConnectionFactoryImpl(jcaConnectionFactory, jcaManagedQueueConnectionFactory);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "createQueueConnectionFactory", qcf);
        return qcf;
    }
109085
public Queue createDeadletterQueue(final String queueName) {
        return new Queue(queueName, true, false, false, getTTLArgs());
    }
791562
@NonNull
  public Queue<Node> newQueryPlan(
      @Nullable Request request, @NonNull String executionProfileName, @Nullable Session session) {
    switch (stateRef.get()) {
      case BEFORE_INIT:
      case DURING_INIT:
        // The contact points are not stored in the metadata yet:
        List<Node> nodes = new ArrayList<>(context.getMetadataManager().getContactPoints());
        Collections.shuffle(nodes);
        return new ConcurrentLinkedQueue<>(nodes);
      case RUNNING:
        LoadBalancingPolicy policy = policiesPerProfile.get(executionProfileName);
        if (policy == null) {
          policy = policiesPerProfile.get(DriverExecutionProfile.DEFAULT_NAME);
        }
        return policy.newQueryPlan(request, session);
      default:
        return new ConcurrentLinkedQueue<>();
    }
  }
922831
protected T createAndInitQueue(QueueSpec spec) throws Exception {
        T queue = createQueueInstance(spec);
        queue.setQueueName(spec.name);
        initQueue(queue, spec);
        return queue;
    }
10062
public QueueProducer<Object> createQueueJsonMessageProducer(final String topic)
    {
        Preconditions.checkState(connectionFactory != null, "connection factory was never injected!");
        return new QueueProducer<Object>(connectionFactory, jmsConfig, topic, producerCallback);
    }
1309893
@Override
	public QueueSender createSender(Queue queue) throws JMSException
    {
    	externalAccessLock.readLock().lock();
    	try
		{
	        checkNotClosed();
	        
	        RemoteQueueSender sender =  new RemoteQueueSender(this,
	                                                          DestinationTools.asRef(queue),
	                                                          idProvider.createID());
	        registerProducer(sender);
	        return sender;
		}
    	finally
    	{
    		externalAccessLock.readLock().unlock();
    	}
    }
298265
@Override
    public HttpSession getSession(boolean create) {
        String methodName = "getSession";

        // 321485
        if (TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE)) { //306998.15
            logger.logp(Level.FINE, CLASS_NAME, methodName, "create " + String.valueOf(create) + ", this -> " + this);
        }

        HttpSession session = super.getSession(create);

        if (session != null) {
            _sessionCreated = true;
        }

        if (TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE)) {
            logger.logp(Level.FINE, CLASS_NAME, methodName, "_sessionCreated " + _sessionCreated + ", this -> " + this);
        }

        return session;
    }
507988
private HttpSession2 buildSession(boolean create) {
        if (create) {
            session = buildSession(sessionManager.getSessionIdGenerator().generate(request), true);
            log.debug("Build new session[{}].", session.getId());
            return session;
        } else {
            return null;
        }
    }
537970
@Override
    protected void initQueue(T queue, QueueSpec spec) throws Exception {
        queue.setConnectionFactory(defaultConnectionFactory).setUri(defaultUri)
                .setQueueName(defaultQueueName);

        String uri = spec.getField(SPEC_FIELD_URI);
        if (!StringUtils.isBlank(uri)) {
            queue.setUri(uri);
        }

        String queueName = spec.getField(SPEC_FIELD_QUEUE_NAME);
        if (!StringUtils.isBlank(uri)) {
            queue.setQueueName(queueName);
        }

        super.initQueue(queue, spec);
    }