Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / third_party / protobuf / java / src / main / java / com / google / protobuf / Service.java
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 // http://code.google.com/p/protobuf/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 //     * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 //     * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 package com.google.protobuf;
32
33 /**
34  * Abstract base interface for protocol-buffer-based RPC services.  Services
35  * themselves are abstract classes (implemented either by servers or as
36  * stubs), but they subclass this base interface.  The methods of this
37  * interface can be used to call the methods of the service without knowing
38  * its exact type at compile time (analogous to the Message interface).
39  *
40  * <p>Starting with version 2.3.0, RPC implementations should not try to build
41  * on this, but should instead provide code generator plugins which generate
42  * code specific to the particular RPC implementation.  This way the generated
43  * code can be more appropriate for the implementation in use and can avoid
44  * unnecessary layers of indirection.
45  *
46  * @author kenton@google.com Kenton Varda
47  */
48 public interface Service {
49   /**
50    * Get the {@code ServiceDescriptor} describing this service and its methods.
51    */
52   Descriptors.ServiceDescriptor getDescriptorForType();
53
54   /**
55    * <p>Call a method of the service specified by MethodDescriptor.  This is
56    * normally implemented as a simple {@code switch()} that calls the standard
57    * definitions of the service's methods.
58    *
59    * <p>Preconditions:
60    * <ul>
61    *   <li>{@code method.getService() == getDescriptorForType()}
62    *   <li>{@code request} is of the exact same class as the object returned by
63    *       {@code getRequestPrototype(method)}.
64    *   <li>{@code controller} is of the correct type for the RPC implementation
65    *       being used by this Service.  For stubs, the "correct type" depends
66    *       on the RpcChannel which the stub is using.  Server-side Service
67    *       implementations are expected to accept whatever type of
68    *       {@code RpcController} the server-side RPC implementation uses.
69    * </ul>
70    *
71    * <p>Postconditions:
72    * <ul>
73    *   <li>{@code done} will be called when the method is complete.  This may be
74    *       before {@code callMethod()} returns or it may be at some point in
75    *       the future.
76    *   <li>The parameter to {@code done} is the response.  It must be of the
77    *       exact same type as would be returned by
78    *       {@code getResponsePrototype(method)}.
79    *   <li>If the RPC failed, the parameter to {@code done} will be
80    *       {@code null}.  Further details about the failure can be found by
81    *       querying {@code controller}.
82    * </ul>
83    */
84   void callMethod(Descriptors.MethodDescriptor method,
85                   RpcController controller,
86                   Message request,
87                   RpcCallback<Message> done);
88
89   /**
90    * <p>{@code callMethod()} requires that the request passed in is of a
91    * particular subclass of {@code Message}.  {@code getRequestPrototype()}
92    * gets the default instances of this type for a given method.  You can then
93    * call {@code Message.newBuilderForType()} on this instance to
94    * construct a builder to build an object which you can then pass to
95    * {@code callMethod()}.
96    *
97    * <p>Example:
98    * <pre>
99    *   MethodDescriptor method =
100    *     service.getDescriptorForType().findMethodByName("Foo");
101    *   Message request =
102    *     stub.getRequestPrototype(method).newBuilderForType()
103    *         .mergeFrom(input).build();
104    *   service.callMethod(method, request, callback);
105    * </pre>
106    */
107   Message getRequestPrototype(Descriptors.MethodDescriptor method);
108
109   /**
110    * Like {@code getRequestPrototype()}, but gets a prototype of the response
111    * message.  {@code getResponsePrototype()} is generally not needed because
112    * the {@code Service} implementation constructs the response message itself,
113    * but it may be useful in some cases to know ahead of time what type of
114    * object will be returned.
115    */
116   Message getResponsePrototype(Descriptors.MethodDescriptor method);
117 }