org.apache.qpid.proton.engine.Delivery Java Examples
The following examples show how to use
org.apache.qpid.proton.engine.Delivery.
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: AmqpMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Creates a new AmqpMessage that wraps the information necessary to handle * an incoming delivery. * * @param receiver the AmqpReceiver that received this message. * @param message the Proton message that was received. * @param delivery the Delivery instance that produced this message. */ @SuppressWarnings("unchecked") public AmqpMessage(AmqpReceiver receiver, Message message, Delivery delivery) { this.receiver = receiver; this.message = message; this.delivery = delivery; if (message.getMessageAnnotations() != null) { messageAnnotationsMap = message.getMessageAnnotations().getValue(); } if (message.getApplicationProperties() != null) { applicationPropertiesMap = message.getApplicationProperties().getValue(); } if (message.getDeliveryAnnotations() != null) { deliveryAnnotationsMap = message.getDeliveryAnnotations().getValue(); } }
Example #2
Source File: Send.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void onLinkFlow(Event event) { Sender snd = (Sender)event.getLink(); if (snd.getCredit() > 0) { 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(nextTag++).getBytes(); Delivery dlv = snd.delivery(tag); snd.send(msgData, 0, length); dlv.settle(); snd.advance(); snd.close(); snd.getSession().close(); snd.getSession().getConnection().close(); } }
Example #3
Source File: Spout.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void onLinkFlow(Event evt) { Link link = evt.getLink(); if (link instanceof Sender) { Sender sender = (Sender) link; while ((sent < count) && sender.getCredit() > 0) { Delivery dlv = sender.delivery(String.format("spout-%s", sent).getBytes()); Message msg = new Message(String.format("Hello World! [%s]", sent)); byte[] bytes = msg.getBytes(); sender.send(bytes, 0, bytes.length); sender.advance(); if (!quiet) { System.out.println(String.format("Sent %s to %s: %s", new String(dlv.getTag()), sender.getTarget().getAddress(), msg)); } sent++; } } }
Example #4
Source File: Drain.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void onDelivery(Event evt) { Delivery dlv = evt.getDelivery(); if (dlv.getLink() instanceof Receiver) { Receiver receiver = (Receiver) dlv.getLink(); if (!dlv.isPartial()) { byte[] bytes = new byte[dlv.pending()]; receiver.recv(bytes, 0, bytes.length); Message msg = new Message(bytes); if (!quiet) { System.out.println(String.format("Got message: %s", msg)); } received++; dlv.settle(); } if ((received >= count) || (!block && !receiver.draining())) { receiver.getSession().getConnection().close(); } } }
Example #5
Source File: EventImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public Reactor getReactor() { if (context instanceof Reactor) { return (Reactor) context; } else if (context instanceof Task) { return ((Task)context).getReactor(); } else if (context instanceof Transport) { return ((TransportImpl)context).getReactor(); } else if (context instanceof Delivery) { return ((Delivery)context).getLink().getSession().getConnection().getReactor(); } else if (context instanceof Link) { return ((Link)context).getSession().getConnection().getReactor(); } else if (context instanceof Session) { return ((Session)context).getConnection().getReactor(); } else if (context instanceof Connection) { return ((Connection)context).getReactor(); } else if (context instanceof Selectable) { return ((Selectable)context).getReactor(); } return null; }
Example #6
Source File: Server.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void onDelivery(Event evt) { Delivery dlv = evt.getDelivery(); Link link = dlv.getLink(); if (link instanceof Sender) { dlv.settle(); } else { Receiver rcv = (Receiver) link; if (!dlv.isPartial()) { byte[] bytes = new byte[dlv.pending()]; rcv.recv(bytes, 0, bytes.length); String address = router.getAddress(rcv); Message message = new Message(bytes); messages.put(address, message); dlv.disposition(Accepted.getInstance()); dlv.settle(); if (!quiet) { System.out.println(String.format("Got message(%s): %s", address, message)); } send(address); } } }
Example #7
Source File: DeferredSettlementTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
private Delivery sendMessageToClient(String deliveryTag, int messageBody) { byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8); Message m = Proton.message(); m.setBody(new AmqpValue(messageBody)); byte[] encoded = new byte[BUFFER_SIZE]; int len = m.encode(encoded, 0, BUFFER_SIZE); assertTrue("given array was too small", len < BUFFER_SIZE); Sender serverSender = getServer().getSender(); Delivery serverDelivery = serverSender.delivery(tag); int sent = serverSender.send(encoded, 0, len); assertEquals("sender unable to send all data at once as assumed for simplicity", len, sent); boolean senderAdvanced = serverSender.advance(); assertTrue("sender has not advanced", senderAdvanced); return serverDelivery; }
Example #8
Source File: ProtonTransactionImpl.java From activemq-artemis with Apache License 2.0 | 6 votes |
public ProtonTransactionImpl(final Xid xid, final StorageManager storageManager, final int timeoutSeconds, final AMQPConnectionContext connection) { super(xid, storageManager, timeoutSeconds, true); addOperation(new TransactionOperationAbstract() { @Override public void afterCommit(Transaction tx) { super.afterCommit(tx); connection.runNow(() -> { // Settle all unsettled deliveries if commit is successful for (Pair<Delivery, ProtonServerSenderContext> p : deliveries.values()) { if (!p.getA().isSettled()) p.getB().settle(p.getA()); } connection.flush(); }); } }); }
Example #9
Source File: ProtonTransactionRefsOperation.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void rollbackRedelivery(Transaction txn, MessageReference ref, long timeBase, Map<QueueImpl, LinkedList<MessageReference>> queueMap) throws Exception { ProtonTransactionImpl tx = (ProtonTransactionImpl) txn; if (tx.getDeliveries().containsKey(ref)) { Delivery del = tx.getDeliveries().get(ref).getA(); ServerConsumer consumer = (ServerConsumer) tx.getDeliveries().get(ref).getB().getBrokerConsumer(); // Rollback normally if the delivery is not settled or a forced TX rollback is done (e.g. connection drop). if (del.remotelySettled() || !tx.isDischarged()) { super.rollbackRedelivery(tx, ref, timeBase, queueMap); } else { ref.incrementDeliveryCount(); consumer.backToDelivering(ref); del.disposition(del.getLocalState() == null ? del.getDefaultDeliveryState() : del.getLocalState()); } } else { super.rollbackRedelivery(tx, ref, timeBase, queueMap); } }
Example #10
Source File: AmqpSender.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void encodeAndSend(Message message, Delivery delivery) throws IOException { int encodedSize; while (true) { try { encodedSize = message.encode(encodeBuffer, 0, encodeBuffer.length); break; } catch (java.nio.BufferOverflowException e) { encodeBuffer = new byte[encodeBuffer.length * 2]; } } int sentSoFar = 0; while (true) { int sent = getEndpoint().send(encodeBuffer, sentSoFar, encodedSize - sentSoFar); if (sent > 0) { sentSoFar += sent; if ((encodedSize - sentSoFar) == 0) { break; } } else { LOG.warn("{} failed to send any data from current Message.", this); } } }
Example #11
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testGetTransportWithDeliveryContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); Session session = connection.session(); Sender sender = session.sender("mySender"); Delivery delivery = sender.delivery("tag".getBytes()); EventImpl event = createEvent(delivery, Event.Type.DELIVERY); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #12
Source File: AmqpReceiver.java From activemq-artemis with Apache License 2.0 | 6 votes |
protected Message decodeIncomingMessage(Delivery incoming) { int count; byte[] chunk = new byte[2048]; ByteArrayOutputStream stream = new ByteArrayOutputStream(); while ((count = getEndpoint().recv(chunk, 0, chunk.length)) > 0) { stream.write(chunk, 0, count); } byte[] messageBytes = stream.toByteArray(); try { Message protonMessage = Message.Factory.create(); protonMessage.decode(messageBytes, 0, messageBytes.length); return protonMessage; } finally { try { stream.close(); } catch (IOException e) { } } }
Example #13
Source File: AmqpReceiver.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void processDelivery(Delivery incoming) throws Exception { doDeliveryInspection(incoming); Message message = null; try { message = decodeIncomingMessage(incoming); } catch (Exception e) { LOG.warn("Error on transform: {}", e.getMessage()); deliveryFailed(incoming, true); return; } AmqpMessage amqpMessage = new AmqpMessage(this, message, incoming); // Store reference to envelope in delivery context for recovery incoming.setContext(amqpMessage); prefetch.add(amqpMessage); // We processed a message, signal completion // of a message pull request if there is one. if (pullRequest != null) { pullRequest.onSuccess(); pullRequest = null; } }
Example #14
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 #15
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 #16
Source File: ProtonServerReceiverContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void deliveryFailed(Delivery delivery, Receiver receiver, Exception e) { connection.runNow(() -> { DeliveryState deliveryState = determineDeliveryState(((Source) receiver.getSource()), useModified, e); delivery.disposition(deliveryState); settle(delivery); connection.flush(); }); }
Example #17
Source File: ProtonTransactionHandler.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void txError(Delivery delivery, Throwable e) { log.warn(e.getMessage(), e); connection.runNow(() -> { delivery.settle(); if (e instanceof ActiveMQAMQPException) { delivery.disposition(createRejected(((ActiveMQAMQPException) e).getAmqpError(), e.getMessage())); } else { delivery.disposition(createRejected(Symbol.getSymbol("failed"), e.getMessage())); } connection.flush(); }); }
Example #18
Source File: AmqpConsumer.java From qpid-jms with Apache License 2.0 | 5 votes |
private void handleDelivered(JmsInboundMessageDispatch envelope, Delivery delivery) { LOG.debug("Delivered Ack of message: {}", envelope); deliveredCount++; envelope.setRecovered(false); envelope.setDelivered(true); delivery.setDefaultDeliveryState(MODIFIED_FAILED); }
Example #19
Source File: ProtonServerReceiverContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void actualDelivery(AMQPMessage message, Delivery delivery, Receiver receiver, Transaction tx) { try { sessionSPI.serverSend(this, tx, receiver, delivery, address, routingContext, message); } catch (Exception e) { log.warn(e.getMessage(), e); deliveryFailed(delivery, receiver, e); } }
Example #20
Source File: ProtonServerSenderContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void deliverLarge(MessageReference messageReference, AMQPLargeMessage message) { // we only need a tag if we are going to settle later byte[] tag = preSettle ? new byte[0] : protonSession.getTag(); final Delivery delivery; delivery = sender.delivery(tag, 0, tag.length); delivery.setMessageFormat((int) message.getMessageFormat()); delivery.setContext(messageReference); pendingLargeMessage = new LargeMessageDeliveryContext(messageReference, message, delivery); pendingLargeMessage.deliver(); }
Example #21
Source File: ProtonReceiverImpl.java From vertx-proton with Apache License 2.0 | 5 votes |
private void handlePartial(final Receiver receiver, final Delivery delivery) { if (sessionIncomingCapacity <= 0 || maxFrameSize <= 0 || session.getIncomingBytes() < windowFullThreshhold) { // No window, or there is still capacity, so do nothing. } else { // The session window could be effectively full, we need to // read part of the delivery content to ensure there is // room made for receiving more of the delivery. if(delivery.available() > 0) { ReadableBuffer buff = receiver.recv(); if(splitContent == null && buff instanceof CompositeReadableBuffer) { // Its a composite and there is no prior partial content, use it. splitContent = (CompositeReadableBuffer) buff; } else { int remaining = buff.remaining(); if(remaining > 0) { if (splitContent == null) { splitContent = new CompositeReadableBuffer(); } byte[] chunk = new byte[remaining]; buff.get(chunk); splitContent.append(chunk); } } } } }
Example #22
Source File: AmqpReceiver.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void doDeliveryInspection(Delivery delivery) { try { getStateInspector().inspectDelivery(getReceiver(), delivery); } catch (Throwable error) { getStateInspector().markAsInvalid(error.getMessage()); } }
Example #23
Source File: ProtonSenderImpl.java From vertx-proton with Apache License 2.0 | 5 votes |
@Override public ProtonDelivery send(byte[] tag, Message message, Handler<ProtonDelivery> onUpdated) { if (anonymousSender && message.getAddress() == null) { throw new IllegalArgumentException("Message must have an address when using anonymous sender."); } // TODO: prevent odd combination of onRecieved callback + SenderSettleMode.SETTLED, or just allow it? Delivery delivery = sender().delivery(tag); // start a new delivery.. ProtonWritableBufferImpl buffer = new ProtonWritableBufferImpl(); MessageImpl msg = (MessageImpl) message; msg.encode(buffer); ReadableBuffer encoded = new ProtonReadableBufferImpl(buffer.getBuffer()); sender().sendNoCopy(encoded); if (link.getSenderSettleMode() == SenderSettleMode.SETTLED) { delivery.settle(); } sender().advance(); // ends the delivery. ProtonDeliveryImpl protonDeliveryImpl = new ProtonDeliveryImpl(delivery); if (onUpdated != null) { protonDeliveryImpl.setAutoSettle(autoSettle); protonDeliveryImpl.handler(onUpdated); } else { protonDeliveryImpl.setAutoSettle(true); } getSession().getConnectionImpl().flush(); return protonDeliveryImpl; }
Example #24
Source File: AmqpReceiver.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void processDeliveryUpdates(AmqpConnection connection, Delivery delivery) throws IOException { Delivery incoming = null; do { incoming = getEndpoint().current(); if (incoming != null) { if (incoming.isReadable() && !incoming.isPartial()) { LOG.trace("{} has incoming Message(s).", this); try { processDelivery(incoming); } catch (Exception e) { throw IOExceptionSupport.create(e); } getEndpoint().advance(); } else { LOG.trace("{} has a partial incoming Message(s), deferring.", this); incoming = null; } } else { // We have exhausted the locally queued messages on this link. // Check if we tried to stop and have now run out of credit. if (getEndpoint().getRemoteCredit() <= 0) { if (stopRequest != null) { stopRequest.onSuccess(); stopRequest = null; } } } } while (incoming != null); super.processDeliveryUpdates(connection, delivery); }
Example #25
Source File: AmqpReceiver.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Reject a message that was dispatched under the given Delivery instance. * * @param delivery * the Delivery instance to reject. * @throws IOException * if an error occurs while sending the release. */ public void reject(final Delivery delivery) throws IOException { checkClosed(); if (delivery == null) { throw new IllegalArgumentException("Delivery to release cannot be null"); } final ClientFuture request = new ClientFuture(); session.getScheduler().execute(new Runnable() { @Override public void run() { checkClosed(); try { if (!delivery.isSettled()) { delivery.disposition(new Rejected()); delivery.settle(); session.pumpToProtonTransport(request); } request.onSuccess(); } catch (Exception e) { request.onFailure(e); } } }); request.sync(); }
Example #26
Source File: AmqpConsumer.java From qpid-jms with Apache License 2.0 | 5 votes |
private void handleAccepted(JmsInboundMessageDispatch envelope, Delivery delivery) { LOG.debug("Accepted Ack of message: {}", envelope); if (!delivery.remotelySettled()) { if (session.isTransacted() && !getResourceInfo().isBrowser()) { if (session.isTransactionFailed()) { LOG.trace("Skipping ack of message {} in failed transaction.", envelope); return; } Binary txnId = session.getTransactionContext().getAmqpTransactionId(); if (txnId != null) { delivery.disposition(session.getTransactionContext().getTxnAcceptState()); delivery.settle(); session.getTransactionContext().registerTxConsumer(this); } } else { delivery.disposition(Accepted.getInstance()); delivery.settle(); } } else { delivery.settle(); } if (envelope.isDelivered()) { deliveredCount--; } dispatchedCount--; }
Example #27
Source File: Server.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private int send(String address, Sender snd) { if (snd == null) { Router.Routes<Sender> routes = router.getOutgoing(address); snd = routes.choose(); if (snd == null) { return 0; } } int count = 0; while (snd.getCredit() > 0 && snd.getQueued() < 1024) { Message msg = messages.get(address); if (msg == null) { snd.drained(); return count; } Delivery dlv = snd.delivery(nextTag()); byte[] bytes = msg.getBytes(); snd.send(bytes, 0, bytes.length); dlv.settle(); count++; if (!quiet) { System.out.println(String.format("Sent message(%s): %s", address, msg)); } } return count; }
Example #28
Source File: AmqpMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * @return the AMQP Delivery object linked to a received message. */ public Delivery getWrappedDelivery() { if (delivery != null) { return UnmodifiableProxy.deliveryProxy(delivery); } return null; }
Example #29
Source File: AmqpReceiver.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * 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 #30
Source File: AmqpReceiver.java From activemq-artemis with Apache License 2.0 | 5 votes |
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); } }