Package org.cristian.t4j
Class TelnetServer
- java.lang.Object
-
- java.lang.Thread
-
- org.cristian.t4j.TelnetServer
-
- All Implemented Interfaces:
java.lang.Runnable
public class TelnetServer extends java.lang.Thread
Telnet Monitor Service (Thread) which allows users to telnet in and request/monitor internal services.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TelnetServer.Authenticator
Absctract class used as template for authenticators.static class
TelnetServer.Command
This is the class that should be extended when wanting to add available commands to the Telnet Monitor.static class
TelnetServer.Handler
Absctract class used as template for handlers.
-
Field Summary
Fields Modifier and Type Field Description static TelnetServer.Authenticator
DEFAULT_AUTHENTICATOR
static TelnetServer.Handler
DEFAULT_HANDLER
static java.lang.String
DEFAULT_PORT
static java.lang.String
DEFAULT_PROMPT_LINE
static java.lang.String
DEFAULT_WELCOME_MESSAGE
static java.util.logging.Logger
LOG
static java.lang.String
PORT_KEY
static java.lang.String
PROMPT_LINE_KEY
protected TelnetServer.Authenticator
ServerAuthenticator
static java.lang.String
WELCOME_MESSAGE_KEY
-
Constructor Summary
Constructors Constructor Description TelnetServer()
TelnetServer(java.lang.String Port, java.lang.String Prompt, java.lang.String Welcome, TelnetServer.Handler ServerHandler, TelnetServer.Authenticator ServerAuthenticator)
TelnetServer(java.lang.String Port, java.lang.String Welcome, TelnetServer.Handler ServerHandler, TelnetServer.Authenticator ServerAuthenticator)
TelnetServer(java.lang.String Port, TelnetServer.Handler ServerHandler, TelnetServer.Authenticator ServerAuthenticator)
TelnetServer(TelnetServer.Handler ServerHandler, TelnetServer.Authenticator ServerAuthenticator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAvailableCommands()
Get the available commands on this server.java.lang.String
getCommandPrompt()
Get the server's prompt line.java.util.Optional<TelnetServer.Command>
getRequest(java.lang.String CommandInput)
Match a user input to a registered command.java.lang.String
getWelcomeMessage()
Get the server's welcome message.void
registerCommand(TelnetServer.Command Command)
Register a Telnet command on this server.void
removeHandler(java.lang.String Name)
Remove a handler from this server.void
run()
void
terminate()
Safely kill the thread.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
LOG
public static final java.util.logging.Logger LOG
-
PORT_KEY
public static final java.lang.String PORT_KEY
- See Also:
- Constant Field Values
-
WELCOME_MESSAGE_KEY
public static final java.lang.String WELCOME_MESSAGE_KEY
- See Also:
- Constant Field Values
-
PROMPT_LINE_KEY
public static final java.lang.String PROMPT_LINE_KEY
- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final java.lang.String DEFAULT_PORT
- See Also:
- Constant Field Values
-
DEFAULT_WELCOME_MESSAGE
public static final java.lang.String DEFAULT_WELCOME_MESSAGE
- See Also:
- Constant Field Values
-
DEFAULT_PROMPT_LINE
public static final java.lang.String DEFAULT_PROMPT_LINE
- See Also:
- Constant Field Values
-
DEFAULT_AUTHENTICATOR
public static final TelnetServer.Authenticator DEFAULT_AUTHENTICATOR
-
DEFAULT_HANDLER
public static final TelnetServer.Handler DEFAULT_HANDLER
-
ServerAuthenticator
protected final TelnetServer.Authenticator ServerAuthenticator
-
-
Constructor Detail
-
TelnetServer
public TelnetServer(java.lang.String Port, java.lang.String Prompt, java.lang.String Welcome, TelnetServer.Handler ServerHandler, TelnetServer.Authenticator ServerAuthenticator)
-
TelnetServer
public TelnetServer(java.lang.String Port, java.lang.String Welcome, TelnetServer.Handler ServerHandler, TelnetServer.Authenticator ServerAuthenticator)
-
TelnetServer
public TelnetServer(java.lang.String Port, TelnetServer.Handler ServerHandler, TelnetServer.Authenticator ServerAuthenticator)
-
TelnetServer
public TelnetServer(TelnetServer.Handler ServerHandler, TelnetServer.Authenticator ServerAuthenticator)
-
TelnetServer
public TelnetServer()
-
-
Method Detail
-
terminate
public void terminate()
Safely kill the thread.
-
removeHandler
public void removeHandler(java.lang.String Name)
Remove a handler from this server.- Parameters:
Name
- The handler's name.
-
registerCommand
public void registerCommand(TelnetServer.Command Command)
Register a Telnet command on this server.- Parameters:
Command
- The Telnet Command.
-
getRequest
public java.util.Optional<TelnetServer.Command> getRequest(java.lang.String CommandInput)
Match a user input to a registered command.- Parameters:
CommandInput
- The user input.- Returns:
- A Command if there is one, empty otherwise.
-
getAvailableCommands
public java.lang.String getAvailableCommands()
Get the available commands on this server.- Returns:
- A list of all available commands.
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
getWelcomeMessage
public java.lang.String getWelcomeMessage()
Get the server's welcome message.- Returns:
- The Welcome Message that is given to user on first connections.
-
getCommandPrompt
public java.lang.String getCommandPrompt()
Get the server's prompt line.- Returns:
- The command prompt.
-
-