public synchronized boolean switchConnection(Connection newCon) throws InterruptedException {
    Connection oldCon = null;
    synchronized (this) {
      if (shouldDestroy()) return false;

      if (this.active && !shouldDestroy()) {
        this.waitingToSwitch = true;
        try {
          while (this.active && !shouldDestroy()) {
            wait();
          }
        } finally {
          this.waitingToSwitch = false;
          notifyAll();
        }
      }
      if (shouldDestroy()) return false;
      assert !this.active;
      final long now = System.nanoTime();
      oldCon = this.connection;
      this.connection = newCon;
      this.endpoint = newCon.getEndpoint();
      this.birthDate = now;
    }
    if (oldCon != null) {
      try {
        // do this outside of sync
        oldCon.close(false);
      } catch (Exception e) {
        // ignore
      }
    }
    return true;
  }
 @Override
 public String toString() {
   Connection myCon = connection;
   if (myCon != null) {
     return "Pooled Connection to " + this.endpoint + ": " + myCon.toString();
   } else {
     return "Pooled Connection to " + this.endpoint + ": Connection[DESTROYED]";
   }
 }
 public void internalClose(boolean keepAlive) throws Exception {
   try {
     Connection con = this.connection;
     if (con != null) {
       con.close(keepAlive);
     }
   } finally {
     internalDestroy();
   }
 }
 public void internalDestroy() {
   this.shouldDestroy.set(true); // probably already set but make sure
   synchronized (this) {
     this.active = false;
     notifyAll();
     Connection myCon = connection;
     if (myCon != null) {
       myCon.destroy();
       connection = null;
     }
   }
 }
 public PooledConnection(ConnectionManagerImpl manager, Connection connection) {
   //    this.manager = manager;
   this.connection = connection;
   this.endpoint = connection.getEndpoint();
   this.birthDate = System.nanoTime();
   this.lastAccessed = this.birthDate;
 }
 public static void acquireConnectionsAndDestroyEntriesK1andK2() {
   try {
     Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
     assertNotNull(r1);
     String poolName = r1.getAttributes().getPoolName();
     assertNotNull(poolName);
     PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
     assertNotNull(pool);
     Connection conn = pool.acquireConnection();
     final Connection conn1;
     if (conn.getServer().getPort() != PORT2) {
       conn1 = pool.acquireConnection(); // Ensure we have a server with the proper port
     } else {
       conn1 = conn;
     }
     assertNotNull(conn1);
     assertEquals(PORT2, conn1.getServer().getPort());
     ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
     srp.destroyOnForTestsOnly(
         conn1,
         "key1",
         null,
         Operation.DESTROY,
         new EntryEventImpl(new EventID(new byte[] {1}, 100000, 1)),
         null);
     srp.destroyOnForTestsOnly(
         conn1,
         "key2",
         null,
         Operation.DESTROY,
         new EntryEventImpl(new EventID(new byte[] {1}, 100000, 2)),
         null);
   } catch (Exception ex) {
     throw new TestException("Failed while setting acquireConnectionsAndDestroyEntry  ", ex);
   }
 }