Called by the next channel in the chain when an outstanding read request has completed
successfully.

@see TCPReadCompletedCallback#complete(VirtualConnection, TCPReadRequestContext)
547657
public void complete(NetworkConnection vc, IOReadRequestContext rctx)
   {	
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "complete", new Object[] {vc, rctx});
      if (thisConnection.isLoggingIOEvents()) thisConnection.getConnectionEventRecorder().logDebug("complete method invoked on read context "+System.identityHashCode(rctx));

      // First update the invocation count. If we are being called back on the same thread as
      // last time, increment the counter. Otherwise, start counting from 1 again.
      synchronized (invocationCountLock)
      {
         if (lastInvokedOnThread == Thread.currentThread())
         {
            invocationCount++;
         }
         else
         {
            invocationCount = 1;
            lastInvokedOnThread = Thread.currentThread();
         }
      }

      try
      {
         synchronized(this)
         {
            boolean done = false;
            do
            {
               done = true;
               WsByteBuffer contextBuffer = rctx.getBuffer();

               contextBuffer.flip();

               // Notify PMI that read has completed.
               if (conversation.getConversationType() == Conversation.CLIENT)
               {
                  xmitParser.setType(Conversation.CLIENT);
               }
               else if (conversation.getConversationType() == Conversation.ME)
               {
                  xmitParser.setType(Conversation.ME);
               }

               if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) JFapUtils.debugTraceWsByteBuffer(this, tc, contextBuffer, 16, "data received");

               xmitParser.parse(contextBuffer);

         		if ((rctx != null) && (!receivePhysicalCloseRequest))
         		{
                  // Calculate the amount of time before the request times out
                  // This is the mechanism by which we implement heartbeat
                  // intervals and time outs.
                  int timeout;
                  if (awaitingHeartbeatResponse.isSet())
                  {
                     // We can only reach this point in the code if we have
                     // made a heartbeat request but this callback was driven
                     // because of a non-heartbeat response.  In previous versions
                     // of the code we were careful to calculate the remaining time and
                     // make another read request.  This caused timeouts ala defect
                     // 363463.  So, now the code is more generous and resets its
                     // timer to the full heartbeat timeout value every time any
                     // non-heartbeat trasmission is received from our peer.  This isn't
                     // unreasonable as the fact we are receiving data indicates that the
                     // peer is probably still healthy.
                     timeout = currentHeartbeatTimeout*1000;
                     if (timeout < 1) timeout = 1;
                  }
                  else
                  {
                     // We are not awaiting a heartbeat response, use the
                     // heartbeat interval as our timeout.
                     timeout = thisConnection.getHeartbeatInterval()*1000;
                  }

                  if (timeout > 0)
                  {
                     if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "setting heartbeat timeout to: "+timeout+" milliseconds");
                  }
                  else
                  {
                     if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "not using a heartbeat timeout");
                     timeout = IOReadRequestContext.NO_TIMEOUT;
                  }

                  boolean closing = false;
                  synchronized(connectionClosingLock)
                  {
                     closing = connectionClosing;
                  }

                  //If the connection is closing/closed our buffers will have been released, so make sure we don't use them again.
                  if (!closing)
                  {
                     // Crude way to ensure we end up with the right sized read buffer.
                     if (isFirstCompleteInvocation)
                     {
                        int readBufferSize =
                           Integer.parseInt(RuntimeInfo.getProperty("com.ibm.ws.sib.jfapchannel.DEFAULT_READ_BUFFER_SIZE", ""+JFapChannelConstants.DEFAULT_READ_BUFFER_SIZE));
                        if (!contextBuffer.isDirect() || (contextBuffer.capacity() < readBufferSize))
                        {
                           //Make sure we release the other buffer so we don't leak memory.
                           contextBuffer.release();

                           contextBuffer = WsByteBufferPool.getInstance().allocateDirect(readBufferSize);
                           rctx.setBuffer(contextBuffer);
                        }
                        isFirstCompleteInvocation = false;
                     }

                     contextBuffer.clear();

                     // Decide whether to explictly request a thread switch. We'll do this if we
                     // have been recursively called more than MAX_INVOCATIONS_BEFORE_THREAD_SWITCH
                     boolean forceQueue = false;
                     synchronized (invocationCountLock)
                     {
                        if (invocationCount > MAX_INVOCATIONS_BEFORE_THREAD_SWITCH)
                        {
                           forceQueue = true;
                           lastInvokedOnThread = null;
                        }
                     }

                     if (thisConnection.isLoggingIOEvents()) thisConnection.getConnectionEventRecorder().logDebug("invoking readCtx.read() on context "+System.identityHashCode(rctx)+" with a timeout of "+timeout);
                     done = (rctx.read(1, this, forceQueue, timeout) == null);
                   
                  }
         		}
            }
            while(!done);
         }
      }
      catch(Error error)
      {
         FFDCFilter.processException
         (error, "com.ibm.ws.sib.jfapchannel.impl.ConnectionReadCompletedCallback", JFapChannelConstants.CONNREADCOMPCALLBACK_COMPLETE_01, thisConnection.getDiagnostics(true));
         if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) SibTr.exception(this, tc, error);

         // It might appear slightly odd for this code to catch Error (especially since the JDK docs say
         // that Error means that something has gone so badly wrong that you should abandon all hope).
         // This code makes one final stab at putting out some diagnostics about what happened (if we
         // propagate the Error up to the TCP Channel, it is sometimes lost) and closing down the
         // connection.  I figured that we might as well try to do something - as we can hardly make
         // things worse... (famous last words)

         thisConnection.invalidate(false, error, "Error caught in ConnectionReadCompletedCallback.complete()");

         // Re-throw the error to ensure that it causes the maximum devastation.
         // The JVM is probably very ill if an Error is thrown so attempt no recovery.
         throw error;
      }
      catch(RuntimeException runtimeException)
      {
         FFDCFilter.processException
         (runtimeException, "com.ibm.ws.sib.jfapchannel.impl.ConnectionReadCompletedCallback", JFapChannelConstants.CONNREADCOMPCALLBACK_COMPLETE_02, thisConnection.getDiagnostics(true));
         if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) SibTr.exception(this, tc, runtimeException);

         // We can reasonably try to recover from a runtime exception by invalidating the associated
         // connection.  This should drive the underlying TCP/IP socket to be closed.
         thisConnection.invalidate(false, runtimeException, "RuntimeException caught in ConnectionReadCompletedCallback.complete");

         // Don't throw the RuntimeException on as we risk blowing away part of the TCP channel.
      }

		if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "complete");
	}
350259
public synchronized void setComplete(boolean completed) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setComplete", completed);
        this.completed = completed;
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setComplete");
    }
98634
@Override
  public boolean complete()
  {
    OutputStream os = _os;
    _os = null;
    
    IoUtil.close(os);

    return true;
  }
658306
@Override
    public void afterCompletion(TransactionCommon transaction, boolean committed)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "afterCompletion", new Object[] { transaction, Boolean.valueOf(committed) });

        synchronized (this)
        {
            // If the connection is already closed this transaction
            // will have been removed.
            if (!_closed)
            {
                synchronized (_ownedTransactions)
                {
                    // Remove the transaction from the connections list
                    _ownedTransactions.remove(transaction);
                }
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "afterCompletion");
    }
303606
@Override
  public void onContainersCompleted(final List<ContainerStatus> completedContainers) {
    for (final ContainerStatus containerStatus : completedContainers) {
      this.onContainerStatus(containerStatus);
    }
  }
1002319
private boolean completeResponse(OperationResponse response, Runnable callback) {
    // If the response is null, that indicates an exception occurred. The best we can do is complete
    // the response in sequential order.
    if (response == null) {
      log.trace("Completing failed request");
      callback.run();
      return true;
    }

    // If the response's event index is greater than the current event index, that indicates that events that were
    // published prior to the response have not yet been completed. Attempt to complete pending events.
    if (response.eventIndex() > eventIndex) {
      // For each pending event with an eventIndex less than or equal to the response eventIndex, complete the event.
      // This is safe since we know that sequenced responses should see sequential order of events.
      EventCallback eventCallback = eventCallbacks.peek();
      while (eventCallback != null && eventCallback.request.eventIndex() <= response.eventIndex()) {
        eventCallbacks.remove();
        log.trace("Completing event {}", eventCallback.request);
        eventCallback.run();
        eventIndex = eventCallback.request.eventIndex();
        eventCallback = eventCallbacks.peek();
      }
    }

    // If after completing pending events the eventIndex is greater than or equal to the response's eventIndex, complete the response.
    // Note that the event protocol initializes the eventIndex to the session ID.
    if (response.eventIndex() <= eventIndex || (eventIndex == 0 && response.eventIndex() == state.getSessionId().id())) {
      log.trace("Completing response {}", response);
      callback.run();
      return true;
    } else {
      return false;
    }
  }
706134
public void complete() {
        long seqNo = this.operation.getSequenceNumber();
        Preconditions.checkState(seqNo >= 0, "About to complete a CompletableOperation that has no sequence number.");

        this.done = true;
        if (this.successHandler != null) {
            Callbacks.invokeSafely(this.successHandler, null, cex -> log.error("Success Callback invocation failure.", cex));
        }
    }
1201790
private void invokeOnComplete() {
        for (; ; ) {
            if (pooledBuffers != null) {
                for (PooledByteBuffer buffer : pooledBuffers) {
                    buffer.close();
                }
                pooledBuffers = null;
            }
            IoCallback callback = this.callback;
            this.buffer = null;
            this.fileChannel = null;
            this.callback = null;
            inCallback = true;
            try {
                callback.onComplete(exchange, this);
            } finally {
                inCallback = false;
            }

            StreamSinkChannel channel = this.channel;
            if (this.buffer != null) {
                long t = Buffers.remaining(buffer);
                final long total = t;
                long written = 0;

                try {
                    do {
                        long res = channel.write(buffer);
                        written += res;
                        if (res == 0) {
                            if(writeListener == null) {
                                initWriteListener();
                            }
                            channel.getWriteSetter().set(writeListener);
                            channel.resumeWrites();
                            return;
                        }
                    } while (written < total);
                    //we loop and invoke onComplete again
                } catch (IOException e) {
                    invokeOnException(callback, e);
                }
            } else if (this.fileChannel != null) {
                if(transferTask == null) {
                    transferTask = new TransferTask();
                }
                if (!transferTask.run(false)) {
                    return;
                }
            } else {
                return;
            }

        }
    }
14061
public void complete(VirtualConnection vc, TCPWriteRequestContext wsc) {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "complete() called: vc=" + vc);
        }
        HttpOutboundServiceContextImpl mySC = (HttpOutboundServiceContextImpl) vc.getStateMap().get(CallbackIDs.CALLBACK_HTTPOSC);
        // LI4335 - handle early reads
        if (mySC.isEarlyRead()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Notifying app channel of write complete");
            }
            mySC.getAppWriteCallback().complete(vc);
            return;
        }
        // if only the headers have been sent, then we need to check some
        // special case handling scenarios
        // 381105 - only start response read after just the headers have been
        // sent and no body... eventually need to get the isPartialBody state
        // implemented to make this simpler.
        if (mySC.isHeadersSentState() && 0 == mySC.getNumBytesWritten()) {
            if (mySC.shouldReadResponseImmediately()) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Sent headers, reading for response");
                }
                mySC.startResponseRead();
                return;
            }
        }

        // if we're here and we need to, notify the channel above that the
        // write has completed, otherwise start the read for the response
        // message
        if (!mySC.isMessageSent()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Calling write complete callback of app channel.");
            }
            mySC.getAppWriteCallback().complete(vc);
        } else {
            if (mySC.shouldReadResponseImmediately()) {
                // we've already done the "read first" call so jump to the
                // regular method now
                mySC.readAsyncResponse();
            } else {
                // initial read for a response
                mySC.startResponseRead();
            }
        }
    }
250415
public void complete() throws CompletionFailure {
        if (completer != Completer.NULL_COMPLETER) {
            Completer c = completer;
            completer = Completer.NULL_COMPLETER;
            c.complete(this);
        }
    }
1107063
@Override
    public final void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        try {
            onChannelReadComplete(ctx);
        } finally {
            parentReadInProgress = false;
            tail = head = null;
            // We always flush as this is what Http2ConnectionHandler does for now.
            flush0(ctx);
        }
        channelReadComplete0(ctx);
    }
1051158
def send_complete(self):
        
        self.active = True

        if self.should_finish():
            self._detach()

            # Avoid race condition when waiting for write callback and session getting closed in between
            if not self._finished:
                self.safe_finish()
        else:
            if self.session:
                self.session.flush()
1017335
private boolean completeResponse(OperationResponse response, Runnable callback) {
    // If the response is null, that indicates an exception occurred. The best we can do is complete
    // the response in sequential order.
    if (response == null) {
      LOGGER.trace("{} - Completing failed request", state.getSessionId());
      callback.run();
      return true;
    }

    // If the response's event index is greater than the current event index, that indicates that events that were
    // published prior to the response have not yet been completed. Attempt to complete pending events.
    long responseEventIndex = response.eventIndex();
    if (responseEventIndex > eventIndex) {
      // For each pending event with an eventIndex less than or equal to the response eventIndex, complete the event.
      // This is safe since we know that sequenced responses should see sequential order of events.
      EventCallback eventCallback = eventCallbacks.peek();
      while (eventCallback != null && eventCallback.request.eventIndex() <= responseEventIndex) {
        eventCallbacks.remove();
        LOGGER.trace("{} - Completing {}", state.getSessionId(), eventCallback.request);
        eventCallback.run();
        eventIndex = eventCallback.request.eventIndex();
        eventCallback = eventCallbacks.peek();
      }

      // If the response event index is still greater than the last sequenced event index, check
      // enqueued events to determine whether any events can be skipped. This is necessary to
      // ensure that a response with a missing event can still trigger prior events.
      if (responseEventIndex > eventIndex) {
        for (EventCallback event : eventCallbacks) {
          // If the event's previous index is consistent with the current event index and the event
          // index is greater than the response event index, set the response event index to the
          // event's previous index.
          if (event.request.previousIndex() <= eventIndex && event.request.eventIndex() >= response.eventIndex()) {
            responseEventIndex = event.request.previousIndex();
            break;
          }
        }
      }
    }

    // If after completing pending events the eventIndex is greater than or equal to the response's eventIndex, complete the response.
    // Note that the event protocol initializes the eventIndex to the session ID.
    if (responseEventIndex <= eventIndex || (eventIndex == 0 && responseEventIndex == state.getSessionId())) {
      LOGGER.trace("{} - Completing {}", state.getSessionId(), response);
      callback.run();
      return true;
    } else {
      return false;
    }
  }
202391
@SuppressWarnings("unchecked")
  protected <T> Completes<T> completes() {
    if (completes == null) {
      throw new IllegalStateException("Completes is not available for this protocol behavior.");
    }
    return (Completes<T>) completes;
  }
792287
private void finishCompletion() {
        // assert state > COMPLETING;
        for (WaitNode q; (q = waiters) != null;) {
            if (U.compareAndSwapObject(this, WAITERS, q, null)) {
                for (;;) {
                    Thread t = q.thread;
                    if (t != null) {
                        q.thread = null;
                        LockSupport.unpark(t);
                    }
                    WaitNode next = q.next;
                    if (next == null)
                        break;
                    q.next = null; // unlink to help gc
                    q = next;
                }
                break;
            }
        }

        done();

        callable = null;        // to reduce footprint
    }
78904
public synchronized boolean complete(Response result) {
        if (completed) {
            return false;
        }
        completed = true;
        this.result = result;
        notifyAll();
        return true;
    }
883997
public void finished()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "finished");
      
		msgIterator = null;
		aiStream = null;
    
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "finished");
  }