RpcController.java revision fbaaef999ba563838ebd00874ed8a1c01fbf286d
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 *
38fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * <p>The methods provided by the {@code RpcController} interface are intended
39fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * to be a "least common denominator" set of features which we expect all
40fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * implementations to support.  Specific implementations may provide more
41fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * advanced features (e.g. deadline propagation).
42fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville *
43fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville * @author kenton@google.com Kenton Varda
44fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville */
45fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Savillepublic interface RpcController {
46fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // -----------------------------------------------------------------
47fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // These calls may be made from the client side only.  Their results
48fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // are undefined on the server side (may throw RuntimeExceptions).
49fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
50fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  /**
51fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * Resets the RpcController to its initial state so that it may be reused in
52fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * a new call.  This can be called from the client side only.  It must not
53fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * be called while an RPC is in progress.
54fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   */
55fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void reset();
56fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
57fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  /**
58fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * After a call has finished, returns true if the call failed.  The possible
59fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * reasons for failure depend on the RPC implementation.  {@code failed()}
60fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * most only be called on the client side, and must not be called before a
61fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * call has finished.
62fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   */
63fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  boolean failed();
64fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
65fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  /**
66fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * If {@code failed()} is {@code true}, returns a human-readable description
67fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * of the error.
68fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   */
69fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  String errorText();
70fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
71fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  /**
72fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * Advises the RPC system that the caller desires that the RPC call be
73fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * canceled.  The RPC system may cancel it immediately, may wait awhile and
74fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * then cancel it, or may not even cancel the call at all.  If the call is
75fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * canceled, the "done" callback will still be called and the RpcController
76fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * will indicate that the call failed at that time.
77fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   */
78fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void startCancel();
79fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
80fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // -----------------------------------------------------------------
81fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // These calls may be made from the server side only.  Their results
82fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  // are undefined on the client side (may throw RuntimeExceptions).
83fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
84fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  /**
85fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * Causes {@code failed()} to return true on the client side.  {@code reason}
86fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * will be incorporated into the message returned by {@code errorText()}.
87fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * If you find you need to return machine-readable information about
88fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * failures, you should incorporate it into your response protocol buffer
89fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * and should NOT call {@code setFailed()}.
90fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   */
91fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void setFailed(String reason);
92fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
93fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  /**
94fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * If {@code true}, indicates that the client canceled the RPC, so the server
95fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * may as well give up on replying to it.  This method must be called on the
96fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * server side only.  The server should still call the final "done" callback.
97fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   */
98fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  boolean isCanceled();
99fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville
100fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  /**
101fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * Asks that the given callback be called when the RPC is canceled.  The
102fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * parameter passed to the callback will always be {@code null}.  The
103fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * callback will always be called exactly once.  If the RPC completes without
104fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * being canceled, the callback will be called after completion.  If the RPC
105fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * has already been canceled when NotifyOnCancel() is called, the callback
106fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * will be called immediately.
107fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   *
108fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * <p>{@code notifyOnCancel()} must be called no more than once per request.
109fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   * It must be called on the server side only.
110fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville   */
111fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville  void notifyOnCancel(RpcCallback<Object> callback);
112fbaaef999ba563838ebd00874ed8a1c01fbf286dWink Saville}
113