use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF in project swiftmq-client by iitsoftware.
the class AMQPMessage method accept.
/**
* Accepts delivery of this message. This is part of settlement with QoS modes at-least-once and exactly-once.
*
* @throws InvalidStateException If the state is invalid to perform this operation
*/
public void accept() throws InvalidStateException {
if (consumer == null)
throw new InvalidStateException("Message not associated with a consumer");
if (settled && txnIdIF == null)
throw new InvalidStateException("Accept not required; message has already been settled");
DeliveryStateIF deliveryStateIF = null;
if (txnIdIF == null)
deliveryStateIF = new Accepted();
else {
TransactionalState transactionalState = new TransactionalState();
transactionalState.setTxnId(txnIdIF);
transactionalState.setOutcome(new Accepted());
deliveryStateIF = transactionalState;
}
consumer.sendDisposition(this, deliveryStateIF);
}
use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF in project swiftmq-client by iitsoftware.
the class AMQPMessage method reject.
/**
* <p>Rejects delivery of this message. This is part of settlement with QoS modes at-least-once and exactly-once.
* </p>
* <p>
* This operation causes the delivery count to be incremented and the message to be redelivered to this or other
* competing consumers.
* </p>
*
* @throws InvalidStateException If the state is invalid to perform this operation
*/
public void reject() throws InvalidStateException {
if (consumer == null)
throw new InvalidStateException("Message not associated with a consumer");
if (settled && txnIdIF == null)
throw new InvalidStateException("Reject not possible; message has already been settled");
DeliveryStateIF deliveryStateIF = null;
if (txnIdIF == null)
deliveryStateIF = new Rejected();
else {
TransactionalState transactionalState = new TransactionalState();
transactionalState.setTxnId(txnIdIF);
transactionalState.setOutcome(new Rejected());
deliveryStateIF = transactionalState;
}
consumer.sendDisposition(this, deliveryStateIF);
}
use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF in project swiftmq-ce by iitsoftware.
the class SourceLink method verifyLocalAddress.
public void verifyLocalAddress() throws AuthenticationException, QueueException, TopicException, InvalidSelectorException {
if (!dynamic) {
// This is for the case of reconnecting to a Durable Subscriber without specifying a Source in the attach frame.
if (localAddress == null) {
String topicName = ctx.topicManager.getDurableTopicName(getName(), mySessionHandler.getVersionedConnection().getActiveLogin());
if (topicName != null)
localAddress = new AddressString(topicName);
durability = TerminusDurability.CONFIGURATION;
}
super.verifyLocalAddress();
}
if (receiver == null) {
MessageSelector msel = null;
if (messageSelector != null) {
msel = new MessageSelector(messageSelector);
msel.compile();
}
if (dynamic) {
expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
durability = TerminusDurability.NONE;
// sndSettleMode = SenderSettleMode.SETTLED.getValue(); // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
queueName = ctx.queueManager.createTemporaryQueue();
receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
} else {
if (isQueue) {
expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
durability = TerminusDurability.CONFIGURATION;
// sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
receiver = ctx.queueManager.createQueueReceiver(getLocalAddress().getValueString(), mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
} else {
if (durability.getValue() == TerminusDurability.CONFIGURATION.getValue() || durability.getValue() == TerminusDurability.UNSETTLED_STATE.getValue()) {
if (!expiryPolicy.getValue().equals(TerminusExpiryPolicy.LINK_DETACH.getValue()))
expiryPolicy = TerminusExpiryPolicy.NEVER;
durability = TerminusDurability.CONFIGURATION;
// sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
queueName = ctx.topicManager.subscribeDurable(name, (TopicImpl) getLocalDestination(), msel, noLocal, mySessionHandler.getVersionedConnection().getActiveLogin());
} else {
expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
queueName = ctx.queueManager.createTemporaryQueue();
// sndSettleMode = SenderSettleMode.SETTLED.getValue(); // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
subscriberId = ctx.topicManager.subscribe((TopicImpl) localDestination, msel, noLocal, queueName, mySessionHandler.getVersionedConnection().getActiveLogin());
}
receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), null);
}
}
}
if (remoteUnsettled != null) {
final AbstractQueue aq = ctx.queueManager.getQueueForInternalUse(receiver.getQueueName());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, abstractQueue=" + aq);
DataByteArrayInputStream dbis = new DataByteArrayInputStream();
for (Iterator iter = remoteUnsettled.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
AMQPBinary deliveryTag = (AMQPBinary) entry.getKey();
DeliveryStateIF deliveryStateIF = null;
try {
deliveryStateIF = DeliveryStateFactory.create((AMQPList) entry.getValue());
} catch (Exception e) {
throw new QueueException("Unable to create delivery tag");
}
final MessageIndex messageIndex = new MessageIndex();
dbis.setBuffer(deliveryTag.getValue());
try {
messageIndex.readContent(dbis);
} catch (IOException e) {
throw new QueueException("Unable to convert delivery tag into a message index");
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", deliveryStateIF=" + deliveryStateIF);
if (deliveryStateIF != null) {
deliveryStateIF.accept(new DeliveryStateVisitorAdapter() {
public void visit(Accepted accepted) {
try {
if (aq != null) {
MessageIndex indexEntry = aq.getIndexEntry(messageIndex);
if (indexEntry != null) {
aq.removeMessageByIndex(indexEntry);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + indexEntry + ", removed");
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", NOT FOUND!");
}
}
} catch (QueueException e) {
e.printStackTrace();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", exception=" + e);
}
}
});
}
}
}
}
use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF in project swiftmq-ce by iitsoftware.
the class TargetLink method transformAndStore.
private void transformAndStore(TransferFrame frame) throws EndWithErrorException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/transformAndStore, frame=" + frame);
if (mySessionHandler.maxMessageSize > 0 && frame.getPayloadLength() > mySessionHandler.maxMessageSize)
throw new LinkEndException(this, LinkError.MESSAGE_SIZE_EXCEEDED, new AMQPString("Message size (" + frame.getPayloadLength() + ") > max message size (" + mySessionHandler.maxMessageSize));
if (coordinator)
handleTransactionRequest(frame);
else {
try {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/transformAndStore, localDestination=" + localDestination);
long payloadLength = frame.getPayloadLength();
MessageImpl msg = getTransformer(frame.getMessageFormat().getValue()).transform(frame, this);
if (msg.getJMSDestination() == null)
msg.setJMSDestination(getLocalDestination());
msg.setStringProperty(MessageImpl.PROP_CLIENT_ID, mySessionHandler.getVersionedConnection().getActiveLogin().getClientId());
if (remoteUnsettled != null) {
DeliveryTag deliveryTag = frame.getDeliveryTag();
if (remoteUnsettled.remove(deliveryTag) != null) {
msg.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
if (remoteUnsettled.size() == 0)
remoteUnsettled = null;
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/transformAndStore, msg=" + msg);
DeliveryStateIF state = frame.getState();
if (state != null && state instanceof TransactionalState) {
TransactionalState txState = (TransactionalState) state;
TxnIdIF txnId = txState.getTxnId();
if (txnId != null) {
transactionRegistry.addToTransaction(txnId, name, msg, this);
} else
throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Missing TxnId in TransactionalState: " + txState));
} else {
QueuePushTransaction tx = sender.createTransaction();
tx.putMessage(msg);
tx.commit();
setFlowcontrolDelay(tx.getFlowControlDelay());
}
} catch (Exception e) {
throw new SessionEndException(AmqpError.INTERNAL_ERROR, new AMQPString("Exception during transformAndStore: " + e));
}
}
}
use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF in project swiftmq-ce by iitsoftware.
the class TransactionRegistry method addToTransaction.
public void addToTransaction(TxnIdIF txnIdIF, DispositionFrame frame) throws EndWithErrorException {
String txnId = new String(((TransactionId) txnIdIF).getValue());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", frame=" + frame);
long from = frame.getFirst().getValue();
long to = from;
if (frame.getLast() != null)
to = frame.getLast().getValue();
DeliveryStateIF deliveryStateIF = frame.getState();
long current = from;
while (current <= to) {
addToTransaction(txnId, current, deliveryStateIF);
current++;
}
}
Aggregations