public class GameClient extends Object
A GameClient
is used to connect to a Interactive integration that is hosted on the Interactive service.
A client can only connect to the integration that was specified when the client was created.
Once connected a client has the ability to query information on the integration from the Interactive service, as well as manipulate resources in the integration by making requests to the Interactive service.
Modifier and Type | Field and Description |
---|---|
static Class<ControlServiceProvider> |
CONTROL_SERVICE_PROVIDER |
static Class<GroupServiceProvider> |
GROUP_SERVICE_PROVIDER |
static com.google.gson.Gson |
GSON
Gson singleton used for serialization/deserialization. |
static Class<ParticipantServiceProvider> |
PARTICIPANT_SERVICE_PROVIDER |
static Class<RemoteProcedureCallServiceProvider> |
RPC_SERVICE_PROVIDER
Collection of service providers
|
static Class<SceneServiceProvider> |
SCENE_SERVICE_PROVIDER |
static Class<TransactionServiceProvider> |
TRANSACTION_SERVICE_PROVIDER |
Constructor and Description |
---|
GameClient(Number projectVersionId)
Initializes a new
GameClient . |
GameClient(Number projectVersionId,
boolean useStateManager)
Initializes a new
GameClient . |
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Boolean> |
connect(String token)
Connects the game client to it's associated Interactive integration on the Interactive service, using either an
OAuth Bearer token or an xtoken to authenticate itself with the Interactive service.
|
CompletableFuture<Boolean> |
connect(String authToken,
String shareCode)
Connects the game client to it's associated Interactive integration on the Interactive service, using either an
OAuth Bearer token or an xtoken to authenticate itself with the Interactive service and the appropriate share
code for the integration.
|
CompletableFuture<Boolean> |
connectTo(String authToken,
String shareCode,
URI interactiveHost)
Connects the game client to it's associated Interactive integration on a specific Interactive service host,
using either an OAuth Bearer token or a xtoken to authenticate itself with the Interactive service and the
appropriate share code for the integration.
|
CompletableFuture<Boolean> |
connectTo(String authToken,
URI interactiveHost)
Connects the game client to it's associated Interactive integration on a specific Interactive service host,
using either an OAuth Bearer token or a xtoken to authenticate itself with the Interactive service.
|
CompletableFuture<Void> |
disconnect()
Disconnects the client from the Interactive service.
|
com.google.common.eventbus.EventBus |
getEventBus()
Returns the
EventBus associated with the client. |
ScheduledExecutorService |
getExecutorService()
Returns the thread executor service used for creating
CompletableFutures . |
CompletableFuture<InteractiveMemoryStatistic> |
getMemoryStats()
Retrieves the current memory usage for the Interactive integration this client is connected to on the
Interactive service.
|
Number |
getProjectVersionId()
Returns the project version ID for the Interactive integration the client connects to.
|
ServiceManager<AbstractServiceProvider> |
getServiceManager()
Returns the
ServiceManager associated with the client. |
StateManager |
getStateManager()
Gets the StateManager for this game client.
|
CompletableFuture<Map<InteractiveMethod,ThrottleState>> |
getThrottleState()
Retrieves statistics on the state of throttling rules set up in
InteractiveMethod.SET_BANDWIDTH_THROTTLE method requests. |
CompletableFuture<Long> |
getTime()
Retrieves the current server time from the Interactive service, given as a milliseconds UTC unix timestamp.
|
InteractiveWebSocketClient |
getWebSocketClient()
Returns the web socket client that this game client uses to communicate with the Interactive service.
|
boolean |
isConnected()
Returns
true if this client is currently connected to the Interactive service,
false otherwise. |
void |
ready(boolean isReady)
Notifies the Interactive service whether or not this client is ready to have clients connect and start
interacting.
|
CompletableFuture<Boolean> |
setBandwidthThrottle(Map<InteractiveMethod,BandwidthThrottle> throttleMap)
Sets up throttling for certain server-to-client method calls, such as
InteractiveMethod.GIVE_INPUT ,
which could become problematic in very high-traffic scenarios. |
CompletableFuture<CompressionScheme> |
setCompression(Collection<String> schemes)
Changes the compression algorithm the client uses to encode/decode messages to/from the Interactive
service.
|
CompletableFuture<CompressionScheme> |
setCompression(CompressionScheme... schemes)
Changes the compression algorithm the client uses to encode/decode messages to/from the Interactive
service.
|
CompletableFuture<CompressionScheme> |
setCompression(String... schemes)
Changes the compression algorithm the client uses to encode/decode messages to/from the Interactive
service.
|
<T extends AbstractServiceProvider> |
using(Class<T> clazz)
Retrieves the service provider specified by the provided class from the service manager.
|
public static final com.google.gson.Gson GSON
Gson
singleton used for serialization/deserialization.public static final Class<RemoteProcedureCallServiceProvider> RPC_SERVICE_PROVIDER
public static final Class<ParticipantServiceProvider> PARTICIPANT_SERVICE_PROVIDER
public static final Class<GroupServiceProvider> GROUP_SERVICE_PROVIDER
public static final Class<SceneServiceProvider> SCENE_SERVICE_PROVIDER
public static final Class<ControlServiceProvider> CONTROL_SERVICE_PROVIDER
public static final Class<TransactionServiceProvider> TRANSACTION_SERVICE_PROVIDER
public GameClient(Number projectVersionId)
GameClient
.projectVersionId
- The project version ID for the Interactive integration the client will usepublic GameClient(Number projectVersionId, boolean useStateManager)
GameClient
.projectVersionId
- The project version ID for the Interactive integration the client will useuseStateManager
- Whether or not to use built in caching for the game clientpublic Number getProjectVersionId()
public ServiceManager<AbstractServiceProvider> getServiceManager()
ServiceManager
associated with the client.ServiceManager
associated with the clientpublic StateManager getStateManager()
public com.google.common.eventbus.EventBus getEventBus()
EventBus
associated with the client.EventBus
associated with the clientpublic InteractiveWebSocketClient getWebSocketClient()
public ScheduledExecutorService getExecutorService()
CompletableFutures
.CompletableFutures
.public <T extends AbstractServiceProvider> T using(Class<T> clazz)
null
is returned.T
- Type of service provider to be usedclazz
- Class of service provider to be usednull
is returned.public boolean isConnected()
true
if this client is currently connected to the Interactive service,
false
otherwise.true
if this client is currently connected to the Interactive service,
false
otherwisepublic CompletableFuture<Boolean> connect(String token)
token
- Authentication tokenCompletableFuture
that completes when the connection attempt is finishedpublic CompletableFuture<Boolean> connect(String authToken, String shareCode)
interactive/hosts
endpoint. If no connection succeeds, then the future returns an
InteractiveConnectionException
.authToken
- Authentication tokenshareCode
- The share code provided by the author of the Interactive integrationCompletableFuture
that completes when the connection attempt is finishedpublic CompletableFuture<Boolean> connectTo(String authToken, URI interactiveHost)
authToken
- Authentication tokeninteractiveHost
- URI
for an Interactive service hostCompletableFuture
that completes when the connection attempt is finishedpublic CompletableFuture<Boolean> connectTo(String authToken, String shareCode, URI interactiveHost)
authToken
- Authentication tokenshareCode
- The share code provided by the author of the Interactive integrationinteractiveHost
- URI
for an Interactive service hostCompletableFuture
that completes when the connection attempt is finishedpublic CompletableFuture<Void> disconnect()
CompletableFuture
that completes when the client has been disconnected from the
Interactive servicepublic void ready(boolean isReady)
Notifies the Interactive service whether or not this client is ready to have clients connect and start interacting.
The parameters of the request (isReady: true
or isReady: false
) determine whether
or not the Interactive integration this client is connected to is ready to have clients connect and start
interacting or not, respectively.
isReady
- The value to pass along in the ready
method callpublic CompletableFuture<CompressionScheme> setCompression(CompressionScheme... schemes)
Changes the compression algorithm the client uses to encode/decode messages to/from the Interactive service.
Developers supply a collection of preferred schemes in order of preference, from greatest to least preference, from which the Interactive service will select a preferred common one. All subsequent requests and replies will be sent in using the new compression scheme.
If no preferred common scheme is found, the Interactive server will fall back to the
plain text
scheme.
schemes
- An array of preferred CompressionSchemes
in order of preference, from greatest to
least preferenceCompressionScheme
that the client is to use to communicate with
the Interactive serviceCompressionScheme
public CompletableFuture<CompressionScheme> setCompression(String... schemes)
Changes the compression algorithm the client uses to encode/decode messages to/from the Interactive service.
Developers supply a collection of preferred schemes in order of preference, from greatest to least preference, from which the Interactive service will select a preferred common one. All subsequent requests and replies will be sent in using the new compression scheme.
If no preferred common scheme is found, the Interactive server will fall back to the
plain text
scheme.
schemes
- An array of preferred compression schemes in order of preference, from greatest to
least preferenceCompressionScheme
that the client is to use to communicate with
the Interactive serviceCompressionScheme
public CompletableFuture<CompressionScheme> setCompression(Collection<String> schemes)
Changes the compression algorithm the client uses to encode/decode messages to/from the Interactive service.
Developers supply a collection of preferred schemes in order of preference, from greatest to least preference, from which the Interactive service will select a preferred common one. All subsequent requests and replies will be sent in using the new compression scheme.
If no preferred common scheme is found, the Interactive server will fall back to the
plain text
scheme.
schemes
- An Collection
of preferred CompressionSchemes
in order of preference, from
greatest to least preferenceCompressionScheme
that the client is to use to communicate with
the Interactive serviceCompressionScheme
public CompletableFuture<Long> getTime()
Retrieves the current server time from the Interactive service, given as a milliseconds UTC unix timestamp.
The result of the CompletableFuture
may include checked exceptions that were thrown in the event
that there was a problem with the reply from the Interactive service. Specifically, two types of checked
exceptions may be thrown:
InteractiveRequestNoReplyException
may be thrown if no reply is received from the Interactive
service.InteractiveReplyWithErrorException
may be thrown if the reply received from the Interactive service
contains an InteractiveError
.Considerations should be made for these possibilities when interpreting the results of the returned
CompletableFuture
.
CompletableFuture
that when complete returns the Interactive service's current server
time, given as a UTC unix timestamp (in milliseconds)public CompletableFuture<InteractiveMemoryStatistic> getMemoryStats()
Retrieves the current memory usage for the Interactive integration this client is connected to on the Interactive service. The memory usage returned is a dump of information regarding current memory allocations, as well as a breakdown of how much memory is allocated where. This information is provided for debugging purposes.
The result of the CompletableFuture
may include checked exceptions that were thrown in the event
that there was a problem with the reply from the Interactive service. Specifically, two types of checked
exceptions may be thrown:
InteractiveRequestNoReplyException
may be thrown if no reply is received from the Interactive
service.InteractiveReplyWithErrorException
may be thrown if the reply received from the Interactive service
contains an InteractiveError
.Considerations should be made for these possibilities when interpreting the results of the returned
CompletableFuture
.
CompletableFuture
that when complete returns a InteractiveMemoryStatistic
representing the current memory usage of the Interactive integration the client is connected toInteractiveMemoryStatistic
public CompletableFuture<Map<InteractiveMethod,ThrottleState>> getThrottleState()
Retrieves statistics on the state of throttling rules set up in
InteractiveMethod.SET_BANDWIDTH_THROTTLE
method requests. It returns the number of sent packets (ones
inserted into the bucket) and the number of rejected packets for each method that has a throttle set.
The result of the CompletableFuture
may include checked exceptions that were thrown in the event
that there was a problem with the reply from the Interactive service. Specifically, two types of checked
exceptions may be thrown:
InteractiveRequestNoReplyException
may be thrown if no reply is received from the Interactive
service.InteractiveReplyWithErrorException
may be thrown if the reply received from the Interactive service
contains an InteractiveError
.Considerations should be made for these possibilities when interpreting the results of the returned
CompletableFuture
.
CompletableFuture
that when complete returns a Map
of
InteractiveMethods
and their associated ThrottleState
BandwidthThrottle
,
InteractiveMethod
,
ThrottleState
public CompletableFuture<Boolean> setBandwidthThrottle(Map<InteractiveMethod,BandwidthThrottle> throttleMap)
Sets up throttling for certain server-to-client method calls, such as InteractiveMethod.GIVE_INPUT
,
which could become problematic in very high-traffic scenarios.
The Interactive service implements a leaky bucket algorithm; the client specifies the total bucket capacity in bytes and its drain rate in bytes per second. The client supplies a map of method names and their associated throttle rules. Throttling previously enabled on a method can be disabled by setting it to null.
The result of the CompletableFuture
may include checked exceptions that were thrown in the event
that there was a problem with the reply from the Interactive service. Specifically, two types of checked
exceptions may be thrown:
InteractiveRequestNoReplyException
may be thrown if no reply is received from the Interactive
service.InteractiveReplyWithErrorException
may be thrown if the reply received from the Interactive service
contains an InteractiveError
.Considerations should be made for these possibilities when interpreting the results of the returned
CompletableFuture
.
throttleMap
- A Map
of InteractiveMethods
and their associated
BandwidthThrottle
CompletableFuture
that when complete returns true
if the
setBandwidthThrottle
method call completes with no
errorsBandwidthThrottle
,
InteractiveMethod
Copyright © 2018. All rights reserved.