@SuppressWarnings("unchecked")
  void check() {

    watchDogRuns++;

    long current = System.currentTimeMillis();

    ArrayList<WeakReference<TimeoutMgmHandle>> connectionsCopy = null;
    synchronized (handles) {
      connectionsCopy = (ArrayList<WeakReference<TimeoutMgmHandle>>) handles.clone();
    }

    for (WeakReference<TimeoutMgmHandle> handleRef : connectionsCopy) {

      TimeoutMgmHandle handle = handleRef.get();
      if (handle == null) {
        remove(handleRef);

      } else {
        NonBlockingConnection con = handle.getConnection();
        if (con.isOpen()) {
          checkTimeout(con, current);

        } else {
          remove(handleRef);
        }
      }
    }

    computeSize();
  }
  void close() {

    // closing watch dog
    if (conCheckWatchDogTask != null) {
      conCheckWatchDogTask.cancel();
      conCheckWatchDogTask = null;
    }

    // close open connections
    try {
      for (NonBlockingConnection connection : getConnections()) {
        try {
          connection.close();
        } catch (IOException ioe) {
          if (LOG.isLoggable(Level.FINE)) {
            LOG.fine(
                "error occured by closing connection "
                    + connection.getId()
                    + " "
                    + DataConverter.toString(ioe));
          }
        }
      }
    } catch (Throwable e) {
      if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("error occured by closing open connections " + DataConverter.toString(e));
      }
    }

    // clear handle list
    handles.clear();
  }
  private void checkTimeout(NonBlockingConnection connection, long current) {

    boolean timeoutOccured = connection.checkIdleTimeout(current);
    if (timeoutOccured) {
      countIdleTimeouts++;
    }

    timeoutOccured = connection.checkConnectionTimeout(current);
    if (timeoutOccured) {
      countConnectionTimeouts++;
    }
  }