public interface Session
| 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 |
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.
|
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.
|
void connect()
void connect(boolean wait)
wait - Whether to wait for the connection to be established before returning.String getHost()
int getPort()
SocketAddress getLocalAddress()
SocketAddress getRemoteAddress()
PacketProtocol getPacketProtocol()
Map<String,Object> getFlags()
boolean hasFlag(String key)
key - Key of the flag to check for.<T> T getFlag(String key)
T - Type of the flag.key - Key of the flag.IllegalStateException - If the flag's value isn't of the required type.<T> T getFlag(String key, T def)
T - Type of the flag.key - Key of the flag.def - Default value of the flag.IllegalStateException - If the flag's value isn't of the required type.void setFlag(String key, Object value)
key - Key of the flag.value - Value to set the flag to.List<SessionListener> getListeners()
void addListener(SessionListener listener)
listener - Listener to add.void removeListener(SessionListener listener)
listener - Listener to remove.void callEvent(SessionEvent event)
event - Event to call.void callPacketReceived(Packet packet)
packet - Packet to notify.void callPacketSent(Packet packet)
packet - Packet to notify.int getCompressionThreshold()
void setCompressionThreshold(int threshold,
boolean validateDecompression)
threshold - The new compression threshold.validateDecompression - whether to validate that the decompression fits within size checks.void enableEncryption(PacketEncryption encryption)
encryption - the encryption to encrypt withint getConnectTimeout()
void setConnectTimeout(int timeout)
timeout - Connect timeout to set.int getReadTimeout()
void setReadTimeout(int timeout)
timeout - Read timeout to set.int getWriteTimeout()
void setWriteTimeout(int timeout)
timeout - Write timeout to set.boolean isConnected()
void send(Packet packet)
packet - Packet to send.void disconnect(String reason)
reason - Reason for disconnecting.Copyright © 2021. All rights reserved.