Search in sources :

Example 21 with QueueImpl

use of com.swiftmq.jms.QueueImpl in project swiftmq-ce by iitsoftware.

the class NontransactedQueueSession method visit.

public void visit(CreateProducerRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateProducerRequest");
    CreateProducerReply reply = (CreateProducerReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incProducers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    QueueImpl queue = req.getQueue();
    try {
        int producerId;
        QueueProducer producer;
        producerId = ArrayListTool.setFirstFreeOrExpand(producerList, null);
        producer = new QueueProducer(ctx, queue.getQueueName());
        producerList.set(producerId, producer);
        reply.setQueueProducerId(producerId);
        reply.setOk(true);
        if (senderEntityList != null) {
            Entity senderEntity = senderEntityList.createEntity();
            senderEntity.setName(queue.getQueueName() + "-" + producerId);
            senderEntity.setDynamicObject(producer);
            senderEntity.createCommands();
            Property prop = senderEntity.getProperty("queue");
            prop.setValue(queue.getQueueName());
            prop.setReadOnly(true);
            senderEntityList.addEntity(senderEntity);
        }
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
        ctx.logSwiftlet.logError("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
        reply.setOk(false);
        reply.setException(e);
        ctx.activeLogin.getResourceLimitGroup().decProducers();
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) JMSException(javax.jms.JMSException) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException)

Example 22 with QueueImpl

use of com.swiftmq.jms.QueueImpl in project swiftmq-ce by iitsoftware.

the class TransactedQueueSession method visit.

public void visit(CreateProducerRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateProducerRequest");
    CreateProducerReply reply = (CreateProducerReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incProducers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    QueueImpl queue = req.getQueue();
    try {
        int producerId;
        QueueProducer producer;
        producerId = ArrayListTool.setFirstFreeOrExpand(producerList, null);
        producer = new QueueProducer(ctx, queue.getQueueName());
        producerList.set(producerId, producer);
        reply.setQueueProducerId(producerId);
        reply.setOk(true);
        if (senderEntityList != null) {
            Entity senderEntity = senderEntityList.createEntity();
            senderEntity.setName(queue.getQueueName() + "-" + producerId);
            senderEntity.setDynamicObject(producer);
            senderEntity.createCommands();
            Property prop = senderEntity.getProperty("queue");
            prop.setValue(queue.getQueueName());
            prop.setReadOnly(true);
            senderEntityList.addEntity(senderEntity);
        }
        // enlist it at the transaction manager
        transactionManager.addTransactionFactory(producer);
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
        ctx.logSwiftlet.logError("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
        reply.setOk(false);
        reply.setException(e);
        ctx.activeLogin.getResourceLimitGroup().decProducers();
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) JMSException(javax.jms.JMSException) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException)

Example 23 with QueueImpl

use of com.swiftmq.jms.QueueImpl in project swiftmq-client by iitsoftware.

the class CreateBrowserRequest method readContent.

/**
 * Read the content of this object from the stream.
 *
 * @param in input stream
 * @throws IOException if an error occurs
 */
public void readContent(DataInput in) throws IOException {
    super.readContent(in);
    byte set = in.readByte();
    if (set == 0) {
        queue = null;
    } else {
        queue = new QueueImpl(in.readUTF());
    }
    set = in.readByte();
    if (set == 0) {
        messageSelector = null;
    } else {
        messageSelector = in.readUTF();
    }
}
Also used : QueueImpl(com.swiftmq.jms.QueueImpl)

Example 24 with QueueImpl

use of com.swiftmq.jms.QueueImpl in project swiftmq-client by iitsoftware.

the class CreateConsumerRequest method readContent.

/**
 * Read the content of this object from the stream.
 *
 * @param in input stream
 * @throws IOException if an error occurs
 */
public void readContent(DataInput in) throws IOException {
    super.readContent(in);
    byte set = in.readByte();
    if (set == 0) {
        queue = null;
    } else {
        queue = new QueueImpl(in.readUTF());
    }
    set = in.readByte();
    if (set == 0) {
        messageSelector = null;
    } else {
        messageSelector = in.readUTF();
    }
}
Also used : QueueImpl(com.swiftmq.jms.QueueImpl)

Example 25 with QueueImpl

use of com.swiftmq.jms.QueueImpl 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

QueueImpl (com.swiftmq.jms.QueueImpl)78 InvalidSelectorException (javax.jms.InvalidSelectorException)51 JMSException (javax.jms.JMSException)51 InvalidDestinationException (javax.jms.InvalidDestinationException)49 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)42 Entity (com.swiftmq.mgmt.Entity)35 Property (com.swiftmq.mgmt.Property)35 MessageImpl (com.swiftmq.jms.MessageImpl)21 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)16 MessageSelector (com.swiftmq.ms.MessageSelector)9 RingBuffer (com.swiftmq.tools.collection.RingBuffer)7 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)7 List (java.util.List)6 EntityList (com.swiftmq.mgmt.EntityList)5 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)4 TopicImpl (com.swiftmq.jms.TopicImpl)4 SwiftletException (com.swiftmq.swiftlet.SwiftletException)3 TextMessageImpl (com.swiftmq.jms.TextMessageImpl)2 JNDIRequest (com.swiftmq.jndi.protocol.v400.JNDIRequest)2 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)2