Exemplo n.º 1
0
  /** Transport connected. {@link IOTransport} calls this when a connection is established. */
  public void transportConnected() {

    setState(STATE_READY);
    if (reconnectTask != null) {
      reconnectTask.cancel();
      reconnectTask = null;
    }
    resetTimeout();
    synchronized (outputBuffer) {
      if (transport.canSendBulk()) {
        ConcurrentLinkedQueue<String> outputBuffer = this.outputBuffer;
        this.outputBuffer = new ConcurrentLinkedQueue<String>();
        try {
          // DEBUG
          String[] texts = outputBuffer.toArray(new String[outputBuffer.size()]);
          log.debug("Bulk start:");
          for (String text : texts) {
            log.debug("> " + text);
          }
          log.debug("Bulk end");
          // DEBUG END
          transport.sendBulk(texts);
        } catch (IOException e) {
          this.outputBuffer = outputBuffer;
        }
      } else {
        String text;
        while ((text = outputBuffer.poll()) != null) {
          sendPlain(text);
        }
      }
      this.keepAliveInQueue = false;
    }
  }
Exemplo n.º 2
0
  /**
   * Forces a reconnect. This had become useful on some android devices which do not shut down
   * TCP-connections when switching from HSDPA to Wifi
   */
  public void reconnect() {

    log.info("reconnect called!");

    synchronized (this) {
      if (getState() != STATE_INVALID) {
        invalidateTransport();
        setState(STATE_INTERRUPTED);
        if (reconnectTask != null) {
          reconnectTask.cancel();
        }
        reconnectTask = new ReconnectTask();
        backgroundTimer.schedule(reconnectTask, 1000);
      }
    }
  }