コード例 #1
0
ファイル: ProtonJInterop.java プロジェクト: ChugR/qpid-proton
 @Override
 public void onLinkFlow(Event event) {
   Sender snd = (Sender) event.getLink();
   if (snd.getCredit() > 0 && snd.getLocalState() != EndpointState.CLOSED) {
     Message message = Proton.message();
     ++count;
     message.setBody(new AmqpValue("message-" + count));
     byte[] msgData = new byte[1024];
     int length;
     while (true) {
       try {
         length = message.encode(msgData, 0, msgData.length);
         break;
       } catch (BufferOverflowException e) {
         msgData = new byte[msgData.length * 2];
       }
     }
     byte[] tag = String.valueOf(count).getBytes();
     Delivery dlv = snd.delivery(tag);
     snd.send(msgData, 0, length);
     dlv.settle();
     snd.advance();
     if (count == numMsgs) {
       snd.close();
       snd.getSession().close();
       snd.getSession().getConnection().close();
       result = true;
     }
   }
 }
コード例 #2
0
ファイル: ProtonJInterop.java プロジェクト: ChugR/qpid-proton
    @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);

        ++count;
        String msgBody = ((AmqpValue) msg.getBody()).getValue().toString();
        String expected = "message-" + count;
        if (!expected.equals(msgBody)) {
          throw new RuntimeException(
              "Received message body '" + msgBody + "', expected: '" + expected + "'");
        }

        if (count == numMsgs) {
          recv.close();
          recv.getSession().close();
          recv.getSession().getConnection().close();
          acceptor.close();
        }
      }
    }
コード例 #3
0
ファイル: SessionImpl.java プロジェクト: rajith77/Eris
 void setDispositionAndSettleIfRequired(IncommingMessage msg, DeliveryState state) {
   Delivery d = _unsettled.get(msg.getSequence());
   d.disposition(state);
   if (d.getLink().getReceiverSettleMode() == ReceiverSettleMode.FIRST) {
     d.settle();
     ((ReceiverImpl) d.getLink().getContext()).decrementUnsettledCount();
   }
 }
コード例 #4
0
 @Override
 public Link getLink() {
   if (delivery.getLink() instanceof Sender) {
     return new UnmodifiableSender((Sender) delivery.getLink());
   } else if (delivery.getLink() instanceof Receiver) {
     return new UnmodifiableReceiver((Receiver) delivery.getLink());
   } else {
     throw new IllegalStateException("Delivery has unknown link type");
   }
 }
コード例 #5
0
ファイル: AmqpSender.java プロジェクト: sdnnfv/qpid
  @Override
  protected void processDelivery(Delivery delivery) {
    final MessageDelivery md = (MessageDelivery) delivery.getContext();
    if (delivery.remotelySettled()) {
      if (delivery.getTag().length > 0) {
        checkinTag(delivery.getTag());
      }

      final DeliveryState state = delivery.getRemoteState();
      if (state == null || state instanceof Accepted) {
        if (!delivery.remotelySettled()) {
          delivery.disposition(new Accepted());
        }
      } else if (state instanceof Rejected) {
        // re-deliver /w incremented delivery counter.
        md.delivery = null;
        md.incrementDeliveryCount();
        outbound.addLast(md);
      } else if (state instanceof Released) {
        // re-deliver && don't increment the counter.
        md.delivery = null;
        outbound.addLast(md);
      } else if (state instanceof Modified) {
        Modified modified = (Modified) state;
        if (modified.getDeliveryFailed()) {
          // increment delivery counter..
          md.incrementDeliveryCount();
        }
      }
      delivery.settle();
    }
    md.fireWatches();
  }
コード例 #6
0
ファイル: AmqpSender.java プロジェクト: sdnnfv/qpid
  protected void pumpDeliveries() {
    assertExecuting();
    try {
      while (true) {
        while (currentBuffer != null) {
          if (sender.getCredit() > 0) {
            int sent = sender.send(currentBuffer.data, currentBuffer.offset, currentBuffer.length);
            currentBuffer.moveHead(sent);
            if (currentBuffer.length == 0) {
              Delivery current = currentDelivery;
              MessageDelivery md = (MessageDelivery) current.getContext();
              currentBuffer = null;
              currentDelivery = null;
              if (qos == QoS.AT_MOST_ONCE) {
                current.settle();
              } else {
                sender.advance();
              }
              md.fireWatches();
            }
          } else {
            return;
          }
        }

        if (outbound.isEmpty()) {
          return;
        }

        final MessageDelivery md = outbound.removeFirst();
        outboundBufferSize -= md.initialSize;
        currentBuffer = md.encoded();
        if (qos == QoS.AT_MOST_ONCE) {
          currentDelivery = sender.delivery(EMPTY_BYTE_ARRAY, 0, 0);
        } else {
          final byte[] tag = nextTag();
          currentDelivery = sender.delivery(tag, 0, tag.length);
        }
        md.delivery = currentDelivery;
        currentDelivery.setContext(md);
      }
    } finally {
      fireWatches();
    }
  }
コード例 #7
0
 @Override
 public DeliveryState getLocalState() {
   return delivery.getLocalState();
 }
コード例 #8
0
 @Override
 public byte[] getTag() {
   return delivery.getTag();
 }
コード例 #9
0
 @Override
 public boolean isBuffered() {
   return delivery.isBuffered();
 }
コード例 #10
0
 @Override
 public Delivery getWorkNext() {
   return new UnmodifiableDelivery(delivery.getWorkNext());
 }
コード例 #11
0
 @Override
 public boolean isSettled() {
   return delivery.isSettled();
 }
コード例 #12
0
 @Override
 public Object getContext() {
   return delivery.getContext();
 }
コード例 #13
0
 @Override
 public boolean isReadable() {
   return delivery.isReadable();
 }
コード例 #14
0
 @Override
 public boolean isWritable() {
   return delivery.isWritable();
 }
コード例 #15
0
 @Override
 public DeliveryState getRemoteState() {
   return delivery.getRemoteState();
 }
コード例 #16
0
 @Override
 public int getMessageFormat() {
   return delivery.getMessageFormat();
 }
コード例 #17
0
 @Override
 public boolean isUpdated() {
   return delivery.isUpdated();
 }
コード例 #18
0
 @Override
 public boolean remotelySettled() {
   return delivery.remotelySettled();
 }
コード例 #19
0
 @Override
 public boolean isPartial() {
   return delivery.isPartial();
 }
コード例 #20
0
 @Override
 public Delivery next() {
   return new UnmodifiableDelivery(delivery.next());
 }
コード例 #21
0
 @Override
 public int pending() {
   return delivery.pending();
 }