private JMSConnection startConnectionAndSession() {
       JMSConnection result = null;
       Connection connection = null;
       Session session = null;
       try {
          connection = factory.createConnection();
          if ( connection != null ) {
             session = connection.createSession( sessionTransacted, sessionAck );
             result = new JMSConnection(connection,session);
             if ( logger.isDebugEnabled() ) {
                logger.debug( "KieServerMDB sessionTransacted={}, sessionAck={}",
                        sessionTransacted,
                        sessionAck);
             }
          }
       } catch (JMSException jmse) {
          String errMsg = "Unable to obtain connection/session";
          logger.error( errMsg, jmse );
          throw new JMSRuntimeException( errMsg, jmse );
       } finally {
           if (connection != null && session == null){
               logger.error("KieServerMDB: Session creation failed - closing connection");
               try {
                   connection.close();
               } catch (JMSException jmse) {
                   String errMsg = "KieServerMDB: Error closing connection after failing to open session";
                   throw new JMSRuntimeException(errMsg, jmse);
               }
           }
       }
       return result;
    }
private JMSConnection startConnectionAndSession ( ) { JMSConnection result = null ; Connection connection = null ; Session session = null ; try { connection = factory . createConnection ( ) ; if ( connection != null ) { session = connection . createSession ( sessionTransacted , sessionAck ) ; result = new JMSConnection ( connection , session ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "KieServerMDB sessionTransacted={}, sessionAck={}" , sessionTransacted , sessionAck ) ; } } } catch ( JMSException jmse ) { String errMsg = "Unable to obtain connection/session" ; logger . error ( errMsg , jmse ) ; throw new JMSRuntimeException ( errMsg , jmse ) ; } finally { if ( connection != null && session == null ) { logger . error ( "KieServerMDB: Session creation failed - closing connection" ) ; try { connection . close ( ) ; } catch ( JMSException jmse ) { String errMsg = "KieServerMDB: Error closing connection after failing to open session" ; throw new JMSRuntimeException ( errMsg , jmse ) ; } } } return result ; }
This method is used to initialize the JMS connection and
session. It is done in its own method so that if the
point at which it is done needs to be changed then
it can be done by just changing the invocation point.