package votorola.g.web.gwt; // Copyright 2011-2012, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import com.google.gwt.jsonp.client.JsonpRequest; /** A guard to enforce non-overlapping JSONP request/response exchanges. It ensures that * only a single response is ever pending. */ public final class JSONPAtomizer { /** Nulls the pending request if it matches the one specified. * * @see #pendingRequest() */ public void clearPendingRequest( JsonpRequest oldRequest ) { if( oldRequest.equals( pendingRequest )) pendingRequest = null; } /** The serial request to the server that is currently pending, or null if there is * none. Requesters are required 1) to call this method on receiving a response to a * request in order to confirm that it is recorded as pending. If it is, then 2) * clear the record and 3) act on the response; otherwise do nothing. * * @see #clearPendingRequest(JsonpRequest) * @see #setPendingRequest(JsonpRequest) */ public JsonpRequest pendingRequest() { return pendingRequest; } private JsonpRequest pendingRequest; /** Records the start of a new request to the server and cancels any previous request * that is pending. Requesters are required to call this prior to sending each * serial request. * * @see #pendingRequest() */ public void setPendingRequest( JsonpRequest newRequest ) { if( newRequest == null ) throw new NullPointerException(); // should use clearPendingRequest() if( pendingRequest != null ) pendingRequest.cancel(); // just to be tidy pendingRequest = newRequest; } }