Interface Server
- All Known Implementing Classes:
AbstractServer,NetworkServer
public interface Server
Listens for new sessions to connect.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ServerListener listener) Adds a listener to this server.bind()Binds the listener to its host and port.bind(boolean wait) Binds the listener to its host and port.Binds the listener to its host and port.voidclose()Closes the listener.voidclose(boolean wait) Closes the listener.voidCloses the listener.Gets the bind address the server is listening on.default <T> TgetGlobalFlag(Flag<T> flag) Gets the value of the given flag as an instance of the given type.default <T> TgetGlobalFlag(Flag<T> flag, T def) Gets this server's set flags.<T> TgetGlobalFlagSupplied(Flag<T> flag, Supplier<T> defSupplier) Gets the value of the given flag as an instance of the given type.Gets the listeners listening on this session.Supplier<? extends PacketProtocol>Gets the packet protocol of the server.Gets all sessions belonging to this server.booleanhasGlobalFlag(Flag<?> flag) Checks whether this server has a flag set.booleanReturns true if the listener is listening.voidremoveListener(ServerListener listener) Removes a listener from this server.<T> voidsetGlobalFlag(Flag<T> flag, T value) Sets the value of a flag.
-
Method Details
-
getBindAddress
SocketAddress getBindAddress()Gets the bind address the server is listening on.- Returns:
- The listening bind address.
-
getPacketProtocol
Supplier<? extends PacketProtocol> getPacketProtocol()Gets the packet protocol of the server.- Returns:
- The server's packet protocol.
-
isListening
boolean isListening()Returns true if the listener is listening.- Returns:
- True if the listener is listening.
-
getGlobalFlags
Gets this server's set flags.- Returns:
- This server's flags.
-
hasGlobalFlag
Checks whether this server has a flag set.- Parameters:
flag- Flag to check for.- Returns:
- Whether this server has a flag set.
-
getGlobalFlag
Gets the value of the given flag as an instance of the given type.- Type Parameters:
T- Type of the flag.- Parameters:
flag- Flag to check for.- Returns:
- Value of the flag.
- Throws:
IllegalStateException- If the flag's value isn't of the required type.
-
getGlobalFlag
- See Also:
-
getGlobalFlagSupplied
Gets the value of the given flag as an instance of the given type. If the flag is not set, the specified default value will be returned.- Type Parameters:
T- Type of the flag.- Parameters:
flag- Flag to check for.defSupplier- Default value supplier.- Returns:
- Value of the flag.
- Throws:
IllegalStateException- If the flag's value isn't of the required type.
-
setGlobalFlag
Sets the value of a flag. The flag will be used in sessions if a session does not contain a value for the flag.- Type Parameters:
T- Type of the flag.- Parameters:
flag- Flag to check for.value- Value to set the flag to.
-
getListeners
List<ServerListener> getListeners()Gets the listeners listening on this session.- Returns:
- This server's listeners.
-
addListener
Adds a listener to this server.- Parameters:
listener- Listener to add.
-
removeListener
Removes a listener from this server.- Parameters:
listener- Listener to remove.
-
getSessions
Gets all sessions belonging to this server.- Returns:
- Sessions belonging to this server.
-
bind
AbstractServer bind()Binds the listener to its host and port.- Returns:
- The server.
-
bind
Binds the listener to its host and port.- Parameters:
wait- Whether to wait for the listener to finish binding.- Returns:
- The server.
-
bind
Binds the listener to its host and port.- Parameters:
wait- Whether to wait for the listener to finish binding.callback- Callback to call when the listener has finished binding.- Returns:
- The server.
-
close
void close()Closes the listener. -
close
void close(boolean wait) Closes the listener.- Parameters:
wait- Whether to wait for the listener to finish closing.
-
close
Closes the listener.- Parameters:
wait- Whether to wait for the listener to finish closing.callback- Callback to call when the listener has finished closing.
-