org.apache.avro

## Class Protocol

- java.lang.Object
- - org.apache.avro.JsonProperties
  - - org.apache.avro.Protocol

    public class Protocol
    extends JsonProperties

A set of messages forming an application protocol.

A protocol consists of:

- a name for the protocol;
- an optional namespace, further qualifying the name;
- a list of types, or named `schemas`;
- a list of errors, or named `schemas` for exceptions;
- a list of named messages, each of which specifies,
  - request, the parameter schemas;
  - one of either;
    - one-way
    or
    - response, the response schema;
    - errors, an optional list of potential error schema names.

### Nested Class Summary

Nested Classes
`class` `Protocol.Message` A protocol message.

### Nested classes/interfaces inherited from class org.apache.avro.JsonProperties

`JsonProperties.Null`

### Field Summary

Fields
`static Schema` `SYSTEM_ERROR` An error that can be thrown by any message.
`static Schema` `SYSTEM_ERRORS` Union type for generating system errors.
`static long` `VERSION` The version of the protocol specification implemented here.

### Fields inherited from class org.apache.avro.JsonProperties

`NULL_VALUE`

### Constructor Summary

Constructors
Constructor and Description
`Protocol(Protocol p)` Constructs a similar Protocol instance with the same `name`, `doc`, and `namespace` as {code p} has.
`Protocol(String name, String namespace)`
`Protocol(String name, String doc, String namespace)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
`Protocol.Message` `createMessage(Protocol.Message m, Schema request)` Create a one-way message using the `name`, `doc`, and `props` of `m`.
`Protocol.Message` `createMessage(Protocol.Message m, Schema request, Schema response, Schema errors)` Create a two-way message using the `name`, `doc`, and `props` of `m`.
`<T> Protocol.Message` `createMessage(String name, String doc, JsonProperties propMap, Schema request)` Create a one-way message.
`<T> Protocol.Message` `createMessage(String name, String doc, JsonProperties propMap, Schema request, Schema response, Schema errors)` Create a two-way message.
`<T> Protocol.Message` `createMessage(String name, String doc, Map<String,?> propMap, Schema request)` Create a one-way message.
`<T> Protocol.Message` `createMessage(String name, String doc, Map<String,?> propMap, Schema request, Schema response, Schema errors)` Create a two-way message.
`Protocol.Message` `createMessage(String name, String doc, Schema request)` Deprecated.
`Protocol.Message` `createMessage(String name, String doc, Schema request, Schema response, Schema errors)` Deprecated.
`boolean` `equals(Object o)`
`String` `getDoc()` Doc string for this protocol.
`byte[]` `getMD5()` Return the MD5 hash of the text of this protocol.
`Map<String,Protocol.Message>` `getMessages()` The messages of this protocol.
`String` `getName()` The name of this protocol.
`String` `getNamespace()` The namespace of this protocol.
`Schema` `getType(String name)` Returns the named type.
`Collection<Schema>` `getTypes()` The types of this protocol.
`int` `hashCode()`
`static void` `main(String[] args)`
`static Protocol` `parse(File file)` Read a protocol from a Json file.
`static Protocol` `parse(InputStream stream)` Read a protocol from a Json stream.
`static Protocol` `parse(String string)` Read a protocol from a Json string.
`static Protocol` `parse(String string, String... more)` Read a protocol from one or more json strings
`void` `setTypes(Collection<Schema> newTypes)` Set the types of this protocol.
`String` `toString()` Render this as JSON.
`String` `toString(boolean pretty)` Render this as JSON.

### Methods inherited from class org.apache.avro.JsonProperties

`addAllProps, addProp, addProp, getObjectProp, getObjectProps, getProp, hasProps, putAll`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### VERSION

    public static final long VERSION

The version of the protocol specification implemented here.

See Also:
  Constant Field Values

#### SYSTEM_ERROR

    public static final Schema SYSTEM_ERROR

An error that can be thrown by any message.

#### SYSTEM_ERRORS

    public static final Schema SYSTEM_ERRORS

Union type for generating system errors.

### Constructor Detail

#### Protocol

    public Protocol(Protocol p)

Constructs a similar Protocol instance with the same `name`, `doc`, and `namespace` as {code p} has. It also copies all the `props`.

#### Protocol

    public Protocol(String name,
                    String doc,
                    String namespace)

#### Protocol

    public Protocol(String name,
                    String namespace)

### Method Detail

#### getName

    public String getName()

The name of this protocol.

#### getNamespace

    public String getNamespace()

The namespace of this protocol. Qualifies its name.

#### getDoc

    public String getDoc()

Doc string for this protocol.

#### getTypes

    public Collection<Schema> getTypes()

The types of this protocol.

#### getType

    public Schema getType(String name)

Returns the named type.

#### setTypes

    public void setTypes(Collection<Schema> newTypes)

Set the types of this protocol.

#### getMessages

    public Map<String,Protocol.Message> getMessages()

The messages of this protocol.

#### createMessage

    @Deprecated
    public Protocol.Message createMessage(String name,
                                                      String doc,
                                                      Schema request)

Deprecated.
Create a one-way message.

#### createMessage

    public Protocol.Message createMessage(Protocol.Message m,
                                          Schema request)

Create a one-way message using the `name`, `doc`, and `props` of `m`.

#### createMessage

    public <T> Protocol.Message createMessage(String name,
                                              String doc,
                                              JsonProperties propMap,
                                              Schema request)

Create a one-way message.

#### createMessage

    public <T> Protocol.Message createMessage(String name,
                                              String doc,
                                              Map<String,?> propMap,
                                              Schema request)

Create a one-way message.

#### createMessage

    @Deprecated
    public Protocol.Message createMessage(String name,
                                                      String doc,
                                                      Schema request,
                                                      Schema response,
                                                      Schema errors)

Deprecated.
Create a two-way message.

#### createMessage

    public Protocol.Message createMessage(Protocol.Message m,
                                          Schema request,
                                          Schema response,
                                          Schema errors)

Create a two-way message using the `name`, `doc`, and `props` of `m`.

#### createMessage

    public <T> Protocol.Message createMessage(String name,
                                              String doc,
                                              JsonProperties propMap,
                                              Schema request,
                                              Schema response,
                                              Schema errors)

Create a two-way message.

#### createMessage

    public <T> Protocol.Message createMessage(String name,
                                              String doc,
                                              Map<String,?> propMap,
                                              Schema request,
                                              Schema response,
                                              Schema errors)

Create a two-way message.

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Render this as JSON.

Overrides:
  `toString` in class `Object`

#### toString

    public String toString(boolean pretty)

Render this as JSON.

Parameters:
  `pretty` - if true, pretty-print JSON.

#### getMD5

    public byte[] getMD5()

Return the MD5 hash of the text of this protocol.

#### parse

    public static Protocol parse(File file)
                          throws IOException

Read a protocol from a Json file.

Throws:
  `IOException`

#### parse

    public static Protocol parse(InputStream stream)
                          throws IOException

Read a protocol from a Json stream.

Throws:
  `IOException`

#### parse

    public static Protocol parse(String string,
                                 String... more)

Read a protocol from one or more json strings

#### parse

    public static Protocol parse(String string)

Read a protocol from a Json string.

#### main

    public static void main(String[] args)
                     throws Exception

Throws:
  `Exception`