Class SpdyConnection
java.lang.Object
com.squareup.okhttp.internal.spdy.SpdyConnection
- All Implemented Interfaces:
Closeable,AutoCloseable
public final class SpdyConnection extends Object implements Closeable
A socket connection to a remote peer. A connection hosts streams which can
send and receive data.
Many methods in this API are synchronous: the call is completed before the method returns. This is typical for Java but atypical for SPDY. This is motivated by exception transparency: an IOException that was triggered by a certain caller can be caught and handled by that caller.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSpdyConnection.Builder -
Method Summary
Modifier and Type Method Description voidclose()Closes this connection.voidflush()longgetIdleStartTimeNs()Returns the time in ns when this connection became idle or 0L if connection is not idle.booleanisIdle()Returns true if this connection is idle.SpdyStreamnewStream(List<String> requestHeaders, boolean out, boolean in)Returns a new locally-initiated stream.voidnoop()Sends a noop frame to the peer.intopenStreamCount()Returns the number ofopen streamson this connection.Pingping()Sends a ping frame to the peer.voidshutdown(int statusCode)Degrades this connection such that new streams can neither be created locally, nor accepted from the remote peer.
-
Method Details
-
openStreamCount
public int openStreamCount()Returns the number ofopen streamson this connection. -
isIdle
public boolean isIdle()Returns true if this connection is idle. -
getIdleStartTimeNs
public long getIdleStartTimeNs()Returns the time in ns when this connection became idle or 0L if connection is not idle. -
newStream
public SpdyStream newStream(List<String> requestHeaders, boolean out, boolean in) throws IOExceptionReturns a new locally-initiated stream.- Parameters:
out- true to create an output stream that we can use to send data to the remote peer. Corresponds toFLAG_FIN.in- true to create an input stream that the remote peer can use to send data to us. Corresponds toFLAG_UNIDIRECTIONAL.- Throws:
IOException
-
ping
Sends a ping frame to the peer. Use the returned object to await the ping's response and observe its round trip time.- Throws:
IOException
-
noop
Sends a noop frame to the peer.- Throws:
IOException
-
flush
- Throws:
IOException
-
shutdown
Degrades this connection such that new streams can neither be created locally, nor accepted from the remote peer. Existing streams are not impacted. This is intended to permit an endpoint to gracefully stop accepting new requests without harming previously established streams.- Parameters:
statusCode- one ofGOAWAY_OK,GOAWAY_INTERNAL_ERRORorGOAWAY_PROTOCOL_ERROR.- Throws:
IOException
-
close
Closes this connection. This cancels all open streams and unanswered pings. It closes the underlying input and output streams and shuts down internal executor services.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-