use of io.grpc.okhttp.internal.framed.FrameWriter in project grpc-java by grpc.
the class OkHttpClientTransport method start.
@Override
public Runnable start(Listener listener) {
this.listener = Preconditions.checkNotNull(listener, "listener");
if (enableKeepAlive) {
scheduler = SharedResourceHolder.get(TIMER_SERVICE);
keepAliveManager = new KeepAliveManager(this, scheduler, keepAliveDelayNanos, keepAliveTimeoutNanos, false);
keepAliveManager.onTransportStarted();
}
frameWriter = new AsyncFrameWriter(this, serializingExecutor);
outboundFlow = new OutboundFlowController(this, frameWriter);
// Connecting in the serializingExecutor, so that some stream operations like synStream
// will be executed after connected.
serializingExecutor.execute(new Runnable() {
@Override
public void run() {
if (isForTest()) {
if (connectingCallback != null) {
connectingCallback.run();
}
clientFrameHandler = new ClientFrameHandler(testFrameReader);
executor.execute(clientFrameHandler);
synchronized (lock) {
maxConcurrentStreams = Integer.MAX_VALUE;
startPendingStreams();
}
frameWriter.becomeConnected(testFrameWriter, socket);
connectedFuture.set(null);
return;
}
// Use closed source on failure so that the reader immediately shuts down.
BufferedSource source = Okio.buffer(new Source() {
@Override
public long read(Buffer sink, long byteCount) {
return -1;
}
@Override
public Timeout timeout() {
return Timeout.NONE;
}
@Override
public void close() {
}
});
Variant variant = new Http2();
BufferedSink sink;
Socket sock;
try {
if (proxyAddress == null) {
sock = new Socket(address.getAddress(), address.getPort());
} else {
sock = createHttpProxySocket(address, proxyAddress, proxyUsername, proxyPassword);
}
if (sslSocketFactory != null) {
sock = OkHttpTlsUpgrader.upgrade(sslSocketFactory, sock, getOverridenHost(), getOverridenPort(), connectionSpec);
}
sock.setTcpNoDelay(true);
source = Okio.buffer(Okio.source(sock));
sink = Okio.buffer(Okio.sink(sock));
} catch (StatusException e) {
startGoAway(0, ErrorCode.INTERNAL_ERROR, e.getStatus());
return;
} catch (Exception e) {
onException(e);
return;
} finally {
clientFrameHandler = new ClientFrameHandler(variant.newReader(source, true));
executor.execute(clientFrameHandler);
}
FrameWriter rawFrameWriter;
synchronized (lock) {
socket = sock;
maxConcurrentStreams = Integer.MAX_VALUE;
startPendingStreams();
}
rawFrameWriter = variant.newWriter(sink, true);
frameWriter.becomeConnected(rawFrameWriter, socket);
try {
// Do these with the raw FrameWriter, so that they will be done in this thread,
// and before any possible pending stream operations.
rawFrameWriter.connectionPreface();
Settings settings = new Settings();
rawFrameWriter.settings(settings);
} catch (Exception e) {
onException(e);
return;
}
}
});
return null;
}
Aggregations