Package com.google.protobuf
Class RpcUtil
- java.lang.Object
-
- com.google.protobuf.RpcUtil
-
public final class RpcUtil extends java.lang.Object
Grab-bag of utility functions useful when dealing with RPCs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RpcUtil.AlreadyCalledException
Exception thrown when a one-time callback is called more than once.
-
Constructor Summary
Constructors Modifier Constructor Description private
RpcUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static <Type extends Message>
TypecopyAsType(Type typeDefaultInstance, Message source)
Creates a new message of type "Type" which is a copy of "source".static <Type extends Message>
RpcCallback<Message>generalizeCallback(RpcCallback<Type> originalCallback, java.lang.Class<Type> originalClass, Type defaultInstance)
Take anRpcCallback
accepting a specific message type and convert it to anRpcCallback<Message>
.static <ParameterType>
RpcCallback<ParameterType>newOneTimeCallback(RpcCallback<ParameterType> originalCallback)
Creates a callback which can only be called once.static <Type extends Message>
RpcCallback<Type>specializeCallback(RpcCallback<Message> originalCallback)
Take anRpcCallback<Message>
and convert it to anRpcCallback
accepting a specific message type.
-
-
-
Method Detail
-
specializeCallback
public static <Type extends Message> RpcCallback<Type> specializeCallback(RpcCallback<Message> originalCallback)
Take anRpcCallback<Message>
and convert it to anRpcCallback
accepting a specific message type. This is always type-safe (parameter type contravariance).
-
generalizeCallback
public static <Type extends Message> RpcCallback<Message> generalizeCallback(RpcCallback<Type> originalCallback, java.lang.Class<Type> originalClass, Type defaultInstance)
Take anRpcCallback
accepting a specific message type and convert it to anRpcCallback<Message>
. The generalized callback will accept any message object which has the same descriptor, and will convert it to the correct class before calling the original callback. However, if the generalized callback is given a message with a different descriptor, an exception will be thrown.
-
copyAsType
private static <Type extends Message> Type copyAsType(Type typeDefaultInstance, Message source)
Creates a new message of type "Type" which is a copy of "source". "source" must have the same descriptor but may be a different class (e.g. DynamicMessage).
-
newOneTimeCallback
public static <ParameterType> RpcCallback<ParameterType> newOneTimeCallback(RpcCallback<ParameterType> originalCallback)
Creates a callback which can only be called once. This may be useful for security, when passing a callback to untrusted code: most callbacks do not expect to be called more than once, so doing so may expose bugs if it is not prevented.
-
-