Search in sources :

Example 6 with QueueException

use of com.swiftmq.swiftlet.queue.QueueException 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 7 with QueueException

use of com.swiftmq.swiftlet.queue.QueueException in project swiftmq-ce by iitsoftware.

the class Output method send.

/**
 * Sends a Message.
 *
 * @param message Message
 * @return Output
 * @throws Exception
 */
public Output send(Message message) throws Exception {
    try {
        if (sender == null) {
            sender = createSender();
            dest = getDestination();
        }
        txSent++;
        MessageImpl impl = message.getImpl();
        impl.setJMSDestination(dest);
        impl.setJMSTimestamp(System.currentTimeMillis());
        impl.setJMSMessageID(ctx.nextId());
        QueuePushTransaction transaction = sender.createTransaction();
        transaction.putMessage(impl);
        ctx.addTransaction(transaction, new TransactionFinishListener() {

            @Override
            public void transactionFinished() {
                txSent--;
                if (closed) {
                    try {
                        if (sender != null) {
                            if (txSent == 0) {
                                sender.close();
                            }
                        }
                    } catch (QueueException e) {
                        ctx.logStackTrace(e);
                    }
                }
            }
        });
        if (sent + 1 == Integer.MAX_VALUE)
            sent = 1;
        else
            sent++;
    } catch (Exception e) {
        if (!getDestination().toString().startsWith("tmp$"))
            throw e;
    }
    dirty = true;
    return this;
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) TransactionFinishListener(com.swiftmq.impl.streams.TransactionFinishListener) QueueException(com.swiftmq.swiftlet.queue.QueueException) MessageImpl(com.swiftmq.jms.MessageImpl) QueueException(com.swiftmq.swiftlet.queue.QueueException)

Example 8 with QueueException

use of com.swiftmq.swiftlet.queue.QueueException in project swiftmq-ce by iitsoftware.

the class RegularQueueFactory method createQueue.

public AbstractQueue createQueue(String queueName, Entity queueEntity) throws QueueException {
    PersistentStore pStore = null;
    NonPersistentStore nStore = null;
    try {
        pStore = ctx.storeSwiftlet.getPersistentStore(queueName);
        nStore = ctx.storeSwiftlet.getNonPersistentStore(queueName);
    } catch (Exception e) {
        e.printStackTrace();
        throw new QueueException(e.toString());
    }
    Property prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
    int cacheSize = ((Integer) prop.getValue()).intValue();
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
    int cacheSizeBytesKB = ((Integer) prop.getValue()).intValue();
    Cache cache = new CacheImpl(cacheSize, cacheSizeBytesKB, pStore, nStore);
    cache.setCacheTable(ctx.cacheTableFactory.createCacheTable(queueName, cacheSize));
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
    prop.setPropertyChangeListener(new PropertyChangeAdapter(cache) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            Cache myCache = (Cache) configObject;
            myCache.setMaxMessages(((Integer) newValue).intValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
    prop.setPropertyChangeListener(new PropertyChangeAdapter(cache) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            Cache myCache = (Cache) configObject;
            myCache.setMaxBytesKB(((Integer) newValue).intValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CLEANUP_INTERVAL);
    long cleanUp = ((Long) prop.getValue()).longValue();
    MessageQueue mq = ctx.messageQueueFactory.createMessageQueue(ctx, queueName, cache, pStore, nStore, cleanUp, myTP);
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_MESSAGES_MAXIMUM);
    int maxMessages = ((Integer) prop.getValue()).intValue();
    mq.setMaxMessages(maxMessages);
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            myMq.setMaxMessages(((Integer) newValue).intValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_PERSISTENCE);
    int pm = SwiftUtilities.persistenceModeToInt((String) prop.getValue());
    mq.setPersistenceMode(pm);
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            myMq.setPersistenceMode(SwiftUtilities.persistenceModeToInt((String) newValue));
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_FLOWCONTROL_QUEUE_SIZE);
    int fcQueueSize = ((Integer) prop.getValue()).intValue();
    if (fcQueueSize >= 0)
        mq.setFlowController(new FlowControllerImpl(fcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            int newFcQueueSize = ((Integer) newValue).intValue();
            if (newFcQueueSize >= 0)
                myMq.setFlowController(new FlowControllerImpl(newFcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
            else
                myMq.setFlowController(null);
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_ENABLED);
    mq.setDuplicateDetectionEnabled(((Boolean) prop.getValue()).booleanValue());
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            myMq.setDuplicateDetectionEnabled(((Boolean) newValue).booleanValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_BACKLOG_SIZE);
    mq.setDuplicateDetectionBacklogSize(((Integer) prop.getValue()).intValue());
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            myMq.setDuplicateDetectionBacklogSize(((Integer) newValue).intValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CONSUMER);
    if (prop != null) {
        mq.setConsumerMode(ctx.consumerModeInt((String) prop.getValue()));
        prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                MessageQueue myMq = (MessageQueue) configObject;
                int cm = ctx.consumerModeInt((String) newValue);
                if (cm == AbstractQueue.EXCLUSIVE && myMq.getReceiverCount() > 1)
                    throw new PropertyChangeException("Can't set EXCLUSIVE consumer mode - queue has already '" + myMq.getReceiverCount() + "' receivers");
                myMq.setConsumerMode(cm);
            }
        });
    }
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_MONITOR_ALERT_THRESHOLD);
    if (prop != null) {
        mq.setMonitorAlertThreshold(((Integer) prop.getValue()).intValue());
        prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                MessageQueue myMq = (MessageQueue) configObject;
                myMq.setMonitorAlertThreshold(((Integer) newValue).intValue());
            }
        });
    }
    return mq;
}
Also used : NonPersistentStore(com.swiftmq.swiftlet.store.NonPersistentStore) PersistentStore(com.swiftmq.swiftlet.store.PersistentStore) PropertyChangeException(com.swiftmq.mgmt.PropertyChangeException) QueueException(com.swiftmq.swiftlet.queue.QueueException) PropertyChangeException(com.swiftmq.mgmt.PropertyChangeException) NonPersistentStore(com.swiftmq.swiftlet.store.NonPersistentStore) PropertyChangeAdapter(com.swiftmq.mgmt.PropertyChangeAdapter) QueueException(com.swiftmq.swiftlet.queue.QueueException) Property(com.swiftmq.mgmt.Property)

Example 9 with QueueException

use of com.swiftmq.swiftlet.queue.QueueException in project swiftmq-ce by iitsoftware.

the class SystemQueueFactory method createQueue.

public AbstractQueue createQueue(String queueName, Entity queueController) throws QueueException {
    PersistentStore pStore = null;
    NonPersistentStore nStore = null;
    try {
        pStore = ctx.storeSwiftlet.getPersistentStore(queueName);
        nStore = ctx.storeSwiftlet.getNonPersistentStore(queueName);
    } catch (Exception e) {
        throw new QueueException(e.toString());
    }
    Property prop = queueController.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
    int cacheSize = ((Integer) prop.getValue()).intValue();
    prop = queueController.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
    int cacheSizeBytesKB = ((Integer) prop.getValue()).intValue();
    Cache cache = new CacheImpl(cacheSize, cacheSizeBytesKB, pStore, nStore);
    cache.setCacheTable(ctx.cacheTableFactory.createCacheTable(queueName, cacheSize));
    prop = queueController.getProperty(QueueManagerImpl.PROP_CLEANUP_INTERVAL);
    long cleanUp = ((Long) prop.getValue()).longValue();
    MessageQueue mq = ctx.messageQueueFactory.createMessageQueue(ctx, queueName, cache, pStore, nStore, cleanUp, myTP);
    prop = queueController.getProperty(QueueManagerImpl.PROP_MESSAGES_MAXIMUM);
    int maxMessages = ((Integer) prop.getValue()).intValue();
    mq.setMaxMessages(maxMessages);
    prop = queueController.getProperty(QueueManagerImpl.PROP_PERSISTENCE);
    int pm = SwiftUtilities.persistenceModeToInt((String) prop.getValue());
    mq.setPersistenceMode(pm);
    prop = queueController.getProperty(QueueManagerImpl.PROP_FLOWCONTROL_QUEUE_SIZE);
    int fcQueueSize = ((Integer) prop.getValue()).intValue();
    if (fcQueueSize >= 0)
        mq.setFlowController(new FlowControllerImpl(fcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
    prop = queueController.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_ENABLED);
    mq.setDuplicateDetectionEnabled(((Boolean) prop.getValue()).booleanValue());
    prop = queueController.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_BACKLOG_SIZE);
    mq.setDuplicateDetectionBacklogSize(((Integer) prop.getValue()).intValue());
    prop = queueController.getProperty(QueueManagerImpl.PROP_CONSUMER);
    mq.setConsumerMode(ctx.consumerModeInt((String) prop.getValue()));
    mq.setQueueController(queueController);
    return mq;
}
Also used : NonPersistentStore(com.swiftmq.swiftlet.store.NonPersistentStore) PersistentStore(com.swiftmq.swiftlet.store.PersistentStore) QueueException(com.swiftmq.swiftlet.queue.QueueException) NonPersistentStore(com.swiftmq.swiftlet.store.NonPersistentStore) QueueException(com.swiftmq.swiftlet.queue.QueueException) Property(com.swiftmq.mgmt.Property)

Example 10 with QueueException

use of com.swiftmq.swiftlet.queue.QueueException in project swiftmq-ce by iitsoftware.

the class TempQueueFactory method createQueue.

public AbstractQueue createQueue(String queueName, Entity queueController) throws QueueException {
    NonPersistentStore nStore = null;
    try {
        nStore = ctx.storeSwiftlet.getNonPersistentStore(queueName);
    } catch (Exception e) {
        throw new QueueException(e.toString());
    }
    Property prop = queueController.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
    int cacheSize = ((Integer) prop.getValue()).intValue();
    prop = queueController.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
    int cacheSizeBytesKB = ((Integer) prop.getValue()).intValue();
    Cache cache = new CacheImpl(cacheSize, cacheSizeBytesKB, null, nStore);
    cache.setCacheTable(ctx.cacheTableFactory.createCacheTable(queueName, cacheSize));
    prop = queueController.getProperty(QueueManagerImpl.PROP_CLEANUP_INTERVAL);
    long cleanUp = ((Long) prop.getValue()).longValue();
    MessageQueue mq = ctx.messageQueueFactory.createMessageQueue(ctx, queueName, cache, null, nStore, cleanUp, myTP);
    prop = queueController.getProperty(QueueManagerImpl.PROP_MESSAGES_MAXIMUM);
    int maxMessages = ((Integer) prop.getValue()).intValue();
    mq.setMaxMessages(maxMessages);
    prop = queueController.getProperty(QueueManagerImpl.PROP_PERSISTENCE);
    int pm = SwiftUtilities.persistenceModeToInt((String) prop.getValue());
    mq.setPersistenceMode(pm);
    prop = queueController.getProperty(QueueManagerImpl.PROP_FLOWCONTROL_QUEUE_SIZE);
    int fcQueueSize = ((Integer) prop.getValue()).intValue();
    if (fcQueueSize >= 0)
        mq.setFlowController(new FlowControllerImpl(fcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
    prop = queueController.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_ENABLED);
    mq.setDuplicateDetectionEnabled(((Boolean) prop.getValue()).booleanValue());
    prop = queueController.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_BACKLOG_SIZE);
    mq.setDuplicateDetectionBacklogSize(((Integer) prop.getValue()).intValue());
    prop = queueController.getProperty(QueueManagerImpl.PROP_CONSUMER);
    mq.setConsumerMode(ctx.consumerModeInt((String) prop.getValue()));
    mq.setQueueController(queueController);
    return mq;
}
Also used : QueueException(com.swiftmq.swiftlet.queue.QueueException) NonPersistentStore(com.swiftmq.swiftlet.store.NonPersistentStore) QueueException(com.swiftmq.swiftlet.queue.QueueException) Property(com.swiftmq.mgmt.Property)

Aggregations

QueueException (com.swiftmq.swiftlet.queue.QueueException)20 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)8 EntityRemoveException (com.swiftmq.mgmt.EntityRemoveException)7 JMSException (javax.jms.JMSException)7 Property (com.swiftmq.mgmt.Property)3 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)3 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)3 NonPersistentStore (com.swiftmq.swiftlet.store.NonPersistentStore)3 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)2 MessageImpl (com.swiftmq.jms.MessageImpl)2 QueueImpl (com.swiftmq.jms.QueueImpl)2 TopicImpl (com.swiftmq.jms.TopicImpl)2 EntityList (com.swiftmq.mgmt.EntityList)2 PropertyChangeException (com.swiftmq.mgmt.PropertyChangeException)2 PersistentStore (com.swiftmq.swiftlet.store.PersistentStore)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)1 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)1