Called by the channel below us when a read has completed.

@param vc
@param req
339275
public void complete(VirtualConnection vc, TCPReadRequestContext req) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "complete() called: vc=" + vc);
        }
        HttpOutboundServiceContextImpl mySC = (HttpOutboundServiceContextImpl) vc.getStateMap().get(CallbackIDs.CALLBACK_HTTPOSC);
        // keep reading and handling new data until either we're done
        // parsing headers or until we're waiting on a read to finish
        VirtualConnection readVC = null;
        try {
            do {
                if (mySC.parseMessage()) {
                    // start processing the new parsed message
                    mySC.handleParsedMessage();
                    return;
                }
                // not done parsing, read for more data
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Reading for more data");
                }
                // configure the buffers for reading
                mySC.setupReadBuffers(mySC.getHttpConfig().getIncomingHdrBufferSize(), false);
                readVC = req.read(1, this, false, mySC.getReadTimeout());
            } while (null != readVC);
        } catch (Exception e) {
            FFDCFilter.processException(e, getClass().getName() + ".complete", "112", this);
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Caught exception: " + e.getMessage());
            }
            mySC.setPersistent(false);
            mySC.getAppWriteCallback().error(vc, e);
        }
    }
258833
public void setCompletedRequestCallback(ICompletedRequestCallback callback) {
		RequestWriter requestWriter = (RequestWriter) m_connection.getTraceWriter();
		requestWriter.getRequestSeparator().setCompletedRequestCallback(callback);
	}
367951
public void error(VirtualConnection vc, TCPReadRequestContext rsc, IOException ioe) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "error() called: vc=" + vc + " ioe=" + ioe);
        }
        HttpOutboundServiceContextImpl mySC = (HttpOutboundServiceContextImpl) vc.getStateMap().get(CallbackIDs.CALLBACK_HTTPOSC);

        // Reading a body from an HTTP/1.0 server that closes the connection
        // after completely sending the body will trigger an IOException here.
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Socket closure, signaling close.");
        }
        // only valid if this response is a non-length delimited body
        // otherwise pass the exception up to the application channel

        // PK18799 - check the stored SC values instead of msg as Proxy may
        // change it on the fly
        if (!mySC.isChunkedEncoding() && !mySC.isContentLength()) {
            mySC.prepareClosure();
            mySC.getAppReadCallback().complete(vc);
        } else {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "IOException during body read");
            }
            mySC.setPersistent(false);
            mySC.getAppReadCallback().error(vc, ioe);
        }
    }
863750
@Override
    public void complete(VirtualConnection vc) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())    
            Tr.debug(tc, "complete callback called , WriteListener enabled: " + this._wl); 


        synchronized(_hout) {
            if (null == vc) {
                return;
            }
            if (_hout.getExceptionDuringOnWP()){
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())    
                    Tr.debug(tc, "earlier exception happened, onError was called , WriteListener enabled: " + this._wl); 
                _hout.setExceptionDuringOnWP(false);
                return;
            }
            //clean up any request state we had on this thread.
            WebContainerRequestState reqState = WebContainerRequestState.getInstance(true);                 
            reqState.init();

            try {                    
                _hout.writeRemainingToBuffers();
            } catch (Exception ex) {
                //Print exception
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
                    Tr.debug(tc, "Exception during writeRemainingToBuffers : " + ex);
                }
                this.error(vc, ex);
                return;
            }

            // everything must be written now , 
            if (_hout.get_internalReady()) {
                // this case will only be true if write which went aysnc was from println, now we have to write crlf
                if(_hout.write_crlf_pending){
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())    
                        Tr.debug(tc, "ready to write CRLF bytes  , WriteListener enabled: " + this._wl); 
                    try {                    
                        //_hout.set_internalReady(true); // since CRLF needs to be written we are still not external ready
                        reqState.setAttribute("com.ibm.ws.webcontainer.WriteAllowedonThisThread", true);        
                        reqState.setAttribute("com.ibm.ws.webcontainer.CRLFWriteinPorgress", true);                            
                        _out.writeCRLFIfNeeded();
                    } catch (IOException e) {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
                            Tr.debug(tc, "Exception during write CRLF bytes: " + e);
                        }
                        _hout.write_crlf_pending = false;
                        this.error(vc, e);                       
                        return;
                    }                   
                }
            }
            if (_hout.get_internalReady()) {
                synchronized(_hout._writeReadyLockObj){   

                    //Setting isReady to true since a complete call means data is written out                      
                    WebContainerRequestState.getInstance(true).setAttribute("com.ibm.ws.webcontainer.WriteAllowedonThisThread", true);
                    _hout.setWriteReady(true);
                }
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
                    Tr.debug(tc, "WriteListener enabled: " + this._wl + " , status_not_ready_checked -->" + _hout.status_not_ready_checked);
                }
                if( _hout.status_not_ready_checked) {                                       
                    try{
                        _hout.status_not_ready_checked = false;
                        
                        SRTServletRequestThreadData.getInstance().init(_requestDataAsyncWriteCallbackThread);
                        
                        //Push the original thread's context onto the current thread, also save off the current thread's context
                        tcm.pushContextData();
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
                            Tr.debug(tc, "WriteListener enabled: " + this._wl + " , call onWritePossible.");
                        }
                        //Call into the user's WriteListener to indicate more data cane be written
                        _wl.onWritePossible();

                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
                            Tr.debug(tc, "WriteListener enabled: " + this._wl + " , returned from onWritePossible.");
                        }
                    } catch (Exception ex) {
                        //Print exception
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
                            Tr.debug(tc, "Exception during onWritePossible : " + ex);
                        }
                        this.error(vc, ex);    
                    }
                    finally{
                        //Revert back to the thread's current context
                        tcm.popContextData();
                    }
                }
                else{
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
                        Tr.debug(tc, "WriteListener enabled: " + this._wl + " , onWritePossible will be skipped as isReady has not been checked since write has gone async");
                    }
                }
            }
        }


    }
111841
public void onOperationCompleted(String clientId, String conversationId, int requestId,
                                   Conversation.AVIMOperation operation, Throwable throwable) {
    if (AVIMOperation.CONVERSATION_QUERY == operation) {
      AVCallback callback = RequestCache.getInstance().getRequestCallback(clientId, null, requestId);
      if (null != callback) {
        // internal query conversation.
        callback.internalDone(null, AVIMException.wrapperAVException(throwable));
        RequestCache.getInstance().cleanRequestCallback(clientId, null, requestId);
        return;
      }
    }
    IntentUtil.sendIMLocalBroadcast(clientId, conversationId, requestId, throwable, operation);
  }
1220380
public void requestDone() {
        currentRequest = null;

        if (anyAreSet(state, CLOSE_REQ)) {
            safeClose(connection);
        } else if (anyAreSet(state, UPGRADE_REQUESTED)) {
            safeClose(connection); //we don't support upgrade, just close the connection to be safe
            return;
        }

        AjpClientExchange next = pendingQueue.poll();

        if (next != null) {
            initiateRequest(next);
        }
    }
265012
@Override
    public final void channelRead(final ChannelHandlerContext ctx, final Object msg) {
        try {
            JNRPERequest req = (JNRPERequest) msg;

            ReturnValue ret = commandInvoker.invoke(req.getCommand(), req.getArguments());

            JNRPEResponse res = new JNRPEResponse();
            res.setResult(ret.getStatus().intValue(), ret.getMessage());

            ChannelFuture channelFuture = ctx.writeAndFlush(res);
            channelFuture.addListener(ChannelFutureListener.CLOSE);
        } catch ( RuntimeException re ) {
            re.printStackTrace();
        } finally {
            ReferenceCountUtil.release(msg);
        }
    }
216669
public void requestCompleted (T result)
    {
        if (_chain != null) {
            _chain.requestCompleted(result);

        } else if (_invChain instanceof InvocationService.ResultListener) {
            ((InvocationService.ResultListener)_invChain).requestProcessed(result);

        } else if (_invChain instanceof InvocationService.ConfirmListener) {
            ((InvocationService.ConfirmListener)_invChain).requestProcessed();
        }
    }
560596
public static void if_keepAliveRequest_then_resumeReading_else_closeOnComplete(
            final HttpRequest request, final Channel channel, final ChannelFuture channelFuture
    ) {
        // TODO:
        // Add Connection: Close, or Keep-Alive?
        // res.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
        if (HttpUtil.isKeepAlive(request)) {
            channelFuture.addListener(new ChannelFutureListener() {
                public void operationComplete(ChannelFuture future) {
                    resumeReading(channel);
                }
            });
        } else {
            channelFuture.addListener(ChannelFutureListener.CLOSE);
        }
    }
923021
public void initialRead() {
        try {
            this.buffer = this.isc.getRequestBodyBuffer();
            if (null != this.buffer) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Buffer returned from getRequestBodyBuffer : " + this.buffer);
                }
                // record the new amount of data read from the channel
                this.bytesRead += this.buffer.remaining();
            }
        } catch (IOException e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Exception encountered during initialRead : " + e);
            }
        }
    }
280355
protected void readProxyResponse(VirtualConnection inVC) {

        int size = 1;
        if (!this.isProxyResponseValid) {
            // we need at least 12 bytes for the first line
            size = 12;
        }
        if (connLink.isAsyncConnect()) {
            VirtualConnection vcRC = connLink.getReadInterface().read(size, this.proxyReadCB, false, TCPRequestContext.USE_CHANNEL_TIMEOUT);
            if (null != vcRC) {
                this.proxyReadCB.complete(vcRC, connLink.getReadInterface());
            }
        } else {
            try {
                connLink.getReadInterface().read(size, TCPRequestContext.USE_CHANNEL_TIMEOUT);
            } catch (IOException x) {
                // no FFDC required
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "could not complete proxy handshake, read request failed");
                }
                releaseProxyReadBuffer();
                connLink.connectFailed(x);
            }
        }
    }
764197
@Override
    protected boolean performRequest() {
        VirtualConnection vci = null;
        boolean completeOperation = true;
        TCPBaseRequestContext req = null;
        SelectionKey selectedKey = null;

        // If we were woken up because we have work to do, do it.
        Set<SelectionKey> keySet = selector.selectedKeys();
        Iterator<SelectionKey> selectedIterator = keySet.iterator();
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(this, tc, "performRequest - processing " + keySet.size() + " items");
        }
        while (selectedIterator.hasNext()) {
            selectedKey = selectedIterator.next();
            // safely remove from set while looping
            selectedIterator.remove();
            req = (TCPBaseRequestContext) selectedKey.attachment();
            vci = req.getTCPConnLink().getVirtualConnection();
            completeOperation = true;

            // looking at the vci is messy here, but we're doing the try, catch
            // to save synchronization logic. vci could be null if connection
            // is closing before we can asked to request permission to finish
            // the read.
            if (vci == null) {
                completeOperation = false;
            } else {
                // only check if operation was an async read/write request
                if (vci.isInputStateTrackingOperational() && !req.blockedThread) {
                    completeOperation = false;
                    if (req.isRequestTypeRead()) {
                        if (vci.requestPermissionToFinishRead()) {
                            completeOperation = true;
                        }
                    } else {
                        if (vci.requestPermissionToFinishWrite()) {
                            completeOperation = true;
                        }
                    }
                }
            }

            if (completeOperation) {
                // try to dispatch request. if it fails, just leave key alone,
                // and it should get selected and tried again the next time through
                // the selector.
                if (wqm.dispatch(req, null)) {
                    // Dispatch worked, so set key's interest set to empty, so it isn't
                    // re-selected
                    // until the user asks us to do more work.
                    try {
                        selectedKey.interestOps(0);
                    } catch (CancelledKeyException cke) {
                        // ignore, since we already got the key and the data
                    }
                }
            } else {
                // permission denied, assume close has been processed on this VC
                // therefore disregard this read.
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                    Tr.event(this, tc, "IO cancelled on closed key " + selectedKey);
                }
                try {
                    selectedKey.interestOps(0);
                } catch (CancelledKeyException cke) {
                    // ignore, since the vc is closed/ing
                }
            }
        }

        return false;
    }
842155
@Override
    public void error(VirtualConnection vc, Throwable t) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())    
            Tr.debug(tc, "error callback called , WriteListener enabled: " + this._wl); 

        // reset the reqState
        WebContainerRequestState reqState = WebContainerRequestState.getInstance(true);                         
        reqState.init();  

        synchronized(_hout._writeReadyLockObj){
            // Make sure the ready is set to true before calling onError
            _hout.set_internalReady(true);            
            _hout.setWriteReady(true);   
            reqState.setAttribute("com.ibm.ws.webcontainer.AllowWriteFromE", true); 
            reqState.setAttribute("com.ibm.ws.webcontainer.WriteAllowedonThisThread", true);
        }
        
        SRTServletRequestThreadData.getInstance().init(_requestDataAsyncWriteCallbackThread);
        
        //Push the original thread's context onto the current thread, also save off the current thread's context
        tcm.pushContextData();

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
            Tr.debug(tc, "WriteListener enabled: " + this._wl +" , calling user's onError : " + vc );            
        }       
        try{  
            synchronized(_hout) {
                //An error occurred. Issue the onError call on the user's WriteListener
                _wl.onError(t);
            }
            
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
                Tr.debug(tc, "WriteListener enabled: " + this._wl +" , returned from user's onError : " + vc );            
            }  
        } catch (Exception e) {
             
            Tr.error(tc, "writeListener.onError.failed", new Object[] {this._wl, e.toString()});
            
        }
        finally{

            tcm.popContextData();//Revert back to the thread's current context

            reqState.removeAttribute("com.ibm.ws.webcontainer.AllowWriteFromE");
        }
    }
1332059
private void notifyListenersAfterRequest(ModbusRequest req) {
        synchronized (listeners) {
            for (AbstractSerialTransportListener listener : listeners) {
                listener.afterRequestRead(commPort, req);
            }
        }
    }
294767
@Override
    @FFDCIgnore(IOException.class)
    public void complete(VirtualConnection vc) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "complete",  vc);
        }
        synchronized( this.in.getCompleteLockObj()){
            
            SRTServletRequestThreadData.getInstance().init(_requestDataAsyncReadCallbackThread);
            
            //Push the original thread's context onto the current thread, also save off the current thread's context
            this.threadContextManager.pushContextData();

            //Call into the user's ReadListener to indicate there is data available
            try{
                if (!in.isFinished()) {
                    this.in.getReadListener().onDataAvailable();
                }   
            } catch (Throwable onDataAvailableException){
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Exception occurred during ReadListener.onDataAvailable : " + onDataAvailableException + ", " + this.in.getReadListener());
                }
                this.threadContextManager.popContextData();
                error(vc, onDataAvailableException);
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                    Tr.exit(tc, "complete");
                }
                return;
            }

            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                 Tr.debug(tc, "Message is fully read, calling ReadListener onAllDataRead : " + this.in.getReadListener());
            }
            
            if(this.in.getReadListener() != null){
                // if all the data has been read we are done.
                if (in.isFinished()) {
                    try{
                        this.in.getReadListener().onAllDataRead();
                    } catch (Throwable onAllDataReadException){
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "Exception occurred during ReadListener.onAllDataRead : " + onAllDataReadException + ", " + this.in.getReadListener());
                        }
                        this.threadContextManager.popContextData();
                        error(vc, onAllDataReadException);
                        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                            Tr.exit(tc, "complete");
                        }
                        return;
                    }
                } else if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "onDataAavailabe returned without reading all data. Read Listener will no be called again : "  + this.in.getReadListener());
                }
                else{
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "ReadListener is not set , stream must be closed, cannot call onAllDataRead()");
                    }
                }
            }
            
            //Revert back to the thread's current context
            this.threadContextManager.popContextData();

        }
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "complete");
        }
    }
1010638
private void onRstStreamRead(int streamId, long errorCode) {
    NettyClientStream.TransportState stream = clientStream(connection().stream(streamId));
    if (stream != null) {
      Status status = GrpcUtil.Http2Error.statusForCode((int) errorCode)
          .augmentDescription("Received Rst Stream");
      stream.transportReportStatus(
          status,
          errorCode == Http2Error.REFUSED_STREAM.code()
              ? RpcProgress.REFUSED : RpcProgress.PROCESSED,
          false /*stop delivery*/,
          new Metadata());
      if (keepAliveManager != null) {
        keepAliveManager.onDataReceived();
      }
    }
  }
436459
void afterRead(Node<K, V> node, long now, boolean recordHit) {
    if (recordHit) {
      statsCounter().recordHits(1);
    }

    boolean delayable = skipReadBuffer() || (readBuffer.offer(node) != Buffer.FULL);
    if (shouldDrainBuffers(delayable)) {
      scheduleDrainBuffers();
    }
    refreshIfNeeded(node, now);
  }