class ByteChannelReader {

    public void blockingStart(final ReadableByteChannel readableByteChannel)
    {
        try
        {
            while ((readableByteChannel.read(buffer)) != -1)
            {
                blocker.mayWait();
                buffer.flip();
                byteStreamMessageParser.parse(buffer);
                buffer.clear();
            }

        }
        catch (final ClosedChannelException e)
        {
            //Yes closed.
        }
        catch (final IOException e)
        {
            LOGGER.error("An error occurred trying to read from the socket", e);
        }
        finally
        {
            if (readableByteChannel != null)
            {
                try
                {
                    if (readableByteChannel.isOpen())
                    {
                        readableByteChannel.close();
                    }
                }
                catch (IOException e)
                {
                    //I don't care
                }
                connectionObserver.connectionClosed();
            }
        }
    }

    public  ByteChannelReader(final ByteStreamMessageParser byteStreamMessageParser, final Blocker blocker, final ConnectionObserver connectionObserver);

}