Package org.apache.activemq.util

Examples of org.apache.activemq.util.ByteSequence


    }

    public synchronized ByteSequence read(Location location) throws IOException, IllegalStateException {
        DataFile dataFile = getDataFile(location);
        DataFileAccessor reader = accessorPool.openDataFileAccessor(dataFile);
        ByteSequence rc = null;
        try {
            rc = reader.readRecord(location);
        } finally {
            accessorPool.closeDataFileAccessor(reader);
        }
View Full Code Here


        }
        storeState(sync);
    }

    protected synchronized void storeState(boolean sync) throws IOException {
        ByteSequence state = marshallState();
        appender.storeItem(state, Location.MARK_TYPE, sync);
        controlFile.store(state, sync);
    }
View Full Code Here

//        // same
//        if (!cacheEnabled && ((DataStructure)command).isMarshallAware()) {
//            ma = (MarshallAware)command;
//        }

        ByteSequence sequence = null;
        // if( ma!=null ) {
        // sequence = ma.getCachedMarshalledForm(this);
        // }

        if (sequence == null) {

            int size = 1;
            if (command != null) {

                DataStructure c = (DataStructure)command;
                byte type = c.getDataStructureType();
                DataStreamMarshaller dsm = (DataStreamMarshaller)dataMarshallers[type & 0xFF];
                if (dsm == null) {
                    throw new IOException("Unknown data type: " + type);
                }
                if (tightEncodingEnabled) {

                    BooleanStream bs = new BooleanStream();
                    size += dsm.tightMarshal1(this, c, bs);
                    size += bs.marshalledSize();

                    bytesOut.restart(size);
                    if (!sizePrefixDisabled) {
                        bytesOut.writeInt(size);
                    }
                    bytesOut.writeByte(type);
                    bs.marshal(bytesOut);
                    dsm.tightMarshal2(this, c, bytesOut, bs);
                    sequence = bytesOut.toByteSequence();

                } else {
                    bytesOut.restart();
                    if (!sizePrefixDisabled) {
                        bytesOut.writeInt(0); // we don't know the final size
                                                // yet but write this here for
                                                // now.
                    }
                    bytesOut.writeByte(type);
                    dsm.looseMarshal(this, c, bytesOut);
                    sequence = bytesOut.toByteSequence();

                    if (!sizePrefixDisabled) {
                        size = sequence.getLength() - 4;
                        int pos = sequence.offset;
                        ByteSequenceData.writeIntBig(sequence, size);
                        sequence.offset = pos;
                    }
                }
View Full Code Here

                looseOut.writeByte(type);
                dsm.looseMarshal(this, c, looseOut);

                if (!sizePrefixDisabled) {
                    ByteSequence sequence = bytesOut.toByteSequence();
                    dataOut.writeInt(sequence.getLength());
                    dataOut.write(sequence.getData(), sequence.getOffset(), sequence.getLength());
                }

            }

        } else {
View Full Code Here

            return 0;
        }

        if (o.isMarshallAware()) {
            // MarshallAware ma = (MarshallAware)o;
            ByteSequence sequence = null;
            // sequence=ma.getCachedMarshalledForm(this);
            bs.writeBoolean(sequence != null);
            if (sequence != null) {
                return 1 + sequence.getLength();
            }
        }

        byte type = o.getDataStructureType();
        DataStreamMarshaller dsm = (DataStreamMarshaller)dataMarshallers[type & 0xFF];
View Full Code Here

                        write = (WriteCommand)write.getNext();
                    }

                    // Now do the 1 big write.
                    ByteSequence sequence = buff.toByteSequence();
                    file.write(sequence.getData(), sequence.getOffset(), sequence.getLength());
                    buff.reset();
                }

                if( forceToDisk ) {
                    file.getFD().sync();
View Full Code Here

    public void addMessage(ConnectionContext context, Message message) throws IOException {

        EntityManager manager = adapter.beginEntityManager(context);
        try {

            ByteSequence sequence = wireFormat.marshal(message);
            sequence.compact();

            StoredMessage sm = new StoredMessage();
            sm.setDestination(destinationName);
            sm.setId(message.getMessageId().getBrokerSequenceId());
            sm.setMessageId(message.getMessageId().toString());
View Full Code Here

                Query query = manager.createQuery("select m from StoredMessage m where m.messageId=?1");
                query.setParameter(1, identity.toString());
                message = (StoredMessage)query.getSingleResult();
            }

            rc = (Message)wireFormat.unmarshal(new ByteSequence(message.getData()));
        } catch (Throwable e) {
            adapter.rollbackEntityManager(null, manager);
            throw IOExceptionSupport.create(e);
        }
        adapter.commitEntityManager(null, manager);
View Full Code Here

        EntityManager manager = adapter.beginEntityManager(null);
        try {
            Query query = manager.createQuery("select m from StoredMessage m where m.destination=?1 order by m.id asc");
            query.setParameter(1, destinationName);
            for (StoredMessage m : (List<StoredMessage>)query.getResultList()) {
                Message message = (Message)wireFormat.unmarshal(new ByteSequence(m.getData()));
                container.recoverMessage(message);
            }
        } catch (Throwable e) {
            adapter.rollbackEntityManager(null, manager);
            throw IOExceptionSupport.create(e);
View Full Code Here

            query.setParameter(1, destinationName);
            query.setParameter(2, lastMessageId.get());
            query.setMaxResults(maxReturned);
            int count = 0;
            for (StoredMessage m : (List<StoredMessage>)query.getResultList()) {
                Message message = (Message)wireFormat.unmarshal(new ByteSequence(m.getData()));
                listener.recoverMessage(message);
                lastMessageId.set(m.getId());
                count++;
                if (count >= maxReturned) {
                    return;
View Full Code Here

TOP

Related Classes of org.apache.activemq.util.ByteSequence

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.