private void doWork() throws IOException { CountingInputStream input = null; CountingOutputStream output = null; try { input = new CountingInputStream(s.getInputStream()); output = new CountingOutputStream(s.getOutputStream()); ByteStreams.copy(input, output); Counters.increment("BytesIn", input.getCount()); Counters.increment("BytesOut", output.getCount()); } finally { Closeables.closeQuietly(input); Closeables.closeQuietly(output); } }
public void run() { while (true) { try { Socket s = ss.accept(); TagList tags = getTags(s); LOGGER.info("received connection from {} with tags {}", s.getRemoteSocketAddress(), tags); Counters.increment("RequestCount", tags); ClientTask task = new ClientTask(tags, s); Thread t = new Thread(task, "ClientTask"); t.start(); } catch (IOException e) { LOGGER.error("failure accepting connection", e); } } }