Search in sources :

Example 1 with QueueMetricImpl

use of com.swiftmq.impl.queue.standard.cluster.v700.QueueMetricImpl 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)

Aggregations

QueueMetricImpl (com.swiftmq.impl.queue.standard.cluster.v700.QueueMetricImpl)1 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)1