Search in sources :

Example 1 with Versionable

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

the class ContextImpl method lookup.

public synchronized Object lookup(String name) throws NamingException {
    if (closed)
        throw new NamingException("context is closed!");
    if (name == null)
        throw new OperationNotSupportedException("context cloning is not supported!");
    boolean connectionClosed = false;
    Object obj = null;
    try {
        checkConnection();
        TemporaryQueue tq = session.createTemporaryQueue();
        MessageConsumer consumer = session.createConsumer(tq);
        Versionable versionable = new Versionable();
        versionable.addVersioned(Versions.JNDI_CURRENT, createVersioned(Versions.JNDI_CURRENT, new LookupRequest(name)), "com.swiftmq.jndi.protocol.v" + Versions.JNDI_CURRENT + ".JNDIRequestFactory");
        BytesMessage request = createMessage(versionable, tq);
        producer.send(getLookupDestination(session), request, DeliveryMode.NON_PERSISTENT, MessageImpl.MAX_PRIORITY, 0);
        MessageImpl reply = null;
        if (jndiInfo.getTimeout() == 0)
            reply = (MessageImpl) consumer.receive();
        else
            reply = (MessageImpl) consumer.receive(jndiInfo.getTimeout());
        if (reply != null) {
            if (reply instanceof ObjectMessageImpl)
                obj = ((ObjectMessageImpl) reply).getObject();
            else {
                BytesMessageImpl msg = (BytesMessageImpl) reply;
                Versionable vreply = Versionable.toVersionable(msg);
                vreply.selectVersions(Versions.cutAfterIndex(Versions.getSelectedIndex(Versions.JMS_CURRENT, Versions.JMS), Versions.JMS));
                obj = vreply.createVersionedObject();
            }
        }
        if (!((SwiftMQMessageConsumer) consumer).isClosed()) {
            consumer.close();
            tq.delete();
        } else
            connectionClosed = true;
    } catch (Exception e) {
        throw new CommunicationException("exception occurred during lookup: " + e);
    }
    if (connectionClosed)
        throw new CommunicationException("Connection lost!");
    if (obj == null)
        throw new NameNotFoundException("Name '" + name + "' not found (timeout occured)!");
    return obj;
}
Also used : StopRetryException(com.swiftmq.jndi.StopRetryException) Versionable(com.swiftmq.tools.versioning.Versionable)

Example 2 with Versionable

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

the class ContextImpl method bind.

public synchronized void bind(String name, Object obj) throws NamingException {
    if (closed)
        throw new NamingException("context is closed!");
    if (!(obj instanceof TemporaryTopicImpl || obj instanceof TemporaryQueueImpl))
        throw new OperationNotSupportedException("bind is only supported for TemporaryQueues/TemporaryTopics!");
    try {
        checkConnection();
        TemporaryTopic tt = session.createTemporaryTopic();
        MessageConsumer consumer = session.createConsumer(tt);
        Versionable versionable = new Versionable();
        versionable.addVersioned(Versions.JNDI_CURRENT, createVersioned(Versions.JNDI_CURRENT, new BindRequest(name, (QueueImpl) obj)), "com.swiftmq.jndi.protocol.v" + Versions.JNDI_CURRENT + ".JNDIRequestFactory");
        BytesMessage request = createMessage(versionable, tt);
        producer.send(session.createTopic(JNDISwiftlet.JNDI_TOPIC), request, DeliveryMode.NON_PERSISTENT, MessageImpl.MAX_PRIORITY, 0);
        TextMessage reply = (TextMessage) consumer.receive();
        String text = reply.getText();
        consumer.close();
        tt.delete();
        if (text != null)
            throw new Exception(text);
    } catch (Exception e) {
        throw new NamingException("exception occurred during bind: " + e);
    }
}
Also used : Versionable(com.swiftmq.tools.versioning.Versionable) StopRetryException(com.swiftmq.jndi.StopRetryException)

Example 3 with Versionable

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

the class TopicManagerImpl method registerJNDI.

private void registerJNDI(String name, TopicImpl topic) {
    try {
        DataByteArrayOutputStream dos = new DataByteArrayOutputStream();
        DestinationFactory.dumpDestination(topic, dos);
        Versionable versionable = new Versionable();
        versionable.addVersioned(-1, new Versioned(-1, dos.getBuffer(), dos.getCount()), "com.swiftmq.jms.DestinationFactory");
        ctx.jndiSwiftlet.registerJNDIObject(name, versionable);
    } 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 4 with Versionable

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

the class RequestVisitor method visit.

public void visit(LookupRequest request) {
    String name = request.getName();
    Object object = ctx.jndiSwiftlet.getJNDIObject(name);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": request '" + name + " returns: " + object);
    if (object == null) {
        if (forwardToTopic) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": not found, forward to topic " + JNDISwiftlet.JNDI_TOPIC);
            try {
                QueueSender sender = ctx.queueManager.createQueueSender(ctx.topicManager.getQueueForTopic(JNDISwiftlet.JNDI_TOPIC), null);
                QueuePushTransaction transaction = sender.createTransaction();
                Versionable versionable = new Versionable();
                versionable.addVersioned(400, createVersioned(400, request), "com.swiftmq.jndi.protocol.v400.JNDIRequestFactory");
                BytesMessageImpl msg = createMessage(versionable, replyToQueue);
                transaction.putMessage(msg);
                transaction.commit();
                sender.close();
            } catch (Exception e1) {
                e1.printStackTrace();
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception occurred while forwarding lookup request: " + e1);
            }
        }
    } else {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": replyTo " + replyToQueue);
        if (replyToQueue != null) {
            try {
                QueueSender sender = ctx.queueManager.createQueueSender(replyToQueue.getQueueName(), null);
                QueuePushTransaction transaction = sender.createTransaction();
                MessageImpl reply = createReply(object);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": sending reply " + reply);
                transaction.putMessage(reply);
                transaction.commit();
                sender.close();
            } catch (Exception e1) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception occurred while sending reply: " + e1);
            }
        } else if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": replyTo is not set. Unable to send.");
    }
}
Also used : Versionable(com.swiftmq.tools.versioning.Versionable) QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) QueueSender(com.swiftmq.swiftlet.queue.QueueSender)

Example 5 with Versionable

use of com.swiftmq.tools.versioning.Versionable 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

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