Show / Hide Table of Contents

Class GenericClientManager<TKey, TClient>

A generic client manager.

Inheritance
object
ClientScopeBase<TKey>
GenericClientManager<TKey, TClient>
PhoenixClientManager<TClient>
Implements
ICanConnect<TKey>
IEnumerable<TKey>
IEnumerable
IClientManager<TKey, TClient>
IClientManager<TKey>
ICanDisconnect<TKey>
IHoldsBaggage<TKey>
IDisposable
Inherited Members
ClientScopeBase<TKey>.ConnectAsync(IEnumerable<TKey>, CancellationOptions?)
ClientScopeBase<TKey>.GetAllBaggage<TBaggage>()
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Microsoft.XboxStudios.ClientManager
Assembly: ClientManager.dll
Syntax
public class GenericClientManager<TKey, TClient> : ClientScopeBase<TKey>, ICanConnect<TKey>, IEnumerable<TKey>, IEnumerable, IClientManager<TKey, TClient>, IClientManager<TKey>, ICanDisconnect<TKey>, IHoldsBaggage<TKey>, IDisposable where TKey : notnull where TClient : class
Type Parameters
Name Description
TKey

The key object that contains the TClient.

TClient

The client type.

Remarks

Initializes a new instance of the GenericClientManager<TKey, TClient> class.

Constructors

View Source

GenericClientManager(IClientManagerAdapter<TKey, TClient>, IEnumerable<IBaggageFactory<TClient>>?)

A generic client manager.

Declaration
public GenericClientManager(IClientManagerAdapter<TKey, TClient> adapter, IEnumerable<IBaggageFactory<TClient>>? baggageFactories = null)
Parameters
Type Name Description
IClientManagerAdapter<TKey, TClient> adapter

The client manager adapter to manage connections.

IEnumerable<IBaggageFactory<TClient>> baggageFactories

An enumeration of factories to create baggages and attach them to clients.

Remarks

Initializes a new instance of the GenericClientManager<TKey, TClient> class.

Methods

View Source

ClientAndBaggageFor(TKey)

Gets a client and its baggage, or creates it if possible.

Declaration
protected (ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object>? Baggage)? ClientAndBaggageFor(TKey key)
Parameters
Type Name Description
TKey key

The client key.

Returns
Type Description
(ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object> Baggage)?

The client and baggage if it existed or could be created.

View Source

ClientFor(TKey)

Gets a client, or creates it if possible.

Declaration
protected TClient? ClientFor(TKey key)
Parameters
Type Name Description
TKey key

The client key.

Returns
Type Description
TClient

The client if it existed or could be created.

View Source

ConnectAsync(TKey, CancellationOptions?)

Connects a client to a game instance.

Declaration
public override ValueTask<bool> ConnectAsync(TKey key, CancellationOptions? co = null)
Parameters
Type Name Description
TKey key

The TKey to use to fetch a client and attempt a connection.

CancellationOptions? co

The Microsoft.XboxStudios.Bifrost.CancellationOptions.

Returns
Type Description
ValueTask<bool>

A value indicating whether connection was successful or not.

Overrides
ClientScopeBase<TKey>.ConnectAsync(TKey, CancellationOptions?)
Remarks

This method reuses the same client to connect if it got disconnected externally.

View Source

ConnectionChanged((TKey Key, TClient Client))

Sends an event that connection has changed.

Declaration
protected void ConnectionChanged((TKey Key, TClient Client) eventArgs)
Parameters
Type Name Description
(TKey Key, TClient Client) eventArgs

The event args.

View Source

CreateScope()

Creates a connection scope to manage reservations.

Declaration
public IConnectionScope<TKey, TClient> CreateScope()
Returns
Type Description
IConnectionScope<TKey, TClient>

A connection scope.

View Source

Disconnect(IEnumerable<TKey>)

Disconnect clients from a game instance synchronously.

Declaration
public void Disconnect(IEnumerable<TKey> keys)
Parameters
Type Name Description
IEnumerable<TKey> keys

The keys to use to fetch clients and attempt disconnections synchronously.

View Source

Disconnect(TKey)

Disconnects a client from a game instance synchronously.

Declaration
public void Disconnect(TKey key)
Parameters
Type Name Description
TKey key

The TKey to use to fetch a client and attempt a disconnection.

View Source

DisconnectAsync(IEnumerable<TKey>)

Disconnect clients from a game instance asynchronously.

Declaration
public ValueTask DisconnectAsync(IEnumerable<TKey> keys)
Parameters
Type Name Description
IEnumerable<TKey> keys

The keys to use to fetch clients and attempt disconnections asynchronously.

Returns
Type Description
ValueTask

A Task that represents the asynchronous operation.

View Source

DisconnectAsync(TKey)

Disconnects a client from a game instance asynchronously.

Declaration
public ValueTask DisconnectAsync(TKey key)
Parameters
Type Name Description
TKey key

The TKey to use to fetch a client and attempt a disconnection.

Returns
Type Description
ValueTask

A Task that represents the asynchronous operation.

View Source

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public virtual void Dispose()
View Source

ExistingClientFor(TKey)

Gets an existing client.

Declaration
protected TClient? ExistingClientFor(TKey key)
Parameters
Type Name Description
TKey key

The client key.

Returns
Type Description
TClient

The client if it existed.

View Source

GetBaggageFactory<T>()

Gets a registered baggage factory.

Declaration
protected IBaggageFactory<TClient> GetBaggageFactory<T>()
Returns
Type Description
IBaggageFactory<TClient>

The factory.

Type Parameters
Name Description
T

The baggage type.

Exceptions
Type Condition
MissingBaggageFactoryException

If no such factory was registered.

View Source

GetBaggage<TBaggage>(TKey)

Gets the baggage associated with a key.

Declaration
public override TBaggage GetBaggage<TBaggage>(TKey key)
Parameters
Type Name Description
TKey key

The TKey to use to fetch a baggage.

Returns
Type Description
TBaggage

The baggage or null if no connection exists.

Type Parameters
Name Description
TBaggage

The type of the baggage.

Overrides
ClientScopeBase<TKey>.GetBaggage<TBaggage>(TKey)
Exceptions
Type Condition
BaggageNullException

Thrown if the registered baggage factory returned null.

MissingBaggageFactoryException

Thrown if the baggage factory of the requested baggage is not registered.

View Source

GetEnumerator()

Returns an enumerator that iterates through the collection.

Declaration
public override IEnumerator<TKey> GetEnumerator()
Returns
Type Description
IEnumerator<TKey>

An enumerator that can be used to iterate through the collection.

Overrides
ClientScopeBase<TKey>.GetEnumerator()
View Source

NeedsToConnect(TClient)

Checks whether a client needs to connect or not.

Declaration
public bool NeedsToConnect(TClient client)
Parameters
Type Name Description
TClient client

The client to check for.

Returns
Type Description
bool

True if client needs to connect. False otherwise.

View Source

Reserve(TKey)

Reserves the client for a specific TKey. Callers are responsible to dispose of the reserved client.

Declaration
public Reserved<TClient>? Reserve(TKey key)
Parameters
Type Name Description
TKey key

The key to use.

Returns
Type Description
Reserved<TClient>

The client assosciated with the requested key.

View Source

ReserveAndConnectAsync(TKey, CancellationOptions?)

Reserves the client for a specific TKey and establishes connection if necessary. Callers are responsible to dispose of the reserved client.

Declaration
public ValueTask<Reserved<TClient>?> ReserveAndConnectAsync(TKey key, CancellationOptions? co = null)
Parameters
Type Name Description
TKey key

The key to use.

CancellationOptions? co

The Microsoft.XboxStudios.Bifrost.CancellationOptions.

Returns
Type Description
ValueTask<Reserved<TClient>>

The client assosciated with the requested key. Null if connection failed.

View Source

TryGetClientAndBaggage(TKey, out (ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object>? Baggage))

Gets an existing client and its baggage.

Declaration
protected bool TryGetClientAndBaggage(TKey key, out (ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object>? Baggage) clientAndBaggage)
Parameters
Type Name Description
TKey key

The client key.

(ISharedRef<TClient, Reserved<TClient>> Connection, ConcurrentDictionary<Type, object> Baggage) clientAndBaggage

Stores the client and baggage, if it exists.

Returns
Type Description
bool

True if the client existed.

Events

View Source

OnConnected

Event triggered when client has connected.

Declaration
public event EventHandler<TClient>? OnConnected
Event Type
Type Description
EventHandler<TClient>
View Source

OnConnecting

Event triggered when client is connecting.

Declaration
public event EventHandler<TClient>? OnConnecting
Event Type
Type Description
EventHandler<TClient>
View Source

OnConnectionChanged

Event triggered when connection changes on a client.

Declaration
public event EventHandler<(TKey Key, TClient Client)>? OnConnectionChanged
Event Type
Type Description
EventHandler<(TKey Key, TClient Client)>
View Source

OnDisconnected

Event triggered when client has disconnected.

Declaration
public event EventHandler<TClient>? OnDisconnected
Event Type
Type Description
EventHandler<TClient>
View Source

OnDisconnecting

Event triggered when client is disconnecting.

Declaration
public event EventHandler<TClient>? OnDisconnecting
Event Type
Type Description
EventHandler<TClient>

Implements

ICanConnect<TKey>
IEnumerable<T>
IEnumerable
IClientManager<TKey, TClient>
IClientManager<TKey>
ICanDisconnect<TKey>
IHoldsBaggage<TKey>
IDisposable
  • View Source
In this article
Back to top Generated by DocFX