Class DefaultNetworkChannel
java.lang.Object
eu.cloudnetservice.driver.network.DefaultNetworkChannel
- All Implemented Interfaces:
NetworkChannel,PacketSender
- Direct Known Subclasses:
NettyNetworkChannel
The default abstract implementation of a network channel.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AtomicLongprivate final longprivate final HostAndPortprivate final booleanprivate final NetworkChannelHandlerprivate final PacketListenerRegistryprivate final QueryPacketManagerprivate final HostAndPort -
Constructor Summary
ConstructorsConstructorDescriptionDefaultNetworkChannel(@NonNull PacketListenerRegistry packetRegistry, @NonNull HostAndPort serverAddress, @NonNull HostAndPort clientAddress, boolean clientProvidedChannel, @NonNull NetworkChannelHandler handler) Constructs a new default network channel instance. -
Method Summary
Modifier and TypeMethodDescriptionlongGet a unique numeric id of this channel.Get the client host from/to the channel is connected.booleanGet if this client is opened by a client rather than a server.handler()Get the handler of this channel listening to all kind of operations on this channel.Get the packet listener registry responsible for this channel.Get the query packet manager of this channel.Converts and sends the given packet as a query into this channel, blocking the current thread until a response is available or a timeout of 30 seconds was reached.sendQueryAsync(@NonNull Packet packet) Converts and sends the given packet as a query into this channel, returning a future either completed with the response to the query or an exception if no response to the packet was received in time.Get the server host from/to the channel is connected.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.network.NetworkChannel
active, close, writeableMethods inherited from interface eu.cloudnetservice.driver.network.protocol.PacketSender
sendPacket, sendPacket, sendPacketSync, sendPacketSync
-
Field Details
-
CHANNEL_ID_COUNTER
-
channelId
private final long channelId -
queryPacketManager
-
packetRegistry
-
serverAddress
-
clientAddress
-
clientProvidedChannel
private final boolean clientProvidedChannel -
handler
-
-
Constructor Details
-
DefaultNetworkChannel
public DefaultNetworkChannel(@NonNull @NonNull PacketListenerRegistry packetRegistry, @NonNull @NonNull HostAndPort serverAddress, @NonNull @NonNull HostAndPort clientAddress, boolean clientProvidedChannel, @NonNull @NonNull NetworkChannelHandler handler) Constructs a new default network channel instance.- Parameters:
packetRegistry- the packet registry to use for the channel.serverAddress- the associated server address for the connection.clientAddress- the associated client address for the connection.clientProvidedChannel- true if this channel was opened by a client, false otherwise.handler- the handler to post underlying network events to.- Throws:
NullPointerException- if one of the given arguments is null.
-
-
Method Details
-
sendQueryAsync
@NonNull public @NonNull eu.cloudnetservice.common.concurrent.Task<Packet> sendQueryAsync(@NonNull @NonNull Packet packet) Converts and sends the given packet as a query into this channel, returning a future either completed with the response to the query or an exception if no response to the packet was received in time.- Specified by:
sendQueryAsyncin interfaceNetworkChannel- Parameters:
packet- the packet to send as a query.- Returns:
- a future completed with the result of the query or an exception in case of a timeout.
-
sendQuery
Converts and sends the given packet as a query into this channel, blocking the current thread until a response is available or a timeout of 30 seconds was reached.- Specified by:
sendQueryin interfaceNetworkChannel- Parameters:
packet- the packet to send as a query.- Returns:
- the response to the query or null if no response was received in time.
-
channelId
public long channelId()Get a unique numeric id of this channel. The ids are starting at 1.- Specified by:
channelIdin interfaceNetworkChannel- Returns:
- a unique numeric id of this channel.
-
packetRegistry
Get the packet listener registry responsible for this channel.- Specified by:
packetRegistryin interfaceNetworkChannel- Returns:
- the packet listener registry responsible for this channel.
-
queryPacketManager
Get the query packet manager of this channel.- Specified by:
queryPacketManagerin interfaceNetworkChannel- Returns:
- the query packet manager of this channel.
-
serverAddress
Get the server host from/to the channel is connected.- Specified by:
serverAddressin interfaceNetworkChannel- Returns:
- the server address of the channel.
-
clientAddress
Get the client host from/to the channel is connected.- Specified by:
clientAddressin interfaceNetworkChannel- Returns:
- the client address of the channel.
-
clientProvidedChannel
public boolean clientProvidedChannel()Get if this client is opened by a client rather than a server.- Specified by:
clientProvidedChannelin interfaceNetworkChannel- Returns:
- true if this channel was opened by a client, false otherwise.
-
handler
Get the handler of this channel listening to all kind of operations on this channel.- Specified by:
handlerin interfaceNetworkChannel- Returns:
- the listener for channel operations.
-