Package com.yahoo.jdisc.handler
Class BufferedContentChannel
java.lang.Object
com.yahoo.jdisc.handler.BufferedContentChannel
- All Implemented Interfaces:
ContentChannel
This class implements an unlimited, non-blocking content queue. All
ContentChannel
methods are implemented
by pushing to a thread-safe internal queue. All of the queued calls are forwarded to another ContentChannel when
connectTo(ContentChannel)
is called. Once connected, this class becomes a non-buffering proxy for the
connected ContentChannel.- Author:
- Simon Thoresen Hult
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close
(CompletionHandler handler) Closes this ContentChannel.void
connectTo
(ContentChannel content) Connects this BufferedContentChannel to a ContentChannel.boolean
Returns whether or notconnectTo(ContentChannel)
has been called.Creates aReadableContentChannel
andconnects
to it.toStream()
Creates aContentInputStream
andconnects
to its internal ContentChannel.void
write
(ByteBuffer buf, CompletionHandler handler) Schedules the givenByteBuffer
to be written to the content corresponding to this ContentChannel.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.yahoo.jdisc.handler.ContentChannel
onError
-
Constructor Details
-
BufferedContentChannel
public BufferedContentChannel()
-
-
Method Details
-
connectTo
Connects this BufferedContentChannel to a ContentChannel. First, this method forwards all queued calls to the connected ContentChannel. Once this method has been called, all future calls to
write(ByteBuffer, CompletionHandler)
andclose(CompletionHandler)
are synchronously forwarded to the connected ContentChannel.- Parameters:
content
- The ContentChannel to connect to.- Throws:
NullPointerException
- If the content argument is null.IllegalStateException
- If another ContentChannel has already been connected.
-
isConnected
public boolean isConnected()Returns whether or not
connectTo(ContentChannel)
has been called. Even if this method returns false, callingconnectTo(ContentChannel)
might still throw an IllegalStateException if there is a race.- Returns:
- True if
connectTo(ContentChannel)
has been called.
-
toReadable
Creates a
ReadableContentChannel
andconnects
to it.- Returns:
- The new ReadableContentChannel that this connected to.
-
toStream
Creates a
ContentInputStream
andconnects
to its internal ContentChannel.- Returns:
- The new ContentInputStream that this connected to.
-
write
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
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.
-