Package io.hekate.network
Interface NetworkClientCallback<T>
-
- Type Parameters:
T
- Base type of messages that can be sent/received by aNetworkClient
.
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface NetworkClientCallback<T>
Callback for receiving messages and tracking state changes inNetworkClient
.Instances of this interface should be passed to the
NetworkClient.connect(InetSocketAddress, NetworkClientCallback)
method.- See Also:
NetworkClient
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
onConnect(NetworkClient<T> client)
default void
onDisconnect(NetworkClient<T> client, Optional<Throwable> cause)
Called right afterNetworkClient
gets disconnected and switched to theDISCONNECTED
state either by explicit call ofNetworkEndpoint.disconnect()
method or if connection was closed due to an error.void
onMessage(NetworkMessage<T> message, NetworkClient<T> client)
Called when a new message is received from the server.
-
-
-
Method Detail
-
onMessage
void onMessage(NetworkMessage<T> message, NetworkClient<T> client) throws IOException
Called when a new message is received from the server.- Parameters:
message
- Message.client
- Client that received this message.- Throws:
IOException
- Message handling error.
-
onConnect
default void onConnect(NetworkClient<T> client)
Called upon successful completion ofconnect
operation right after client switches to theCONNECTED
state.Note that this method will not be called in case of
connect
operation failure,onDisconnect(NetworkClient, Optional)
method will be called instead with a non-emptycause
.- Parameters:
client
- Client that was connected.
-
onDisconnect
default void onDisconnect(NetworkClient<T> client, Optional<Throwable> cause)
Called right afterNetworkClient
gets disconnected and switched to theDISCONNECTED
state either by explicit call ofNetworkEndpoint.disconnect()
method or if connection was closed due to an error.- Parameters:
client
- Client that was disconnected.cause
- Error that caused this disconnect.
-
-