GrpcAgonesSdk

class GrpcAgonesSdk(val host: String = AGONES_SDK_HOST, val port: Int = AGONES_SDK_PORT) : AgonesSdk(source)

A GrpcAgonesSdk represents the gRPC implementation of the Agones SDK. The implementation is based on the official Protobufs released with Agones. Each platform only needs one implementation of the Agones SDK, but does not have to worry about selecting the best implementation. Instead, the factory method specifies the implementation. All implementations fully comply with the Agones specification.

When creating an instance of this implementation, the corresponding network channel is dynamically assembled for this purpose. The port is obtained through the environment variable AGONES_SDK_PORT_ENV_KEY, if any value has been set for this key. The corresponding stubs for coroutine-based communication with the interface are instantiated for the channel to the attached sidecar. No action is taken by creating this instance, and communication with the external interface is not initiated.

Parameters

host

The host, under which the gRPC server of the sidecar SDK can be reached and that will therefore be used to establish the connection.

port

The port, under which the gRPC server of the sidecar SDK can be reached and that will therefore be used to establish the connection.

Constructors

Link copied to clipboard
constructor(host: String = AGONES_SDK_HOST, port: Int = AGONES_SDK_PORT)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class GrpcAlpha(channel: Channel) : AgonesSdk.Alpha

The GrpcAlpha class provides gRPC-based implementations for all interfaces of the Alpha-Channel of the Agones SDK. The implementation encapsulates the communication the external interface of the SDK and manages the corresponding stubs. This sub SDK operates on the same channel as the primary SDK and therefore shares its connections and related resources as well as its state.

Link copied to clipboard
class GrpcBeta(channel: Channel) : AgonesSdk.Beta

The GrpcBeta class provides gRPC-based implementations for all interfaces of the Beta-Channel of the Agones SDK. The implementation encapsulates the communication the external interface of the SDK and manages the corresponding stubs. This sub SDK operates on the same channel as the primary SDK and therefore shares its connections and related resources as well as its state.

Properties

Link copied to clipboard

The host of the external interface of the sidecar SDK, that will be used to establish the connection.

Link copied to clipboard
val port: Int

The port of the sidecar SDK's external interface that will be used to establish the connection.

Functions

Link copied to clipboard
open suspend override fun allocate()

Notifies Agones that this instance has been allocated/claimed and is currently not available for any other GameServerAllocations. It is preferred, that instances are assigned through GameServerAllocations. However, in cases where this is not possible (e.g., when working with external systems), this interface can be used to manually assign the instance.

Link copied to clipboard
open override fun alpha(): AgonesSdk.Alpha

Returns the encapsulated Alpha-Channel of the Agones SDK. This sub channel allows the use of the less tested and isolated interfaces within the Agones SDK. The retrieval of the channel does not trigger any communication with the SDK. The interfaces of the Alpha-Channel were not yet extensively tested and are deactivated by default. The endpoints can be freely used, but some bugs are to be expected.

Link copied to clipboard
open suspend override fun annotation(key: String, value: String)

Adds a new annotation with a specific key and value to the GameServer resource of this instance. The key always gets a METADATA_KEY_PREFIX assigned automatically to ensure better isolation and security. Therefore, the keys cannot collide with normal Kubernetes annotations. This allows further metadata to be published about this instance, which can be read elsewhere, and it is possible to filter the GameServer instances more precisely using the key-value pair.

Link copied to clipboard
open override fun beta(): AgonesSdk.Beta

Returns the encapsulated Beta of the Agones SDK. This sub channel allows the use of the less tested and isolated interfaces within the Agones SDK. The retrieval of the channel does not trigger any communication with the SDK. The interfaces of the Beta were already extensively tested and are activated by default. The endpoints can be freely used and only very few bugs are expected.

Link copied to clipboard
open override fun close()

Closes all open resources that are associated with the Agones SDK. After this operation, this instance of the Agones SDK may no longer be used, as all connections are no longer usable. This method can be called any number of times without changing its behavior. It is guaranteed that after this call, all open connections and allocated resources will be closed or released. Although not all implementations have such resources, the method should still always be called (for example, within a Try-With_Resources block or a use method) to cleanly terminate resource usage.

Link copied to clipboard
open suspend override fun gameServer(): Sdk.GameServer

Gets a new, immutable Snapshot of the GameServer resource of this instance. The data includes, among meta information, the current state, the allocation/assignment and the configuration as present in the Kubernetes resource. This snapshot cannot be changed, and modifications to the state have to happen through the other interfaces of the Agones SDK. The returned value is guaranteed to match the value set within the SDK, even if the value was not yet synchronized with the Kubernetes resource.

Link copied to clipboard
open suspend override fun health(stream: Flow<Unit>)

Notifies Agones that this instance is still running and healthy. This notification must be sent periodically, otherwise this instance will be marked as Unhealthy and eventually removed. The interval is configured in the Agones GameServer resource and tolerates short delays. These health checks are independent of the normal application lifecycle and should be sent from the beginning. They can be sent at an arbitrary interval.

Link copied to clipboard
open suspend override fun label(key: String, value: String)

Adds a new label with a specific key and value to the GameServer resource of this instance. The key always gets a METADATA_KEY_PREFIX assigned automatically to ensure better isolation and security. Therefore, the keys cannot collide with normal Kubernetes labels. This allows further metadata to be published about this instance, which can be read elsewhere, and it is possible to filter the GameServer instances more precisely using the key-value pair.

Link copied to clipboard
open suspend override fun ready()

Notifies Agones that this instance is now ready to accept player connections. Once this state is set, the associated GameServer resource will be set to Ready, and the address and ports for accessing this instance will be populated and published. Before calling this method, the initialization of this instance must be fully completed.

Link copied to clipboard
open suspend override fun reserve(seconds: Long)

Notifies Agones to set this instance to Reserved state for a specific duration. This prevents the instance from being deleted during that time period and does not trigger any scaling within the fleet. After the duration passed, the instance will be set back to the Ready state. While the instance is in the Reserved state, it cannot be deleted by fleet updates or scaling, and it cannot be assigned with a GameServerAllocation. Invoking any state changing methods like allocate, ready or shutdown deactivates the scheduled reset to Ready after the duration expires.

Link copied to clipboard
open suspend override fun shutdown()

Notified Agones to shut down this instance and release any allocations for it in the process. The state will immediately be set to Shutdown and the pod of this instance will be stopped and deleted. The actual instance shutdown is triggered only through this method call, and the instance will be shut down by the pod triggering a SIGTERM signal during termination.

Link copied to clipboard
open override fun watchGameServer(): Flow<Sdk.GameServer>

Subscribes to changes of the GameServer resource of this instance. The Flow receives a new item, whenever a change is made to the resource. For changes triggered by this SDK as well as for external changes applied directly to the GameServer resource within Kubernetes. The items always contain all properties of the updated GameServer resource and not just the updated fields.