Package com.yahoo.jdisc.handler
Class NullContent
- java.lang.Object
-
- com.yahoo.jdisc.handler.NullContent
-
- All Implemented Interfaces:
ContentChannel
public final class NullContent extends java.lang.Object implements ContentChannel
This class provides a convenient implementation of
ContentChannel
that does not support being written to. Ifwrite(ByteBuffer, CompletionHandler)
is called, it throws an UnsupportedOperationException. Ifclose(CompletionHandler)
is called, it calls the givenCompletionHandler
.A
RequestHandler
s that does not expect content can simply return theINSTANCE
of this class for every invocation of itsRequestHandler.handleRequest(Request, ResponseHandler)
.- Author:
- Simon Thoresen Hult
-
-
Field Summary
Fields Modifier and Type Field Description static NullContent
INSTANCE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close(CompletionHandler handler)
Closes this ContentChannel.void
write(java.nio.ByteBuffer buf, CompletionHandler handler)
Schedules the givenByteBuffer
to be written to the content corresponding to this ContentChannel.
-
-
-
Field Detail
-
INSTANCE
public static final NullContent INSTANCE
-
-
Method Detail
-
write
public void write(java.nio.ByteBuffer buf, CompletionHandler handler)
Description copied from interface:ContentChannel
Schedules the givenByteBuffer
to be written to the content corresponding to this ContentChannel. This call transfers ownership of the given ByteBuffer to this ContentChannel, i.e. no further calls can be made to the buffer. The execution of writes happen in the same order as this method was invoked.- Specified by:
write
in interfaceContentChannel
- Parameters:
buf
- TheByteBuffer
to schedule for write. No further calls can be made to this buffer.handler
- TheCompletionHandler
to call after the write has been executed.
-
close
public void close(CompletionHandler handler)
Description copied from interface:ContentChannel
Closes this ContentChannel. After a channel is closed, any further attempt to invokeContentChannel.write(ByteBuffer, CompletionHandler)
upon it will cause anIllegalStateException
to be thrown. If this channel is already closed then invoking this method has no effect, butCompletionHandler.completed()
will still be called. Notice that you MUST call this method, regardless of any exceptions that might have occurred while writing to this ContentChannel. Failure to do so will prevent theContainer
from ever shutting down.- Specified by:
close
in interfaceContentChannel
- Parameters:
handler
- TheCompletionHandler
to call after the close has been executed.
-
-