1fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Protocol Buffers - Google's data interchange format 2fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Copyright 2008 Google Inc. All rights reserved. 3fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// http://code.google.com/p/protobuf/ 4fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// 5fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// Redistribution and use in source and binary forms, with or without 6fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// modification, are permitted provided that the following conditions are 7fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// met: 8fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// 9fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// * Redistributions of source code must retain the above copyright 10fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// notice, this list of conditions and the following disclaimer. 11fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// * Redistributions in binary form must reproduce the above 12fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// copyright notice, this list of conditions and the following disclaimer 13fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// in the documentation and/or other materials provided with the 14fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// distribution. 15fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// * Neither the name of Google Inc. nor the names of its 16fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// contributors may be used to endorse or promote products derived from 17fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// this software without specific prior written permission. 18fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// 19fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 31fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillepackage com.google.protobuf; 32fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 33fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville/** 34fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * <p>An {@code RpcController} mediates a single method call. The primary 35fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * purpose of the controller is to provide a way to manipulate settings 36fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * specific to the RPC implementation and to find out about RPC-level errors. 37fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * 38d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville * <p>Starting with version 2.3.0, RPC implementations should not try to build 39d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville * on this, but should instead provide code generator plugins which generate 40d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville * code specific to the particular RPC implementation. This way the generated 41d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville * code can be more appropriate for the implementation in use and can avoid 42d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville * unnecessary layers of indirection. 43d0332953cda33fb4f8e24ebff9c49159b69c43d6Wink Saville * 44fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * <p>The methods provided by the {@code RpcController} interface are intended 45fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * to be a "least common denominator" set of features which we expect all 46fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * implementations to support. Specific implementations may provide more 47fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * advanced features (e.g. deadline propagation). 48fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * 49fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * @author kenton@google.com Kenton Varda 50fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville */ 51fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillepublic interface RpcController { 52fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // ----------------------------------------------------------------- 53fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // These calls may be made from the client side only. Their results 54fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // are undefined on the server side (may throw RuntimeExceptions). 55fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 56fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville /** 57fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * Resets the RpcController to its initial state so that it may be reused in 58fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * a new call. This can be called from the client side only. It must not 59fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * be called while an RPC is in progress. 60fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville */ 61fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville void reset(); 62fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 63fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville /** 64fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * After a call has finished, returns true if the call failed. The possible 65fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * reasons for failure depend on the RPC implementation. {@code failed()} 66fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * most only be called on the client side, and must not be called before a 67fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * call has finished. 68fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville */ 69fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville boolean failed(); 70fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 71fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville /** 72fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * If {@code failed()} is {@code true}, returns a human-readable description 73fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * of the error. 74fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville */ 75fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville String errorText(); 76fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 77fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville /** 78fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * Advises the RPC system that the caller desires that the RPC call be 79fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * canceled. The RPC system may cancel it immediately, may wait awhile and 80fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * then cancel it, or may not even cancel the call at all. If the call is 81fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * canceled, the "done" callback will still be called and the RpcController 82fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * will indicate that the call failed at that time. 83fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville */ 84fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville void startCancel(); 85fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 86fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // ----------------------------------------------------------------- 87fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // These calls may be made from the server side only. Their results 88fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville // are undefined on the client side (may throw RuntimeExceptions). 89fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 90fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville /** 91fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * Causes {@code failed()} to return true on the client side. {@code reason} 92fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * will be incorporated into the message returned by {@code errorText()}. 93fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * If you find you need to return machine-readable information about 94fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * failures, you should incorporate it into your response protocol buffer 95fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * and should NOT call {@code setFailed()}. 96fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville */ 97fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville void setFailed(String reason); 98fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 99fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville /** 100fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * If {@code true}, indicates that the client canceled the RPC, so the server 101fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * may as well give up on replying to it. This method must be called on the 102fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * server side only. The server should still call the final "done" callback. 103fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville */ 104fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville boolean isCanceled(); 105fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville 106fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville /** 107fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * Asks that the given callback be called when the RPC is canceled. The 108fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * parameter passed to the callback will always be {@code null}. The 109fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * callback will always be called exactly once. If the RPC completes without 110fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * being canceled, the callback will be called after completion. If the RPC 111fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * has already been canceled when NotifyOnCancel() is called, the callback 112fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * will be called immediately. 113fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * 114fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * <p>{@code notifyOnCancel()} must be called no more than once per request. 115fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * It must be called on the server side only. 116fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville */ 117fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville void notifyOnCancel(RpcCallback<Object> callback); 118fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville} 119