Example #1
0
  /**
   * Setup a session
   *
   * @param cf
   * @return The connection
   * @throws Exception Thrown if an error occurs
   */
  protected ClientSession setupSession(ClientSessionFactory cf) throws Exception {
    ClientSession result = null;

    try {
      result =
          ra.createSession(
              cf,
              spec.getAcknowledgeModeInt(),
              spec.getUser(),
              spec.getPassword(),
              ra.getPreAcknowledge(),
              ra.getDupsOKBatchSize(),
              ra.getTransactionBatchSize(),
              isDeliveryTransacted,
              spec.isUseLocalTx(),
              spec.getTransactionTimeout());

      result.addMetaData("resource-adapter", "inbound");
      result.addMetaData("jms-session", "");
      String clientID = ra.getClientID() == null ? spec.getClientID() : ra.getClientID();
      if (clientID != null) {
        result.addMetaData("jms-client-id", clientID);
      }

      HornetQRALogger.LOGGER.debug("Using queue connection " + result);

      return result;
    } catch (Throwable t) {
      try {
        if (result != null) {
          result.close();
        }
      } catch (Exception e) {
        HornetQRALogger.LOGGER.trace("Ignored error closing connection", e);
      }
      if (t instanceof Exception) {
        throw (Exception) t;
      }
      throw new RuntimeException("Error configuring connection", t);
    }
  }