use of io.datarouter.model.serialize.fielder.DatabeanFielder in project datarouter by hotpads.
the class DirectoryGroupQueueNode method putMulti.
@Override
public void putMulti(Collection<D> databeans, Config config) {
DatabeanFielder<PK, D> fielder = getFieldInfo().getSampleFielder();
StringDatabeanCodec codec = getFieldInfo().getSampleFielder().getStringDatabeanCodec();
List<byte[]> databeansAsBytes = Scanner.of(databeans).map(databean -> codec.toBytes(databean, fielder)).list();
List<List<byte[]>> groups = codec.makeGroups(databeansAsBytes, MAX_MESSAGE_BYTES);
Scanner.of(groups).map(codec::concatGroup).forEach(directoryQueue::putMessage);
}
use of io.datarouter.model.serialize.fielder.DatabeanFielder in project datarouter by hotpads.
the class DirectoryGroupQueueNode method peekMulti.
@Override
public List<GroupQueueMessage<PK, D>> peekMulti(Config config) {
int limit = config.findLimit().orElse(1);
DatabeanFielder<PK, D> fielder = getFieldInfo().getSampleFielder();
StringDatabeanCodec codec = getFieldInfo().getSampleFielder().getStringDatabeanCodec();
Supplier<D> databeanSupplier = getFieldInfo().getDatabeanSupplier();
return Scanner.generate(directoryQueue::peek).limit(limit).advanceWhile(Optional::isPresent).map(Optional::get).map(directoryQueueMessage -> {
byte[] id = directoryQueueMessage.getBytesId();
List<D> databeans = codec.fromStringMulti(directoryQueueMessage.content, fielder, databeanSupplier);
return new GroupQueueMessage<>(id, databeans);
}).list();
}
Aggregations