1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.net.server;
15
16 import java.io.IOException;
17 import java.net.InetAddress;
18 import java.net.ServerSocket;
19 import java.util.concurrent.Executor;
20
21 import javax.net.ServerSocketFactory;
22
23 import ch.qos.logback.core.net.server.ServerListener;
24 import ch.qos.logback.core.net.server.ServerRunner;
25
26
27
28
29
30
31 public class InstrumentedServerSocketReceiver extends ServerSocketReceiver {
32
33 private final ServerSocket serverSocket;
34 private final ServerListener<RemoteAppenderClient> listener;
35 private final ServerRunner<RemoteAppenderClient> runner;
36
37 @SuppressWarnings("rawtypes")
38 private ServerListener lastListener;
39
40 public InstrumentedServerSocketReceiver(ServerSocket serverSocket) {
41 this(serverSocket, new RemoteAppenderServerListener(serverSocket), null);
42 }
43
44 public InstrumentedServerSocketReceiver(ServerSocket serverSocket, ServerListener<RemoteAppenderClient> listener,
45 ServerRunner<RemoteAppenderClient> runner) {
46 this.serverSocket = serverSocket;
47 this.listener = listener;
48 this.runner = runner;
49 }
50
51 @Override
52 protected ServerSocketFactory getServerSocketFactory() throws Exception {
53 return new ServerSocketFactory() {
54
55 @Override
56 public ServerSocket createServerSocket(int port) throws IOException {
57 return serverSocket;
58 }
59
60 @Override
61 public ServerSocket createServerSocket(int port, int backlog) throws IOException {
62 return serverSocket;
63 }
64
65 @Override
66 public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException {
67 return serverSocket;
68 }
69 };
70 }
71
72 @SuppressWarnings("rawtypes")
73 @Override
74 protected ServerRunner createServerRunner(ServerListener<RemoteAppenderClient> listener, Executor executor) {
75 lastListener = listener;
76 return runner != null ? runner : super.createServerRunner(listener, executor);
77 }
78
79 @Override
80 protected ServerListener<RemoteAppenderClient> createServerListener(ServerSocket socket) {
81 return listener;
82 }
83
84 @SuppressWarnings("rawtypes")
85 public ServerListener getLastListener() {
86 return lastListener;
87 }
88
89 }