@Override
	public void eventSunk(final ChannelPipeline pipeline, final ChannelEvent e) throws Exception {

		final ChannelFuture future = e.getFuture();

		if (e instanceof ChannelStateEvent) {

			final ChannelStateEvent stateEvent = (ChannelStateEvent) e;
			final ChannelState state = stateEvent.getState();
			final Object value = stateEvent.getValue();

			switch (state) {

				case OPEN:
					if (Boolean.FALSE.equals(value)) {
						disconnectChannelInternal(future);
					}
					break;

				case BOUND:
					throw new UnsupportedOperationException();

				case CONNECTED:
					if (value != null) {
						remoteAddress = (IOStreamAddress) value;
						outputStream = remoteAddress.getOutputStream();
						inputStream = new PushbackInputStream(remoteAddress.getInputStream());
						Channels.fireChannelConnected(pipeline.getChannel(), remoteAddress);
						future.setSuccess();
						executorService.execute(new ReadRunnable(this));
					}
					break;

				case INTEREST_OPS:
					// TODO implement
					throw new UnsupportedOperationException();

			}

		} else if (e instanceof MessageEvent) {

			final MessageEvent event = (MessageEvent) e;
			if (event.getMessage() instanceof ChannelBuffer) {

				final ChannelBuffer buffer = (ChannelBuffer) event.getMessage();
				buffer.readBytes(outputStream, buffer.readableBytes());
				outputStream.flush();
				future.setSuccess();

			} else {
				throw new IllegalArgumentException(
						"Only ChannelBuffer objects are supported to be written onto the IOStreamChannelSink! "
								+ "Please check if the encoder pipeline is configured correctly."
				);
			}
		}
	}