@Override public final void getAll(Collection<? super StreamConsumerState> result) throws IOException { SortedMap<byte[], byte[]> states = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); fetchAll(streamId.toBytes(), states); for (Map.Entry<byte[], byte[]> entry : states.entrySet()) { byte[] column = entry.getKey(); byte[] value = entry.getValue(); if (value != null) { result.add(new StreamConsumerState(getGroupId(column), getInstanceId(column), decodeOffsets(value))); } } }
@Override public final void remove(Iterable<? extends StreamConsumerState> states) throws IOException { Set<byte[]> columns = Sets.newTreeSet(Bytes.BYTES_COMPARATOR); for (StreamConsumerState state : states) { columns.add(getColumn(state.getGroupId(), state.getInstanceId())); } delete(streamId.toBytes(), columns); }
@Override public final void getByGroup(long groupId, Collection<? super StreamConsumerState> result) throws IOException { SortedMap<byte[], byte[]> states = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); fetchAll(streamId.toBytes(), Bytes.toBytes(groupId), states); for (Map.Entry<byte[], byte[]> entry : states.entrySet()) { byte[] column = entry.getKey(); if (getGroupId(column) != groupId) { continue; } byte[] value = entry.getValue(); if (value != null) { result.add(new StreamConsumerState(groupId, getInstanceId(column), decodeOffsets(value))); } } }
@Override public final void save(Iterable<? extends StreamConsumerState> states) throws IOException { ImmutableSortedMap.Builder<byte[], byte[]> values = ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR); ByteArrayOutputStream os = new ByteArrayOutputStream(); DataOutput output = new DataOutputStream(os); for (StreamConsumerState state : states) { os.reset(); encodeOffsets(state.getState(), output); values.put(getColumn(state.getGroupId(), state.getInstanceId()), os.toByteArray()); } store(streamId.toBytes(), values.build()); }
@Override public final StreamConsumerState get(long groupId, int instanceId) throws IOException { byte[] value = fetch(streamId.toBytes(), getColumn(groupId, instanceId)); return value == null ? null : new StreamConsumerState(groupId, instanceId, decodeOffsets(value)); }
@Override public final void save(StreamConsumerState state) throws IOException { store(streamId.toBytes(), getColumn(state.getGroupId(), state.getInstanceId()), encodeOffsets(state.getState())); }