Search in sources :

Example 21 with DataByteArrayInputStream

use of com.swiftmq.tools.util.DataByteArrayInputStream in project swiftmq-ce by iitsoftware.

the class NettyOutboundConnectionHandler method chunkCompleted.

@Override
public void chunkCompleted(byte[] b, int offset, int len) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$net", toString() + "/chunk completed");
    if (bais == null) {
        zombi = false;
        bais = new DataByteArrayInputStream();
    }
    bais.setBuffer(b, offset, len);
    try {
        inboundHandler.dataAvailable(connection, bais);
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$net", toString() + "/Exception, EXITING: " + e);
        ctx.logSwiftlet.logInformation(toString(), "Exception, EXITING: " + e);
        if (activated) {
            ctx.networkSwiftlet.getConnectionManager().removeConnection(connection);
            activated = true;
        }
    }
}
Also used : DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream)

Example 22 with DataByteArrayInputStream

use of com.swiftmq.tools.util.DataByteArrayInputStream in project swiftmq-client by iitsoftware.

the class SMQPUtil method toMessage.

public static MessageImpl toMessage(byte[] b) throws Exception {
    DataByteArrayInputStream dbis = new DataByteArrayInputStream(b);
    MessageImpl msg = MessageImpl.createInstance(dbis.readInt());
    msg.readContent(dbis);
    return msg;
}
Also used : DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream)

Example 23 with DataByteArrayInputStream

use of com.swiftmq.tools.util.DataByteArrayInputStream in project swiftmq-ce by iitsoftware.

the class TransactedQueueSession method visitCommitRequest.

public void visitCommitRequest(CommitRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCommitRequest");
    CommitReply reply = (CommitReply) req.createReply();
    reply.setOk(true);
    try {
        // first: produce all messages
        Object[] wrapper = req.getMessages();
        ctx.incMsgsSent(wrapper.length);
        req.setMessages(null);
        long fcDelay = 0;
        RingBuffer tempProducers = null;
        for (int i = 0; i < wrapper.length; i++) {
            DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) wrapper[i]);
            int producerId = dis.readInt();
            int type = dis.readInt();
            MessageImpl msg = MessageImpl.createInstance(type);
            msg.readContent(dis);
            dis.close();
            Producer producer = null;
            if (producerId == -1) {
                String queueName = ((QueueImpl) msg.getJMSDestination()).getQueueName();
                if (!ctx.queueManager.isQueueRunning(queueName))
                    throw new InvalidDestinationException("Invalid destination: " + queueName);
                producer = new QueueProducer(ctx, queueName);
                if (tempProducers == null)
                    tempProducers = new RingBuffer(8);
                tempProducers.add(producer);
                transactionManager.addTransactionFactory(producer);
            } else {
                producer = (Producer) producerList.get(producerId);
            }
            QueuePushTransaction transaction = (QueuePushTransaction) producer.getTransaction();
            transaction.putMessage(msg);
            fcDelay = Math.max(fcDelay, transaction.getFlowControlDelay());
            if (producerId == -1)
                producer.markForClose();
        }
        // Next: do the commit
        transactionManager.commit();
        if (tempProducers != null) {
            int size = tempProducers.getSize();
            for (int i = 0; i < size; i++) {
                ((Producer) tempProducers.remove()).close();
            }
        }
        reply.setDelay(fcDelay);
        purgeMarkedProducers();
        purgeMarkedConsumers();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/commit produced messages failed: " + e.getMessage());
        reply.setOk(false);
        reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
    }
    reply.send();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) RingBuffer(com.swiftmq.tools.collection.RingBuffer) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 24 with DataByteArrayInputStream

use of com.swiftmq.tools.util.DataByteArrayInputStream in project swiftmq-ce by iitsoftware.

the class TransactedQueueSession method visitCommitRequest.

public void visitCommitRequest(CommitRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCommitRequest");
    CommitReply reply = (CommitReply) req.createReply();
    reply.setOk(true);
    try {
        // first: produce all messages
        Object[] wrapper = req.getMessages();
        ctx.incMsgsSent(wrapper.length);
        req.setMessages(null);
        long fcDelay = 0;
        RingBuffer tempProducers = null;
        for (int i = 0; i < wrapper.length; i++) {
            DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) wrapper[i]);
            int producerId = dis.readInt();
            int type = dis.readInt();
            MessageImpl msg = MessageImpl.createInstance(type);
            msg.readContent(dis);
            dis.close();
            Producer producer = null;
            if (producerId == -1) {
                String queueName = ((QueueImpl) msg.getJMSDestination()).getQueueName();
                if (!ctx.queueManager.isQueueRunning(queueName))
                    throw new InvalidDestinationException("Invalid destination: " + queueName);
                producer = new QueueProducer(ctx, queueName);
                if (tempProducers == null)
                    tempProducers = new RingBuffer(8);
                tempProducers.add(producer);
                transactionManager.addTransactionFactory(producer);
            } else {
                producer = (Producer) producerList.get(producerId);
            }
            QueuePushTransaction transaction = (QueuePushTransaction) producer.getTransaction();
            transaction.putMessage(msg);
            fcDelay = Math.max(fcDelay, transaction.getFlowControlDelay());
            if (producerId == -1)
                producer.markForClose();
        }
        // Next: do the commit
        transactionManager.commit();
        if (tempProducers != null) {
            int size = tempProducers.getSize();
            for (int i = 0; i < size; i++) {
                ((Producer) tempProducers.remove()).close();
            }
        }
        reply.setDelay(fcDelay);
        purgeMarkedProducers();
        purgeMarkedConsumers();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/commit produced messages failed: " + e.getMessage());
        reply.setOk(false);
        reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
    }
    reply.send();
}
Also used : QueuePushTransaction(com.swiftmq.swiftlet.queue.QueuePushTransaction) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) RingBuffer(com.swiftmq.tools.collection.RingBuffer) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageImpl(com.swiftmq.jms.MessageImpl)

Example 25 with DataByteArrayInputStream

use of com.swiftmq.tools.util.DataByteArrayInputStream in project swiftmq-client by iitsoftware.

the class AuthRequest method readContent.

public void readContent(DataInput input) throws IOException {
    super.readContent(input);
    byte[] b = new byte[input.readInt()];
    input.readFully(b);
    DataByteArrayInputStream dbis = new DataByteArrayInputStream(b);
    ObjectInputStream ois = new ObjectInputStream(dbis);
    try {
        response = (Serializable) ois.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException(e.toString());
    }
    ois.close();
}
Also used : DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream)

Aggregations

DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)68 InvalidSelectorException (javax.jms.InvalidSelectorException)22 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)21 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)21 RingBuffer (com.swiftmq.tools.collection.RingBuffer)21 JMSException (javax.jms.JMSException)21 MessageImpl (com.swiftmq.jms.MessageImpl)20 EntityList (com.swiftmq.mgmt.EntityList)15 List (java.util.List)15 InvalidDestinationException (javax.jms.InvalidDestinationException)14 TopicImpl (com.swiftmq.jms.TopicImpl)8 QueueImpl (com.swiftmq.jms.QueueImpl)7 DataByteArrayOutputStream (com.swiftmq.tools.util.DataByteArrayOutputStream)7 IOException (java.io.IOException)7 com.swiftmq.jms (com.swiftmq.jms)2 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 MessageFormat (com.swiftmq.amqp.v100.generated.transport.definitions.MessageFormat)1 CountableBufferedInputStream (com.swiftmq.impl.net.netty.CountableBufferedInputStream)1 CountableWrappedOutputStream (com.swiftmq.impl.net.netty.CountableWrappedOutputStream)1 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)1