Search in sources :

Example 1 with ProtocolReply

use of com.swiftmq.mgmt.protocol.ProtocolReply 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)

Aggregations

BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)1 QueueImpl (com.swiftmq.jms.QueueImpl)1 com.swiftmq.mgmt (com.swiftmq.mgmt)1 ProtocolReply (com.swiftmq.mgmt.protocol.ProtocolReply)1 ProtocolRequest (com.swiftmq.mgmt.protocol.ProtocolRequest)1 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)1 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)1