use of com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator 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.Coordinator in project swiftmq-client by iitsoftware.
the class SessionDispatcher method visit.
public void visit(POAttachProducer po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " ...");
String name = null;
DeliveryMemory deliveryMemory = po.getDeliveryMemory();
if (deliveryMemory.getLinkName() != null)
name = deliveryMemory.getLinkName();
else {
name = uniqueSessionId + "/" + po.getTarget() + "/" + (nextLinkId++);
deliveryMemory.setLinkName(name);
}
Producer producer = new Producer(mySession, po.getTarget(), name, po.getQoS(), deliveryMemory);
int handle = ArrayListTool.setFirstFreeOrExpand(handles, producer);
producer.setHandle(handle);
po.setLink(producer);
waitingPO.put(name, po);
try {
AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
attachFrame.setName(new AMQPString(name));
attachFrame.setHandle(new Handle(handle));
attachFrame.setRole(Role.SENDER);
switch(producer.getQoS()) {
case QoS.AT_LEAST_ONCE:
attachFrame.setRcvSettleMode(ReceiverSettleMode.FIRST);
break;
case QoS.AT_MOST_ONCE:
attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
break;
case QoS.EXACTLY_ONCE:
attachFrame.setRcvSettleMode(ReceiverSettleMode.SECOND);
break;
}
Source source = new Source();
source.setAddress(new AddressString(name));
source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
source.setTimeout(new Seconds(0));
attachFrame.setSource(source);
String t = po.getTarget();
if (t.equals(Coordinator.DESCRIPTOR_NAME)) {
Coordinator coordinator = new Coordinator();
coordinator.setCapabilities(new AMQPArray(AMQPTypeDecoder.SYM8, new AMQPType[] { TxnCapability.LOCAL_TRANSACTIONS }));
attachFrame.setTarget(coordinator);
} else {
Target target = new Target();
target.setAddress(new AddressString(t));
target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
target.setTimeout(new Seconds(0));
attachFrame.setTarget(target);
}
attachFrame.setInitialDeliveryCount(new SequenceNo(producer.getDeliveryCountSnd()));
attachFrame.setUnsettled(getUnsettledMap(producer.getDeliveryMemory()));
outboundHandler.send(attachFrame);
} catch (Exception e) {
e.printStackTrace();
}
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " done");
}
use of com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator in project swiftmq-ce by iitsoftware.
the class TargetLink method getLastDeliveryState.
public DeliveryStateIF getLastDeliveryState() {
if (coordinator) {
DeliveryStateIF ds = lastDeliveryState;
lastDeliveryState = null;
return ds;
}
return new Accepted();
}
use of com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator in project swiftmq-client by iitsoftware.
the class TargetFactory method create.
/**
* Creates a TargetIF object.
*
* @param bare the bare AMQP type
* @return TargetIF
*/
public static TargetIF 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 == Target.DESCRIPTOR_CODE)
return new Target(((AMQPList) bare).getValue());
if (type == Coordinator.DESCRIPTOR_CODE)
return new Coordinator(((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(Target.DESCRIPTOR_NAME))
return new Target(((AMQPList) bare).getValue());
if (type.equals(Coordinator.DESCRIPTOR_NAME))
return new Coordinator(((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);
}
Aggregations