A socket-based server implementation. This uses a simple, non-standard wire protocol and is not intended for production services. @deprecated use SaslSocketServer instead.
| 41 | * @deprecated use {@link SaslSocketServer} instead. |
| 42 | */ |
| 43 | @Deprecated |
| 44 | public class SocketServer extends Thread implements Server { |
| 45 | private static final Logger LOG = LoggerFactory.getLogger(SocketServer.class); |
| 46 | |
| 47 | private Responder responder; |
| 48 | private ServerSocketChannel channel; |
| 49 | private ThreadGroup group; |
| 50 | |
| 51 | public SocketServer(Responder responder, SocketAddress addr) throws IOException { |
| 52 | String name = "SocketServer on " + addr; |
| 53 | |
| 54 | this.responder = responder; |
| 55 | this.group = new ThreadGroup(name); |
| 56 | this.channel = ServerSocketChannel.open(); |
| 57 | |
| 58 | channel.socket().bind(addr); |
| 59 | |
| 60 | setName(name); |
| 61 | setDaemon(true); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public int getPort() { |
| 66 | return channel.socket().getLocalPort(); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void run() { |
| 71 | LOG.info("starting " + channel.socket().getInetAddress()); |
| 72 | try { |
| 73 | while (true) { |
| 74 | try { |
| 75 | new Connection(channel.accept()); |
| 76 | } catch (ClosedChannelException e) { |
| 77 | return; |
| 78 | } catch (IOException e) { |
| 79 | LOG.warn("unexpected error", e); |
| 80 | throw new RuntimeException(e); |
| 81 | } |
| 82 | } |
| 83 | } finally { |
| 84 | LOG.info("stopping " + channel.socket().getInetAddress()); |
| 85 | try { |
| 86 | channel.close(); |
| 87 | } catch (IOException e) { |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public void close() { |
| 94 | this.interrupt(); |
| 95 | group.interrupt(); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Creates an appropriate {@link Transceiver} for this server. Returns a |
| 100 | * {@link SocketTransceiver} by default. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…