Search in sources :

Example 1 with TransactionId

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId 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 2 with TransactionId

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

the class TransactionRegistry method close.

public void close() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/close");
    lock.lock();
    try {
        Map cloned = (Map) ((HashMap) activeTx).clone();
        for (Iterator iter = cloned.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iter.next();
            try {
                discharge(new TransactionId(((String) entry.getKey()).getBytes()), true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        activeTx.clear();
    } finally {
        lock.unlock();
    }
}
Also used : Iterator(java.util.Iterator) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) HashMap(java.util.HashMap) Map(java.util.Map) QueueException(com.swiftmq.swiftlet.queue.QueueException) TransactionId(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId)

Example 3 with TransactionId

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId 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 4 with TransactionId

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId 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 5 with TransactionId

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId 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)

Aggregations

AMQPString (com.swiftmq.amqp.v100.types.AMQPString)6 HashMap (java.util.HashMap)4 QueueException (com.swiftmq.swiftlet.queue.QueueException)3 TransactionId (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)1 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)1