incubator-s4-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leo Neumeyer <>
Subject Handling Interrupted Exceptions in Listener/Receiver
Date Mon, 19 Dec 2011 06:34:27 GMT
We need to make sure we can shutdown the Server object gracefully. In
the top layer, when an App closes, it closes all the PEs, stops the
Timer threads, and stops all the associated streams.

I tried to add a close() method to receiver to stop the thread but
noticed that netty listener doesn't throw InterruptedException. Also,
Netty and UDP handle interrupted exceptions differently:


 public void run() {
        try {
            while (!Thread.interrupted()) {
                byte[] data = new byte[datagram.getLength()];
                System.arraycopy(datagram.getData(), datagram.getOffset(),
                        data, 0, data.length);
                try {
                } catch (InterruptedException ie) {
        } catch (IOException e) {
            throw new RuntimeException(e);


  public void messageReceived(ChannelHandlerContext ctx,
                MessageEvent e) {
            ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
            try {
                handoffQueue.put(buffer.array()); // this holds up the
Netty upstream I/O thread if
                                                  // there's no
receiver at the other end of the handoff queue
            } catch (InterruptedException ie) {

I don't know much about Netty so before breaking things I wanted to
ask a few questions:

Shouldn't the contract be that Listener implementations always throw

How can we impose the contract?


Leo Neumeyer (@leoneu)

View raw message