class HandshakeTimeoutObject implements Runnable {
    /** Object which used for connection. */
    private final Object connectionObj;

    /** Done. */
    private final AtomicBoolean done = new AtomicBoolean();

    /**
     * @param connectionObj Client.
     */
    public HandshakeTimeoutObject(Object connectionObj) {
        assert connectionObj != null;
        assert connectionObj instanceof GridCommunicationClient || connectionObj instanceof SelectableChannel;

        this.connectionObj = connectionObj;
    }

    /**
     * @return {@code True} if object has not yet been timed out.
     */
    public boolean cancel() {
        return done.compareAndSet(false, true);
    }

    /** {@inheritDoc} */
    @Override public String toString() {
        return S.toString(HandshakeTimeoutObject.class, this);
    }

    /** {@inheritDoc} */
    @Override public void run() {<FILL_FUNCTION_BODY>}
}

        if (done.compareAndSet(false, true)) {
            // Close socket - timeout occurred.
            if (connectionObj instanceof GridCommunicationClient)
                ((GridCommunicationClient)connectionObj).forceClose();
            else
                U.closeQuiet((AutoCloseable)connectionObj);
        }
    
<no_super_class>