当前位置: 首页>>代码示例>>Java>>正文


Java Receiver.recv方法代码示例

本文整理汇总了Java中org.apache.qpid.proton.engine.Receiver.recv方法的典型用法代码示例。如果您正苦于以下问题:Java Receiver.recv方法的具体用法?Java Receiver.recv怎么用?Java Receiver.recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.qpid.proton.engine.Receiver的用法示例。


在下文中一共展示了Receiver.recv方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onDelivery

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
@Override
public void onDelivery(Event evt) {
    Delivery dlv = evt.getDelivery();
    Link link = dlv.getLink();
    if (link instanceof Sender) {
        dlv.settle();
    } else {
        Receiver rcv = (Receiver) link;
        if (!dlv.isPartial()) {
            byte[] bytes = new byte[dlv.pending()];
            rcv.recv(bytes, 0, bytes.length);
            String address = router.getAddress(rcv);
            Message message = new Message(bytes);
            messages.put(address, message);
            dlv.disposition(Accepted.getInstance());
            dlv.settle();
            if (!quiet) {
                System.out.println(String.format("Got message(%s): %s", address, message));
            }
            send(address);
        }
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:24,代码来源:Server.java

示例2: onDelivery

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
@Override
public void onDelivery(Event evt) {
    Delivery dlv = evt.getDelivery();
    if (dlv.getLink() instanceof Receiver) {
        Receiver receiver = (Receiver) dlv.getLink();

        if (!dlv.isPartial()) {
            byte[] bytes = new byte[dlv.pending()];
            receiver.recv(bytes, 0, bytes.length);
            Message msg = new Message(bytes);

            if (!quiet) {
                System.out.println(String.format("Got message: %s", msg));
            }
            received++;
            dlv.settle();
        }

        if ((received >= count) || (!block && !receiver.draining())) {
            receiver.getSession().getConnection().close();
        }
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:24,代码来源:Drain.java

示例3: onDelivery

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
@Override
public void onDelivery(Event event) {
    Receiver recv = (Receiver)event.getLink();
    Delivery delivery = recv.current();
    if (delivery.isReadable() && !delivery.isPartial()) {
        int size = delivery.pending();
        byte[] buffer = new byte[size];
        int read = recv.recv(buffer, 0, buffer.length);
        recv.advance();

        Message msg = Proton.message();
        msg.decode(buffer, 0, read);
        System.out.println(((AmqpValue)msg.getBody()).getValue());
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:16,代码来源:Recv.java

示例4: receiveMessageFromServer

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
private Delivery receiveMessageFromServer(String deliveryTag, int count)
{
    Delivery delivery = getClient().getConnection().getWorkHead();
    Receiver clientReceiver = getClient().getReceiver();

    assertTrue(Arrays.equals(deliveryTag.getBytes(StandardCharsets.UTF_8), delivery.getTag()));
    assertEquals("The received delivery should be on our receiver",
            clientReceiver, delivery.getLink());

    assertNull(delivery.getLocalState());
    assertNull(delivery.getRemoteState());

    assertFalse(delivery.isPartial());
    assertTrue(delivery.isReadable());

    int size = delivery.available();
    byte[] received = new byte[size];

    int len = clientReceiver.recv(received, 0, size);

    assertEquals("Should have received " + size + " bytes", size, len);
    assertEquals("Should be no bytes left", 0, delivery.available());

    Message m = Proton.message();
    m.decode(received, 0, len);

    Object messageBody = ((AmqpValue)m.getBody()).getValue();
    assertEquals("Unexpected message content", count, messageBody);

    boolean receiverAdvanced = clientReceiver.advance();
    assertTrue("receiver has not advanced", receiverAdvanced);

    delivery.setContext(count);

    return delivery;
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:37,代码来源:DeferredSettlementTest.java

示例5: onDelivery

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
@Override
public void onDelivery(Event event) {
  final String methodName = "onDelivery";
  logger.entry(this, methodName, event);

  EngineConnection engineConnection = (EngineConnection)event.getConnection().getContext();
  Delivery delivery = event.getDelivery();
  if (event.getLink() instanceof Sender) {
      SendRequest sr = engineConnection.inProgressOutboundDeliveries.remove(delivery);
      Exception exception = null;
      if (delivery.getRemoteState() instanceof Rejected) {
          final Rejected rejected = (Rejected) delivery.getRemoteState();
          final ErrorCondition error = rejected.getError();
          if (error == null || error.getDescription() == null) {
              exception = new Exception("Message was rejected");
          } else {
              exception = new Exception(error.getDescription());
          }
      } else if (delivery.getRemoteState() instanceof Released) {
          exception = new Exception("Message was released");
      } else if (delivery.getRemoteState() instanceof Modified) {
          exception = new Exception("Message was modified");
      }
      if (!sr.retainLink) {
          event.getLink().close();
          event.getLink().free();
      }
      sr.getSender().tell(new SendResponse(sr, exception), this);
  } else if (delivery.isReadable() && !delivery.isPartial()) {    // Assuming link instanceof Receiver...
      Receiver receiver = (Receiver)event.getLink();
      int amount = delivery.pending();
      byte[] data = new byte[amount];
      receiver.recv(data, 0, amount);
      receiver.advance();

      EngineConnection.SubscriptionData subData = engineConnection.subscriptionData.get(event.getLink().getName());
      subData.unsettled++;
      QOS qos = delivery.remotelySettled() ? QOS.AT_MOST_ONCE : QOS.AT_LEAST_ONCE;
      subData.subscriber.tell(new DeliveryRequest(data, qos, event.getLink().getName(), delivery, event.getConnection()), this);
  }

  logger.exit(this, methodName);
}
 
开发者ID:mqlight,项目名称:java-mqlight,代码行数:44,代码来源:Engine.java

示例6: onMessage

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
@Override
public void onMessage(Delivery delivery) throws ActiveMQAMQPException {
   Receiver receiver;
   try {

      if (!delivery.isReadable()) {
         return;
      }
      if (delivery.isPartial()) {
         return;
      }

      receiver = ((Receiver) delivery.getLink());

      Transaction tx = null;
      byte[] data;

      data = new byte[delivery.available()];
      receiver.recv(data, 0, data.length);
      receiver.advance();

      if (delivery.getRemoteState() instanceof TransactionalState) {
         TransactionalState txState = (TransactionalState) delivery.getRemoteState();
         tx = this.sessionSPI.getTransaction(txState.getTxnId(), false);
      }

      sessionSPI.serverSend(this, tx, receiver, delivery, address, delivery.getMessageFormat(), data);

      flow(amqpCredits, minCreditRefresh);
   } catch (Exception e) {
      log.warn(e.getMessage(), e);
      Rejected rejected = new Rejected();
      ErrorCondition condition = new ErrorCondition();

      if (e instanceof ActiveMQSecurityException) {
         condition.setCondition(AmqpError.UNAUTHORIZED_ACCESS);
      } else {
         condition.setCondition(Symbol.valueOf("failed"));
      }

      condition.setDescription(e.getMessage());
      rejected.setError(condition);
      connection.lock();
      try {
         delivery.disposition(rejected);
         delivery.settle();
      } finally {
         connection.unlock();
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:52,代码来源:ProtonServerReceiverContext.java

示例7: onDelivery

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
void onDelivery() {
  if (this.handler == null) {
    return;
  }

  Receiver receiver = getReceiver();
  Delivery delivery = receiver.current();

  if (delivery != null) {
    int count;
    while ((count = receiver.recv(buffer, 0, buffer.length)) > 0) {
      current.write(buffer, 0, count);
    }

    if (delivery.isPartial()) {
      // Delivery is not yet completely received,
      // return and allow further frames to arrive.
      return;
    }

    byte[] data = current.toByteArray();
    current.reset();

    Message msg = Proton.message();
    msg.decode(data, 0, data.length);

    receiver.advance();

    ProtonDeliveryImpl delImpl = new ProtonDeliveryImpl(delivery);

    handler.handle(delImpl, msg);

    if (autoAccept && delivery.getLocalState() == null) {
      accepted(delImpl, true);
    }

    if (prefetch > 0) {
      // Replenish credit if prefetch is configured.
      // TODO: batch credit replenish, optionally flush if exceeding a given threshold?
      flow(1, false);
    } else {
      processForDrainCompletion();
    }
  }
}
 
开发者ID:vert-x3,项目名称:vertx-proton,代码行数:46,代码来源:ProtonReceiverImpl.java

示例8: verifyDelivery

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
private Delivery verifyDelivery(Receiver receiver, String deliveryTag, String messageContent)
{
    Delivery delivery = receiver.current();

    assertTrue(Arrays.equals(deliveryTag.getBytes(StandardCharsets.UTF_8), delivery.getTag()));

    assertNull(delivery.getLocalState());
    assertNull(delivery.getRemoteState());

    assertFalse(delivery.isPartial());
    assertTrue(delivery.isReadable());

    byte[] received = new byte[BUFFER_SIZE];
    int len = receiver.recv(received, 0, BUFFER_SIZE);

    assertTrue("given array was too small", len < BUFFER_SIZE);

    Message m = Proton.message();
    m.decode(received, 0, len);

    Object messageBody = ((AmqpValue)m.getBody()).getValue();
    assertEquals("Unexpected message content", messageContent, messageBody);

    boolean receiverAdvanced = receiver.advance();
    assertTrue("receiver has not advanced", receiverAdvanced);

    return delivery;
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:29,代码来源:TransportImplTest.java


注:本文中的org.apache.qpid.proton.engine.Receiver.recv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。