private void failedRefresh() {
   refreshState = null;
   GWT.log("CometClient: Failed refesh");
   // dispatch remaining messages;
   if (refreshQueue != null) {
     for (Object object : refreshQueue) {
       if (object == REFRESH || object == DISCONNECT) {
       } else {
         doOnMessage((List<?>) object, primaryTransport);
       }
     }
     refreshQueue.clear();
   }
   doDisconnect();
   doConnect();
 }
  private void doOnDisconnected(CometClientTransportWrapper transport) {
    if (refreshState != null) {
      if (transport == primaryTransport) {
        if (refreshState != RefreshState.CONNECTING) {
          throw new IllegalStateException("Unexpected refreshState");
        }
        refreshState = RefreshState.PRIMARY_DISCONNECTED;
        GWT.log("CometClient: primary disconnected before refresh transport was connected");
      } else {
        // the refresh transport has disconnected
        failedRefresh();
      }
    } else {
      listener.onDisconnected();

      if (running) {
        doConnect();
      }
    }
  }