use of com.ociweb.pronghorn.pipe.PipeUTF8MutableCharSquence in project GreenLightning by oci-pronghorn.
the class HTTPClientRequestTrafficStage method hasOpenConnection.
// has side effect of storing the active connection as a member so it need not be looked up again later.
public boolean hasOpenConnection(Pipe<ClientHTTPRequestSchema> requestPipe, Pipe<NetPayloadSchema>[] output, ClientCoordinator ccm, int activePipe) {
if (PipeReader.peekMsg(requestPipe, -1)) {
return com.ociweb.pronghorn.network.http.HTTPClientRequestStage.hasRoomForEOF(output);
}
final int msgIdx = PipeReader.peekInt(requestPipe, 0);
// these fields are assumed to be the same for all mesage types.
int hostMeta = PipeReader.peekDataMeta(requestPipe, ClientHTTPRequestSchema.MSG_HTTPGET_100_FIELD_HOST_2);
int hostLen = PipeReader.peekDataLength(requestPipe, ClientHTTPRequestSchema.MSG_HTTPGET_100_FIELD_HOST_2);
int port = PipeReader.peekInt(requestPipe, ClientHTTPRequestSchema.MSG_HTTPGET_100_FIELD_PORT_1);
int sessionId = PipeReader.peekInt(requestPipe, ClientHTTPRequestSchema.MSG_HTTPGET_100_FIELD_SESSION_10);
PipeUTF8MutableCharSquence mCharSeq = mCharSequence.setToField(requestPipe, hostMeta, hostLen);
long connectionId;
if (ClientHTTPRequestSchema.MSG_FASTHTTPGET_200 == msgIdx) {
connectionId = PipeReader.peekLong(requestPipe, ClientHTTPRequestSchema.MSG_FASTHTTPGET_200_FIELD_CONNECTIONID_20);
// assert(connectionId == ccm.lookup(mCharSeq, port, sessionId));
} else {
connectionId = ccm.lookup(ClientCoordinator.lookupHostId((CharSequence) mCharSeq, READER), port, sessionId);
}
ClientConnection activeConnection = ClientCoordinator.openConnection(ccm, mCharSeq, port, sessionId, output, connectionId, reader, ccf);
if (null != activeConnection) {
if (ccm.isTLS) {
// If this connection needs to complete a handshake first then do that and do not send the request content yet.
HandshakeStatus handshakeStatus = activeConnection.getEngine().getHandshakeStatus();
if (HandshakeStatus.FINISHED != handshakeStatus && HandshakeStatus.NOT_HANDSHAKING != handshakeStatus) {
activeConnection = null;
return false;
}
}
if (activeConnection.isDisconnecting()) {
if (ccm.isTLS) {
logger.info("Double check the client side certificates");
} else {
logger.info("Double check the server port to ensure it is open");
}
if (PipeReader.tryReadFragment(requestPipe)) {
// special case for connection which was closed, must abandon old data
// and allow trafic cop get back ack and not hang the system.
PipeReader.releaseReadLock(requestPipe);
decReleaseCount(activePipe);
}
return false;
}
} else {
// not yet open, this is not an error just an attempt to try again soon.
return false;
}
// this should be done AFTER any handshake logic
return PipeWriter.hasRoomForWrite(output[activeConnection.requestPipeLineIdx()]);
}
Aggregations