- java.lang.Object
-
- java.lang.Thread
-
- ch.qos.logback.classic.net.SimpleSocketServer
-
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
SimpleSSLSocketServer
public class SimpleSocketServer extends Thread
A simpleSocketNodebased 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 toJoranConfigurator, and each allowedAddress is a client IP or CIDR range that is permitted to connect (e.g.192.168.1.10or192.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)orsetAllowedClientAddresses(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 Constructor Description SimpleSocketServer(LoggerContext lc, int port)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAllowedClientAddress(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.CountDownLatchgetLatch()Used for testing purposesprotected ServerSocketFactorygetServerSocketFactory()Gets the platform defaultServerSocketFactory.protected StringgetServerThreadName()Returns the name given to the server thread.protected booleanisClientAllowed(InetAddress clientAddress)Returnstrueif the client is allowed to connect.booleanisClosed()static voidmain(String[] argv)voidrun()voidsetAllowedClientAddresses(Collection<String> addresses)Replace the set of authorized client addresses with the given collection.voidsocketNodeClosing(SocketNode sn)-
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
-
-
-
-
Constructor Detail
-
SimpleSocketServer
public SimpleSocketServer(LoggerContext lc, int port)
-
-
Method Detail
-
doMain
protected static void doMain(Class<? extends SimpleSocketServer> serverClass, String[] argv) throws Exception
- Throws:
Exception
-
addAllowedClientAddress
public void addAllowedClientAddress(String addressOrCidr)
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
public void setAllowedClientAddresses(Collection<String> addresses)
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
protected boolean isClientAllowed(InetAddress clientAddress)
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
-
getServerThreadName
protected String getServerThreadName()
Returns the name given to the server thread.
-
getClientThreadName
protected String getClientThreadName(Socket socket)
Returns a name to identify each client thread.
-
getServerSocketFactory
protected ServerSocketFactory getServerSocketFactory()
Gets the platform defaultServerSocketFactory.Subclasses may override to provide a custom server socket factory.
-
getLatch
public CountDownLatch getLatch()
Used for testing purposes
-
isClosed
public boolean isClosed()
-
close
public void close()
-
socketNodeClosing
public void socketNodeClosing(SocketNode sn)
-
configureLC
public static void configureLC(LoggerContext lc, String configFile) throws JoranException
- Throws:
JoranException
-
-