本文整理汇总了Java中org.apache.qpid.proton.engine.Delivery.setContext方法的典型用法代码示例。如果您正苦于以下问题:Java Delivery.setContext方法的具体用法?Java Delivery.setContext怎么用?Java Delivery.setContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.qpid.proton.engine.Delivery
的用法示例。
在下文中一共展示了Delivery.setContext方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processDelivery
import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
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;
}
}
示例2: send
import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
TrackerImpl send(org.apache.qpid.proton.message.Message m) throws MessageFormatException, MessagingException {
checkClosed();
Sender sender = (Sender) _link;
byte[] tag = longToBytes(_ssn.getNextDeliveryTag());
Delivery delivery = sender.delivery(tag);
TrackerImpl tracker = new TrackerImpl(_ssn);
delivery.setContext(tracker);
if (m.getAddress() == null) {
m.setAddress(_address);
}
byte[] buffer = new byte[1024];
int encoded = m.encode(buffer, 0, buffer.length);
sender.send(buffer, 0, encoded);
if (sender.getSenderSettleMode() == SenderSettleMode.SETTLED) {
delivery.settle();
tracker.markSettled();
}
sender.advance();
_ssn.getConnection().write();
return tracker;
}
示例3: receiveMessageFromServer
import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
private Delivery receiveMessageFromServer(String deliveryTag, int count)
{
Delivery delivery = getClient().getConnection().getWorkHead();
Receiver clientReceiver = getClient().getReceiver();
assertTrue(Arrays.equals(deliveryTag.getBytes(StandardCharsets.UTF_8), delivery.getTag()));
assertEquals("The received delivery should be on our receiver",
clientReceiver, delivery.getLink());
assertNull(delivery.getLocalState());
assertNull(delivery.getRemoteState());
assertFalse(delivery.isPartial());
assertTrue(delivery.isReadable());
int size = delivery.available();
byte[] received = new byte[size];
int len = clientReceiver.recv(received, 0, size);
assertEquals("Should have received " + size + " bytes", size, len);
assertEquals("Should be no bytes left", 0, delivery.available());
Message m = Proton.message();
m.decode(received, 0, len);
Object messageBody = ((AmqpValue)m.getBody()).getValue();
assertEquals("Unexpected message content", count, messageBody);
boolean receiverAdvanced = clientReceiver.advance();
assertTrue("receiver has not advanced", receiverAdvanced);
delivery.setContext(count);
return delivery;
}
示例4: doSend
import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
private void doSend(AmqpMessage message, AsyncResult request, AmqpTransactionId txId) throws Exception {
LOG.trace("Producer sending message: {}", message);
Delivery delivery = null;
if (presettle) {
delivery = getEndpoint().delivery(EMPTY_BYTE_ARRAY, 0, 0);
} else {
byte[] tag = tagGenerator.getNextTag();
delivery = getEndpoint().delivery(tag, 0, tag.length);
}
delivery.setContext(request);
Binary amqpTxId = null;
if (txId != null) {
amqpTxId = txId.getRemoteTxId();
} else if (session.isInTransaction()) {
amqpTxId = session.getTransactionId().getRemoteTxId();
}
if (amqpTxId != null) {
TransactionalState state = new TransactionalState();
state.setTxnId(amqpTxId);
delivery.disposition(state);
}
encodeAndSend(message.getWrappedMessage(), delivery);
if (presettle) {
delivery.settle();
request.onSuccess();
} else {
pending.add(delivery);
getEndpoint().advance();
}
}
示例5: send
import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
@Override
public Tracker send(Message msg) throws MessageFormatException, MessagingException, NetworkException
{
checkClosed();
if (msg instanceof MessageImpl)
{
Sender sender = (Sender) _link;
byte[] tag = longToBytes(_ssn.getNextDeliveryTag());
Delivery delivery = sender.delivery(tag);
TrackerImpl tracker = new TrackerImpl(_ssn);
delivery.setContext(tracker);
if (sender.getSenderSettleMode() == SenderSettleMode.SETTLED)
{
delivery.settle();
tracker.markSettled();
}
org.apache.qpid.proton.message.Message m = ((MessageImpl) msg).getProtocolMessage();
if (m.getAddress() == null)
{
m.setAddress(_address);
}
byte[] buffer = new byte[1024];
int encoded = m.encode(buffer, 0, buffer.length);
sender.send(buffer, 0, encoded);
sender.advance();
_ssn.getConnection().write();
return tracker;
}
else
{
throw new MessageFormatException("Unsupported message implementation");
}
}
示例6: deliverMessage
import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
/**
* handle an out going message from ActiveMQ Artemis, send via the Proton Sender
*/
public int deliverMessage(MessageReference messageReference, int deliveryCount, Connection transportConnection) throws Exception {
if (closed) {
return 0;
}
AMQPMessage message = CoreAmqpConverter.checkAMQP(messageReference.getMessage());
sessionSPI.invokeOutgoing(message, (ActiveMQProtonRemotingConnection) transportConnection.getProtocolConnection());
// presettle means we can settle the message on the dealer side before we send it, i.e.
// for browsers
boolean preSettle = sender.getRemoteSenderSettleMode() == SenderSettleMode.SETTLED;
// we only need a tag if we are going to settle later
byte[] tag = preSettle ? new byte[0] : protonSession.getTag();
ByteBuf nettyBuffer = PooledByteBufAllocator.DEFAULT.heapBuffer(message.getEncodeSize());
try {
message.sendBuffer(nettyBuffer, deliveryCount);
int size = nettyBuffer.writerIndex();
while (!connection.tryLock(1, TimeUnit.SECONDS)) {
if (closed || sender.getLocalState() == EndpointState.CLOSED) {
// If we're waiting on the connection lock, the link might be in the process of closing. If this happens
// we return.
return 0;
} else {
if (log.isDebugEnabled()) {
log.debug("Couldn't get lock on deliverMessage " + this);
}
}
}
try {
final Delivery delivery;
delivery = sender.delivery(tag, 0, tag.length);
delivery.setMessageFormat((int) message.getMessageFormat());
delivery.setContext(messageReference);
// this will avoid a copy.. patch provided by Norman using buffer.array()
sender.send(nettyBuffer.array(), nettyBuffer.arrayOffset() + nettyBuffer.readerIndex(), nettyBuffer.readableBytes());
if (preSettle) {
// Presettled means the client implicitly accepts any delivery we send it.
sessionSPI.ack(null, brokerConsumer, messageReference.getMessage());
delivery.settle();
} else {
sender.advance();
}
connection.flush();
} finally {
connection.unlock();
}
return size;
} finally {
nettyBuffer.release();
}
}
示例7: ProtonDeliveryImpl
import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
ProtonDeliveryImpl(Delivery delivery) {
this.delivery = delivery;
delivery.setContext(this);
}
示例8: processDelivery
import org.apache.qpid.proton.engine.Delivery; //导入方法依赖的package包/类
private boolean processDelivery(Delivery incoming) throws Exception {
incoming.setDefaultDeliveryState(Released.getInstance());
JmsMessage message = null;
try {
message = AmqpCodec.decodeMessage(this, unwrapIncomingMessage(incoming)).asJmsMessage();
} catch (Exception e) {
LOG.warn("Error on transform: {}", e.getMessage());
// TODO - We could signal provider error but not sure we want to fail
// the connection just because we can't convert the message.
// In the future once the JMS mapping is complete we should be
// able to convert everything to some message even if its just
// a bytes messages as a fall back.
settleDelivery(incoming, MODIFIED_FAILED_UNDELIVERABLE);
return false;
} finally {
incomingBuffer.clear();
}
try {
// Let the message do any final processing before sending it onto a consumer.
// We could defer this to a later stage such as the JmsConnection or even in
// the JmsMessageConsumer dispatch method if we needed to.
message.onDispatch();
JmsInboundMessageDispatch envelope = new JmsInboundMessageDispatch(getNextIncomingSequenceNumber());
envelope.setMessage(message);
envelope.setConsumerId(getResourceInfo().getId());
// Store link to delivery in the hint for use in acknowledge requests.
envelope.setProviderHint(incoming);
envelope.setMessageId(message.getFacade().getProviderMessageIdObject());
// Store reference to envelope in delivery context for recovery
incoming.setContext(envelope);
deliver(envelope);
return true;
} finally {
getEndpoint().advance();
}
}