/game_server/src/com/google/protobuf/Service.java

http://mmorpg-client-server-learning.googlecode.com/ · Java · 117 lines · 10 code · 5 blank · 102 comment · 0 complexity · 55e82d9a2ec470e5f3e899ebf5434990 MD5 · raw file

  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. package com.google.protobuf;
  31. /**
  32. * Abstract base interface for protocol-buffer-based RPC services. Services
  33. * themselves are abstract classes (implemented either by servers or as
  34. * stubs), but they subclass this base interface. The methods of this
  35. * interface can be used to call the methods of the service without knowing
  36. * its exact type at compile time (analogous to the Message interface).
  37. *
  38. * <p>Starting with version 2.3.0, RPC implementations should not try to build
  39. * on this, but should instead provide code generator plugins which generate
  40. * code specific to the particular RPC implementation. This way the generated
  41. * code can be more appropriate for the implementation in use and can avoid
  42. * unnecessary layers of indirection.
  43. *
  44. * @author kenton@google.com Kenton Varda
  45. */
  46. public interface Service {
  47. /**
  48. * Get the {@code ServiceDescriptor} describing this service and its methods.
  49. */
  50. Descriptors.ServiceDescriptor getDescriptorForType();
  51. /**
  52. * <p>Call a method of the service specified by MethodDescriptor. This is
  53. * normally implemented as a simple {@code switch()} that calls the standard
  54. * definitions of the service's methods.
  55. *
  56. * <p>Preconditions:
  57. * <ul>
  58. * <li>{@code method.getService() == getDescriptorForType()}
  59. * <li>{@code request} is of the exact same class as the object returned by
  60. * {@code getRequestPrototype(method)}.
  61. * <li>{@code controller} is of the correct type for the RPC implementation
  62. * being used by this Service. For stubs, the "correct type" depends
  63. * on the RpcChannel which the stub is using. Server-side Service
  64. * implementations are expected to accept whatever type of
  65. * {@code RpcController} the server-side RPC implementation uses.
  66. * </ul>
  67. *
  68. * <p>Postconditions:
  69. * <ul>
  70. * <li>{@code done} will be called when the method is complete. This may be
  71. * before {@code callMethod()} returns or it may be at some point in
  72. * the future.
  73. * <li>The parameter to {@code done} is the response. It must be of the
  74. * exact same type as would be returned by
  75. * {@code getResponsePrototype(method)}.
  76. * <li>If the RPC failed, the parameter to {@code done} will be
  77. * {@code null}. Further details about the failure can be found by
  78. * querying {@code controller}.
  79. * </ul>
  80. */
  81. void callMethod(Descriptors.MethodDescriptor method,
  82. RpcController controller,
  83. Message request,
  84. RpcCallback<Message> done);
  85. /**
  86. * <p>{@code callMethod()} requires that the request passed in is of a
  87. * particular subclass of {@code Message}. {@code getRequestPrototype()}
  88. * gets the default instances of this type for a given method. You can then
  89. * call {@code Message.newBuilderForType()} on this instance to
  90. * construct a builder to build an object which you can then pass to
  91. * {@code callMethod()}.
  92. *
  93. * <p>Example:
  94. * <pre>
  95. * MethodDescriptor method =
  96. * service.getDescriptorForType().findMethodByName("Foo");
  97. * Message request =
  98. * stub.getRequestPrototype(method).newBuilderForType()
  99. * .mergeFrom(input).build();
  100. * service.callMethod(method, request, callback);
  101. * </pre>
  102. */
  103. Message getRequestPrototype(Descriptors.MethodDescriptor method);
  104. /**
  105. * Like {@code getRequestPrototype()}, but gets a prototype of the response
  106. * message. {@code getResponsePrototype()} is generally not needed because
  107. * the {@code Service} implementation constructs the response message itself,
  108. * but it may be useful in some cases to know ahead of time what type of
  109. * object will be returned.
  110. */
  111. Message getResponsePrototype(Descriptors.MethodDescriptor method);
  112. }