org.apache.qpid.proton.amqp.messaging.Modified Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.messaging.Modified. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpTransactionCoordinatorBuilder.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Override
protected Sender createEndpoint(JmsSessionInfo resourceInfo) {
    Coordinator coordinator = new Coordinator();
    coordinator.setCapabilities(TxnCapability.LOCAL_TXN);

    Symbol[] outcomes = new Symbol[]{ Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };

    Source source = new Source();
    source.setOutcomes(outcomes);

    String coordinatorName = "qpid-jms:coordinator:" + resourceInfo.getId().toString();

    Sender sender = getParent().getSession().getEndpoint().sender(coordinatorName);
    sender.setSource(source);
    sender.setTarget(coordinator);
    sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
    sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);

    return sender;
}
 
Example #2
Source File: ModifiedType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public Modified newInstance(Object described)
{
    List l = (List) described;

    Modified o = new Modified();


    switch(3 - l.size())
    {

        case 0:
            o.setMessageAnnotations( (Map) l.get( 2 ) );
        case 1:
            o.setUndeliverableHere( (Boolean) l.get( 1 ) );
        case 2:
            o.setDeliveryFailed( (Boolean) l.get( 0 ) );
    }


    return o;
}
 
Example #3
Source File: ProtonServerReceiverContext.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private DeliveryState determineDeliveryState(final Source source, final boolean useModified, final Exception e) {
   Outcome defaultOutcome = getEffectiveDefaultOutcome(source);

   if (isAddressFull(e) && useModified &&
       (outcomeSupported(source, Modified.DESCRIPTOR_SYMBOL) || defaultOutcome instanceof Modified)) {
      Modified modified = new Modified();
      modified.setDeliveryFailed(true);
      return modified;
   } else {
      if (outcomeSupported(source, Rejected.DESCRIPTOR_SYMBOL) || defaultOutcome instanceof Rejected) {
         return createRejected(e);
      } else if (source.getDefaultOutcome() instanceof DeliveryState) {
         return ((DeliveryState) source.getDefaultOutcome());
      } else {
         // The AMQP specification requires that Accepted is returned for this case. However there exist
         // implementations that set neither outcomes/default-outcome but use/expect for full range of outcomes.
         // To maintain compatibility with these implementations, we maintain previous behaviour.
         return createRejected(e);
      }
   }
}
 
Example #4
Source File: AbstractSender.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a log entry in the given span with information about the message delivery outcome given in the delivery
 * parameter. Sets the {@link Tags#HTTP_STATUS} as well.
 * <p>
 * Also corresponding log output is created.
 *
 * @param currentSpan The current span to log to.
 * @param message The message.
 * @param delivery The updated delivery.
 * @throws NullPointerException if any of the parameters is {@code null}.
 */
protected final void logUpdatedDeliveryState(final Span currentSpan, final Message message, final ProtonDelivery delivery) {
    Objects.requireNonNull(currentSpan);
    final String messageId = message.getMessageId() != null ? message.getMessageId().toString() : "";
    final String messageAddress = getMessageAddress(message);
    final DeliveryState remoteState = delivery.getRemoteState();
    if (Accepted.class.isInstance(remoteState)) {
        log.trace("message [ID: {}, address: {}] accepted by peer", messageId, messageAddress);
        currentSpan.log("message accepted by peer");
        Tags.HTTP_STATUS.set(currentSpan, HttpURLConnection.HTTP_ACCEPTED);
    } else {
        final Map<String, Object> events = new HashMap<>();
        if (Rejected.class.isInstance(remoteState)) {
            final Rejected rejected = (Rejected) delivery.getRemoteState();
            Tags.HTTP_STATUS.set(currentSpan, HttpURLConnection.HTTP_BAD_REQUEST);
            if (rejected.getError() == null) {
                logMessageSendingError("message [ID: {}, address: {}] rejected by peer", messageId, messageAddress);
                events.put(Fields.MESSAGE, "message rejected by peer");
            } else {
                logMessageSendingError("message [ID: {}, address: {}] rejected by peer: {}, {}", messageId,
                        messageAddress, rejected.getError().getCondition(), rejected.getError().getDescription());
                events.put(Fields.MESSAGE, String.format("message rejected by peer: %s, %s",
                        rejected.getError().getCondition(), rejected.getError().getDescription()));
            }
        } else if (Released.class.isInstance(remoteState)) {
            logMessageSendingError("message [ID: {}, address: {}] not accepted by peer, remote state: {}",
                    messageId, messageAddress, remoteState.getClass().getSimpleName());
            Tags.HTTP_STATUS.set(currentSpan, HttpURLConnection.HTTP_UNAVAILABLE);
            events.put(Fields.MESSAGE, "message not accepted by peer, remote state: " + remoteState);
        } else if (Modified.class.isInstance(remoteState)) {
            final Modified modified = (Modified) delivery.getRemoteState();
            logMessageSendingError("message [ID: {}, address: {}] not accepted by peer, remote state: {}",
                    messageId, messageAddress, modified);
            Tags.HTTP_STATUS.set(currentSpan, modified.getUndeliverableHere() ? HttpURLConnection.HTTP_NOT_FOUND
                    : HttpURLConnection.HTTP_UNAVAILABLE);
            events.put(Fields.MESSAGE, "message not accepted by peer, remote state: " + remoteState);
        }
        TracingHelper.logError(currentSpan, events);
    }
}
 
Example #5
Source File: SessionIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testCreateProducerLinkSupportedSourceOutcomes() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        testPeer.expectBegin();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String queueName = "myQueue";

        SourceMatcher sourceMatcher = new SourceMatcher();
        sourceMatcher.withOutcomes(arrayContaining(Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL));
        //TODO: what default outcome for producers?
        //Accepted normally, Rejected for transaction controller?
        //sourceMatcher.withDefaultOutcome(outcomeMatcher);

        TargetMatcher targetMatcher = new TargetMatcher();
        targetMatcher.withAddress(equalTo(queueName));

        testPeer.expectSenderAttach(sourceMatcher, targetMatcher, false, false);
        testPeer.expectClose();

        Queue queue = session.createQueue(queueName);
        session.createProducer(queue);

        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #6
Source File: AmqpProducerBuilder.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
protected Sender createEndpoint(JmsProducerInfo resourceInfo) {
    JmsDestination destination = resourceInfo.getDestination();
    AmqpConnection connection = getParent().getConnection();

    String targetAddress = AmqpDestinationHelper.getDestinationAddress(destination, connection);

    Symbol[] outcomes = new Symbol[]{ Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };
    String sourceAddress = resourceInfo.getId().toString();
    Source source = new Source();
    source.setAddress(sourceAddress);
    source.setOutcomes(outcomes);
    // TODO: default outcome. Accepted normally, Rejected for transaction controller?

    Target target = new Target();
    target.setAddress(targetAddress);
    Symbol typeCapability =  AmqpDestinationHelper.toTypeCapability(destination);
    if (typeCapability != null) {
        target.setCapabilities(typeCapability);
    }

    String senderName = "qpid-jms:sender:" + sourceAddress + ":" + targetAddress;

    Sender sender = getParent().getEndpoint().sender(senderName);
    sender.setSource(source);
    sender.setTarget(target);
    if (resourceInfo.isPresettle()) {
        sender.setSenderSettleMode(SenderSettleMode.SETTLED);
    } else {
        sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
    }
    sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);

    if (!connection.getProperties().isDelayedDeliverySupported()) {
        validateDelayedDeliveryLinkCapability = true;
        sender.setDesiredCapabilities(new Symbol[] { AmqpSupport.DELAYED_DELIVERY });
    }

    return sender;
}
 
Example #7
Source File: ProtonSessionImpl.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
@Override
public ProtonSender createSender(String address, ProtonLinkOptions senderOptions) {
  Sender sender = session.sender(getOrCreateLinkName(senderOptions));

  Symbol[] outcomes = new Symbol[] { Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL,
      Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };
  Source source = new Source();
  source.setOutcomes(outcomes);

  Target target = new Target();
  target.setAddress(address);
  if(senderOptions.isDynamic()) {
    target.setDynamic(true);
  }

  sender.setSource(source);
  sender.setTarget(target);

  ProtonSenderImpl s = new ProtonSenderImpl(sender);
  if (address == null) {
    s.setAnonymousSender(true);
  }

  s.openHandler((result) -> {
    LOG.trace("Sender open completed");
  });
  s.closeHandler((result) -> {
    if (result.succeeded()) {
      LOG.trace("Sender closed");
    } else {
      LOG.warn("Sender closed with error", result.cause());
    }
  });

  // Default to at-least-once
  s.setQoS(ProtonQoS.AT_LEAST_ONCE);

  return s;
}
 
Example #8
Source File: ProtonSessionImpl.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
@Override
public ProtonReceiver createReceiver(String address, ProtonLinkOptions receiverOptions) {
  Receiver receiver = session.receiver(getOrCreateLinkName(receiverOptions));

  Symbol[] outcomes = new Symbol[] { Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL,
      Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };

  Source source = new Source();
  source.setAddress(address);
  source.setOutcomes(outcomes);
  source.setDefaultOutcome(Released.getInstance());
  if(receiverOptions.isDynamic()) {
    source.setDynamic(true);
  }

  Target target = new Target();

  receiver.setSource(source);
  receiver.setTarget(target);

  ProtonReceiverImpl r = new ProtonReceiverImpl(receiver);
  r.openHandler((result) -> {
    LOG.trace("Receiver open completed");
  });
  r.closeHandler((result) -> {
    if (result.succeeded()) {
      LOG.trace("Receiver closed");
    } else {
      LOG.warn("Receiver closed with error", result.cause());
    }
  });

  // Default to at-least-once
  r.setQoS(ProtonQoS.AT_LEAST_ONCE);

  return r;
}
 
Example #9
Source File: ProtonReceiverImpl.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
private void handleDecodeFailure(Receiver receiver, ProtonDeliveryImpl delImpl) {
  Modified modified = new Modified();
  modified.setDeliveryFailed(true);
  modified.setUndeliverableHere(true);

  delImpl.disposition(modified, true);

  if(!receiver.getDrain()) {
    flow(1, false);
  } else {
    processForDrainCompletion();
  }
}
 
Example #10
Source File: AmqpReceiver.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void deliveryFailed(Delivery incoming, boolean expandCredit) {
   Modified disposition = new Modified();
   disposition.setUndeliverableHere(true);
   disposition.setDeliveryFailed(true);
   incoming.disposition(disposition);
   incoming.settle();
   if (expandCredit) {
      getEndpoint().flow(1);
   }
}
 
Example #11
Source File: AmqpReceiver.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void configureSource(Source source) {
   Map<Symbol, DescribedType> filters = new HashMap<>();
   Symbol[] outcomes = new Symbol[] {Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL};

   if (getSubscriptionName() != null && !getSubscriptionName().isEmpty()) {
      source.setExpiryPolicy(TerminusExpiryPolicy.NEVER);
      source.setDurable(TerminusDurability.UNSETTLED_STATE);
      source.setDistributionMode(COPY);
   } else {
      source.setDurable(TerminusDurability.NONE);
      source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
   }

   source.setOutcomes(outcomes);

   Modified modified = new Modified();
   modified.setDeliveryFailed(true);
   modified.setUndeliverableHere(false);

   source.setDefaultOutcome(modified);

   if (isNoLocal()) {
      filters.put(NO_LOCAL_NAME, AmqpNoLocalFilter.NO_LOCAL);
   }

   if (getSelector() != null && !getSelector().trim().equals("")) {
      filters.put(JMS_SELECTOR_NAME, new AmqpJmsSelectorFilter(getSelector()));
   }

   if (!filters.isEmpty()) {
      source.setFilter(filters);
   }
}
 
Example #12
Source File: AmqpReceiver.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Mark a message that was dispatched under the given Delivery instance as Modified.
 *
 * @param delivery
 *        the Delivery instance to mark modified.
 * @param deliveryFailed
 *        indicates that the delivery failed for some reason.
 * @param undeliverableHere
 *        marks the delivery as not being able to be process by link it was sent to.
 * @throws IOException
 *         if an error occurs while sending the reject.
 */
public void modified(final Delivery delivery, final Boolean deliveryFailed, final Boolean undeliverableHere) throws IOException {
   checkClosed();

   if (delivery == null) {
      throw new IllegalArgumentException("Delivery to reject cannot be null");
   }

   final ClientFuture request = new ClientFuture();
   session.getScheduler().execute(new Runnable() {

      @Override
      public void run() {
         checkClosed();
         try {
            if (!delivery.isSettled()) {
               Modified disposition = new Modified();
               disposition.setUndeliverableHere(undeliverableHere);
               disposition.setDeliveryFailed(deliveryFailed);
               delivery.disposition(disposition);
               delivery.settle();
               session.pumpToProtonTransport(request);
            }
            request.onSuccess();
         } catch (Exception e) {
            request.onFailure(e);
         }
      }
   });

   request.sync();
}
 
Example #13
Source File: AmqpFlowControlFailTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Parameterized.Parameters(name = "useModified={0}")
public static Collection<Object[]> parameters() {
   return Arrays.asList(new Object[][] {
         {true, new Symbol[]{Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL}, "failure at remote"},
         {true, new Symbol[]{Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL}, "[condition = amqp:resource-limit-exceeded]"},
         {false, new Symbol[]{Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL}, "[condition = amqp:resource-limit-exceeded]"},
         {false, new Symbol[]{}, "[condition = amqp:resource-limit-exceeded]"}
   });
}
 
Example #14
Source File: CommandContext.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Settles the command message with the given {@code DeliveryState} outcome.
 * <p>
 * This method also finishes the OpenTracing span returned by
 * {@link #getCurrentSpan()}.
 *
 * @param deliveryState The deliveryState to set in the disposition frame.
 * @throws NullPointerException if deliveryState is {@code null}.
 */
public void disposition(final DeliveryState deliveryState) {

    Objects.requireNonNull(deliveryState);
    delivery.disposition(deliveryState, true);
    if (Accepted.class.isInstance(deliveryState)) {
        LOG.trace("accepted command message [{}]", getCommand());
        currentSpan.log("accepted command for device");

    } else if (Released.class.isInstance(deliveryState)) {
        LOG.debug("released command message [{}]", getCommand());
        TracingHelper.logError(currentSpan, "released command for device");

    } else if (Modified.class.isInstance(deliveryState)) {
        final Modified modified = (Modified) deliveryState;
        LOG.debug("modified command message [{}]", getCommand());
        TracingHelper.logError(currentSpan, "modified command for device"
                + (Boolean.TRUE.equals(modified.getDeliveryFailed()) ? "; delivery failed" : "")
                + (Boolean.TRUE.equals(modified.getUndeliverableHere()) ? "; undeliverable here" : ""));

    } else if (Rejected.class.isInstance(deliveryState)) {
        final ErrorCondition errorCondition = ((Rejected) deliveryState).getError();
        LOG.debug("rejected command message [error: {}, command: {}]", errorCondition, getCommand());
        TracingHelper.logError(currentSpan, "rejected command for device"
                + ((errorCondition != null && errorCondition.getDescription() != null) ? "; error: " + errorCondition.getDescription() : ""));
    } else {
        LOG.warn("unexpected delivery state [{}] when settling command message [{}]", deliveryState, getCommand());
        TracingHelper.logError(currentSpan, "unexpected delivery state: " + deliveryState);
    }
    currentSpan.finish();
}
 
Example #15
Source File: ProtonServerReceiverContextTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void addressFull_SourceSupportsModified() throws Exception {
   doOnMessageWithDeliveryException(asList(Rejected.DESCRIPTOR_SYMBOL, Accepted.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL), null, new ActiveMQAddressFullException(), Modified.class);
}
 
Example #16
Source File: ProtonServerReceiverContextTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void otherFailure_SourceSupportsRejects() throws Exception {
   doOnMessageWithDeliveryException(asList(Rejected.DESCRIPTOR_SYMBOL, Accepted.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL), null, new ActiveMQException(), Rejected.class);
}
 
Example #17
Source File: ModifiedType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public Class<Modified> getTypeClass()
{
    return Modified.class;
}
 
Example #18
Source File: ProviderDeliveryModifiedException.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public ProviderDeliveryModifiedException(String message, Modified modification) {
    super(message);

    this.modification = modification;
}
 
Example #19
Source File: ProviderDeliveryModifiedException.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public ProviderDeliveryModifiedException(String message, Throwable cause, Modified modification) {
    super(message, cause);

    this.modification = modification;
}
 
Example #20
Source File: AmqpFixedProducer.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
private void applyDeliveryStateUpdate(InFlightSend send, Delivery delivery, DeliveryState state) {
    ProviderException deliveryError = null;
    if (state == null) {
        return;
    }

    switch (state.getType()) {
        case Transactional:
            LOG.trace("State of delivery is Transactional, retrieving outcome: {}", state);
            applyDeliveryStateUpdate(send, delivery, (DeliveryState) ((TransactionalState) state).getOutcome());
            break;
        case Accepted:
            LOG.trace("Outcome of delivery was accepted: {}", delivery);
            send.onSuccess();
            break;
        case Rejected:
            LOG.trace("Outcome of delivery was rejected: {}", delivery);
            ErrorCondition remoteError = ((Rejected) state).getError();
            if (remoteError == null) {
                remoteError = getEndpoint().getRemoteCondition();
            }

            deliveryError = AmqpSupport.convertToNonFatalException(getParent().getProvider(), getEndpoint(), remoteError);
            break;
        case Released:
            LOG.trace("Outcome of delivery was released: {}", delivery);
            deliveryError = new ProviderDeliveryReleasedException("Delivery failed: released by receiver");
            break;
        case Modified:
            LOG.trace("Outcome of delivery was modified: {}", delivery);
            Modified modified = (Modified) state;
            deliveryError = new ProviderDeliveryModifiedException("Delivery failed: failure at remote", modified);
            break;
        default:
            LOG.warn("Message send updated with unsupported state: {}", state);
    }

    if (deliveryError != null) {
        send.onFailure(deliveryError);
    }
}
 
Example #21
Source File: AmqpConsumerBuilder.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
private void configureSource(Source source) {
    Map<Symbol, DescribedType> filters = new HashMap<Symbol, DescribedType>();
    Symbol[] outcomes = new Symbol[]{ Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL,
                                      Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };

    if (resourceInfo.isDurable()) {
        source.setExpiryPolicy(TerminusExpiryPolicy.NEVER);
        source.setDurable(TerminusDurability.UNSETTLED_STATE);
        source.setDistributionMode(COPY);
    } else {
        source.setDurable(TerminusDurability.NONE);
        source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
    }

    if (resourceInfo.isBrowser()) {
        source.setDistributionMode(COPY);
    }

    // Capabilities
    LinkedList<Symbol> capabilities = new LinkedList<>();

    Symbol typeCapability =  AmqpDestinationHelper.toTypeCapability(resourceInfo.getDestination());
    if (typeCapability != null){
        capabilities.add(typeCapability);
    }

    if (resourceInfo.isShared()) {
        capabilities.add(AmqpSupport.SHARED);

        if(!resourceInfo.isExplicitClientID()) {
            capabilities.add(AmqpSupport.GLOBAL);
        }
    }

    if (!capabilities.isEmpty()) {
        Symbol[] capArray = capabilities.toArray(new Symbol[capabilities.size()]);
        source.setCapabilities(capArray);
    }

    //Outcomes
    source.setOutcomes(outcomes);
    source.setDefaultOutcome(MODIFIED_FAILED);

    // Filters
    if (resourceInfo.isNoLocal()) {
        filters.put(JMS_NO_LOCAL_SYMBOL, AmqpJmsNoLocalType.NO_LOCAL);
    }

    if (resourceInfo.getSelector() != null && !resourceInfo.getSelector().trim().equals("")) {
        filters.put(JMS_SELECTOR_SYMBOL, new AmqpJmsSelectorType(resourceInfo.getSelector()));
    }

    if (!filters.isEmpty()) {
        source.setFilter(filters);
    }
}
 
Example #22
Source File: ModifiedType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public ModifiedWrapper(Modified impl)
{
    _impl = impl;
}
 
Example #23
Source File: ModifiedType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
protected List wrap(Modified val)
{
    return new ModifiedWrapper(val);
}