Package 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
Modifier and Type
Class
Description
`class`
`Protocol.Message`
A protocol message.

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

`JsonProperties.Null`

## Field Summary

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

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

`NULL_VALUE`

## Constructor Summary

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

## Method Summary

Modifier and Type
Method
Description
`Protocol.Message`
`createMessage(String name, String doc, Map<String,?> propMap, Schema request)`
Create a one-way message.
`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, JsonProperties propMap, Schema request)`
Create a one-way message.
`Protocol.Message`
`createMessage(String name, String doc, JsonProperties 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.
`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`.
`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.
`Collection<Schema>`
`getUnresolvedTypes()`
Deprecated.
can return invalid schemata: do NOT use!
`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, forEachProperty, getObjectProp, getObjectProp, getObjectProps, getProp, hasProps, propsContainsKey, putAll`

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

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

## Field Details

### 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 Details

### 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 Details

### 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.

### getUnresolvedTypes

@Deprecated public Collection<Schema> getUnresolvedTypes()
Deprecated.
can return invalid schemata: do NOT use!

### 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 Protocol.Message createMessage(String name, String doc, JsonProperties propMap, Schema request)
Create a one-way message.

### createMessage

public 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 Protocol.Message createMessage(String name, String doc, JsonProperties propMap, Schema request, Schema response, Schema errors)
Create a two-way message.

### createMessage

public 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`