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, long, TimeUnit, Handler)
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 |
---|---|
Future<Void> |
data(DataInfo dataInfo)
Sends asynchronously a DATA frame on this stream.
|
void |
data(DataInfo dataInfo,
long timeout,
TimeUnit unit,
Handler<Void> handler)
Sends asynchronously a DATA frame on this stream.
|
Stream |
getAssociatedStream() |
Object |
getAttribute(String key) |
int |
getId() |
byte |
getPriority() |
Set<Stream> |
getPushedStreams() |
Session |
getSession() |
Future<Void> |
headers(HeadersInfo headersInfo)
Sends asynchronously a HEADER frame on this stream.
|
void |
headers(HeadersInfo headersInfo,
long timeout,
TimeUnit unit,
Handler<Void> handler)
Sends asynchronously a HEADER frame on this stream.
|
boolean |
isClosed() |
boolean |
isHalfClosed() |
boolean |
isReset() |
boolean |
isUnidirectional() |
Object |
removeAttribute(String key) |
Future<Void> |
reply(ReplyInfo replyInfo)
Sends asynchronously a SYN_REPLY frame in response to a SYN_STREAM frame.
|
void |
reply(ReplyInfo replyInfo,
long timeout,
TimeUnit unit,
Handler<Void> handler)
Sends asynchronously a SYN_REPLY frame in response to a SYN_STREAM frame.
|
void |
setAttribute(String key,
Object value) |
Future<Stream> |
syn(SynInfo synInfo)
Initiate a unidirectional spdy pushstream associated to this stream asynchronously
|
void |
syn(SynInfo synInfo,
long timeout,
TimeUnit unit,
Handler<Stream> handler)
Initiate a unidirectional spdy pushstream associated to this stream asynchronously
|
int getId()
byte getPriority()
Session getSession()
Future<Stream> syn(SynInfo synInfo)
Initiate a unidirectional spdy pushstream associated to this stream asynchronously
Callers may use the returned future to get the pushstream once it got created
synInfo
- the metadata to send on stream creationsyn(SynInfo, long, TimeUnit, Handler)
void syn(SynInfo synInfo, long timeout, TimeUnit unit, Handler<Stream> handler)
Initiate a unidirectional spdy pushstream associated to this stream asynchronously
Callers may pass a non-null completion handler to be notified of when the pushstream has been established.
synInfo
- the metadata to send on stream creationtimeout
- the operation's timeoutunit
- the timeout's unithandler
- the completion handler that gets notified once the pushstream is establishedsyn(SynInfo)
Future<Void> reply(ReplyInfo replyInfo)
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 sendreply(ReplyInfo, long, TimeUnit, Handler)
,
SessionFrameListener.onSyn(Stream, SynInfo)
void reply(ReplyInfo replyInfo, long timeout, TimeUnit unit, Handler<Void> handler)
Sends asynchronously a SYN_REPLY frame in response to a SYN_STREAM frame.
Callers may pass a non-null completion handler to be notified of when the reply has been actually sent.
replyInfo
- the metadata to sendtimeout
- the operation's timeoutunit
- the timeout's unithandler
- the completion handler that gets notified of reply sentreply(ReplyInfo)
Future<Void> data(DataInfo dataInfo)
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 senddata(DataInfo, long, TimeUnit, Handler)
,
reply(ReplyInfo)
void data(DataInfo dataInfo, long timeout, TimeUnit unit, Handler<Void> handler)
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 handler to be notified of when the data has been actually sent.
dataInfo
- the metadata to sendtimeout
- the operation's timeoutunit
- the timeout's unithandler
- the completion handler that gets notified of data sentdata(DataInfo)
Future<Void> headers(HeadersInfo headersInfo)
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 sendheaders(HeadersInfo, long, TimeUnit, Handler)
,
reply(ReplyInfo)
void headers(HeadersInfo headersInfo, long timeout, TimeUnit unit, Handler<Void> handler)
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 handler to be notified of when the headers have been actually sent.
headersInfo
- the metadata to sendtimeout
- the operation's timeoutunit
- the timeout's unithandler
- the completion handler 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()
Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.