public void cancel() throws IOException {

    if (!isCancelled.getAndSet(true)) {
      logger.trace("Cancelling {}", uuid);

      if (config.getBroadcasterFactory().getDefault() != null) {
        config.getBroadcasterFactory().getDefault().removeAllAtmosphereResource(this);
        if (transport.equals(TRANSPORT.WEBSOCKET)) {
          String parentUUID = (String) req.getAttribute(SUSPENDED_ATMOSPHERE_RESOURCE_UUID);
          AtmosphereResource p = AtmosphereResourceFactory.getDefault().find(parentUUID);
          if (p != null) {
            config.getBroadcasterFactory().getDefault().removeAllAtmosphereResource(p);
          }
        }
      }

      asyncSupport.complete(this);

      SessionTimeoutSupport.restoreTimeout(req);
      action.type(Action.TYPE.CANCELLED);
      if (asyncSupport != null) asyncSupport.action(this);
      // We must close the underlying WebSocket as well.
      if (AtmosphereResponse.class.isAssignableFrom(response.getClass())) {
        AtmosphereResponse.class.cast(response).close();
        AtmosphereResponse.class.cast(response).destroy();
      }

      if (AtmosphereRequest.class.isAssignableFrom(req.getClass())) {
        AtmosphereRequest.class.cast(req).destroy();
      }
      req.removeAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);
      event.destroy();
    }
  }
  // ----------------------------------------------------------
  int sizeOf(InterfaceConnection ic) throws CharacterCodingException, UnsupportedCharsetException {
    int size = 0;

    datasourceBytes = ic.encodeString(datasource, InterfaceUtilities.SQLCHARSETCODE_UTF8);
    catalogBytes = ic.encodeString(catalog, InterfaceUtilities.SQLCHARSETCODE_UTF8);
    schemaBytes = ic.encodeString(schema, InterfaceUtilities.SQLCHARSETCODE_UTF8);
    locationBytes = ic.encodeString(location, 1);
    userRoleBytes = ic.encodeString(userRole, 1);
    computerNameBytes = ic.encodeString(computerName, InterfaceUtilities.SQLCHARSETCODE_UTF8);
    windowTextBytes = ic.encodeString(windowText, InterfaceUtilities.SQLCHARSETCODE_UTF8);
    connectOptionsBytes = ic.encodeString(connectOptions, 1);

    size = TRANSPORT.size_bytes(datasourceBytes);
    size += TRANSPORT.size_bytes(catalogBytes);
    size += TRANSPORT.size_bytes(schemaBytes);
    size += TRANSPORT.size_bytes(locationBytes);
    size += TRANSPORT.size_bytes(userRoleBytes);

    size += TRANSPORT.size_short; // accessMode
    size += TRANSPORT.size_short; // autoCommit
    size += TRANSPORT.size_int; // queryTimeoutSec
    size += TRANSPORT.size_int; // idleTimeoutSec
    size += TRANSPORT.size_int; // loginTimeoutSec
    size += TRANSPORT.size_short; // txnIsolationLevel
    size += TRANSPORT.size_short; // rowSetSize

    size += TRANSPORT.size_short; // diagnosticFlag
    size += TRANSPORT.size_int; // processId

    size += TRANSPORT.size_bytes(computerNameBytes);
    size += TRANSPORT.size_bytes(windowTextBytes);

    size += TRANSPORT.size_int; // ctxACP
    size += TRANSPORT.size_int; // ctxDataLang
    size += TRANSPORT.size_int; // ctxErrorLang
    size += TRANSPORT.size_short; // ctxCtrlInferNCHAR

    size += TRANSPORT.size_short; // cpuToUse
    size += TRANSPORT.size_short; // cpuToUseEnd
    size += TRANSPORT.size_bytes(connectOptionsBytes);

    size += clientVersionList.sizeOf();

    return size;
  }