Search in sources :

Example 21 with QueuePushTransaction

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

the class DispatchQueue method dispatchClientRequest.

private void dispatchClientRequest(ClientRequest event) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " ...");
    Dispatcher d = (Dispatcher) dispatchers.get(event.getQueueName());
    if (d != null) {
        if (d.isInvalid()) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + ", dispatcher invalid (1): " + d);
            d.close();
            dispatchers.remove(event.getQueueName());
        } else {
            d.process(event);
            if (d.isInvalid()) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + ", dispatcher invalid (2): " + d);
                d.close();
                dispatchers.remove(event.getQueueName());
            }
        }
    } else {
        try {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " try ProtocolRequest ...");
            dis.reset();
            dis.setBuffer(event.getBuffer());
            ProtocolRequest r = null;
            try {
                r = (ProtocolRequest) Dumpalizer.construct(dis, factory);
            } catch (NullPointerException e) {
                // Since we can get old LeaseRequests here, we can ignore it.
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, got exception: " + e + ", probably old LeaseRequest, ignore!");
                return;
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " got ProtocolRequest: " + r);
            ProtocolReply reply = (ProtocolReply) r.createReply();
            switch(r.getVersion()) {
                case 400:
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " create v400 Dispatcher");
                    d = new com.swiftmq.impl.mgmt.standard.v400.DispatcherImpl(ctx, event.getQueueName());
                    dispatchers.put(event.getQueueName(), d);
                    reply.setOk(true);
                    break;
                case 750:
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " create v750 Dispatcher");
                    d = new com.swiftmq.impl.mgmt.standard.v750.DispatcherImpl(ctx, event.getUserName(), event.getQueueName());
                    dispatchers.put(event.getQueueName(), d);
                    reply.setOk(true);
                    break;
                default:
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " failed: Unsupported protocol version: " + r.getVersion());
                    reply.setOk(false);
                    reply.setException(new Exception("Unsupported protocol version: " + r.getVersion()));
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " send reply: " + reply);
            QueueSender sender = ctx.queueManager.createQueueSender(event.getQueueName(), null);
            BytesMessageImpl msg = new BytesMessageImpl();
            msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
            msg.setJMSDestination(new QueueImpl(event.getQueueName()));
            msg.setJMSPriority(MessageImpl.MAX_PRIORITY - 1);
            dos.rewind();
            Dumpalizer.dump(dos, reply);
            msg.writeBytes(dos.getBuffer(), 0, dos.getCount());
            QueuePushTransaction t = sender.createTransaction();
            t.putMessage(msg);
            t.commit();
            sender.close();
            checkStartLeases();
        } catch (Exception e) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " got exception: " + e);
            ctx.logSwiftlet.logError(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " got exception: " + e);
            dispatchers.remove(event.getQueueName());
        }
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " done");
}
Also used : ProtocolReply(com.swiftmq.mgmt.protocol.ProtocolReply) QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) QueueImpl(com.swiftmq.jms.QueueImpl) ProtocolRequest(com.swiftmq.mgmt.protocol.ProtocolRequest) com.swiftmq.mgmt(com.swiftmq.mgmt) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) QueueSender(com.swiftmq.swiftlet.queue.QueueSender)

Example 22 with QueuePushTransaction

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

the class RequestVisitor method visit.

public void visit(BindRequest request) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request);
    String name = request.getName();
    QueueImpl queue = request.getQueue();
    String msg = null;
    boolean registered = false;
    try {
        String queueName = queue.getQueueName();
        if (queueName.endsWith(SwiftletManager.getInstance().getRouterName())) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + " is local");
            registered = true;
            name = name != null ? name : queueName;
            if (ctx.jndiSwiftlet.getJNDIObject(name) != null)
                throw new Exception("bind failed, object '" + name + "' is already registered!");
            ctx.jndiSwiftlet.registerJNDIObject(name, queue);
        }
    } catch (Exception e) {
        msg = e.getMessage();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception: " + msg);
    }
    if (registered) {
        if (replyToQueue != null) {
            try {
                QueueSender sender = ctx.queueManager.createQueueSender(replyToQueue.getQueueName(), null);
                QueuePushTransaction transaction = sender.createTransaction();
                TextMessageImpl reply = new TextMessageImpl();
                reply.setJMSDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT);
                reply.setJMSDestination(replyToQueue);
                reply.setJMSPriority(MessageImpl.MAX_PRIORITY);
                reply.setText(msg);
                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 : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) QueueSender(com.swiftmq.swiftlet.queue.QueueSender)

Example 23 with QueuePushTransaction

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

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

the class RequestVisitor method visit.

public void visit(RebindRequest request) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request);
    String name = request.getName();
    QueueImpl queue = request.getQueue();
    String msg = null;
    boolean registered = false;
    try {
        String queueName = queue.getQueueName();
        if (queueName.endsWith(SwiftletManager.getInstance().getRouterName())) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + " is local");
            registered = true;
            if (ctx.jndiSwiftlet.getJNDIObject(name) != null)
                throw new Exception("rebind failed, object '" + name + "' is already registered!");
            String oldName = ctx.jndiSwiftlet.getJNDIObjectName(queue);
            if (oldName != null) {
                Object ro = ctx.jndiSwiftlet.getJNDIObject(oldName);
                if (ro != null) {
                    if (ro.getClass() != queue.getClass())
                        throw new Exception("rebind failed; attempt to overwrite a different registration class!");
                    ctx.jndiSwiftlet.deregisterJNDIObject(oldName);
                }
            }
            ctx.jndiSwiftlet.registerJNDIObject(name, queue);
        }
    } catch (Exception e) {
        msg = e.getMessage();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception: " + msg);
    }
    if (registered) {
        if (replyToQueue != null) {
            try {
                QueueSender sender = ctx.queueManager.createQueueSender(replyToQueue.getQueueName(), null);
                QueuePushTransaction transaction = sender.createTransaction();
                TextMessageImpl reply = new TextMessageImpl();
                reply.setJMSDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT);
                reply.setJMSDestination(replyToQueue);
                reply.setJMSPriority(MessageImpl.MAX_PRIORITY);
                reply.setText(msg);
                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 : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) QueueSender(com.swiftmq.swiftlet.queue.QueueSender)

Example 25 with QueuePushTransaction

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

the class NontransactedTopicSession method visitProduceMessageRequest.

public void visitProduceMessageRequest(ProduceMessageRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitProduceMessageRequest");
    ctx.incMsgsSent(1);
    ProduceMessageReply reply = null;
    if (req.isReplyRequired())
        reply = (ProduceMessageReply) req.createReply();
    MessageImpl msg = req.getMessage();
    int producerId = req.getQueueProducerId();
    Producer producer = null;
    try {
        if (producerId == -1) {
            TopicImpl topic = (TopicImpl) msg.getJMSDestination();
            if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
                ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
            producer = new TopicProducer(ctx, topic);
        } else {
            producer = (Producer) producerList.get(producerId);
        }
        QueuePushTransaction transaction = (QueuePushTransaction) producer.createTransaction();
        transaction.putMessage(msg);
        transaction.commit();
        if (req.isReplyRequired()) {
            reply.setDelay(transaction.getFlowControlDelay());
            reply.setOk(true);
        }
        if (producerId == -1)
            producer.close();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/produce messages failed: " + e.getMessage());
        if (req.isReplyRequired()) {
            reply.setOk(false);
            reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
        }
    }
    if (req.isReplyRequired())
        reply.send();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) JMSException(javax.jms.JMSException) TopicImpl(com.swiftmq.jms.TopicImpl) MessageImpl(com.swiftmq.jms.MessageImpl) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException)

Aggregations

QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)57 JMSException (javax.jms.JMSException)44 InvalidSelectorException (javax.jms.InvalidSelectorException)43 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)42 MessageImpl (com.swiftmq.jms.MessageImpl)33 InvalidDestinationException (javax.jms.InvalidDestinationException)28 RingBuffer (com.swiftmq.tools.collection.RingBuffer)21 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)21 QueueImpl (com.swiftmq.jms.QueueImpl)16 List (java.util.List)16 EntityList (com.swiftmq.mgmt.EntityList)15 TopicImpl (com.swiftmq.jms.TopicImpl)14 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)7 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)5 com.swiftmq.jms (com.swiftmq.jms)4 QueueException (com.swiftmq.swiftlet.queue.QueueException)4 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)3 XidImpl (com.swiftmq.jms.XidImpl)2 AbstractQueue (com.swiftmq.swiftlet.queue.AbstractQueue)2 Versionable (com.swiftmq.tools.versioning.Versionable)2