Package com.taobao.gecko.core.buffer

Examples of com.taobao.gecko.core.buffer.IoBuffer


    public void testEncode() {
        final TransactionId id = new LocalTransactionId("sessionId", 99);
        final TransactionInfo info = new TransactionInfo(id, "sessionId", TransactionType.COMMIT_ONE_PHASE, null);

        final TransactionCommand cmd = new TransactionCommand(info, 100);
        final IoBuffer buf = cmd.encode();
        assertEquals("transaction TX:sessionId:99 sessionId COMMIT_ONE_PHASE 100\r\n", new String(buf.array()));
    }
View Full Code Here


    public void testEncodeWithTimeout() {
        final TransactionId id = new LocalTransactionId("sessionId", 99);
        final TransactionInfo info = new TransactionInfo(id, "sessionId", TransactionType.BEGIN, null, 3);

        final TransactionCommand cmd = new TransactionCommand(info, 100);
        final IoBuffer buf = cmd.encode();
        assertEquals("transaction TX:sessionId:99 sessionId BEGIN 3 100\r\n", new String(buf.array()));
    }
View Full Code Here

    public void testEncodeWithUniqueQualifier() {
        final TransactionId id = new LocalTransactionId("sessionId", 99);
        final TransactionInfo info = new TransactionInfo(id, "sessionId", TransactionType.BEGIN, "unique-qualifier");

        final TransactionCommand cmd = new TransactionCommand(info, 100);
        final IoBuffer buf = cmd.encode();
        assertEquals("transaction TX:sessionId:99 sessionId BEGIN unique-qualifier 100\r\n", new String(buf.array()));
    }
View Full Code Here

    public void testEncodeWithUniqueQualifierAndTimeout() {
        final TransactionId id = new LocalTransactionId("sessionId", 99);
        final TransactionInfo info = new TransactionInfo(id, "sessionId", TransactionType.BEGIN, "unique-qualifier", 3);

        final TransactionCommand cmd = new TransactionCommand(info, 100);
        final IoBuffer buf = cmd.encode();
        assertEquals("transaction TX:sessionId:99 sessionId BEGIN 3 unique-qualifier 100\r\n", new String(buf.array()));
    }
View Full Code Here

    @Override
    public IoBuffer encode() {
        final int dataLen = this.data == null ? 0 : this.data.length;
        final String transactionKey = this.transactionId != null ? this.transactionId.getTransactionKey() : null;

        final IoBuffer buffer =
                IoBuffer.allocate(11 + ByteUtils.stringSize(this.partition) + ByteUtils.stringSize(dataLen)
                        + ByteUtils.stringSize(this.getOpaque()) + this.getTopic().length()
                        + (transactionKey != null ? transactionKey.length() + 1 : 0) + ByteUtils.stringSize(this.flag)
                        + ByteUtils.stringSize(this.checkSum) + dataLen);
        if (transactionKey != null) {
            ByteUtils.setArguments(buffer, MetaEncodeCommand.PUT_CMD, this.getTopic(), this.partition, dataLen,
                this.flag, this.checkSum, transactionKey, this.getOpaque());
        }
        else {
            ByteUtils.setArguments(buffer, MetaEncodeCommand.PUT_CMD, this.getTopic(), this.partition, dataLen,
                this.flag, this.checkSum, this.getOpaque());
        }
        if (this.data != null) {
            buffer.put(this.data);
        }
        buffer.flip();
        return buffer;
    }
View Full Code Here

            capacity += 1 + ByteUtils.stringSize(this.transactionInfo.getTimeout());
        }
        if (!StringUtils.isBlank(this.transactionInfo.getUniqueQualifier())) {
            capacity += 1 + this.transactionInfo.getUniqueQualifier().length();
        }
        final IoBuffer buffer = IoBuffer.allocate(capacity);
        if (this.transactionInfo.getTimeout() > 0) {
            if (StringUtils.isBlank(this.transactionInfo.getUniqueQualifier())) {
                ByteUtils.setArguments(buffer, MetaEncodeCommand.TRANS_CMD, transactionKey,
                    this.transactionInfo.getSessionId(), type, this.transactionInfo.getTimeout(), this.opaque);
            }
            else {
                ByteUtils.setArguments(buffer, MetaEncodeCommand.TRANS_CMD, transactionKey,
                    this.transactionInfo.getSessionId(), type, this.transactionInfo.getTimeout(),
                    this.transactionInfo.getUniqueQualifier(), this.opaque);
            }
        }
        else {
            if (StringUtils.isBlank(this.transactionInfo.getUniqueQualifier())) {
                ByteUtils.setArguments(buffer, MetaEncodeCommand.TRANS_CMD, transactionKey,
                    this.transactionInfo.getSessionId(), type, this.opaque);
            }
            else {
                ByteUtils.setArguments(buffer, MetaEncodeCommand.TRANS_CMD, transactionKey,
                    this.transactionInfo.getSessionId(), type, this.transactionInfo.getUniqueQualifier(), this.opaque);
            }

        }
        buffer.flip();
        return buffer;
    }
View Full Code Here

    }


    @Override
    public IoBuffer encode() {
        final IoBuffer buf =
                IoBuffer.allocate(13 + this.getTopic().length() + this.getGroup().length()
                        + ByteUtils.stringSize(this.partition) + ByteUtils.stringSize(this.offset)
                        + ByteUtils.stringSize(this.getOpaque()));
        ByteUtils.setArguments(buf, MetaEncodeCommand.OFFSET_CMD, this.getTopic(), this.getGroup(),
            this.getPartition(), this.offset, this.getOpaque());
        buf.flip();
        return buf;
    }
View Full Code Here

    @Override
    public IoBuffer encode() {
        final byte[] bytes = ByteUtils.getBytes(this.message);
        final int messageLen = bytes == null ? 0 : bytes.length;
        final IoBuffer buffer =
                IoBuffer.allocate(11 + ByteUtils.stringSize(this.code) + ByteUtils.stringSize(this.getOpaque())
                        + ByteUtils.stringSize(messageLen) + messageLen);
        ByteUtils.setArguments(buffer, MetaEncodeCommand.RESULT_CMD, this.code, messageLen, this.getOpaque());
        if (bytes != null) {
            buffer.put(bytes);
        }
        buffer.flip();
        return buffer;
    }
View Full Code Here

    @Override
    public final IoBuffer encode() {
        if (this.encodeHeader) {
            int totalDataLength = this.data != null ? this.data.length : 0;
            final IoBuffer buffer =
                    IoBuffer.allocate(9 + ByteUtils.stringSize(totalDataLength)
                        + ByteUtils.stringSize(this.getOpaque()) + totalDataLength);
            ByteUtils.setArguments(buffer, MetaEncodeCommand.VALUE_CMD, totalDataLength, this.getOpaque());
            if (this.data != null) {
                buffer.put(this.data);
            }
            buffer.flip();
            return buffer;
        }
        else {
            // We don't encode header,it is done by message set.
            return null;
View Full Code Here

    }


    @Override
    public IoBuffer encode() {
        final IoBuffer buffer =
                IoBuffer.allocate(11 + this.getGroup().length() + ByteUtils.stringSize(this.partition)
                        + ByteUtils.stringSize(this.getOpaque()) + this.getTopic().length()
                        + ByteUtils.stringSize(this.offset) + ByteUtils.stringSize(this.maxSize));
        ByteUtils.setArguments(buffer, MetaEncodeCommand.GET_CMD, this.getTopic(), this.getGroup(), this.partition,
            this.offset, this.maxSize, this.getOpaque());
        buffer.flip();
        return buffer;
    }
View Full Code Here

TOP

Related Classes of com.taobao.gecko.core.buffer.IoBuffer

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.