@Override
  public Proxy<?>[] releaseProxy(boolean destroy) {
    if (connectionStateMachine.isConnected()) {
      setConnectionState(ConnectionState.DISCONNECTING, null);
    }

    if (this.proxy != null) {
      this.proxy.removeProxyListener(proxyListener);
      if (this.directoryProxy != null && this.directoryProxy != this.proxy) {
        this.directoryProxy.removeProxyListener(proxyListener);
      }
    }
    Proxy<?>[] p = super.releaseProxy(destroy);
    if (connectionStateMachine.getConnectionState() == ConnectionState.DISCONNECTING) {
      setConnectionState(ConnectionState.DISCONNECTED, null);
    }

    if (destroy) {
      setConnectionState(ConnectionState.DESTROYED, null);
      linkListeners.clear();
      responseListeners.clear();
    }

    return p;
  }
 /** @return Returns the connectionState. */
 public ConnectionState getConnectionState() {
   return connectionStateMachine.getConnectionState();
 }