Package ch.qos.logback.core.net.server
Class ServerSocketListener<T extends Client>
- java.lang.Object
-
- ch.qos.logback.core.net.server.ServerSocketListener<T>
-
- All Implemented Interfaces:
ServerListener<T>,java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
RemoteAppenderServerListener,RemoteReceiverServerListener
public abstract class ServerSocketListener<T extends Client> extends java.lang.Object implements ServerListener<T>
AServerListenerthat accepts connections on aServerSocket.
-
-
Field Summary
Fields Modifier and Type Field Description private java.net.ServerSocketserverSocket
-
Constructor Summary
Constructors Constructor Description ServerSocketListener(java.net.ServerSocket serverSocket)Constructs a new listener.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description TacceptClient()Accepts the next client that appears on this listener.voidclose()Closes any underlyingCloseableresources associated with this listener.protected abstract TcreateClient(java.lang.String id, java.net.Socket socket)Creates the client object for a new socket connectionprivate java.lang.StringsocketAddressToString(java.net.SocketAddress address)Converts a socket address to a reasonable display string.java.lang.StringtoString()
-
-
-
Method Detail
-
acceptClient
public T acceptClient() throws java.io.IOException
Accepts the next client that appears on this listener.An implementation of this method is expected to block the calling thread and not return until either a client appears or an exception occurs.
- Specified by:
acceptClientin interfaceServerListener<T extends Client>- Returns:
- client object
- Throws:
java.io.IOException
-
createClient
protected abstract T createClient(java.lang.String id, java.net.Socket socket) throws java.io.IOException
Creates the client object for a new socket connection- Parameters:
id- identifier string for the clientsocket- client's socket connection- Returns:
- client object
- Throws:
java.io.IOException
-
close
public void close()
Closes any underlyingCloseableresources associated with this listener.Note that (as described in Doug Lea's discussion about interrupting I/O operations in "Concurrent Programming in Java" (Addison-Wesley Professional, 2nd edition, 1999) this method is used to interrupt any blocked I/O operation in the client when the server is shutting down. The client implementation must anticipate this potential, and gracefully exit when the blocked I/O operation throws the relevant
IOExceptionsubclass.Note also, that unlike
Closeable.close()this method is not permitted to propagate anyIOExceptionthat occurs when closing the underlying resource(s).- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceServerListener<T extends Client>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
socketAddressToString
private java.lang.String socketAddressToString(java.net.SocketAddress address)
Converts a socket address to a reasonable display string.- Parameters:
address- the subject socket address- Returns:
- display string
-
-