public class RemoteProcedureCallServiceProvider extends AbstractServiceProvider
makeRequest
methods to send method requests to the Interactive
service and interpret the reply. However in the event a developer would like to craft their own
MethodPacket
(e.g., to call a method that does not yet exist in the
InteractiveMethod
enum), send
methods are available to accomplish this goal.InteractiveMethod
,
MethodPacket
gameClient
Constructor and Description |
---|
RemoteProcedureCallServiceProvider(GameClient gameClient)
Initializes a new
RemoteProcedureCallServiceProvider . |
Modifier and Type | Method and Description |
---|---|
int |
claimNextPacketId()
Claims and returns the next available packet id.
|
int |
getSequenceNumber()
Returns the last seen sequence number.
|
CompletableFuture<Boolean> |
makeRequest(InteractiveMethod method,
com.google.gson.JsonElement params)
Prepares and sends a request to the Interactive service.
|
<T> CompletableFuture<T> |
makeRequest(InteractiveMethod method,
com.google.gson.JsonElement params,
String memberName,
Type type)
Prepares and sends a request to the Interactive service, returning the parsed reply.
|
<T> CompletableFuture<T> |
makeRequest(InteractiveMethod method,
com.google.gson.JsonElement params,
Type type)
Prepares and sends a request to the Interactive service, returning the parsed reply.
|
void |
makeRequestNoReply(InteractiveMethod method,
com.google.gson.JsonElement params)
Prepares and sends a request to the Interactive service, expecting no reply.
|
Map<MethodPacket,CompletableFuture<ReplyPacket>> |
send(Collection<MethodPacket> requestPackets)
Prepares and sends one or many requests to the Interactive service, returning a list of replies that are in
the same order as the input collection.
|
Map<MethodPacket,CompletableFuture<ReplyPacket>> |
send(Collection<MethodPacket> requestPackets,
long duration,
TimeUnit timeUnit)
Prepares and sends one or many requests to the Interactive service, returning a list of replies that are in
the same order as the input collection.
|
CompletableFuture<ReplyPacket> |
send(MethodPacket requestPacket)
Sends a request to the Interactive service, returning the reply.
|
CompletableFuture<ReplyPacket> |
send(MethodPacket requestPacket,
long duration,
TimeUnit timeUnit)
Prepares and sends a request to the Interactive service, returning the parsed reply.
|
equals, hashCode
public RemoteProcedureCallServiceProvider(GameClient gameClient)
RemoteProcedureCallServiceProvider
.gameClient
- The GameClient
that owns this service providerpublic void makeRequestNoReply(InteractiveMethod method, com.google.gson.JsonElement params)
method
- An InteractiveMethod
for the requestparams
- Json encoded map of parameters for the requestMethodPacket
public CompletableFuture<Boolean> makeRequest(InteractiveMethod method, com.google.gson.JsonElement params)
Prepares and sends a request to the Interactive service.
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
.
method
- An InteractiveMethod
for the requestparams
- Json encoded map of parameters for the requestCompletableFuture
that when complete returns true
for this request
if it completes with no errorsMethodPacket
public <T> CompletableFuture<T> makeRequest(InteractiveMethod method, com.google.gson.JsonElement params, Type type)
Prepares and sends a request to the Interactive service, returning the parsed reply.
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
.
T
- Class of object to be parsed from the replymethod
- An InteractiveMethod
for the requestparams
- Json encoded map of parameters for the requesttype
- Type of object to be parsed from replyCompletableFuture
that when complete returns a T
object parsed from the
ReplyPacket
sent back from the Interactive service for this request if it completes with
no errorsMethodPacket
public <T> CompletableFuture<T> makeRequest(InteractiveMethod method, com.google.gson.JsonElement params, String memberName, Type type)
Prepares and sends a request to the Interactive service, returning the parsed reply.
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
.
T
- Class of object to be parsed from the replymethod
- An InteractiveMethod
for the requestparams
- Json encoded map of parameters for the requestmemberName
- Member name of parameter to be parsed from replytype
- Type of object to be parsed from replyCompletableFuture
that when complete returns a T
object parsed from the
ReplyPacket
sent back from the Interactive service for this request if it completes with
no errorsMethodPacket
public CompletableFuture<ReplyPacket> send(MethodPacket requestPacket)
InteractiveRequestNoReplyException
exception.requestPacket
- A MethodPacket
representing the request being sentCompletableFuture
that when complete returns the ReplyPacket
sent back from
the Interactive service for the provided method requestMethodPacket
public CompletableFuture<ReplyPacket> send(MethodPacket requestPacket, long duration, TimeUnit timeUnit)
Prepares and sends a request to the Interactive service, returning the parsed reply.
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
.
requestPacket
- A MethodPacket
representing the request being sentduration
- Duration before request is considered timed out (no reply)timeUnit
- A TimeUnit
indicating the units to be used in the timeoutCompletableFuture
that when complete returns the ReplyPacket
sent back from
the Interactive service for the provided method requestMethodPacket
public Map<MethodPacket,CompletableFuture<ReplyPacket>> send(Collection<MethodPacket> requestPackets)
Prepares and sends one or many requests to the Interactive service, returning a list of replies that are in the same order as the input collection.
The result of each reply may include checked exceptions that were thrown in the event that there was a problem with the request to 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 list.
requestPackets
- A Collection
of MethodPacket
representing the requests being sentList
of CompletableFutures
that when complete return the
ReplyPacket
for the corresponding input MethodPacket
. This list is in the same
order as the input collection.public Map<MethodPacket,CompletableFuture<ReplyPacket>> send(Collection<MethodPacket> requestPackets, long duration, TimeUnit timeUnit)
Prepares and sends one or many requests to the Interactive service, returning a list of replies that are in the same order as the input collection.
The result of each reply may include checked exceptions that were thrown in the event that there was a problem with the request to 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 list.
requestPackets
- A Collection
of MethodPacket
representing the requests being sentduration
- Duration before request is considered timed out (no reply)timeUnit
- A TimeUnit
indicating the units to be used in the timeoutList
of CompletableFutures
that when complete return the
ReplyPacket
for the corresponding input MethodPacket
. This list is in the same
order as the input collection.public int claimNextPacketId()
InteractiveWebSocketClient.claimNextPacketId()
public int getSequenceNumber()
InteractiveWebSocketClient.getLastSequenceNumber()
Copyright © 2018. All rights reserved.