use of com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState 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.transactions.coordination.TransactionalState 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.transactions.coordination.TransactionalState 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.transactions.coordination.TransactionalState in project swiftmq-client by iitsoftware.
the class DeliveryStateFactory method create.
/**
* Creates a DeliveryStateIF object.
*
* @param bare the bare AMQP type
* @return DeliveryStateIF
*/
public static DeliveryStateIF create(AMQPType bare) throws Exception {
if (bare.getCode() == AMQPTypeDecoder.NULL)
return null;
AMQPDescribedConstructor constructor = bare.getConstructor();
if (constructor == null)
throw new IOException("Missing constructor: " + bare);
AMQPType descriptor = constructor.getDescriptor();
int code = descriptor.getCode();
if (AMQPTypeDecoder.isULong(code)) {
long type = ((AMQPUnsignedLong) descriptor).getValue();
if (type == Received.DESCRIPTOR_CODE)
return new Received(((AMQPList) bare).getValue());
if (type == Accepted.DESCRIPTOR_CODE)
return new Accepted(((AMQPList) bare).getValue());
if (type == Rejected.DESCRIPTOR_CODE)
return new Rejected(((AMQPList) bare).getValue());
if (type == Released.DESCRIPTOR_CODE)
return new Released(((AMQPList) bare).getValue());
if (type == Modified.DESCRIPTOR_CODE)
return new Modified(((AMQPList) bare).getValue());
if (type == Declared.DESCRIPTOR_CODE)
return new Declared(((AMQPList) bare).getValue());
if (type == TransactionalState.DESCRIPTOR_CODE)
return new TransactionalState(((AMQPList) bare).getValue());
throw new Exception("Invalid descriptor type: " + type + ", bare=" + bare);
} else if (AMQPTypeDecoder.isSymbol(code)) {
String type = ((AMQPSymbol) descriptor).getValue();
if (type.equals(Received.DESCRIPTOR_NAME))
return new Received(((AMQPList) bare).getValue());
if (type.equals(Accepted.DESCRIPTOR_NAME))
return new Accepted(((AMQPList) bare).getValue());
if (type.equals(Rejected.DESCRIPTOR_NAME))
return new Rejected(((AMQPList) bare).getValue());
if (type.equals(Released.DESCRIPTOR_NAME))
return new Released(((AMQPList) bare).getValue());
if (type.equals(Modified.DESCRIPTOR_NAME))
return new Modified(((AMQPList) bare).getValue());
if (type.equals(Declared.DESCRIPTOR_NAME))
return new Declared(((AMQPList) bare).getValue());
if (type.equals(TransactionalState.DESCRIPTOR_NAME))
return new TransactionalState(((AMQPList) bare).getValue());
throw new Exception("Invalid descriptor type: " + type + ", bare=" + bare);
} else
throw new Exception("Invalid type of constructor descriptor (actual type=" + code + ", expected=symbold or ulong), bare= " + bare);
}
use of com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState in project swiftmq-client by iitsoftware.
the class SessionDispatcher method doSend.
private void doSend(POSendMessage po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, po=" + po + ", dataLength=" + po.getPackager().getSize());
try {
Producer producer = po.getProducer();
producer.verifyState();
Packager packager = po.getPackager();
if (remoteIncomingWindow > 0 && outgoingWindow > 0) {
do {
boolean wasFirstPacket = false;
boolean isAtMostOnce = producer.getQoS() == QoS.AT_MOST_ONCE;
packager.setMaxFrameSize(mySession.myConnection.connectionDispatcher.getMaxFrameSize());
TransferFrame frame = new TransferFrame(mySession.getChannel());
frame.setHandle(new Handle(producer.getHandle()));
frame.setSettled(new AMQPBoolean(isAtMostOnce));
if (packager.getCurrentPacketNumber() == 0) {
long dId = nextDeliveryId();
wasFirstPacket = true;
producer.incDeliveryCountSnd();
DeliveryTag deliveryTag = po.getDeliveryTag() != null ? po.getDeliveryTag() : producer.createDeliveryTag();
if (!isAtMostOnce) {
if (po.getTxnId() == null && !po.isRecovery())
producer.getDeliveryMemory().addUnsettledDelivery(new UnsettledDelivery(deliveryTag, null, po.getMessage()));
unsettledOutgoingDeliveries.put(dId, new DeliveryMapping(deliveryTag, producer));
}
frame.setDeliveryTag(deliveryTag);
frame.setDeliveryId(new DeliveryNumber(dId));
frame.setMessageFormat(new MessageFormat(0));
TxnIdIF txnId = po.getTxnId();
if (txnId != null) {
TransactionalState txState = new TransactionalState();
txState.setTxnId(txnId);
frame.setState(txState);
}
}
packager.setMessageFormat(0);
packager.getNextPacket(frame);
// We may increase the outgoing window and send a flow before
if (wasFirstPacket && outgoingWindow - packager.getPredictedNumberPackets() < 0) {
outgoingWindow += packager.getPredictedNumberPackets();
sendFlow();
windowChanged = true;
}
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", sending message, wasFirstPacket=" + wasFirstPacket + ", maxSize=" + packager.getMaxPayloadLength() + ", packetSize=" + frame.getPayload().length + ", predictedNumberPackets=" + packager.getPredictedNumberPackets() + ", currentPacket=" + packager.getCurrentPacketNumber() + ", hasMore=" + packager.hasMore());
outboundHandler.send(frame);
nextOutgoingId++;
remoteIncomingWindow--;
if (!isAtMostOnce)
outgoingWindow--;
if (!packager.hasMore()) {
// b) everything else: after the last packet has been sent
if (producer.isTransactionController() || po.getTxnId() != null)
producer.setWaitingPO(po);
else {
po.setSuccess(true);
if (po.getSemaphore() != null)
po.getSemaphore().notifySingleWaiter();
}
// If that was the last packet and outgoing window was increased for this message, we need to reset it and send another flow
if (windowChanged) {
outgoingWindow = mySession.getOutgoingWindowSize();
sendFlow();
}
break;
}
} while (remoteIncomingWindow > 0 && outgoingWindow > 0);
if (packager.hasMore()) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", has more but no window, storing message");
outboundDeliveries.add(po);
}
} else {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, po=" + po + ", remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", no window, storing message");
outboundDeliveries.add(po);
}
} catch (Exception e) {
po.setSuccess(false);
po.setException(e.getMessage());
if (po.getSemaphore() != null)
po.getSemaphore().notifySingleWaiter();
}
}
Aggregations