public abstract class TcpSession extends io.netty.channel.SimpleChannelInboundHandler<Packet> implements Session
| Modifier and Type | Field and Description |
|---|---|
static boolean |
USE_EVENT_LOOP_FOR_PACKETS
Controls whether non-priority packets are handled in a separate event loop
|
| Constructor and Description |
|---|
TcpSession(String host,
int port,
PacketProtocol protocol) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(SessionListener listener)
Adds a listener to this session.
|
void |
callEvent(SessionEvent event)
Calls an event on the listeners of this session.
|
void |
callPacketReceived(Packet packet)
Notifies all listeners that a packet was just received.
|
void |
callPacketSent(Packet packet)
Notifies all listeners that a packet was just sent.
|
void |
channelActive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
void |
connect()
Connects this session to its host and port.
|
void |
connect(boolean wait)
Connects this session to its host and port.
|
void |
disconnect(String reason)
Disconnects the session.
|
void |
disconnect(String reason,
Throwable cause)
Disconnects the session.
|
void |
enableEncryption(PacketEncryption encryption)
Enables encryption for this session.
|
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
io.netty.channel.Channel |
getChannel() |
int |
getCompressionThreshold()
Gets the compression packet length threshold for this session (-1 = disabled).
|
int |
getConnectTimeout()
Gets the connect timeout for this session in seconds.
|
<T> T |
getFlag(String key)
Gets the value of the given flag as an instance of the given type.
|
<T> T |
getFlag(String key,
T def)
Gets the value of the given flag as an instance of the given type.
|
Map<String,Object> |
getFlags()
Gets this session's set flags.
|
String |
getHost()
Gets the host the session is connected to.
|
List<SessionListener> |
getListeners()
Gets the listeners listening on this session.
|
SocketAddress |
getLocalAddress()
Gets the local address of the session.
|
PacketProtocol |
getPacketProtocol()
Gets the packet protocol of the session.
|
int |
getPort()
Gets the port the session is connected to.
|
int |
getReadTimeout()
Gets the read timeout for this session in seconds.
|
SocketAddress |
getRemoteAddress()
Gets the remote address of the session.
|
int |
getWriteTimeout()
Gets the write timeout for this session in seconds.
|
boolean |
hasFlag(String key)
Checks whether this session has a flag set.
|
boolean |
isConnected()
Returns true if the session is connected.
|
void |
removeListener(SessionListener listener)
Removes a listener from this session.
|
void |
send(Packet packet)
Sends a packet.
|
void |
setCompressionThreshold(int threshold,
boolean validateDecompression)
Sets the compression packet length threshold for this session (-1 = disabled).
|
void |
setConnectTimeout(int timeout)
Sets the connect timeout for this session in seconds.
|
void |
setFlag(String key,
Object value)
Sets the value of a flag.
|
void |
setReadTimeout(int timeout)
Sets the read timeout for this session in seconds.
|
void |
setWriteTimeout(int timeout)
Sets the write timeout for this session in seconds.
|
acceptInboundMessage, channelReadchannelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredhandlerAdded, handlerRemoved, isSharablepublic static boolean USE_EVENT_LOOP_FOR_PACKETS
public TcpSession(String host, int port, PacketProtocol protocol)
public void connect()
Sessionpublic void connect(boolean wait)
Sessionpublic String getHost()
Sessionpublic int getPort()
Sessionpublic SocketAddress getLocalAddress()
SessiongetLocalAddress in interface Sessionpublic SocketAddress getRemoteAddress()
SessiongetRemoteAddress in interface Sessionpublic PacketProtocol getPacketProtocol()
SessiongetPacketProtocol in interface Sessionpublic Map<String,Object> getFlags()
Sessionpublic boolean hasFlag(String key)
Sessionpublic <T> T getFlag(String key)
Sessionpublic <T> T getFlag(String key, T def)
Sessionpublic void setFlag(String key, Object value)
Sessionpublic List<SessionListener> getListeners()
SessiongetListeners in interface Sessionpublic void addListener(SessionListener listener)
SessionaddListener in interface Sessionlistener - Listener to add.public void removeListener(SessionListener listener)
SessionremoveListener in interface Sessionlistener - Listener to remove.public void callEvent(SessionEvent event)
Sessionpublic void callPacketReceived(Packet packet)
SessioncallPacketReceived in interface Sessionpacket - Packet to notify.public void callPacketSent(Packet packet)
SessioncallPacketSent in interface Sessionpacket - Packet to notify.public int getCompressionThreshold()
SessiongetCompressionThreshold in interface Sessionpublic void setCompressionThreshold(int threshold,
boolean validateDecompression)
SessionsetCompressionThreshold in interface Sessionthreshold - The new compression threshold.validateDecompression - whether to validate that the decompression fits within size checks.public void enableEncryption(PacketEncryption encryption)
SessionenableEncryption in interface Sessionencryption - the encryption to encrypt withpublic int getConnectTimeout()
SessiongetConnectTimeout in interface Sessionpublic void setConnectTimeout(int timeout)
SessionsetConnectTimeout in interface Sessiontimeout - Connect timeout to set.public int getReadTimeout()
SessiongetReadTimeout in interface Sessionpublic void setReadTimeout(int timeout)
SessionsetReadTimeout in interface Sessiontimeout - Read timeout to set.public int getWriteTimeout()
SessiongetWriteTimeout in interface Sessionpublic void setWriteTimeout(int timeout)
SessionsetWriteTimeout in interface Sessiontimeout - Write timeout to set.public boolean isConnected()
SessionisConnected in interface Sessionpublic void disconnect(String reason)
Sessiondisconnect in interface Sessionreason - Reason for disconnecting.public void disconnect(String reason, Throwable cause)
Sessiondisconnect in interface Sessionreason - Reason for disconnecting.cause - Throwable responsible for disconnecting.public io.netty.channel.Channel getChannel()
public void channelActive(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelActive in interface io.netty.channel.ChannelInboundHandlerchannelActive in class io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelInactive in interface io.netty.channel.ChannelInboundHandlerchannelInactive in class io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause)
exceptionCaught in interface io.netty.channel.ChannelHandlerexceptionCaught in interface io.netty.channel.ChannelInboundHandlerexceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapterCopyright © 2021. All rights reserved.