Search in sources :

Example 1 with AbstractQueue

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

the class XARecoveryContextImpl method rollback.

public synchronized void rollback() throws XAContextException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/rollback...");
    if (closed)
        throw new XAContextException(XAException.XAER_PROTO, "XA transaction is in closed state");
    for (int i = 0; i < transactions.size(); i++) {
        Object[] wrapper = (Object[]) transactions.get(i);
        try {
            ((AbstractQueue) wrapper[0]).rollback(wrapper[1], xid, true);
            ctx.logSwiftlet.logInformation(ctx.xaSwiftlet.getName(), toString() + "rollback xid=" + signature);
        } catch (Exception e) {
            if (!ctx.queueManager.isTemporaryQueue(((AbstractQueue) wrapper[0]).getQueueName()))
                ctx.logSwiftlet.logError(ctx.xaSwiftlet.getName(), toString() + "rollback (two phase) xid=" + signature + ", failed for queue: " + ((AbstractQueue) wrapper[0]).getQueueName());
        }
    }
    if (liveContext != null)
        liveContext.rollback();
    removeUsageEntity();
    close();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/rollback done");
}
Also used : AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) XAException(javax.transaction.xa.XAException) EntityAddException(com.swiftmq.mgmt.EntityAddException) XAContextException(com.swiftmq.swiftlet.xa.XAContextException)

Example 2 with AbstractQueue

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

the class XAResourceManagerSwiftletImpl method getPreparedQueue.

private AbstractQueue getPreparedQueue(String queueName) throws Exception {
    AbstractQueue queue = ctx.queueManager.getQueueForInternalUse(queueName);
    if (queue == null) {
        if (// hack!
        !ctx.queueManager.isTemporaryQueue(queueName) && !queueName.startsWith("tpc$")) {
            ctx.queueManager.createQueue(queueName, (ActiveLogin) null);
            queue = ctx.queueManager.getQueueForInternalUse(queueName);
        }
    }
    return queue;
}
Also used : AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue)

Example 3 with AbstractQueue

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

the class QueueManagerImpl method createClusteredQueue.

private void createClusteredQueue(Entity entity) throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createClusteredQueue, name=" + entity.getName() + " ...");
    createQueue(entity.getName(), entity, ctx.clusteredQueueFactory);
    EntityListEventAdapter bindingsAdapter = new EntityListEventAdapter((EntityList) entity.getEntity("queue-bindings"), true, true) {

        public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityAdd (bindings), name=" + newEntity.getName() + " ...");
            String qn = fqn(newEntity.getName());
            if (!isQueueDefined(qn))
                throw new EntityAddException("Undefined queue: " + qn + "! To bind a queue to a clustered queue, it must be defined first.");
            AbstractQueue queue = getQueueForInternalUse(qn);
            String clusteredQueueName = parent.getParent().getName();
            DispatchPolicy dp = ctx.dispatchPolicyRegistry.get(clusteredQueueName);
            queue.setQueueReceiverListener(dp);
            Property prop = newEntity.getProperty("redispatch-enabled");
            prop.setPropertyChangeListener(new PropertyChangeListener() {

                public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                    ((QueueMetric) property.getParent().getUserObject()).setRedispatch(((Boolean) newValue).booleanValue());
                }
            });
            QueueMetric qm = new QueueMetricImpl(qn, queue.getReceiverCount() > 0, ((Boolean) prop.getValue()).booleanValue());
            dp.addLocalMetric(qm);
            newEntity.setUserObject(qm);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityAdd (bindings), name=" + newEntity.getName() + " done");
        }

        public void onEntityRemove(Entity parent, Entity oldEntity) throws EntityRemoveException {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove (bindings), name=" + oldEntity.getName() + " ...");
            String qn = fqn(oldEntity.getName());
            if (isQueueDefined(qn)) {
                AbstractQueue queue = getQueueForInternalUse(qn);
                queue.setQueueReceiverListener(null);
                String clusteredQueueName = parent.getParent().getName();
                DispatchPolicy dp = ctx.dispatchPolicyRegistry.get(clusteredQueueName);
                dp.removeLocalMetric((QueueMetric) oldEntity.getUserObject());
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove (bindings), name=" + oldEntity.getName() + " done");
        }
    };
    bindingsAdapter.init();
    entity.setUserObject(bindingsAdapter);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createClusteredQueue, name=" + entity.getName() + " done");
}
Also used : QueueMetricImpl(com.swiftmq.impl.queue.standard.cluster.v700.QueueMetricImpl) AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue)

Example 4 with AbstractQueue

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

the class Remover method execute.

public String[] execute(String[] context, Entity entity, String[] cmd) {
    if (cmd.length < 3 || cmd.length > 5)
        return new String[] { TreeCommands.ERROR, "Invalid command, please try '" + PATTERN + "'" };
    String[] result = null;
    try {
        if (!ctx.queueManager.isQueueDefined(cmd[1]))
            throw new Exception("Unknown queue: " + cmd[1]);
        AbstractQueue aq = (AbstractQueue) ctx.queueManager.getQueueForInternalUse(cmd[1]);
        if (!(aq instanceof MessageQueue))
            throw new Exception("Operation not supported on this type of queue!");
        MessageQueue mq = (MessageQueue) aq;
        SortedSet content = mq.getQueueIndex();
        if (cmd[2].equals("-index")) {
            if (cmd.length != 5)
                return new String[] { TreeCommands.ERROR, "Invalid command, please try 'remove <queue> -index <start> <stop>'" };
            int start = Integer.parseInt(cmd[3]);
            int stop = Integer.parseInt(cmd[4]);
            if (stop < start)
                throw new Exception("Stop index is less than start index.");
            int i = 0, cnt = 0;
            for (Iterator iter = content.iterator(); iter.hasNext(); ) {
                MessageIndex mi = (MessageIndex) iter.next();
                if (i >= start && i <= stop) {
                    try {
                        mq.removeMessageByIndex(mi);
                        cnt++;
                    } catch (MessageLockedException ignored) {
                    }
                }
                if (i > stop)
                    break;
                i++;
            }
            return new String[] { TreeCommands.INFO, cnt + " messages removed." };
        } else {
            String key = cmd[2];
            int id = -1;
            if (!key.equals("*"))
                id = Integer.parseInt(key);
            boolean found = false;
            for (Iterator iter = content.iterator(); iter.hasNext(); ) {
                MessageIndex mi = (MessageIndex) iter.next();
                if (id == -1 || mi.getId() == id) {
                    found = true;
                    mq.removeMessageByIndex(mi);
                    if (id != -1)
                        break;
                }
            }
            if (!found && id != -1)
                throw new Exception("Message key '" + id + "' not found!");
        }
    } catch (Exception e) {
        result = new String[] { TreeCommands.ERROR, e.getMessage() };
    }
    return result;
}
Also used : MessageIndex(com.swiftmq.swiftlet.queue.MessageIndex) AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 5 with AbstractQueue

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

the class ClusterMetricPublisher method performTimeAction.

public void performTimeAction() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction ...");
    ClusteredQueueMetricCollection cmc = ctx.dispatchPolicyRegistry.getClusteredQueueMetricCollection();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction, cmc=" + cmc);
    List list = cmc.getClusteredQueueMetrics();
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            ClusteredQueueMetric cm = (ClusteredQueueMetric) list.get(i);
            List list2 = cm.getQueueMetrics();
            if (list2 != null) {
                for (int j = 0; j < list2.size(); j++) {
                    QueueMetric qm = (QueueMetric) list2.get(j);
                    AbstractQueue queue = ctx.queueManager.getQueueForInternalUse(qm.getQueueName());
                    if (queue != null) {
                        try {
                            if (ctx.traceSpace.enabled)
                                ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction, queue=" + qm.getQueueName() + ", qm.hasReceiver()=" + qm.hasReceiver() + ", cm.isReceiverSomewhere()=" + cm.isReceiverSomewhere() + ", qm.isRedispatch()=" + qm.isRedispatch() + ", queue.getNumberQueueMessages()=" + queue.getNumberQueueMessages());
                            if (!qm.hasReceiver() && cm.isReceiverSomewhere() && qm.isRedispatch() && queue.getNumberQueueMessages() > 0)
                                ctx.redispatcherController.redispatch(qm.getQueueName(), cm.getClusteredQueueName());
                        } catch (QueueException e) {
                        }
                    }
                }
            }
        }
    }
    try {
        QueuePushTransaction transaction = sender.createTransaction();
        Versionable versionable = new Versionable();
        versionable.addVersioned(700, createVersioned(700, cmc), "com.swiftmq.impl.queue.standard.cluster.v700.MetricFactory");
        BytesMessageImpl msg = createMessage(versionable);
        transaction.putMessage(msg);
        transaction.commit();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction, exception=" + e);
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction done");
}
Also used : Versionable(com.swiftmq.tools.versioning.Versionable) AbstractQueue(com.swiftmq.swiftlet.queue.AbstractQueue) QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) QueueException(com.swiftmq.swiftlet.queue.QueueException) List(java.util.List) QueueException(com.swiftmq.swiftlet.queue.QueueException) PropertyChangeException(com.swiftmq.mgmt.PropertyChangeException)

Aggregations

AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)19 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)4 XAException (javax.transaction.xa.XAException)4 QueueException (com.swiftmq.swiftlet.queue.QueueException)3 QueueImpl (com.swiftmq.jms.QueueImpl)2 EntityAddException (com.swiftmq.mgmt.EntityAddException)2 EntityRemoveException (com.swiftmq.mgmt.EntityRemoveException)2 MessageSelector (com.swiftmq.ms.MessageSelector)2 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)2 QueueTransaction (com.swiftmq.swiftlet.queue.QueueTransaction)2 JobException (com.swiftmq.swiftlet.scheduler.JobException)2 Iterator (java.util.Iterator)2 QueueMetricImpl (com.swiftmq.impl.queue.standard.cluster.v700.QueueMetricImpl)1 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)1 MessageImpl (com.swiftmq.jms.MessageImpl)1 XidImpl (com.swiftmq.jms.XidImpl)1 PropertyChangeException (com.swiftmq.mgmt.PropertyChangeException)1 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)1 MessageIndex (com.swiftmq.swiftlet.queue.MessageIndex)1