org.apache.qpid.proton.engine.Transport.getInputBuffer()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中org.apache.qpid.proton.engine.Transport.getInputBuffer()方法的一些代码示例,展示了Transport.getInputBuffer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transport.getInputBuffer()方法的具体详情如下:
包路径:org.apache.qpid.proton.engine.Transport
类名称:Transport
方法名:getInputBuffer

Transport.getInputBuffer介绍

[英]Get a buffer that can be used to write input data into the transport. Once the client has finished putting into the input buffer, #processInput()must be called. Successive calls to this method are not guaranteed to return the same object. Once #processInput() is called the buffer must not be used.
[中]获取一个可用于将输入数据写入传输的缓冲区。客户机完成输入缓冲区的输入后,必须调用#processInput()。对该方法的连续调用不能保证返回相同的对象。一旦调用了#processInput(),就不能使用缓冲区。

代码示例

代码示例来源:origin: apache/activemq-artemis

@Override
  public void run() {
   ByteBuffer source = incoming.nioBuffer();
   LOG.trace("Client Received from Broker {} bytes:", source.remaining());
   if (protonTransport.isClosed()) {
     LOG.debug("Ignoring incoming data because transport is closed");
     return;
   }
   do {
     ByteBuffer buffer = protonTransport.getInputBuffer();
     int limit = Math.min(buffer.remaining(), source.remaining());
     ByteBuffer duplicate = source.duplicate();
     duplicate.limit(source.position() + limit);
     buffer.put(duplicate);
     protonTransport.processInput();
     source.position(source.position() + limit);
   }
   while (source.hasRemaining());
   ReferenceCountUtil.release(incoming);
   // Process the state changes from the latest data and then answer back
   // any pending updates to the Broker.
   processUpdates();
   pumpToProtonTransport();
  }
});

代码示例来源:origin: EnMasseProject/enmasse

private void readFromNetwork(Connection connection, InputStream in, BooleanSupplier test) throws IOException, LoginException {
  Transport transport = connection.getTransport();
  while(test.getAsBoolean()) {
    ByteBuffer buf = transport.getInputBuffer();
    byte[] tmpBuf = new byte[buf.remaining()];
    int bytesRead = in.read(tmpBuf);
    LOG.tracev("read {0} bytes", bytesRead);
    if (bytesRead == -1) {
      throw new LoginException("Unexpected EOS experienced when authenticating using SASL delegation");
    } else {
      buf.put(tmpBuf, 0, bytesRead);
      TransportResult result = transport.processInput();
      if(!result.isOk()) {
        LoginException e = new LoginException("Unexpected error when authenticating using SASL delegation");
        e.initCause(result.getException());
        throw e;
      }
    }
  }
}

相关文章