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


Java Receiver.drain方法代码示例

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


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

示例1: onLinkLocalOpen

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

        if (block) {
            receiver.flow(count);
        } else {
            receiver.drain(count);
        }
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:14,代码来源:Drain.java

示例2: stop

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
private void stop(final AsyncResult request) {
   Receiver receiver = getEndpoint();
   if (receiver.getRemoteCredit() <= 0) {
      if (receiver.getQueued() == 0) {
         // We have no remote credit and all the deliveries have been processed.
         request.onSuccess();
      } else {
         // There are still deliveries to process, wait for them to be.
         stopRequest = request;
      }
   } else {
      // TODO: We don't actually want the additional messages that could be sent while
      // draining. We could explicitly reduce credit first, or possibly use 'echo' instead
      // of drain if it was supported. We would first need to understand what happens
      // if we reduce credit below the number of messages already in-flight before
      // the peer sees the update.
      stopRequest = request;
      receiver.drain(0);

      if (getDrainTimeout() > 0) {
         // If the remote doesn't respond we will close the consumer and break any
         // blocked receive or stop calls that are waiting.
         final ScheduledFuture<?> future = getSession().getScheduler().schedule(new Runnable() {
            @Override
            public void run() {
               LOG.trace("Consumer {} drain request timed out", this);
               Exception cause = new JmsOperationTimedOutException("Remote did not respond to a drain request in time");
               locallyClosed(session.getConnection(), cause);
               stopRequest.onFailure(cause);
               session.pumpToProtonTransport(stopRequest);
            }
         }, getDrainTimeout(), TimeUnit.MILLISECONDS);

         stopRequest = new ScheduledRequest(future, stopRequest);
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:38,代码来源:AmqpReceiver.java

示例3: testNoReceiverFlowAfterDetachSentWhileDraining

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
/**
 * Verify that no Flow frame is emitted by the Transport should a Receiver
 * have pending drain when a detach is sent for that receiver.
 */
@Test
public void testNoReceiverFlowAfterDetachSentWhileDraining()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName = "myReceiver";
    Receiver receiver = session.receiver(linkName);
    receiver.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
    assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
    assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);

    // Send the necessary responses to open/begin/attach
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach = new Attach();
    attach.setHandle(UnsignedInteger.ZERO);
    attach.setRole(Role.RECEIVER);
    attach.setName(linkName);
    attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach, null));

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    // Start a drain for the Receiver and verify the transport doesn't
    // send any Flow frame, due to the detach being initiated.
    receiver.drain(10);
    pumpMockTransport(transport);

    // Cause the Detach frame to be sent
    receiver.detach();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(4) instanceof Detach);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:57,代码来源:TransportImplTest.java

示例4: stop

import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
/**
 * Stops the consumer, using all link credit and waiting for in-flight messages to arrive.
 *
 * @param request
 *      The request that awaits completion of the consumer stop.
 */
public void stop(AsyncResult request) {
    Receiver receiver = getEndpoint();
    if (receiver.getRemoteCredit() <= 0) {
        if (receiver.getQueued() == 0) {
            // We have no remote credit and all the deliveries have been processed.
            request.onSuccess();
        } else {
            // There are still deliveries to process, wait for them to be.
            stopRequest = request;
        }
    } else {
        // TODO: We don't actually want the additional messages that could be sent while
        // draining. We could explicitly reduce credit first, or possibly use 'echo' instead
        // of drain if it was supported. We would first need to understand what happens
        // if we reduce credit below the number of messages already in-flight before
        // the peer sees the update.
        stopRequest = request;
        receiver.drain(0);

        if (getDrainTimeout() > 0) {
            // If the remote doesn't respond we will close the consumer and break any
            // blocked receive or stop calls that are waiting, unless the consumer is
            // a participant in a transaction in which case we will just fail the request
            // and leave the consumer open since the TX needs it to remain active.
            final ScheduledFuture<?> future = getSession().schedule(new Runnable() {
                @Override
                public void run() {
                    LOG.trace("Consumer {} drain request timed out", getConsumerId());
                    Exception cause = new JmsOperationTimedOutException("Remote did not respond to a drain request in time");
                    if (session.isTransacted() && session.getTransactionContext().isInTransaction(getConsumerId())) {
                        stopRequest.onFailure(cause);
                        stopRequest = null;
                    } else {
                        closeResource(session.getProvider(), cause, false);
                        session.getProvider().pumpToProtonTransport();
                    }
                }
            }, getDrainTimeout());

            stopRequest = new ScheduledRequest(future, stopRequest);
        }
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:50,代码来源:AmqpConsumer.java


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