public interface NetcodeClient
MessageHandler is defined it gets invoked. If no such handler is
specified the messages enter the message queue for synchronous reception
using receive() or tryReceive().
The client can be switched between synchronous and asynchronous operation at
any time. When switching from synchronous to asynchronous mode all the
messages from the synchronous message queue are pushed into the message
handler. During this phase it is possible that messages arrive out of order
or multiple concurrent invocations of the handler exit. It is therefore
recommended to avoid frequent mode switching. Threads blocked in
receive() during the transition to asynchronous operation remain
blocked indefinitely.
Channel events can only be processed asynchronously. For this a
ChannelEventHandler must be specified.NetcodeClientFactory| Modifier and Type | Method and Description |
|---|---|
java.io.Serializable |
ask(java.lang.String userId,
java.io.Serializable data)
Sends a question to another client and awaits its response.
|
void |
disconnect()
Disconnect and terminate the client.
|
ChannelConfiguration |
getChannelConfiguration()
Get the configuration of the connected channel.
|
ChannelInformation |
getChannelInformation()
Requests channel information for the current channel from the server.
|
ChannelEventHandler |
getEventHandler()
Returns the current event handler or
null if none is currently
set. |
MessageHandler |
getMessageHandler()
Returns the current message handler or
null if none is currently
set. |
ChannelInformation[] |
getPublicChannels()
Requests a list of all public channels from the server.
|
ClientQuestionHandler |
getQuestionHandler()
Returns the current question handler or
null if none is currently
set. |
long |
getTimeout()
returns the current timeout value in milliseconds
|
java.lang.String |
getUserId()
Get the userId of this client.
|
java.lang.String[] |
getUsers()
Get a list of all members of the channel.
|
Message |
receive()
Receive the next message synchronously and wait if no message is ready.
|
void |
send(java.io.Serializable payload)
Send the given object to all members of the channel
|
void |
sendPrivately(java.lang.String userId,
java.io.Serializable payload)
Send the given object to the member of the channel with the given userId.
|
void |
setEventHandler(ChannelEventHandler handler)
Replaces the event handler.
|
void |
setMessageHandler(MessageHandler handler)
Replaces the message handler.
|
void |
setQuestionHandler(ClientQuestionHandler handler)
Replaces the question handler.
|
void |
setTimeout(long millis)
Sets a new timeout for server commands and client questions.
|
Message |
tryReceive()
Receive the next message synchronously if it exists.
|
void disconnect()
throws java.io.IOException
java.io.IOException - an i/o exception occurred while disconnecting the client.void send(java.io.Serializable payload)
void sendPrivately(java.lang.String userId,
java.io.Serializable payload)
java.lang.NullPointerException - the userId is nulljava.lang.IllegalArgumentException - the userId is not knownjava.lang.String getUserId()
ChannelConfiguration getChannelConfiguration()
java.lang.String[] getUsers()
MessageHandler getMessageHandler()
null if none is currently
set.void setMessageHandler(MessageHandler handler)
null the
client switches into synchronous operation and messages can be accessed
using receive() or tryReceive().handler - the new message handler. may be null.ChannelEventHandler getEventHandler()
null if none is currently
set.void setEventHandler(ChannelEventHandler handler)
ClientQuestionHandler getQuestionHandler()
null if none is currently
set.void setQuestionHandler(ClientQuestionHandler handler)
null client questions will always be responded to with an
UnsupportedOperationException.ask(String, Serializable)Message receive() throws java.lang.InterruptedException
MessageHandler is present
the call will block indefinitely.java.lang.InterruptedException - the calling thread has been interrupted before a message
became availableMessage tryReceive()
null.receive()long getTimeout()
void setTimeout(long millis)
0 the timeout will be disabled.millis - the new timeout in millisecondsjava.lang.IllegalArgumentException - the timeout value is negativejava.io.Serializable ask(java.lang.String userId,
java.io.Serializable data)
throws java.lang.InterruptedException,
java.util.concurrent.TimeoutException
ClientQuestionHandler.userId - the client to send the question todata - the question payloadjava.lang.InterruptedException - the calling thread was interrupted before a response has been
received.java.util.concurrent.TimeoutException - the timeout has expired before a response has been received.java.lang.IllegalArgumentException - the provided userId is unknownjava.lang.NullPointerException - the provided userId is null.ClientQuestionHandler,
setQuestionHandler(ClientQuestionHandler),
setTimeout(long)ChannelInformation getChannelInformation() throws java.lang.InterruptedException, ConnectionException, java.util.concurrent.TimeoutException
UnsupportedFeatureException - the server does not support server commandsjava.lang.InterruptedException - the thread has been interrupted while waiting on the datajava.util.concurrent.TimeoutException - the client has not received a response before the timeout has
expiredConnectionException - the request has been rejected by the serversetTimeout(long)ChannelInformation[] getPublicChannels() throws java.lang.InterruptedException, ConnectionException, java.util.concurrent.TimeoutException
UnsupportedFeatureException - the server does not support server commandsjava.lang.InterruptedException - the thread has been interrupted while waiting on the datajava.util.concurrent.TimeoutException - the client has not received a response before the timeout has
expired.ConnectionException - the request has been rejected by the serversetTimeout(long)Copyright © 2018. All Rights Reserved.