Java Code Examples for org.apache.qpid.proton.engine.Delivery#getContext()
The following examples show how to use
org.apache.qpid.proton.engine.Delivery#getContext() .
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: AmqpFixedProducer.java From qpid-jms with Apache License 2.0 | 6 votes |
@Override public void processDeliveryUpdates(AmqpProvider provider, Delivery delivery) throws ProviderException { DeliveryState state = delivery.getRemoteState(); if (state != null) { InFlightSend send = (InFlightSend) delivery.getContext(); if (state.getType() == DeliveryStateType.Accepted) { LOG.trace("Outcome of delivery was accepted: {}", delivery); send.onSuccess(); } else { applyDeliveryStateUpdate(send, delivery, state); } } super.processDeliveryUpdates(provider, delivery); }
Example 2
Source File: AmqpConsumer.java From qpid-jms with Apache License 2.0 | 6 votes |
private void acknowledgeUndeliveredRecoveredMessages() { if(acknowledgementMode == Session.CLIENT_ACKNOWLEDGE) { // Send dispositions for any messages which were previously delivered and // session recovered, but were then not delivered again afterwards. Delivery delivery = getEndpoint().head(); while (delivery != null) { Delivery current = delivery; delivery = delivery.next(); if (!(current.getContext() instanceof JmsInboundMessageDispatch)) { continue; } JmsInboundMessageDispatch envelope = (JmsInboundMessageDispatch) current.getContext(); if (envelope.isRecovered() && !envelope.isDelivered()) { handleDisposition(envelope, current, MODIFIED_FAILED); } } } }
Example 3
Source File: AmqpConsumer.java From qpid-jms with Apache License 2.0 | 6 votes |
private void releasePrefetch() { Delivery delivery = getEndpoint().head(); while (delivery != null) { Delivery current = delivery; delivery = delivery.next(); if (current.getContext() instanceof JmsInboundMessageDispatch) { JmsInboundMessageDispatch envelope = (JmsInboundMessageDispatch) current.getContext(); if (!envelope.isDelivered()) { handleDisposition(envelope, current, Released.getInstance()); } } else { LOG.debug("{} Found incomplete delivery with no context during release processing", AmqpConsumer.this); } } }
Example 4
Source File: AmqpTransactionCoordinator.java From qpid-jms with Apache License 2.0 | 5 votes |
@Override public void closeResource(AmqpProvider provider, ProviderException cause, boolean localClose) { // Alert any pending operation that the link failed to complete the pending // begin / commit / rollback operation. Delivery pending = getEndpoint().head(); while (pending != null) { Delivery nextPending = pending.next(); if (pending.getContext() != null && pending.getContext() instanceof OperationContext) { OperationContext context = (OperationContext) pending.getContext(); context.request.onFailure(cause); } pending = nextPending; } // Override the base class version because we do not want to propagate // an error up to the client if remote close happens as that is an // acceptable way for the remote to indicate the discharge could not // be applied. if (getParent() != null) { getParent().removeChildResource(this); } if (getEndpoint() != null) { getEndpoint().close(); getEndpoint().free(); } LOG.debug("Transaction Coordinator link {} was remotely closed", getResourceInfo()); }
Example 5
Source File: AmqpTransactionCoordinator.java From qpid-jms with Apache License 2.0 | 4 votes |
@Override public void processDeliveryUpdates(AmqpProvider provider, Delivery delivery) throws ProviderException { try { if (delivery != null && delivery.remotelySettled()) { DeliveryState state = delivery.getRemoteState(); if (delivery.getContext() == null || !(delivery.getContext() instanceof OperationContext)) { return; } OperationContext context = (OperationContext) delivery.getContext(); AsyncResult pendingRequest = context.getRequest(); JmsTransactionId txId = context.getTransactionId(); if (state instanceof Declared) { LOG.debug("New TX started: {}", txId); Declared declared = (Declared) state; txId.setProviderHint(declared.getTxnId()); pendingRequest.onSuccess(); } else if (state instanceof Rejected) { LOG.debug("Last TX request failed: {}", txId); Rejected rejected = (Rejected) state; ProviderException cause = AmqpSupport.convertToNonFatalException(getParent().getProvider(), getEndpoint(), rejected.getError()); if (COMMIT_MARKER.equals(txId.getProviderContext()) && !(cause instanceof ProviderTransactionRolledBackException)){ cause = new ProviderTransactionRolledBackException(cause.getMessage(), cause); } else { cause = new ProviderTransactionInDoubtException(cause.getMessage(), cause); } txId.setProviderHint(null); pendingRequest.onFailure(cause); } else { LOG.debug("Last TX request succeeded: {}", txId); pendingRequest.onSuccess(); } // Reset state for next TX action. delivery.settle(); pendingRequest = null; if (context.getTimeout() != null) { context.getTimeout().cancel(false); } } super.processDeliveryUpdates(provider, delivery); } catch (Throwable e) { throw ProviderExceptionSupport.createNonFatalOrPassthrough(e); } }
Example 6
Source File: AmqpConsumer.java From qpid-jms with Apache License 2.0 | 4 votes |
/** * Called to acknowledge all messages that have been marked as delivered but * have not yet been marked consumed. Usually this is called as part of an * client acknowledge session operation. * * Only messages that have already been acknowledged as delivered by the JMS * framework will be in the delivered Map. This means that the link credit * would already have been given for these so we just need to settle them. * * @param ackType the type of acknowledgement to perform */ public void acknowledge(ACK_TYPE ackType) { LOG.trace("Session Acknowledge for consumer {} with ack type {}", getResourceInfo().getId(), ackType); Delivery delivery = getEndpoint().head(); while (delivery != null) { Delivery current = delivery; delivery = delivery.next(); if (!(current.getContext() instanceof JmsInboundMessageDispatch)) { LOG.debug("{} Found incomplete delivery with no context during session acknowledge processing", AmqpConsumer.this); continue; } JmsInboundMessageDispatch envelope = (JmsInboundMessageDispatch) current.getContext(); if(ackType == ACK_TYPE.SESSION_SHUTDOWN && (envelope.isDelivered() || envelope.isRecovered())) { handleDisposition(envelope, current, MODIFIED_FAILED); } else if (envelope.isDelivered()) { final DeliveryState disposition; switch (ackType) { case ACCEPTED: disposition = Accepted.getInstance(); break; case RELEASED: disposition = Released.getInstance(); break; case REJECTED: disposition = REJECTED; break; case MODIFIED_FAILED: disposition = MODIFIED_FAILED; break; case MODIFIED_FAILED_UNDELIVERABLE: disposition = MODIFIED_FAILED_UNDELIVERABLE; break; default: throw new IllegalArgumentException("Invalid acknowledgement type specified: " + ackType); } handleDisposition(envelope, current, disposition); } } tryCompleteDeferredClose(); }
Example 7
Source File: AmqpConsumer.java From qpid-jms with Apache License 2.0 | 4 votes |
/** * Recovers all previously delivered but not acknowledged messages. * * @throws Exception if an error occurs while performing the recover. */ public void recover() throws Exception { LOG.debug("Session Recover for consumer: {}", getResourceInfo().getId()); ArrayList<JmsInboundMessageDispatch> redispatchList = new ArrayList<JmsInboundMessageDispatch>(); Delivery delivery = getEndpoint().head(); while (delivery != null) { Delivery current = delivery; delivery = delivery.next(); if (!(current.getContext() instanceof JmsInboundMessageDispatch)) { LOG.debug("{} Found incomplete delivery with no context during recover processing", AmqpConsumer.this); continue; } JmsInboundMessageDispatch envelope = (JmsInboundMessageDispatch) current.getContext(); if (envelope.isDelivered()) { envelope.getMessage().getFacade().setRedeliveryCount( envelope.getMessage().getFacade().getRedeliveryCount() + 1); envelope.setEnqueueFirst(true); envelope.setDelivered(false); if(acknowledgementMode == Session.CLIENT_ACKNOWLEDGE) { envelope.setRecovered(true); } redispatchList.add(envelope); } } // Previously delivered messages should be tagged as dispatched messages again so we // can properly compute the next credit refresh, so subtract them from both the delivered // and dispatched counts and then dispatch them again as a new message. deliveredCount -= redispatchList.size(); dispatchedCount -= redispatchList.size(); ListIterator<JmsInboundMessageDispatch> reverseIterator = redispatchList.listIterator(redispatchList.size()); while (reverseIterator.hasPrevious()) { deliver(reverseIterator.previous()); } }