Package org.codehaus.activemq.util

Examples of org.codehaus.activemq.util.BitArray


     * @param dataIn the data input stream to build the packet from
     * @throws IOException
     */
    public void buildPacket(Packet packet, DataInput dataIn) throws IOException {
        MessageAck ack = (MessageAck) packet;
        BitArray ba = ack.getBitArray();
        ba.readFromStream(dataIn);
        boolean cachingEnabled = ba.get(MessageAck.CACHED_VALUES_INDEX);
        ack.setMessageRead(ba.get(MessageAck.MESSAGE_READ_INDEX));
        ack.setPersistent(ba.get(MessageAck.PERSISTENT_INDEX));
        ack.setExpired(ba.get(MessageAck.EXPIRED_INDEX));
        if (ba.get(AbstractPacket.RECEIPT_REQUIRED_INDEX)) {
            ack.setReceiptRequired(true);
            ack.setId(dataIn.readShort());
        }
        if (ba.get(MessageAck.EXTERNAL_MESSAGE_ID_INDEX)) {
            ack.setExternalMessageId(true);
            ack.setMessageID(dataIn.readUTF());
        }
        else {
            if (cachingEnabled) {
                short key = dataIn.readShort();
                ack.setProducerKey((String) wireFormat.getValueFromReadCache(key));
            }
            else {
                ack.setProducerKey(dataIn.readUTF());
            }
            if (ba.get(MessageAck.LONG_SEQUENCE_INDEX)) {
                ack.setSequenceNumber(dataIn.readLong());
            }
            else {
                ack.setSequenceNumber(dataIn.readInt());
            }
        }
        if (ba.get(AbstractPacket.BROKERS_VISITED_INDEX)) {
            int visitedLen = dataIn.readShort();
            for (int i = 0;i < visitedLen;i++) {
                ack.addBrokerVisited(dataIn.readUTF());
            }
        }
        if (ba.get(MessageAck.TRANSACTION_ID_INDEX)) {
            if (ba.get(ActiveMQMessage.XA_TRANS_INDEX)) {
                ack.setTransactionId(ActiveMQXid.read(dataIn));
            }
            else {
                ack.setTransactionId(super.readUTF(dataIn));
            }
View Full Code Here


        boolean longSequence = ack.getSequenceNumber() > Integer.MAX_VALUE;
       
      
        Object[] visited = ack.getBrokersVisited();
        boolean writeVisited = visited != null && visited.length > 0;
        BitArray ba = ack.getBitArray();
        ba.reset();
        ba.set(AbstractPacket.RECEIPT_REQUIRED_INDEX, ack.isReceiptRequired());
        ba.set(AbstractPacket.BROKERS_VISITED_INDEX,writeVisited);
        ba.set(MessageAck.MESSAGE_READ_INDEX, ack.isMessageRead());
        ba.set(MessageAck.TRANSACTION_ID_INDEX, ack.isPartOfTransaction());
        ba.set(MessageAck.XA_TRANS_INDEX, ack.isXaTransacted());
        ba.set(MessageAck.PERSISTENT_INDEX,ack.isPersistent());
        ba.set(MessageAck.EXPIRED_INDEX,ack.isExpired());
        ba.set(MessageAck.EXTERNAL_MESSAGE_ID_INDEX, ack.isExternalMessageId());
        ba.set(MessageAck.CACHED_VALUES_INDEX,cachingEnabled);
        ba.set(MessageAck.LONG_SEQUENCE_INDEX, longSequence);
        ba.writeToStream(dataOut);
       
        if (ack.isReceiptRequired()){
            dataOut.writeShort(ack.getId());
        }
        if (ack.isExternalMessageId()){
View Full Code Here

     * @param dataIn the data input stream to build the packet from
     * @throws IOException
     */
    public void buildPacket(Packet packet, DataInput dataIn) throws IOException {
        ActiveMQMessage msg = (ActiveMQMessage) packet;
        BitArray ba = msg.getBitArray();
        ba.readFromStream(dataIn);
       
        boolean receiptRequired = ba.get(AbstractPacket.RECEIPT_REQUIRED_INDEX);
        if (receiptRequired){
            msg.setReceiptRequired(receiptRequired);
            msg.setId(dataIn.readShort());
        }
        boolean externalMessageId = ba.get(ActiveMQMessage.EXTERNAL_MESSAGE_ID_INDEX);
       
        if (externalMessageId){
            msg.setExternalMessageId(externalMessageId);
            msg.setJMSMessageID(readUTF(dataIn));
        }
       
        boolean cachingEnabled = ba.get(ActiveMQMessage.CACHED_VALUES_INDEX);
        boolean cachingDestination = ba.get(ActiveMQMessage.CACHED_DESTINATION_INDEX);
       
        boolean messagePart = ba.get(ActiveMQMessage.MESSAGE_PART_INDEX);
        msg.setMessagePart(messagePart);
        if (messagePart){
            msg.setParentMessageID(dataIn.readUTF());
            msg.setNumberOfParts(dataIn.readShort());
            msg.setPartNumber(dataIn.readShort());
        }
      
        if (ba.get(AbstractPacket.BROKERS_VISITED_INDEX)){
            int visitedLen = dataIn.readShort();
            for (int i =0; i < visitedLen; i++){
                msg.addBrokerVisited(dataIn.readUTF());
            }       
        }
        if (cachingEnabled){
            short key = dataIn.readShort();
            msg.setJMSClientID((String)wireFormat.getValueFromReadCache(key));
            key = dataIn.readShort();
            msg.setProducerKey((String)wireFormat.getValueFromReadCache(key));
            if (cachingDestination){
                key = dataIn.readShort();
                msg.setJMSDestination((Destination)wireFormat.getValueFromReadCache(key));
            }else{
                msg.setJMSDestination(ActiveMQDestination.readFromStream(dataIn));
            }
            if (ba.get(ActiveMQMessage.REPLY_TO_INDEX)) {
                key = dataIn.readShort();
                msg.setJMSReplyTo((Destination)wireFormat.getValueFromReadCache(key));
            }
           
        }else {
            msg.setJMSClientID(super.readUTF(dataIn));
            msg.setProducerKey(dataIn.readUTF());
            msg.setJMSDestination(ActiveMQDestination.readFromStream(dataIn));
            if (ba.get(ActiveMQMessage.REPLY_TO_INDEX)) {
                msg.setJMSReplyTo(ActiveMQDestination.readFromStream(dataIn));
            }
        }
       
       
        msg.setJMSDeliveryMode(dataIn.readByte());
        msg.setJMSPriority(dataIn.readByte());
    
        msg.setJMSRedelivered(ba.get(ActiveMQMessage.REDELIVERED_INDEX));

        if (ba.get(ActiveMQMessage.CORRELATION_INDEX)) {
            msg.setJMSCorrelationID(super.readUTF(dataIn));
        }
        if (ba.get(ActiveMQMessage.TYPE_INDEX)) {
            msg.setJMSType(super.readUTF(dataIn));
        }
        if (ba.get(ActiveMQMessage.BROKER_NAME_INDEX)) {
            msg.setEntryBrokerName(super.readUTF(dataIn));
        }
        if (ba.get(ActiveMQMessage.CLUSTER_NAME_INDEX)) {
            msg.setEntryClusterName(super.readUTF(dataIn));
        }
        if (ba.get(ActiveMQMessage.TRANSACTION_ID_INDEX)) {
            if( ba.get(ActiveMQMessage.XA_TRANS_INDEX) ) {
                msg.setTransactionId(ActiveMQXid.read(dataIn));               
            } else {
                msg.setTransactionId(super.readUTF(dataIn));
            }
        } else {
            msg.setTransactionId(null);
        }
       
        if (ba.get(ActiveMQMessage.TIMESTAMP_INDEX)) {
            msg.setJMSTimestamp(dataIn.readLong());
        }
        if (ba.get(ActiveMQMessage.EXPIRATION_INDEX)) {
            msg.setJMSExpiration(dataIn.readLong());
        }
        if (ba.get(ActiveMQMessage.CID_INDEX)) {
            int cidlength = dataIn.readShort();
            if (cidlength > 0) {
                int[] cids = new int[cidlength];
                for (int i = 0; i < cids.length; i++) {
                    cids[i] = dataIn.readShort();
                }
                msg.setConsumerNos(cids);
            }
        }
        if (ba.get(ActiveMQMessage.PROPERTIES_INDEX)) {
            msg.setProperties(msg.readMapProperties(dataIn));
        }
        if (ba.get(ActiveMQMessage.DISPATCHED_FROM_DLQ_INDEX)){
            msg.setDispatchedFromDLQ(true);
        }
        if (ba.get(ActiveMQMessage.PAYLOAD_INDEX)) {
            int payloadLength = dataIn.readInt();
            if (payloadLength >= 0) {
                if (dataIn instanceof WireByteArrayInputStream){
                    WireByteArrayInputStream wireIn = (WireByteArrayInputStream)dataIn;
                    msg.setBodyAsBytes(wireIn.getRawData(), wireIn.position(), payloadLength);
                }else {
                byte[] payload = new byte[payloadLength];
                dataIn.readFully(payload);
                msg.setBodyAsBytes(payload,0,payload.length);
                }
            }
        }
        if (ba.get(ActiveMQMessage.LONG_SEQUENCE_INDEX)){
            msg.setSequenceNumber(dataIn.readLong());
        }else {
            msg.setSequenceNumber(dataIn.readInt());
        }
        msg.setDeliveryCount(dataIn.readByte());
View Full Code Here

     * @throws IOException
     */
    public void buildPacket(Packet p, DataInput dataIn) throws IOException {
        AbstractPacket packet = (AbstractPacket) p;
        packet.setId(dataIn.readShort());
        BitArray ba = packet.getBitArray();
        ba.readFromStream(dataIn);
        packet.setReceiptRequired(ba.get(AbstractPacket.RECEIPT_REQUIRED_INDEX));
        if (ba.get(AbstractPacket.BROKERS_VISITED_INDEX)) {
            int visitedLen = dataIn.readShort();
            for (int i = 0;i < visitedLen;i++) {
                packet.addBrokerVisited(dataIn.readUTF());
            }
        }
View Full Code Here

     * @throws IOException thrown if an error occurs
     */
    public void writePacket(Packet p, DataOutput dataOut) throws IOException {
        AbstractPacket packet = (AbstractPacket)p;
        dataOut.writeShort(packet.getId());
        BitArray ba = packet.getBitArray();
        ba.set(AbstractPacket.RECEIPT_REQUIRED_INDEX, packet.isReceiptRequired());
        Object[] visited = packet.getBrokersVisited();
        boolean writeVisited = visited != null && visited.length > 0;
        ba.set(AbstractPacket.BROKERS_VISITED_INDEX,writeVisited);
        ba.writeToStream(dataOut);
        if (writeVisited){
            dataOut.writeShort(visited.length);
            for(int i =0; i < visited.length; i++){
                dataOut.writeUTF(visited[i].toString());
            }
View Full Code Here

        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){
View Full Code Here

    private transient int memoryUsageReferenceCount;

    private CopyOnWriteArraySet brokersVisited;
  
    protected AbstractPacket(){
        this.bitArray = new BitArray();
    }
View Full Code Here

        super.writeUTF(msg.getProducerID(), dataOut);
        ActiveMQDestination.writeToStream((ActiveMQDestination) msg.getJMSDestination(), dataOut);
        dataOut.write(msg.getJMSDeliveryMode());
        dataOut.write(msg.getJMSPriority());

        BitArray ba = new BitArray();
        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.PAYLOAD_INDEX, payload != null);
        ba.writeToStream(dataOut);

        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)) {
            super.writeUTF(msg.getTransactionId(), dataOut);
        }
        if (ba.get(ActiveMQMessage.REPLY_TO_INDEX)) {
            ActiveMQDestination.writeToStream((ActiveMQDestination) msg.getJMSReplyTo(), 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.length);
            dataOut.write(payload);
        }
    }
View Full Code Here

        msg.setJMSClientID(super.readUTF(dataIn));
        msg.setProducerID(super.readUTF(dataIn));
        msg.setJMSDestination(ActiveMQDestination.readFromStream(dataIn));
        msg.setJMSDeliveryMode(dataIn.readByte());
        msg.setJMSPriority(dataIn.readByte());
        BitArray ba = new BitArray();
        ba.readFromStream(dataIn);
        msg.setJMSRedelivered(ba.get(ActiveMQMessage.REDELIVERED_INDEX));
        msg.setXaTransacted(ba.get(ActiveMQMessage.XA_TRANS_INDEX));

        if (ba.get(ActiveMQMessage.CORRELATION_INDEX)) {
            msg.setJMSCorrelationID(super.readUTF(dataIn));
        }
        if (ba.get(ActiveMQMessage.TYPE_INDEX)) {
            msg.setJMSType(super.readUTF(dataIn));
        }
        if (ba.get(ActiveMQMessage.BROKER_NAME_INDEX)) {
            msg.setEntryBrokerName(super.readUTF(dataIn));
        }
        if (ba.get(ActiveMQMessage.CLUSTER_NAME_INDEX)) {
            msg.setEntryClusterName(super.readUTF(dataIn));
        }
        if (ba.get(ActiveMQMessage.TRANSACTION_ID_INDEX)) {
            msg.setTransactionId(super.readUTF(dataIn));
        }
        if (ba.get(ActiveMQMessage.REPLY_TO_INDEX)) {
            msg.setJMSReplyTo(ActiveMQDestination.readFromStream(dataIn));
        }
        if (ba.get(ActiveMQMessage.TIMESTAMP_INDEX)) {
            msg.setJMSTimestamp(dataIn.readLong());
        }
        if (ba.get(ActiveMQMessage.EXPIRATION_INDEX)) {
            msg.setJMSExpiration(dataIn.readLong());
        }
        if (ba.get(ActiveMQMessage.CID_INDEX)) {
            int cidlength = dataIn.readShort();
            if (cidlength > 0) {
                int[] cids = new int[cidlength];
                for (int i = 0; i < cids.length; i++) {
                    cids[i] = dataIn.readShort();
                }
                msg.setConsumerNos(cids);
            }
        }
        if (ba.get(ActiveMQMessage.PROPERTIES_INDEX)) {
            msg.setProperties(msg.readMapProperties(dataIn));
        }
        if (ba.get(ActiveMQMessage.PAYLOAD_INDEX)) {
            int payloadLength = dataIn.readInt();
            if (payloadLength >= 0) {
                byte[] payload = new byte[payloadLength];
                dataIn.readFully(payload);
                msg.setBodyAsBytes(payload);
View Full Code Here

    private transient int memoryUsageReferenceCount;

    private CopyOnWriteArraySet brokersVisited;
  
    protected AbstractPacket(){
        this.bitArray = new BitArray();
    }
View Full Code Here

TOP

Related Classes of org.codehaus.activemq.util.BitArray

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.