Example usage for com.google.gwt.xhr.client XMLHttpRequest UNSENT

List of usage examples for com.google.gwt.xhr.client XMLHttpRequest UNSENT

Introduction

In this page you can find the example usage for com.google.gwt.xhr.client XMLHttpRequest UNSENT.

Prototype

int UNSENT

To view the source code for com.google.gwt.xhr.client XMLHttpRequest UNSENT.

Click Source Link

Document

When constructed, the XMLHttpRequest object must be in the UNSENT state.

Usage

From source file:org.atmosphere.gwt.client.impl.HTTPRequestCometTransport.java

License:Apache License

@Override
public void disconnect() {
    aborted = true;/*from   w ww. j  ava2  s.  com*/
    expectingDisconnection = true;
    super.disconnect();
    if (xmlHttpRequest != null) {
        if (xmlHttpRequest.getReadyState() >= XMLHttpRequest.HEADERS_RECEIVED) {
            //                if readystate >= HEADERS_RECEIVED we can abort otherwise wait for this in onReadyStateChange
            xmlHttpRequest.clearOnReadyStateChange();
            if (xmlHttpRequest.getReadyState() != XMLHttpRequest.DONE) {
                listener.onDisconnected();
                xmlHttpRequest.abort();
            }
            xmlHttpRequest = null;
        } else {
            new Timer() {
                XMLHttpRequest r = xmlHttpRequest;

                @Override
                public void run() {
                    r.clearOnReadyStateChange();
                    if (r.getReadyState() != XMLHttpRequest.DONE
                            && r.getReadyState() != XMLHttpRequest.UNSENT) {
                        listener.onDisconnected();
                        r.abort();
                    }
                    r = null;
                }
            }.schedule(5000);
            xmlHttpRequest = null;
        }
    }
}