Search in sources :

Example 6 with BytesMessageImpl

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

the class AMQPNativeInboundTransformer method transform.

public MessageImpl transform(TransferFrame frame, DestinationFactory destinationFactory) throws AMQPException, JMSException {
    BytesMessageImpl msg = null;
    if (frame.getMorePayloads() == null) {
        byte[] payload = frame.getPayload();
        msg = new BytesMessageImpl(payload, payload.length);
    } else {
        byte[] b = new byte[frame.getPayloadLength()];
        byte[] payload = frame.getPayload();
        System.arraycopy(payload, 0, b, 0, payload.length);
        int pos = payload.length;
        List morePayloads = frame.getMorePayloads();
        for (int i = 0; i < morePayloads.size(); i++) {
            payload = (byte[]) morePayloads.get(i);
            System.arraycopy(payload, 0, b, pos, payload.length);
            pos += payload.length;
        }
        msg = new BytesMessageImpl(b, b.length);
    }
    try {
        msg.setLongProperty(messageFormat, frame.getMessageFormat().getValue());
        msg.setBooleanProperty(amqpNative, true);
        setDefaultHeader(msg);
    } catch (Exception e) {
        throw new AMQPException(e.toString());
    }
    msg.reset();
    return msg;
}
Also used : AMQPException(com.swiftmq.amqp.v100.client.AMQPException) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) List(java.util.List) AMQPException(com.swiftmq.amqp.v100.client.AMQPException) JMSException(javax.jms.JMSException)

Example 7 with BytesMessageImpl

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

the class DispatcherImpl method send.

private void send(Dumpable dumpable) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/send, dumpable: " + dumpable);
    try {
        BytesMessageImpl msg = new BytesMessageImpl();
        msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
        msg.setJMSDestination(replyQueue);
        msg.setJMSPriority(MessageImpl.MAX_PRIORITY - 1);
        dos.rewind();
        Dumpalizer.dump(dos, dumpable);
        msg.writeBytes(dos.getBuffer(), 0, dos.getCount());
        QueuePushTransaction t = queueSender.createTransaction();
        t.putMessage(msg);
        t.commit();
    } catch (Exception e) {
        valid = false;
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/send, got exception: " + e);
    }
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl)

Example 8 with BytesMessageImpl

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

the class DispatcherImpl method send.

private void send(Dumpable dumpable) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/send, dumpable: " + dumpable);
    try {
        BytesMessageImpl msg = new BytesMessageImpl();
        msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
        msg.setJMSDestination(replyQueue);
        msg.setJMSPriority(MessageImpl.MAX_PRIORITY - 1);
        dos.rewind();
        Dumpalizer.dump(dos, dumpable);
        msg.writeBytes(dos.getBuffer(), 0, dos.getCount());
        QueuePushTransaction t = queueSender.createTransaction();
        t.putMessage(msg);
        t.commit();
    } catch (Exception e) {
        valid = false;
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/send, got exception: " + e);
    }
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl)

Example 9 with BytesMessageImpl

use of com.swiftmq.jms.BytesMessageImpl 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 10 with BytesMessageImpl

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

the class PreparedLogQueue method preload.

private void preload() throws Exception {
    List qiEntries = queueIndex.getEntries();
    queueIndex.unloadPages();
    for (int i = 0; i < qiEntries.size(); i++) {
        QueueIndexEntry entry = (QueueIndexEntry) qiEntries.get(i);
        StoreEntry storeEntry = queueIndex.get(entry);
        BytesMessageImpl msg = (BytesMessageImpl) storeEntry.message;
        byte[] b = new byte[(int) msg.getBodyLength()];
        msg.readBytes(b);
        inStream.setBuffer(b, 0, b.length);
        PrepareLogRecordImpl logRecord = new PrepareLogRecordImpl(0);
        logRecord.readContent(inStream);
        CacheEntry cacheEntry = new CacheEntry();
        cacheEntry.logRecord = logRecord;
        long address = (long) ArrayListTool.setFirstFreeOrExpand(cache, cacheEntry);
        logRecord.setAddress(address);
        cacheEntry.indexEntry = entry;
    }
    queueIndex.unloadPages();
}
Also used : BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) StoreEntry(com.swiftmq.swiftlet.store.StoreEntry) ArrayList(java.util.ArrayList) List(java.util.List) QueueIndexEntry(com.swiftmq.impl.store.standard.index.QueueIndexEntry)

Aggregations

BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)26 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)5 QueueImpl (com.swiftmq.jms.QueueImpl)4 List (java.util.List)4 JMSException (javax.jms.JMSException)4 Endpoint (com.swiftmq.admin.mgmt.Endpoint)2 ContentHeaderProperties (com.swiftmq.amqp.v091.types.ContentHeaderProperties)2 ByteBuf (com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)2 TextMessageImpl (com.swiftmq.jms.TextMessageImpl)2 XidImpl (com.swiftmq.jms.XidImpl)2 StoreEntry (com.swiftmq.swiftlet.store.StoreEntry)2 Dumpable (com.swiftmq.tools.dump.Dumpable)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BytesMessage (javax.jms.BytesMessage)2 Field (com.swiftmq.amqp.v091.types.Field)1 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)1 Delivery (com.swiftmq.impl.amqp.amqp.v00_09_01.Delivery)1 MqttFixedHeader (com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader)1 QueueIndexEntry (com.swiftmq.impl.store.standard.index.QueueIndexEntry)1