Search in sources :

Example 6 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF 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++;
    }
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) AMQPString(com.swiftmq.amqp.v100.types.AMQPString)

Example 7 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.

the class TransactionRegistry method discharge.

public void discharge(TxnIdIF btxnId, boolean rollback) throws EndWithErrorException {
    String txnId = new String(((TransactionId) btxnId).getValue());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge, txnId=" + txnId + ", rollback=" + rollback);
    lock.lock();
    try {
        ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.remove(txnId);
        if (activeTxEntry == null) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge, txnId=" + txnId + ", not found!");
            throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
        }
        if (activeTxEntry.inboundTxEntryMap != null) {
            for (Iterator iter = activeTxEntry.inboundTxEntryMap.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                InboundTxEntry inboundTxEntry = (InboundTxEntry) entry.getValue();
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge txnid=" + txnId + ", linkName=" + entry.getKey());
                if (rollback)
                    inboundTxEntry.tx.rollback();
                else
                    inboundTxEntry.tx.commit();
                inboundTxEntry.targetLink.setFlowcontrolDelay(inboundTxEntry.tx.getFlowControlDelay());
                inboundTxEntry.targetLink.decreaseActiveTransactions();
                inboundTxEntry.targetLink.closeResource();
            }
            activeTxEntry.inboundTxEntryMap.clear();
        }
        if (activeTxEntry.outboundTxEntryMap != null) {
            for (Iterator iter = activeTxEntry.outboundTxEntryMap.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                long deliveryId = ((Long) entry.getKey()).longValue();
                OutboundTxEntry outboundTxEntry = (OutboundTxEntry) entry.getValue();
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/discharge txnid=" + txnId + ", deliveryId=" + deliveryId);
                if (rollback) {
                    if (outboundTxEntry.sourceLink != null)
                        sessionHandler.settleOutbound(deliveryId, RELEASED);
                } else
                    sessionHandler.settleOutbound(deliveryId, outboundTxEntry.deliveryStateIF);
                if (outboundTxEntry.sourceLink != null) {
                    outboundTxEntry.sourceLink.decreaseActiveTransactions();
                    outboundTxEntry.sourceLink.closeResource();
                }
            }
            activeTxEntry.outboundTxEntryMap.clear();
            sessionHandler.sendOutboundDeliveries();
        }
    } catch (QueueException e) {
        throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString(e.toString()));
    } finally {
        lock.unlock();
    }
}
Also used : AMQPString(com.swiftmq.amqp.v100.types.AMQPString) Iterator(java.util.Iterator) QueueException(com.swiftmq.swiftlet.queue.QueueException) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.

the class TransactionRegistry method createTxId.

public TxnIdIF createTxId() {
    lock.lock();
    try {
        StringBuffer b = new StringBuffer();
        b.append(startupTime);
        b.append('-');
        b.append(++lastId);
        String id = b.toString();
        activeTx.put(id, new ActiveTxEntry());
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/createTxId: " + id);
        return new TransactionId(id.getBytes());
    } finally {
        lock.unlock();
    }
}
Also used : AMQPString(com.swiftmq.amqp.v100.types.AMQPString) TransactionId(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId)

Example 9 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.

the class TransactionRegistry method addToTransaction.

public void addToTransaction(TxnIdIF btxnId, String linkName, MessageImpl message, TargetLink targetLink) throws EndWithErrorException {
    String txnId = new String(((TransactionId) btxnId).getValue());
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", linkName=" + linkName + ", message=" + message);
    lock.lock();
    try {
        ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.get(txnId);
        if (activeTxEntry == null) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", not found!");
            throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
        }
        if (activeTxEntry.inboundTxEntryMap == null)
            activeTxEntry.inboundTxEntryMap = new HashMap();
        InboundTxEntry inboundTxEntry = (InboundTxEntry) activeTxEntry.inboundTxEntryMap.get(linkName);
        try {
            if (inboundTxEntry == null) {
                QueuePushTransaction tx = targetLink.getQueueSender().createTransaction();
                targetLink.increaseActiveTransactions();
                inboundTxEntry = new InboundTxEntry(tx, targetLink);
                activeTxEntry.inboundTxEntryMap.put(linkName, inboundTxEntry);
            }
            ((QueuePushTransaction) inboundTxEntry.tx).putMessage(message);
        } catch (QueueException e) {
            throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString(e.toString()));
        }
    } finally {
        lock.unlock();
    }
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) HashMap(java.util.HashMap) QueueException(com.swiftmq.swiftlet.queue.QueueException) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString)

Example 10 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.

the class Replier method serviceRequests.

public void serviceRequests() {
    try {
        for (int i = 0; i < nMsgs; i++) {
            TxnIdIF txnIdIF = txc.createTxnId();
            AMQPMessage request = consumer.receive();
            request.setTxnIdIF(txnIdIF);
            if (request != null) {
                messageFactory.verify(request);
                if (!request.isSettled())
                    request.accept();
                Properties prop = request.getProperties();
                if (prop == null)
                    throw new Exception("Properties not set in request: " + request);
                AddressIF replyTo = prop.getReplyTo();
                if (replyTo == null)
                    throw new Exception("replyTo not set in request: " + request);
                Producer p = getSession().createProducer(replyTo.getValueString(), qos);
                AMQPMessage reply = messageFactory.createReplyMessage(request);
                reply.setTxnIdIF(txnIdIF);
                Properties prop2 = new Properties();
                prop2.setTo(replyTo);
                prop2.setCorrelationId(prop.getMessageId());
                reply.setProperties(prop2);
                p.send(reply);
                p.close();
            } else
                throw new Exception("Msg == null at i=" + i);
            txc.commit(txnIdIF);
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) Producer(com.swiftmq.amqp.v100.client.Producer) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Aggregations

TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)22 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)21 AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)8 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)8 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)8 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)5 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)5 Producer (com.swiftmq.amqp.v100.client.Producer)4 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)4 QueueException (com.swiftmq.swiftlet.queue.QueueException)4 IOException (java.io.IOException)4 AMQPContext (com.swiftmq.amqp.AMQPContext)3 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)3 HashMap (java.util.HashMap)3 InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)2 Rejected (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected)2 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)2 Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)1 TransactionId (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId)1 Packager (com.swiftmq.amqp.v100.transport.Packager)1