Package io.hekate.network
Interface NetworkEndpoint<T>
-
- Type Parameters:
T
- Base type of messages that can be supported by this endpoint.
- All Known Subinterfaces:
NetworkClient<T>
public interface NetworkEndpoint<T>
Base interface for network communication endpoints.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description NetworkFuture<T>
disconnect()
Asynchronously disconnects this endpoint.Object
getContext()
Returns the custom user context object that was set viasetContext(Object)
.boolean
isReceiving()
Returnsfalse
if receiving of messages from a remote peer ispauseReceiving(Consumer)
paused} or if this endpoint is disconnected.boolean
isSecure()
Returnstrue
if SSL is enabled (seeNetworkServiceFactory.setSsl(NetworkSslConfig)
).InetSocketAddress
localAddress()
Returns the local address of this endpoint.void
pauseReceiving(Consumer<NetworkEndpoint<T>> callback)
Pauses receiving of messages from a remote peer.String
protocol()
Returns the protocol name of this endpoint.InetSocketAddress
remoteAddress()
Returns the remote address of this endpoint.void
resumeReceiving(Consumer<NetworkEndpoint<T>> callback)
Resumes receiving of messages from a remote peer.void
send(T msg)
Asynchronously sends the specified message.void
send(T msg, NetworkSendCallback<T> callback)
Asynchronously sends the specified message and notifies the specified callback on operation result.void
setContext(Object ctx)
Sets the custom user context object that should be associated with this endpoint.
-
-
-
Method Detail
-
protocol
String protocol()
Returns the protocol name of this endpoint.- Returns:
- Protocol name.
- See Also:
NetworkConnectorConfig.setProtocol(String)
-
remoteAddress
InetSocketAddress remoteAddress()
Returns the remote address of this endpoint. Returnsnull
if this endpoint is not connected.- Returns:
- Remote address or
null
if endpoint is not connected.
-
localAddress
InetSocketAddress localAddress()
Returns the local address of this endpoint. Returnsnull
if this endpoint is not connected.- Returns:
- Local address or
null
if this endpoint is not connected.
-
isSecure
boolean isSecure()
Returnstrue
if SSL is enabled (seeNetworkServiceFactory.setSsl(NetworkSslConfig)
).- Returns:
true
if SSL.
-
getContext
Object getContext()
Returns the custom user context object that was set viasetContext(Object)
.- Returns:
- Context object.
-
setContext
void setContext(Object ctx)
Sets the custom user context object that should be associated with this endpoint.- Parameters:
ctx
- Context object.
-
send
void send(T msg)
Asynchronously sends the specified message.Note that this methods doesn't provide any feedback on whether operation completes successfully or with an error. Consider using
send(Object, NetworkSendCallback)
method if such feedback is required.- Parameters:
msg
- Message.
-
send
void send(T msg, NetworkSendCallback<T> callback)
Asynchronously sends the specified message and notifies the specified callback on operation result.Note that the specified callback will be called on the
NetworkEndpoint
's NIO thread. It must be executed as fast as possible in order to prevent blocking other endpoints that can be associated with the same thread. In case of long/heavy computations consider scheduling such tasks to another thread.- Parameters:
msg
- Message.callback
- Callback.
-
pauseReceiving
void pauseReceiving(Consumer<NetworkEndpoint<T>> callback)
Pauses receiving of messages from a remote peer. Does nothing if receiving is already paused or is disconnected.Note that pausing is an asynchronous operation and some messages, that were buffered prior to this method call, can still be received.
- Parameters:
callback
- Optional callback to be notified once pausing takes effect (can benull
).- See Also:
resumeReceiving(Consumer)
,isReceiving()
-
resumeReceiving
void resumeReceiving(Consumer<NetworkEndpoint<T>> callback)
Resumes receiving of messages from a remote peer. Does nothing if receiving is not paused or is disconnected.- Parameters:
callback
- Optional callback to be notified once resuming takes effect (can benull
).- See Also:
pauseReceiving(Consumer)
,isReceiving()
-
isReceiving
boolean isReceiving()
Returnsfalse
if receiving of messages from a remote peer ispauseReceiving(Consumer)
paused} or if this endpoint is disconnected.- Returns:
false
if receiving is paused viapauseReceiving(Consumer)
.- See Also:
pauseReceiving(Consumer)
,resumeReceiving(Consumer)
-
disconnect
NetworkFuture<T> disconnect()
Asynchronously disconnects this endpoint.- Returns:
- Future object that can be used to obtain result of this operation.
-
-