Re-transfer ownership of a given output buffer to the connection

@param ctx An OutputContext previously returned by {@link #borrowOutputContext()}
357894
public void returnOutputContext(OutputContext ctx) {
        List<ByteBuffer> remaining = ctx.releaseRemaining();
        if (pending == null) {
            pending = remaining;
        } else {
            List<ByteBuffer> tmp = pending;
            pending = remaining;
            pending.addAll(tmp);
        }
    }
1364946
@Override
    public void transfer(BasicBlock basicBlock, @CheckForNull InstructionHandle end, Fact start, Fact result)
            throws DataflowAnalysisException {
        copy(start, result);

        if (isFactValid(result)) {
            Iterator<InstructionHandle> i = isForwards() ? basicBlock.instructionIterator() : basicBlock
                    .instructionReverseIterator();

            while (i.hasNext()) {
                InstructionHandle handle = i.next();
                if (handle == end) {
                    break;
                }

                if (DEBUG && end == null) {
                    System.out.print("Transfer " + handle);
                }

                // Transfer the dataflow value
                transferInstruction(handle, basicBlock, result);

                if (DEBUG && end == null) {
                    System.out.println(" ==> " + result.toString());
                }
            }
        }
    }
1340293
@Nullable
    public TransactionOutput getConnectedOutput() {
        if (fromTx != null) {
            return fromTx.getOutputs().get((int) index);
        } else if (connectedOutput != null) {
            return connectedOutput;
        }
        return null;
    }
1038546
private void resetStatesAfterDecode(final ChannelHandlerContext ctx) {
        if (traceEnabled) {
            LOGGER.trace("{}Finished decoding of {}", logIdent(ctx, endpoint), currentRequest);
        }
        currentRequest = null;
        currentDecodingState = DecodingState.INITIAL;
    }
1328276
public OutputStream reset(OutputStream out)
            throws IOException
    {
        OutputStream old = this.out;
        this.out = out;
        return old;
    }
1278127
synchronized Transport borrowTransport() {
        long now = System.currentTimeMillis();

        List<PooledTransport> garbageTransports = new ArrayList<PooledTransport>();
        PooledTransport candidate = null;

        // Grab a transport
        for (Map.Entry<PooledTransport, Long> entry : idle.entrySet()) {
            PooledTransport transport = entry.getKey();
            if (validate(transport)) {
                candidate = transport;
                break;
            } else {
                garbageTransports.add(transport);
            }
        }

        // Remove any dead connections found
        for (PooledTransport transport : garbageTransports) {
            idle.remove(transport);
            release(transport);
        }

        // Create the connection if we didn't find any, remove it from the pool if we did.
        if (candidate == null) {
            candidate = create();
        } else {
            idle.remove(candidate);
        }

        // Lease.
        leased.put(candidate, now);
        return new LeasedTransport(candidate, this);
    }
924287
public static void transferStream(Reader in, Writer out)
   {
       try {
           char[] cbuf = new char[1000];
           int iLen = 0;
           while ((iLen = in.read(cbuf, 0, cbuf.length)) > 0)
           {   // Write the entire file to the output buffer
               out.write(cbuf, 0, iLen);
           }
           in.close();
       } catch (MalformedURLException ex)  {
           ex.printStackTrace();
       } catch (IOException ex) {
           ex.printStackTrace();
       }
   }
475277
public synchronized void setOutputStream(OutputStream out)
    {
        _reopen=isStarted() && out!=out;
        _filename=null;
        if (_buffer!=null)
            _buffer.resetWriter();
        _out=out;
    }
389503
public TransactionOutput addOutput(TransactionOutput to) {
        unCache();
        to.setParent(this);
        outputs.add(to);
        adjustLength(outputs.size(), to.length);
        return to;
    }
1204497
public void initContext(Context ctx)
	{
		// 模板静态文本部分
		ctx.staticTextArray = staticTextArray;
		// 模板各种缓存存放地

		// 临时标量所在空间
		ctx.tempVarStartIndex = tempVarStartIndex;
		// 分配变量空间,最后一个为模板的返回值
		ctx.vars = new Object[varIndexSize + 1];
		ctx.vars[varIndexSize] = Context.NOT_EXIST_OBJECT;

		// 将全局变量放到数组
		putGlobaToArray(ctx);

	}
570503
private void sendAndCleanupConnection(ChannelHandlerContext ctx, FullHttpResponse response) {
        final FullHttpRequest request = this.request;
        final boolean keepAlive = HttpUtil.isKeepAlive(request);
        HttpUtil.setContentLength(response, response.content().readableBytes());
        if (!keepAlive) {
            // We're going to close the connection as soon as the response is sent,
            // so we should also make it clear for the client.
            response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
        } else if (request.protocolVersion().equals(HTTP_1_0)) {
            response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
        }

        ChannelFuture flushPromise = ctx.writeAndFlush(response);

        if (!keepAlive) {
            // Close the connection as soon as the response is sent.
            flushPromise.addListener(ChannelFutureListener.CLOSE);
        }
    }
334076
@Override
  @SuppressWarnings("FutureReturnValueIgnored")
  public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
    if (failCause != null) {
      promise.setFailure(failCause);
      ReferenceCountUtil.release(msg);
    } else {
      bufferedWrites.add(new ChannelWrite(msg, promise));
    }
  }
217765
@Override
    public void channelHandlerContext(ChannelHandlerContext ctx) throws Http2Exception {
        this.ctx = checkNotNull(ctx, "ctx");

        // Writing the pending bytes will not check writability change and instead a writability change notification
        // to be provided by an explicit call.
        channelWritabilityChanged();

        // Don't worry about cleaning up queued frames here if ctx is null. It is expected that all streams will be
        // closed and the queue cleanup will occur when the stream state transitions occur.

        // If any frames have been queued up, we should send them now that we have a channel context.
        if (isChannelWritable()) {
            writePendingBytes();
        }
    }
724282
@Override
    public void handle(CommandContext ctx) throws CommandLineException {

        ModelControllerClient client = ctx.getModelControllerClient();
        if(client == null) {
            throw new CommandFormatException("You are disconnected at the moment." +
                    " Type 'connect' to connect to the server" +
                    " or 'help' for the list of supported commands.");
        }
        RequestWithAttachments reqWithAttachments
                = (RequestWithAttachments) ctx.get(Scope.REQUEST, "OP_REQ");
        if (reqWithAttachments == null) {
            throw new CommandLineException("Parsed request isn't available.");
        }
        ModelNode request = reqWithAttachments.getRequest();
        OperationBuilder opBuilder = new OperationBuilder(request, true);
        for (String path : reqWithAttachments.getAttachedFiles()) {
            opBuilder.addFileAsAttachment(new File(path));
        }
        Operation op = opBuilder.build();

        if(ctx.getConfig().isValidateOperationRequests()) {
            ModelNode opDescOutcome = Util.validateRequest(ctx, request);
            if (opDescOutcome != null) { // operation has params that might need to be replaced
                Util.replaceFilePathsWithBytes(request, opDescOutcome);
            }
        }

        try {
            final ModelNode result = ctx.execute(op, "Operation request");
            if (Util.isSuccess(result)) {
                ctx.printDMR(result);
            } else {
                throw new CommandLineException(result.toString());
            }
        } catch(NoSuchElementException e) {
            throw new CommandLineException("ModelNode request is incomplete", e);
        } catch (CancellationException e) {
            throw new CommandLineException("The result couldn't be retrieved (perhaps the task was cancelled", e);
        } catch (IOException e) {
            if (e.getCause() != null && !(e.getCause() instanceof InterruptedException)) {
                ctx.disconnectController();
            }
            throw new CommandLineException("Communication error", e);
        } catch (RuntimeException e) {
            throw new CommandLineException("Failed to execute operation.", e);
        }
    }
122151
static JobContext copy() {
        JobContext current = current_.get();
        //JobContext ctxt = new JobContext(keepParent ? current : null);
        JobContext ctxt = new JobContext(null);
        if (null != current) {
            ctxt.bag_.putAll(current.bag_);
        }
        return ctxt;
    }
809203
private <T> CompletableFuture<T> executeCommandAsyncWithInjectedTx(InvocationContext ctx, VisitableCommand command) {
      CompletableFuture<T> cf;
      final Transaction implicitTransaction;
      try {
         // interceptors must not access thread-local transaction anyway
         implicitTransaction = transactionManager.suspend();
         assert implicitTransaction != null;
         //noinspection unchecked
         cf = (CompletableFuture<T>) invoker.invokeAsync(ctx, command);
      } catch (SystemException e) {
         throw new CacheException("Cannot suspend implicit transaction", e);
      } catch (Throwable e) {
         tryRollback();
         throw e;
      }
      return cf.handle((result, throwable) -> {
         if (throwable != null) {
            try {
               implicitTransaction.rollback();
            } catch (SystemException e) {
               log.trace("Could not rollback", e);
               throwable.addSuppressed(e);
            }
            throw CompletableFutures.asCompletionException(throwable);
         }
         try {
            implicitTransaction.commit();
         } catch (Exception e) {
            log.couldNotCompleteInjectedTransaction(e);
            throw CompletableFutures.asCompletionException(e);
         }
         return result;
      });
   }
643864
public Cache copyAs(String source, String destination) throws CacheException {
		if(!Strings.areValid(source, destination)) {
			logger.error("invalid input parameters for copy from '{}' to '{}'", source, destination);
			throw new CacheException("invalid input parameters (source: '" + source + "', destination: '" + destination + "')");
		}
		try (InputStream input = storage.retrieve(source); OutputStream output = storage.store(destination)) {
			long copied = Streams.copy(input, output);
			logger.trace("copied {} bytes from '{}' to '{}'", copied, source, destination);
		} catch (IOException e) {
			logger.error("error copying from '" + source + "' to '" + destination + "'", e);
			throw new CacheException("error copying from '" + source + "' to '" + destination + "'", e);
		}
		return this;
	}