Package com.netflix.astyanax.model

Examples of com.netflix.astyanax.model.RangeEndpoint


                                                      MutationBatch m,
                                                      long curTimeMicros) throws BusyLockException, MessageQueueException {

        try {
            List<MessageContext> entries = Lists.newArrayList();
            RangeEndpoint re = ShardedDistributedMessageQueue.entrySerializer
                                              .makeEndpoint((byte) MessageQueueEntryType.Message.ordinal(), Equality.EQUAL)
                                              .append((byte) 0, Equality.EQUAL);
            if(lockColumn!=null) {
                re.append(lockColumn.getTimestamp(), Equality.LESS_THAN_EQUALS);
            } else {
                re.append(TimeUUIDUtils.getMicrosTimeUUID(curTimeMicros), Equality.LESS_THAN_EQUALS);
            }

            ColumnList<MessageQueueEntry> result = queue.keyspace.prepareQuery(queue.queueColumnFamily)
                    .setConsistencyLevel(queue.consistencyLevel).getKey(shardName).
                    withColumnRange(new RangeBuilder()
                                        .setLimit(itemsToPop + (lockColumn == null? 0:(lockColumnCount + 1)))
                                        .setEnd(re.toBytes())
                                        .build()).execute().getResult();
            for (Column<MessageQueueEntry> column : result) {
                if (itemsToPop == 0) {
                    break;
                }
View Full Code Here


            }
        };
    }

    public <T1> RangeEndpoint makeEndpoint(T1 value, Equality equality) {
        RangeEndpoint endpoint = new RangeEndpoint() {
            private ByteBuffer out = ByteBuffer.allocate(bufferSize);
            private int position = 0;
            private boolean done = false;
           
            @Override
            public RangeEndpoint append(Object value, Equality equality) {
                ComponentSerializer<?> serializer = components.get(position);
                position++;
                // First, serialize the ByteBuffer for this component
                ByteBuffer cb;
                try {
                    cb = serializer.serializeValue(value);
                }
                catch (Exception e) {
                    throw new RuntimeException(e);
                }

                if (cb == null) {
                    cb = EMPTY_BYTE_BUFFER;
                }

                if (cb.limit() + COMPONENT_OVERHEAD > out.remaining()) {
                    int exponent = (int) Math.ceil(Math.log((double) (cb.limit() + COMPONENT_OVERHEAD) / (double) out.limit()) / Math.log(2));
                    int newBufferSize = out.limit() * (int) Math.pow(2, exponent);
                    ByteBuffer temp = ByteBuffer.allocate(newBufferSize);
                    out.flip();
                    temp.put(out);
                    out = temp;
                }

                // Write the data: <length><data><0>
                out.putShort((short) cb.remaining());
                out.put(cb.slice());
                out.put(equality.toByte());
                return this;
            }

            @Override
            public ByteBuffer toBytes() {
                if (!done) {
                    out.flip();
                    done = true;
                }
                return out;
            }
        };
        endpoint.append(value, equality);
        return endpoint;
    }
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.model.RangeEndpoint

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.