Module org.firebirdsql.jaybird
Package org.firebirdsql.gds.ng.wire

# Class ProtocolCollection

java.lang.Object
org.firebirdsql.gds.ng.wire.ProtocolCollection

All Implemented Interfaces:
  `Iterable<ProtocolDescriptor>`

public final class ProtocolCollection extends Object implements Iterable<ProtocolDescriptor>
Collection of protocols for a connect request.

In general, `getProtocols(String)` should be used with the `enableProtocol` connection property value.

Since:
  3.0
Author:
  Mark Rotteveel

## Method Summary

Modifier and Type
Method
Description
`static ProtocolCollection`
`create(ProtocolDescriptor... descriptors)`
Creates a ProtocolCollection with the specified ProtocolDescriptors.
`static ProtocolCollection`
`getAvailableProtocols()`
Returns the available ProtocolCollection.
`int`
`getProtocolCount()`
`ProtocolDescriptor`
`getProtocolDescriptor(int protocolVersion)`
`static ProtocolCollection`
`getProtocols(String enableProtocol)`
Returns the protocol collection consisting of the supported protocol versions and the additional protocol versions defined by the `enableProtocol` connection string property.
`List<Integer>`
`getProtocolVersions()`
Get a list with the protocol versions in this collection.
`static ProtocolCollection`
`getSupportedProtocols()`
Returns the supported ProtocolCollection.
`Iterator<ProtocolDescriptor>`
`iterator()`
`Stream<ProtocolDescriptor>`
`stream()`

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

## Method Details

### iterator

public Iterator<ProtocolDescriptor> iterator()

Specified by:
  `iterator` in interface `Iterable<ProtocolDescriptor>`

### getProtocolDescriptor

public ProtocolDescriptor getProtocolDescriptor(int protocolVersion)

Parameters:
  `protocolVersion` - Version of the protocol
Returns:
  ProtocolDescriptor for the specified version, or null if the version is not in this ProtocolCollection

### getProtocolCount

public int getProtocolCount()

Returns:
  The protocol count

### getProtocolVersions

public List<Integer> getProtocolVersions()
Get a list with the protocol versions in this collection.

The returned List is created fresh on every call. Changes to the list have no effect on this object.

Returns:
  Protocol version numbers

### stream

public Stream<ProtocolDescriptor> stream()

Returns:
  stream of the protocol descriptors held by this protocol collection
Since:
  6

### create

public static ProtocolCollection create(ProtocolDescriptor... descriptors)
Creates a ProtocolCollection with the specified ProtocolDescriptors.

If `descriptors` contains multiple implementations with the same value for `ProtocolDescriptor.getVersion()`, then the first implementation with the highest value for `ProtocolDescriptor.getWeight()` will be loaded into the collection.

Parameters:
  `descriptors` - Vararg parameter with ProtocolDescriptors
Returns:
  ProtocolCollection

### getSupportedProtocols

public static ProtocolCollection getSupportedProtocols()
Returns the supported ProtocolCollection.

The supported ProtocolCollection is created when this class is loaded by the classloader.

The returned collection is a subset of `getAvailableProtocols()`, retaining only the supported protocol versions.

Returns:
  supported ProtocolCollection
Since:
  6
See Also:
  - `create(ProtocolDescriptor...)`

### getAvailableProtocols

public static ProtocolCollection getAvailableProtocols()
Returns the available ProtocolCollection.

The available ProtocolCollection is created when this class is loaded by the classloader.

This implementation uses the `ServiceLoader` to load the collection based on all `ProtocolDescriptor` implementations found using all the `/META-INF/services/org.firebirdsql.gds.ng.wire.ProtocolDescriptor` in the classpath. If multiple implementations with the same value for `ProtocolDescriptor.getVersion()` are found, then the first implementation with the highest value for `ProtocolDescriptor.getWeight()` will be loaded into the default collection.

Returns:
  available ProtocolCollection
Since:
  6
See Also:
  - `create(ProtocolDescriptor...)`

### getProtocols

public static ProtocolCollection getProtocols(String enableProtocol)
Returns the protocol collection consisting of the supported protocol versions and the additional protocol versions defined by the `enableProtocol` connection string property.

Parameters:
  `enableProtocol` - enable protocol connection property value, see `AttachmentProperties.getEnableProtocol()`.
Returns:
  supported protocols and the available additional protocols listed in `enableProtocol`
Since:
  6