Search in sources :

Example 1 with Coordinator

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));
        }
    }
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) MessageImpl(com.swiftmq.jms.MessageImpl) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) QueueException(com.swiftmq.swiftlet.queue.QueueException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicException(com.swiftmq.swiftlet.topic.TopicException)

Example 2 with Coordinator

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");
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) Coordinator(com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator) IOException(java.io.IOException)

Example 3 with Coordinator

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();
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) Accepted(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)

Example 4 with Coordinator

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);
}
Also used : IOException(java.io.IOException) Coordinator(com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)3 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)2 Coordinator (com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator)2 Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)1 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 MessageImpl (com.swiftmq.jms.MessageImpl)1 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)1 TopicException (com.swiftmq.swiftlet.topic.TopicException)1 MalformedURLException (java.net.MalformedURLException)1 InvalidSelectorException (javax.jms.InvalidSelectorException)1