コード例 #1
0
 /**
  * This will be called if the Connection returned by the getConnection method came from a
  * PooledConnection, and the user calls the close() method of this connection object. What we need
  * to do here is to release this PooledConnection from our pool...
  */
 @Override
 public void connectionClosed(ConnectionEvent event) {
   PooledConnection pc = (PooledConnection) event.getSource();
   // if this event occurred because we were validating, or if this
   // connection has been marked for removal, ignore it
   // otherwise return the connection to the pool.
   if (!validatingSet.contains(pc)) {
     PooledConnectionAndInfo pci = pcMap.get(pc);
     if (pci == null) {
       throw new IllegalStateException(NO_KEY_MESSAGE);
     }
     try {
       _pool.returnObject(pci.getUserPassKey(), pci);
     } catch (Exception e) {
       System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + "NOT BE RETURNED TO THE POOL");
       pc.removeConnectionEventListener(this);
       try {
         _pool.invalidateObject(pci.getUserPassKey(), pci);
       } catch (Exception e3) {
         System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
         e3.printStackTrace();
       }
     }
   }
 }
コード例 #2
0
 /** Closes the PooledConnection and stops listening for events from it. */
 @Override
 public void destroyObject(UserPassKey key, PooledObject<PooledConnectionAndInfo> p)
     throws Exception {
   PooledConnection pc = p.getObject().getPooledConnection();
   pc.removeConnectionEventListener(this);
   pcMap.remove(pc);
   pc.close();
 }
コード例 #3
0
 private synchronized void disposeConnection(PooledConnection pconn) {
   pconn.removeConnectionEventListener(poolConnectionEventListener);
   if (!recycledConnections.remove(pconn) && pconn != connectionInTransition) {
     // If the PooledConnection is not in the recycledConnections list
     // and is not currently within a PooledConnection.getConnection() call,
     // we assume that the connection was active.
     if (activeConnections <= 0) {
       throw new AssertionError();
     }
     activeConnections--;
     semaphore.release();
   }
   closeConnectionAndIgnoreException(pconn);
   assertInnerState();
 }
コード例 #4
0
  /**
   * If a fatal error occurs, close the underlying physical connection so as not to be returned in
   * the future
   */
  @Override
  public void connectionErrorOccurred(ConnectionEvent event) {
    PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
      System.err.println(
          "CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    PooledConnectionAndInfo info = pcMap.get(pc);
    if (info == null) {
      throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
      _pool.invalidateObject(info.getUserPassKey(), info);
    } catch (Exception e) {
      System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info);
      e.printStackTrace();
    }
  }
コード例 #5
0
 /**
  * Cleans up pooled connections from cleanupMap. 1) remove PoolableConnectionAndInfo wrapper from
  * pcMap 2) remove from MuteMap
  */
 private void cleanupListeners() {
   try {
     Iterator iter = cleanupMap.keySet().iterator();
     while (iter.hasNext()) {
       PooledConnection pc = (PooledConnection) iter.next();
       pcMap.remove(pc);
       muteMap.remove(pc);
       try {
         pc.removeConnectionEventListener(this);
       } catch (Exception ex) {
         System.err.println("EXCEPTION REMOVING CONNECTION LISTENER ");
         ex.printStackTrace();
       }
     }
   } catch (Exception e) {
     System.err.println("EXCEPTION CLEANING UP CONNECTION LISTENERS ");
     e.printStackTrace();
   } finally {
     cleanupMap.clear();
   }
 }
コード例 #6
0
 @Override
 public void removeConnectionEventListener(ConnectionEventListener eventTarget) {
   passthru.removeConnectionEventListener(eventTarget);
 }