private boolean processSelection(SelectionKey selection) { assert isRead(selection) : "only expected read"; final SocketChannel socketChannel = (SocketChannel)selection.channel(); //get the context object so we know what the channel identifier is ConnectionContext connectionContext = (ConnectionContext)selection.attachment(); long channelId = connectionContext.getChannelId(); assert(channelId>=0); //logger.info("\nnew key selection in reader for connection {}",channelId); return processConnection(selection, socketChannel, channelId, coordinator.lookupConnectionById(channelId)); }
private int sendError(TrieParserReader trieReader, final long channel, final int idx, int tempLen, int tempPos) { ////////////////////////////////////////////////////////////////// //did not pass validation so we return 404 without giving any clues why ////////////////////////////////////////////////////////////////// sendError(trieReader, channel, idx, tempLen, tempPos, 404); trieReader.sourceLen = 0; trieReader.sourcePos = 0; BaseConnection con = coordinator.lookupConnectionById(channel); if (null!=con) { con.clearPoolReservation(); } return SUCCESS; }
private void badVerbParse(TrieParserReader trieReader, final long channel, final int idx, int tempLen, int tempPos) { //trieReader.debugAsUTF8(trieReader, System.out); logger.trace("bad HTTP data recieved by server, channel will be closed. Bytes abandoned:{} looking for verb at {} ",tempLen, tempPos); sendError(trieReader, channel, idx, tempLen, tempPos, 400); //we have bad data we have been sent, there is enough data yet the verb was not found final boolean debug = false; if(debug) { trieReader.sourceLen = tempLen; trieReader.sourcePos = tempPos; logger.warn("error at position: {} length: {}",trieReader.sourcePos, trieReader.sourceLen); StringBuilder builder = new StringBuilder(); TrieParserReader.debugAsUTF8(trieReader, builder, config.verbMap.longestKnown()*2); logger.warn("{} looking for verb but found:\n{} at position {} \n\n",channel,builder,tempPos); } trieReader.sourceLen = 0; trieReader.sourcePos = 0; BaseConnection con = coordinator.lookupConnectionById(channel); if (null!=con) { con.clearPoolReservation(); } //logger.info("success"); }
private int abandonConnection(long channelId, Pipe<NetPayloadSchema> targetPipe, boolean isOpen, boolean newBeginning) { //logger.info("{} abandon one record, did not publish because length was {} {}",System.currentTimeMillis(), len,targetPipe); Pipe.unstoreBlobWorkingHeadPosition(targetPipe);//we did not use or need the writing buffers above. if (isOpen && newBeginning) { //Gatling does this a lot, TODO: we should optimize this case. //we will abandon but we also must release the reservation because it was never used responsePipeLinePool.release(channelId); BaseConnection conn = coordinator.lookupConnectionById(channelId); if (null!=conn) { conn.clearPoolReservation(); } // logger.info("client is sending zero bytes, ZERO LENGTH RELESE OF UNUSED PIPE FOR {}", channelId); } return 1;//yes we are done }
void sendError(TrieParserReader trieReader, final long channel, final int idx, int tempLen, int tempPos, int errorCode) { BaseConnection con = coordinator.lookupConnectionById(channel); boolean sent = sendError(channel, idx, errorCode); if (sent) {
private void releaseIfUnused(int id, long idToClear, long pos, int seq) { if (idToClear<0) { throw new UnsupportedOperationException(); } int pipeIdx = PoolIdx.getIfReserved(responsePipeLinePool,idToClear); //if we can not look it up then we can not release it? /////////////////////////////////////////////////// //if sent tail matches the current head then this pipe has nothing in flight and can be re-assigned if (pipeIdx>=0 && (Pipe.headPosition(output[pipeIdx]) == pos)) { // logger.info("NEW RELEASE for pipe {} connection {} at pos {}",pipeIdx, idToClear, pos); responsePipeLinePool.release(idToClear); assert( 0 == Pipe.releasePendingByteCount(output[pipeIdx])); if (id == ReleaseSchema.MSG_RELEASEWITHSEQ_101) { BaseConnection conn = coordinator.lookupConnectionById(idToClear); if (null!=conn) { conn.setSequenceNo(seq);//only set when we release a pipe conn.clearPoolReservation(); } } } }
trieReader.sourcePos = 0; BaseConnection con = coordinator.lookupConnectionById(channel); if (null!=con) { con.clearPoolReservation();
long connectionId = Pipe.takeLong(selectedInput); BaseConnection con = that.coordinator.lookupConnectionById(connectionId); if (null!=con) { if (con instanceof ClientConnection) {
ServerConnection serverCon = coordinator.<ServerConnection>lookupConnectionById(channel);