コード例 #1
0
  /*
   * @see com.atomikos.datasource.xa.XATransactionalResource#refreshXAConnection()
   */
  protected XAResource refreshXAConnection() throws ResourceException {
    if (LOGGER.isInfoEnabled()) {
      LOGGER.logInfo("refreshXAConnection() for resource: " + getName());
    }

    XAResource ret = null;
    if (connection != null) {
      try {
        connection.destroy();
      } catch (Exception normal) {
        // this can be expected, since this method is only called
        // if there is a connection problem
      }
    }

    try {

      LOGGER.logInfo("about to block for new connection...");
      // System.out.println ( "ABOUT TO BLOCK FOR NEW CONNECTION");
      connection = mcf.createManagedConnection(null, null);

    } catch (javax.resource.ResourceException e) {
      // ignore and return null: happens if resource is down
      // at this moment
      connection = null;
    } finally {
      // System.out.println ( "BLOCKING DONE");
      if (LOGGER.isInfoEnabled()) {
        LOGGER.logInfo("blocking done.");
      }
    }

    try {
      if (connection != null) ret = connection.getXAResource();
    } catch (javax.resource.ResourceException e) {
      LOGGER.logWarning("error getting XAResource: " + e.getMessage());

      throw new ResourceException("Error in getting XA resource", e);
    }

    LOGGER.logInfo("refreshXAConnection() done.");

    // System.out.println ( "DONE REFRESHXACONNECTION FOR RESOURCE: " +
    // getName() );

    return ret;
  }