MCPcopy Create free account
hub / github.com/apache/avro / SocketServer

Class SocketServer

lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java:43–151  ·  view source on GitHub ↗

A socket-based server implementation. This uses a simple, non-standard wire protocol and is not intended for production services. @deprecated use SaslSocketServer instead.

Source from the content-addressed store, hash-verified

41 * @deprecated use {@link SaslSocketServer} instead.
42 */
43@Deprecated
44public 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.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…