# Class RpcUtil (3.19.4)

    public final class RpcUtil

Grab-bag of utility functions useful when dealing with RPCs.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> RpcUtil

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### \<ParameterType\>newOneTimeCallback(RpcCallback\<ParameterType\> originalCallback)

    public static RpcCallback<ParameterType> <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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `originalCallback` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RpcCallback<ParameterType>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RpcCallback<ParameterType>` |   |

### \<Type\>generalizeCallback(RpcCallback\<Type\> originalCallback, Class\<Type\> originalClass, Type defaultInstance)

    public static RpcCallback<Message> <Type>generalizeCallback(RpcCallback<Type> originalCallback, Class<Type> originalClass, Type defaultInstance)

Take an `RpcCallback` accepting a specific message type and convert it to an `
RpcCallback<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.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `originalCallback` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RpcCallback<Type>` |
| `originalClass` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<Type>` |
| `defaultInstance` | `Type` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RpcCallback<https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message>` |   |

### \<Type\>specializeCallback(RpcCallback\<Message\> originalCallback)

    public static RpcCallback<Type> <Type>specializeCallback(RpcCallback<Message> originalCallback)

Take an `RpcCallback<Message>` and convert it to an `RpcCallback` accepting a
specific message type. This is always type-safe (parameter type contravariance).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `originalCallback` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RpcCallback<https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.RpcCallback<Type>` |   |