public interface Stream
A Stream
represents a bidirectional exchange of data on top of a Session
.
Differently from socket streams, where the input and output streams are permanently associated with the socket (and hence with the connection that the socket represents), there can be multiple SPDY streams for a SPDY session.
SPDY streams may terminate without this implying that the SPDY session is terminated.
If SPDY is used to transport the HTTP protocol, then a SPDY stream maps to a HTTP request/response cycle, and after the request/response cycle is completed, the stream is closed, and other streams may be opened. Differently from HTTP, though, multiple SPDY streams may be opened concurrently on the same SPDY session.
Like Session
, Stream
is the
active part and by calling its API applications can generate events on the stream; conversely, StreamFrameListener
is the passive part, and its callbacks are invoked when events happen on the stream.
A
Stream
can send multiple data frames one after the other but implementations use a flow control mechanism
that only sends the data frames if the other end has signalled that it can accept the frame.
Data frames should be sent sequentially only when the previous frame has been completely sent. The reason for this requirement is to avoid potentially confusing code such as:
// WRONG CODE, DO NOT USE IT final Stream stream = ...; stream.data(StringDataInfo("chunk1", false), 5, TimeUnit.SECONDS, new Handler<Void>() { ... }); stream.data(StringDataInfo("chunk2", true), 1, TimeUnit.SECONDS, new Handler<Void>() { ... });
where the second call to data(DataInfo, Callback)
has a timeout smaller than the previous call.
The behavior of such style of invocations is unspecified (it may even throw an exception - similar to WritePendingException
).
The correct sending of data frames is the following:
final Stream stream = ...; ... // Blocking version stream.data(new StringDataInfo("chunk1", false)).get(1, TimeUnit.SECONDS); stream.data(new StringDataInfo("chunk2", true)).get(1, TimeUnit.SECONDS); // Asynchronous version stream.data(new StringDataInfo("chunk1", false), 1, TimeUnit.SECONDS, new Handler.Adapter<Void>() { public void completed(Void context) { stream.data(new StringDataInfo("chunk2", true)); } });
StreamFrameListener
Modifier and Type | Method and Description |
---|---|
void |
data(DataInfo dataInfo)
Sends asynchronously a DATA frame on this stream.
|
void |
data(DataInfo dataInfo,
Callback callback)
Sends asynchronously a DATA frame on this stream.
|
Stream |
getAssociatedStream() |
Object |
getAttribute(String key) |
int |
getId() |
long |
getIdleTimeout()
Get the idle timeout set for this particular stream
|
byte |
getPriority() |
Set<Stream> |
getPushedStreams() |
Session |
getSession() |
void |
headers(HeadersInfo headersInfo)
Sends asynchronously a HEADER frame on this stream.
|
void |
headers(HeadersInfo headersInfo,
Callback callback)
Sends asynchronously a HEADER frame on this stream.
|
boolean |
isClosed() |
boolean |
isHalfClosed() |
boolean |
isReset() |
boolean |
isUnidirectional() |
Stream |
push(PushInfo pushInfo)
Initiate a unidirectional spdy pushstream associated to this stream asynchronously
|
void |
push(PushInfo pushInfo,
Promise<Stream> promise)
Initiate a unidirectional spdy pushstream associated to this stream asynchronously
|
Object |
removeAttribute(String key) |
void |
reply(ReplyInfo replyInfo)
Sends asynchronously a SYN_REPLY frame in response to a SYN_STREAM frame.
|
void |
reply(ReplyInfo replyInfo,
Callback callback)
Sends asynchronously a SYN_REPLY frame in response to a SYN_STREAM frame.
|
void |
setAttribute(String key,
Object value) |
void |
setIdleTimeout(long timeout)
Set an idle timeout for this stream
|
int getId()
byte getPriority()
Session getSession()
Stream push(PushInfo pushInfo) throws InterruptedException, ExecutionException, TimeoutException
Initiate a unidirectional spdy pushstream associated to this stream asynchronously
Callers may use the returned future to get the pushstream once it got created
pushInfo
- the metadata to send on stream creationInterruptedException
ExecutionException
TimeoutException
push(PushInfo, Promise)
void push(PushInfo pushInfo, Promise<Stream> promise)
Initiate a unidirectional spdy pushstream associated to this stream asynchronously
Callers may pass a non-null completion promise to be notified of when the pushstream has been established.
pushInfo
- the metadata to send on stream creationpromise
- the completion promise that gets notified once the pushstream is establishedpush(PushInfo)
void reply(ReplyInfo replyInfo) throws InterruptedException, ExecutionException, TimeoutException
Sends asynchronously a SYN_REPLY frame in response to a SYN_STREAM frame.
Callers may use the returned future to wait for the reply to be actually sent.
replyInfo
- the metadata to sendInterruptedException
ExecutionException
TimeoutException
reply(ReplyInfo, Callback)
,
SessionFrameListener.onSyn(Stream, SynInfo)
void reply(ReplyInfo replyInfo, Callback callback)
Sends asynchronously a SYN_REPLY frame in response to a SYN_STREAM frame.
Callers may pass a non-null completion callback to be notified of when the reply has been actually sent.
replyInfo
- the metadata to sendcallback
- the completion callback that gets notified of reply sentreply(ReplyInfo)
void data(DataInfo dataInfo) throws InterruptedException, ExecutionException, TimeoutException
Sends asynchronously a DATA frame on this stream.
DATA frames should always be sent after a SYN_REPLY frame.
Callers may use the returned future to wait for the data to be actually sent.
dataInfo
- the metadata to sendInterruptedException
ExecutionException
TimeoutException
data(DataInfo, Callback)
,
reply(ReplyInfo)
void data(DataInfo dataInfo, Callback callback)
Sends asynchronously a DATA frame on this stream.
DATA frames should always be sent after a SYN_REPLY frame.
Callers may pass a non-null completion callback to be notified of when the data has been actually sent.
dataInfo
- the metadata to sendcallback
- the completion callback that gets notified of data sentdata(DataInfo)
void headers(HeadersInfo headersInfo) throws InterruptedException, ExecutionException, TimeoutException
Sends asynchronously a HEADER frame on this stream.
HEADERS frames should always be sent after a SYN_REPLY frame.
Callers may use the returned future to wait for the headers to be actually sent.
headersInfo
- the metadata to sendInterruptedException
ExecutionException
TimeoutException
headers(HeadersInfo, Callback)
,
reply(ReplyInfo)
void headers(HeadersInfo headersInfo, Callback callback)
Sends asynchronously a HEADER frame on this stream.
HEADERS frames should always be sent after a SYN_REPLY frame.
Callers may pass a non-null completion callback to be notified of when the headers have been actually sent.
headersInfo
- the metadata to sendcallback
- the completion callback that gets notified of headers sentheaders(HeadersInfo)
boolean isUnidirectional()
boolean isReset()
boolean isClosed()
isHalfClosed()
boolean isHalfClosed()
isClosed()
Object getAttribute(String key)
key
- the attribute keysetAttribute(String, Object)
void setAttribute(String key, Object value)
key
- the attribute keyvalue
- an arbitrary object to associate with the given key to this streamgetAttribute(String)
,
removeAttribute(String)
Object removeAttribute(String key)
key
- the attribute keysetAttribute(String, Object)
Stream getAssociatedStream()
Set<Stream> getPushedStreams()
long getIdleTimeout()
void setIdleTimeout(long timeout)
timeout
- Copyright © 1995-2015 Webtide. All Rights Reserved.