java.lang.Object
java.lang.Thread
ch.qos.logback.classic.net.SimpleSocketServer
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
SimpleSSLSocketServer
A simple
SocketNode based server.
<b>Usage:</b> java ch.qos.logback.classic.net.SimpleSocketServer port configFile
allowedAddress [allowedAddress ...]
where port is a port number where the server listens,
configFile is an XML configuration file fed to
JoranConfigurator, and each allowedAddress is a client IP
or CIDR range that is permitted to connect (e.g. 192.168.1.10 or
192.168.1.0/24). At least one allowed address must be specified on
the command line.
When embedding the server programmatically, allowed client addresses must be
registered with addAllowedClientAddress(String) or
setAllowedClientAddresses(Collection) before clients can connect.
Supported forms are single IPs and CIDR network ranges. An empty whitelist
means no clients are allowed.
- Since:
- 0.8.4
- Author:
- Ceki Gülcü, Sébastien Pennec
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllowedClientAddress(String addressOrCidr) Authorize a single client IP address or a CIDR network range.voidclose()static voidconfigureLC(LoggerContext lc, String configFile) protected static voiddoMain(Class<? extends SimpleSocketServer> serverClass, String[] argv) protected StringgetClientThreadName(Socket socket) Returns a name to identify each client thread.getLatch()Used for testing purposesprotected ServerSocketFactoryGets the platform defaultServerSocketFactory.protected StringReturns the name given to the server thread.protected booleanisClientAllowed(InetAddress clientAddress) Returnstrueif the client is allowed to connect.booleanisClosed()static voidvoidrun()voidsetAllowedClientAddresses(Collection<String> addresses) Replace the set of authorized client addresses with the given collection.voidMethods 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
-
Constructor Details
-
SimpleSocketServer
-
-
Method Details
-
main
- Throws:
Exception
-
doMain
protected static void doMain(Class<? extends SimpleSocketServer> serverClass, String[] argv) throws Exception - Throws:
Exception
-
addAllowedClientAddress
Authorize a single client IP address or a CIDR network range.Only matching clients are accepted; others are closed immediately after
accept(). When no allowed addresses are registered, no clients are accepted.- Parameters:
addressOrCidr- a single IP (e.g.10.0.0.5) or CIDR range (e.g.192.168.1.0/24)- Throws:
IllegalArgumentException- if the specification is invalid- Since:
- 1.6.2
-
setAllowedClientAddresses
Replace the set of authorized client addresses with the given collection. Each entry must be a single IP or CIDR range. Passing an empty collection (ornull) clears the whitelist so that no clients are allowed.- Parameters:
addresses- allowed addresses / CIDR ranges, ornull- Throws:
IllegalArgumentException- if any specification is invalid- Since:
- 1.6.2
-
isClientAllowed
Returnstrueif the client is allowed to connect.When no allowed addresses are configured, no clients are allowed.
- Parameters:
clientAddress- the remote address of the connecting client- Returns:
trueif the connection should be accepted- Since:
- 1.6.2
-
run
-
getServerThreadName
Returns the name given to the server thread. -
getClientThreadName
Returns a name to identify each client thread. -
getServerSocketFactory
Gets the platform defaultServerSocketFactory.Subclasses may override to provide a custom server socket factory.
-
getLatch
Used for testing purposes -
isClosed
-
close
-
socketNodeClosing
-
configureLC
- Throws:
JoranException
-