Package org.codehaus.activemq.message.util

Examples of org.codehaus.activemq.message.util.ByteArray


                            bas[i] = array[i].getBodyAsBytes();
                            if (i >= 1){
                                array[i].clearBody();
                            }
                        }
                        ByteArray ba = fragmentation.assemble(bas);
                        result.setBodyAsBytes(ba);
                    }
                    catch (IOException ioe) {
                        JMSException jmsEx = new JMSException("Failed to assemble fragment message: " + parentId);
                        jmsEx.setLinkedException(ioe);
View Full Code Here


                    }
                    else {
                        msg = (ActiveMQMessage) consumer.receiveNoWait();
                    }
                    if (msg != null) {
                        ByteArray ba = msg.getBodyAsBytes();
                        if (ba != null) {
                            len += ba.getLength();
                            process(ba);
                        }
                    }
                    else if (closed) {
                        break;
View Full Code Here

                    ByteArray[] bas = new ByteArray[array.length];
                    try {
                        for (int i = 0;i < bas.length;i++) {
                            bas[i] = array[i].getBodyAsBytes();
                        }
                        ByteArray ba = fragmentation.assemble(bas);
                        result.setBodyAsBytes(ba);
                    }
                    catch (IOException ioe) {
                        JMSException jmsEx = new JMSException("Failed to assemble fragment message: " + parentId);
                        jmsEx.setLinkedException(ioe);
View Full Code Here

    protected void writeTextMessage(ActiveMQTextMessage message, DataOutput out) throws JMSException, IOException {
        writeMessage(message, message.getText(), out);
    }

    protected void writeBytesMessage(ActiveMQBytesMessage message, DataOutput out) throws IOException {
        ByteArray data = message.getBodyAsBytes();
        String text = encodeBinary(data.getBuf(),data.getOffset(),data.getLength());
        writeMessage(message, text, out);
    }
View Full Code Here

        //check producerKey is set (will not be set by most Junit tests)
        boolean externalMessageId = msg.isExternalMessageId() || msg.getProducerKey() == null || msg.getProducerKey().length() == 0;
        msg.setExternalMessageId(externalMessageId);
       
        ActiveMQDestination destination = msg.getJMSActiveMQDestination();
        ByteArray payload = msg.getBodyAsBytes();
        BitArray ba = msg.getBitArray();
        ba.reset();
        boolean cachingEnabled = wireFormat.isCachingEnabled();
        boolean cachingDestination = cachingEnabled && destination != null && !destination.isOrdered() && !destination.isExclusive();
        boolean longSequence = msg.getSequenceNumber() > Integer.MAX_VALUE;
       
        ba.set(AbstractPacket.RECEIPT_REQUIRED_INDEX, packet.isReceiptRequired());
        Object[] visited = msg.getBrokersVisited();
        boolean writeVisited = visited != null && visited.length > 0;
        ba.set(AbstractPacket.BROKERS_VISITED_INDEX,writeVisited);
        ba.set(ActiveMQMessage.CORRELATION_INDEX, msg.getJMSCorrelationID() != null);
        ba.set(ActiveMQMessage.TYPE_INDEX, msg.getJMSType() != null);
        ba.set(ActiveMQMessage.BROKER_NAME_INDEX, msg.getEntryBrokerName() != null);
        ba.set(ActiveMQMessage.CLUSTER_NAME_INDEX, msg.getEntryClusterName() != null);
        ba.set(ActiveMQMessage.TRANSACTION_ID_INDEX, msg.getTransactionId() != null);
        ba.set(ActiveMQMessage.REPLY_TO_INDEX, msg.getJMSReplyTo() != null);
        ba.set(ActiveMQMessage.TIMESTAMP_INDEX, msg.getJMSTimestamp() > 0);
        ba.set(ActiveMQMessage.EXPIRATION_INDEX, msg.getJMSExpiration() > 0);
        ba.set(ActiveMQMessage.REDELIVERED_INDEX, msg.getJMSRedelivered());
        ba.set(ActiveMQMessage.XA_TRANS_INDEX, msg.isXaTransacted());
        ba.set(ActiveMQMessage.CID_INDEX, msg.getConsumerNos() != null);
        ba.set(ActiveMQMessage.PROPERTIES_INDEX, msg.getProperties() != null && msg.getProperties().size() > 0);
        ba.set(ActiveMQMessage.DISPATCHED_FROM_DLQ_INDEX,msg.isDispatchedFromDLQ());
        ba.set(ActiveMQMessage.PAYLOAD_INDEX, payload != null);
        ba.set(ActiveMQMessage.EXTERNAL_MESSAGE_ID_INDEX,msg.isExternalMessageId());
        ba.set(ActiveMQMessage.MESSAGE_PART_INDEX,msg.isMessagePart());
        ba.set(ActiveMQMessage.CACHED_VALUES_INDEX, cachingEnabled);
        ba.set(ActiveMQMessage.CACHED_DESTINATION_INDEX,cachingDestination);
        ba.set(ActiveMQMessage.LONG_SEQUENCE_INDEX, longSequence);
       
        ba.writeToStream(dataOut);
        if (msg.isReceiptRequired()){
            dataOut.writeShort(msg.getId());
        }
        if (msg.isExternalMessageId()){
            writeUTF(msg.getJMSMessageID(),dataOut);
        }
        if (msg.isMessagePart()){
            writeUTF(msg.getParentMessageID(), dataOut);
            dataOut.writeShort(msg.getNumberOfParts());
            dataOut.writeShort(msg.getPartNumber());
        }
        if (writeVisited){
            dataOut.writeShort(visited.length);
            for(int i =0; i < visited.length; i++){
                final String brokerName = visited[i].toString();
                if (brokerName != null) {
                    dataOut.writeUTF(brokerName);
                } else {
                    log.warn("The brokerVisited name is null");
                }
            }
        }
      
        if (cachingEnabled){
            dataOut.writeShort(wireFormat.getWriteCachedKey(msg.getJMSClientID()));
            dataOut.writeShort(wireFormat.getWriteCachedKey(msg.getProducerKey()));
            if (cachingDestination){
                dataOut.writeShort(wireFormat.getWriteCachedKey(destination));
            }else {
                ActiveMQDestination.writeToStream(destination, dataOut);
            }
            if (msg.getJMSReplyTo() != null){
                dataOut.writeShort(wireFormat.getWriteCachedKey(msg.getJMSReplyTo()));
            }
           
        }else {
            super.writeUTF(msg.getJMSClientID(), dataOut);
            writeUTF(msg.getProducerKey(),dataOut);
            ActiveMQDestination.writeToStream(destination, dataOut);
            if (ba.get(ActiveMQMessage.REPLY_TO_INDEX)) {
                ActiveMQDestination.writeToStream((ActiveMQDestination) msg.getJMSReplyTo(), dataOut);
            }
        }
       
        dataOut.writeByte(msg.getJMSDeliveryMode());
        dataOut.writeByte(msg.getJMSPriority());
       

        if (ba.get(ActiveMQMessage.CORRELATION_INDEX)) {
            super.writeUTF(msg.getJMSCorrelationID(), dataOut);
        }
        if (ba.get(ActiveMQMessage.TYPE_INDEX)) {
            super.writeUTF(msg.getJMSType(), dataOut);
        }
        if (ba.get(ActiveMQMessage.BROKER_NAME_INDEX)) {
            super.writeUTF(msg.getEntryBrokerName(), dataOut);
        }
        if (ba.get(ActiveMQMessage.CLUSTER_NAME_INDEX)) {
            super.writeUTF(msg.getEntryClusterName(), dataOut);
        }
        if (ba.get(ActiveMQMessage.TRANSACTION_ID_INDEX)) {
            if( ba.get(ActiveMQMessage.XA_TRANS_INDEX) ) {
                ActiveMQXid xid = (ActiveMQXid) msg.getTransactionId();
                xid.write(dataOut);
            } else {
                super.writeUTF((String) msg.getTransactionId(), dataOut);
            }           
        }
       
        if (ba.get(ActiveMQMessage.TIMESTAMP_INDEX)) {
            dataOut.writeLong(msg.getJMSTimestamp());
        }
        if (ba.get(ActiveMQMessage.EXPIRATION_INDEX)) {
            dataOut.writeLong(msg.getJMSExpiration());
        }
        if (ba.get(ActiveMQMessage.CID_INDEX)) {
            //write out consumer numbers ...
            int[] cids = msg.getConsumerNos();
            dataOut.writeShort(cids.length);
            for (int i = 0; i < cids.length; i++) {
                dataOut.writeShort(cids[i]);
            }
        }
        if (ba.get(ActiveMQMessage.PROPERTIES_INDEX)) {
            msg.writeMapProperties(msg.getProperties(), dataOut);
        }
        if (ba.get(ActiveMQMessage.PAYLOAD_INDEX)) {
            dataOut.writeInt(payload.getLength());
            dataOut.write(payload.getBuf(),payload.getOffset(),payload.getLength());
        }
       
        if (longSequence){
            dataOut.writeLong(msg.getSequenceNumber());
        }else{
View Full Code Here

        if (bodyAsBytes == null) {
            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            DataOutputStream dataOut = new DataOutputStream(bytesOut);
            writeBody(dataOut);
            dataOut.flush();
            bodyAsBytes = new ByteArray(bytesOut.toByteArray());
            dataOut.close();
        }
    }
View Full Code Here

     * @param data The bodyAsBytes to set.
     * @param offset
     * @param length
     */
    public void setBodyAsBytes(byte[] data,int offset, int length) {
        this.bodyAsBytes = new ByteArray(data);
    }
View Full Code Here

      msg1.setBodyAsBytes(testdata,0,testdata.length);
      super.initializeMessage(msg1);
      byte[] data = writer.writePacketToByteArray(msg1);
      ActiveMQBytesMessage msg2 = (ActiveMQBytesMessage) reader.readPacketFromByteArray(data);
      super.testEquals(msg1, msg2);
      ByteArray d2 = msg2.getBodyAsBytes();
      assertTrue(d2.getLength()==testdata.length);
      for(int i = 0; i < testdata.length; i++)
      assertTrue(d2.get(i)==testdata[i]);
    }
    catch (IOException e) {
      e.printStackTrace();
      assertTrue(false);
    }
View Full Code Here

    public ActiveMQMessage deepCopy() throws JMSException {
        ActiveMQBytesMessage other = new ActiveMQBytesMessage();
        this.initializeOther(other);
        try {
            if (this.getBodyAsBytes() != null) {
                ByteArray data = this.getBodyAsBytes().copy();
                other.setBodyAsBytes(data);
            }
        }
        catch (IOException e) {
            JMSException jmsEx = new JMSException("setBodyAsBytes() failed");
View Full Code Here

    private void initializeReading() throws MessageNotReadableException {
        if (!super.readOnlyMessage) {
            throw new MessageNotReadableException("This message is in write-only mode");
        }
        try {
            ByteArray data = super.getBodyAsBytes();
            if (this.dataIn == null && data != null) {
                if (ByteArrayCompression.isCompressed(data)){
                    ByteArrayCompression compression = new ByteArrayCompression();
                    data = compression.inflate(data);
                }
                ByteArrayInputStream bytesIn = new ByteArrayInputStream(data.getBuf(),data.getOffset(),data.getLength());
                this.dataIn = new DataInputStream(bytesIn);
            }
        }
        catch (IOException e) {
            MessageNotReadableException mnr = new MessageNotReadableException("getBodyAsBytes failed");
View Full Code Here

TOP

Related Classes of org.codehaus.activemq.message.util.ByteArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.