Search in sources :

Example 6 with Versionable

use of com.swiftmq.tools.versioning.Versionable in project swiftmq-ce by iitsoftware.

the class JNDISwiftletImpl method createStatics.

private void createStatics(EntityList staticList) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "create static objects ...");
    String[] s = staticList.getEntityNames();
    if (s != null) {
        for (int i = 0; i < s.length; i++) {
            try {
                DataByteArrayOutputStream dos = new DataByteArrayOutputStream();
                DestinationFactory.dumpDestination(getStaticQueue(s[i]), dos);
                Versionable versionable = new Versionable();
                versionable.addVersioned(-1, new Versioned(-1, dos.getBuffer(), dos.getCount()), "com.swiftmq.jms.DestinationFactory");
                registerJNDIObject(s[i], versionable);
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), "create static objects for '" + s[i] + "', exception=" + e);
            }
        }
    } else if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "no static objects defined");
    staticList.setEntityAddListener(new EntityChangeAdapter(null) {

        public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
            String name = newEntity.getName();
            try {
                DataByteArrayOutputStream dos = new DataByteArrayOutputStream();
                DestinationFactory.dumpDestination(getStaticQueue(name), dos);
                Versionable versionable = new Versionable();
                versionable.addVersioned(-1, new Versioned(-1, dos.getBuffer(), dos.getCount()), "com.swiftmq.jms.DestinationFactory");
                registerJNDIObject(name, versionable);
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), "onEntityAdd (statics) for '" + name + "', exception=" + e);
                throw new EntityAddException(e.getMessage());
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityAdd (statics): static object=" + name);
        }
    });
    staticList.setEntityRemoveListener(new EntityChangeAdapter(null) {

        public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
            String name = delEntity.getName();
            deregisterJNDIObject(name);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove (statics): static=" + name);
        }
    });
}
Also used : Versionable(com.swiftmq.tools.versioning.Versionable) DataByteArrayOutputStream(com.swiftmq.tools.util.DataByteArrayOutputStream) Versioned(com.swiftmq.tools.versioning.Versioned) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 7 with Versionable

use of com.swiftmq.tools.versioning.Versionable in project swiftmq-ce by iitsoftware.

the class QueueJNDIProcessor method run.

public void run() {
    try {
        t.commit();
        try {
            Versionable versionable = Versionable.toVersionable(msg);
            int version = versionable.selectVersions(JNDISwiftletImpl.VERSIONS);
            switch(version) {
                case 400:
                    {
                        JNDIRequest r = (JNDIRequest) versionable.createVersionedObject();
                        com.swiftmq.impl.jndi.standard.v400.RequestVisitor visitor = new com.swiftmq.impl.jndi.standard.v400.RequestVisitor(ctx, (QueueImpl) msg.getJMSReplyTo(), true);
                        r.accept(visitor);
                    }
                    break;
                default:
                    throw new Exception("Invalid version: " + version);
            }
        } catch (Exception e) {
            if (closed)
                return;
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "QueueJNDIProcessor: exception occurred: " + e);
            ctx.logSwiftlet.logError(ctx.jndiSwiftlet.getName(), "QueueJNDIProcessor: exception occurred: " + e);
        }
        msg = null;
        if (closed)
            return;
        t = receiver.createTransaction(false);
        t.registerMessageProcessor(this);
    } catch (Exception e) {
        if (closed)
            return;
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "QueueJNDIProcessor: exception occurred: " + e + ", EXITING!");
    }
}
Also used : JNDIRequest(com.swiftmq.jndi.protocol.v400.JNDIRequest) QueueImpl(com.swiftmq.jms.QueueImpl) Versionable(com.swiftmq.tools.versioning.Versionable)

Example 8 with Versionable

use of com.swiftmq.tools.versioning.Versionable in project swiftmq-ce by iitsoftware.

the class TopicJNDIProcessor method run.

public void run() {
    try {
        t.commit();
        try {
            Versionable versionable = Versionable.toVersionable(msg);
            int version = versionable.selectVersions(JNDISwiftletImpl.VERSIONS);
            switch(version) {
                case 400:
                    {
                        JNDIRequest r = (JNDIRequest) versionable.createVersionedObject();
                        com.swiftmq.impl.jndi.standard.v400.RequestVisitor visitor = new com.swiftmq.impl.jndi.standard.v400.RequestVisitor(ctx, (QueueImpl) msg.getJMSReplyTo());
                        r.accept(visitor);
                    }
                    break;
                default:
                    throw new Exception("Invalid version: " + version);
            }
        } catch (Exception e) {
            if (closed)
                return;
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "TopicJNDIProcessor: exception occurred: " + e);
            ctx.logSwiftlet.logError(ctx.jndiSwiftlet.getName(), "TopicJNDIProcessor: exception occurred: " + e);
        }
        msg = null;
        if (closed)
            return;
        t = receiver.createTransaction(false);
        t.registerMessageProcessor(this);
    } catch (Exception e) {
        if (closed)
            return;
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "TopicJNDIProcessor: exception occurred: " + e + ", EXITING!");
    }
}
Also used : JNDIRequest(com.swiftmq.jndi.protocol.v400.JNDIRequest) QueueImpl(com.swiftmq.jms.QueueImpl) Versionable(com.swiftmq.tools.versioning.Versionable)

Example 9 with Versionable

use of com.swiftmq.tools.versioning.Versionable in project swiftmq-ce by iitsoftware.

the class QueueManagerImpl method registerJNDI.

private void registerJNDI(String name, QueueImpl queue) {
    try {
        String localName = stripLocalName(name);
        DataByteArrayOutputStream dos = new DataByteArrayOutputStream();
        DestinationFactory.dumpDestination(queue, dos);
        Versionable versionable = new Versionable();
        versionable.addVersioned(-1, new Versioned(-1, dos.getBuffer(), dos.getCount()), "com.swiftmq.jms.DestinationFactory");
        ctx.jndiSwiftlet.registerJNDIObject(name, versionable);
        registerJNDIAlias(localName, name);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Versionable(com.swiftmq.tools.versioning.Versionable) DataByteArrayOutputStream(com.swiftmq.tools.util.DataByteArrayOutputStream) Versioned(com.swiftmq.tools.versioning.Versioned) IOException(java.io.IOException)

Example 10 with Versionable

use of com.swiftmq.tools.versioning.Versionable in project swiftmq-ce by iitsoftware.

the class ClusterMetricSubscriber method run.

public void run() {
    try {
        t.commit();
        try {
            Versionable versionable = Versionable.toVersionable(msg);
            versionable.setClassLoader(getClass().getClassLoader());
            int version = versionable.selectVersions(QueueManagerImpl.VERSIONS);
            switch(version) {
                case 700:
                    {
                        ClusteredQueueMetricCollection cmc = (ClusteredQueueMetricCollection) versionable.createVersionedObject();
                        List list = cmc.getClusteredQueueMetrics();
                        if (list != null) {
                            for (int i = 0; i < list.size(); i++) {
                                ClusteredQueueMetric cm = (ClusteredQueueMetric) list.get(i);
                                if (ctx.traceSpace.enabled)
                                    ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/run, cm=" + cm);
                                DispatchPolicy dp = ctx.dispatchPolicyRegistry.get(cm.getClusteredQueueName());
                                if (dp != null)
                                    dp.addMetric(cmc.getRouterName(), cm);
                            }
                        }
                    }
                    break;
                default:
                    throw new Exception("Invalid version: " + version);
            }
        } catch (Exception e) {
            if (closed)
                return;
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/exception occurred: " + e);
            ctx.logSwiftlet.logError(ctx.queueManager.getName(), toString() + "/exception occurred: " + e);
        }
        msg = null;
        if (closed)
            return;
        t = receiver.createTransaction(false);
        t.registerMessageProcessor(this);
    } catch (Exception e) {
        if (closed)
            return;
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/exception occurred: " + e + ", EXITING!");
    }
}
Also used : Versionable(com.swiftmq.tools.versioning.Versionable) List(java.util.List)

Aggregations

Versionable (com.swiftmq.tools.versioning.Versionable)14 DataByteArrayOutputStream (com.swiftmq.tools.util.DataByteArrayOutputStream)5 Versioned (com.swiftmq.tools.versioning.Versioned)5 StopRetryException (com.swiftmq.jndi.StopRetryException)4 QueueImpl (com.swiftmq.jms.QueueImpl)2 JNDIRequest (com.swiftmq.jndi.protocol.v400.JNDIRequest)2 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)2 IOException (java.io.IOException)2 List (java.util.List)2 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)1 PropertyChangeException (com.swiftmq.mgmt.PropertyChangeException)1 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)1 UnknownHostException (java.net.UnknownHostException)1