Exemplo n.º 1
0
 @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;
     }
   }
 }
Exemplo n.º 2
0
    @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();
        }
      }
    }
Exemplo n.º 3
0
 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();
   }
 }
Exemplo n.º 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");
   }
 }
Exemplo n.º 5
0
  @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();
  }
Exemplo n.º 6
0
  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();
    }
  }
Exemplo n.º 7
0
 @Override
 public DeliveryState getLocalState() {
   return delivery.getLocalState();
 }
Exemplo n.º 8
0
 @Override
 public byte[] getTag() {
   return delivery.getTag();
 }
Exemplo n.º 9
0
 @Override
 public boolean isBuffered() {
   return delivery.isBuffered();
 }
Exemplo n.º 10
0
 @Override
 public Delivery getWorkNext() {
   return new UnmodifiableDelivery(delivery.getWorkNext());
 }
Exemplo n.º 11
0
 @Override
 public boolean isSettled() {
   return delivery.isSettled();
 }
Exemplo n.º 12
0
 @Override
 public Object getContext() {
   return delivery.getContext();
 }
Exemplo n.º 13
0
 @Override
 public boolean isReadable() {
   return delivery.isReadable();
 }
Exemplo n.º 14
0
 @Override
 public boolean isWritable() {
   return delivery.isWritable();
 }
Exemplo n.º 15
0
 @Override
 public DeliveryState getRemoteState() {
   return delivery.getRemoteState();
 }
Exemplo n.º 16
0
 @Override
 public int getMessageFormat() {
   return delivery.getMessageFormat();
 }
Exemplo n.º 17
0
 @Override
 public boolean isUpdated() {
   return delivery.isUpdated();
 }
Exemplo n.º 18
0
 @Override
 public boolean remotelySettled() {
   return delivery.remotelySettled();
 }
Exemplo n.º 19
0
 @Override
 public boolean isPartial() {
   return delivery.isPartial();
 }
Exemplo n.º 20
0
 @Override
 public Delivery next() {
   return new UnmodifiableDelivery(delivery.next());
 }
Exemplo n.º 21
0
 @Override
 public int pending() {
   return delivery.pending();
 }