protected void createOrReuseConnection(ConnectionContext context, boolean start) throws JMSException {
        Connection conn;

        if (isReuseConnection()) {
            conn = getConnection();
            if (conn != null) {
                // already have a connection cached, give it to the context
                context.setConnection(conn);
            } else {
                // there is no connection yet; create it and cache it
                createConnection(context);
                conn = context.getConnection();
                cacheConnection(conn, false);
            }
        } else {
            // we are not to cache connections - always create one
            createConnection(context);
            conn = context.getConnection();
            cacheConnection(conn, false);
        }

        if (start) {
            // Calling start on started connection is ignored.
            // But if an exception is thrown, we need to throw away the connection
            try {
                conn.start();
            } catch (JMSException e) {
                msglog.errorFailedToStartConnection(e);
                cacheConnection(null, true);
                throw e;
            }
        }
    }
protected void createOrReuseConnection ( ConnectionContext context , boolean start ) throws JMSException { Connection conn ; if ( isReuseConnection ( ) ) { conn = getConnection ( ) ; if ( conn != null ) { context . setConnection ( conn ) ; } else { createConnection ( context ) ; conn = context . getConnection ( ) ; cacheConnection ( conn , false ) ; } } else { createConnection ( context ) ; conn = context . getConnection ( ) ; cacheConnection ( conn , false ) ; } if ( start ) { try { conn . start ( ) ; } catch ( JMSException e ) { msglog . errorFailedToStartConnection ( e ) ; cacheConnection ( null , true ) ; throw e ; } } }
This method provides a way to cache and share a connection across
multiple contexts. It combines the creation and setting of the
connection. This also can optionally start the connection immediately.
Use this if you want to reuse any connection that may already be stored
in this processor object (i.e. {@link #getConnection()} is non-null). If
there is no connection yet, one will be created. Whether the connection
is created or reused, that connection will be stored in the given
context.

Note that if this object was told not to cache connections, this method
will always create a new connection and store it in this object, overwriting
any previously created connection (see {@link #cacheConnection}).

@param context the connection will be stored in this context
@param start if true, the created connection will be started.
@throws JMSException any error