use of cz.o2.proxima.direct.view.LocalCachedPartitionedView in project proxima-platform by O2-Czech-Republic.
the class LocalCachedPartitionedView method asFactory.
@Override
public Factory asFactory() {
final CommitLogReader.Factory<?> readerFactory = reader.asFactory();
final OnlineAttributeWriter.Factory<?> writerFactory = writer.asFactory();
final EntityDescriptor entity = this.entity;
return repo -> new LocalCachedPartitionedView(entity, readerFactory.apply(repo), writerFactory.apply(repo));
}
use of cz.o2.proxima.direct.view.LocalCachedPartitionedView in project proxima-platform by O2-Czech-Republic.
the class DirectAttributeFamilyProxyDescriptor method getPartitionedCachedView.
private static Optional<CachedView> getPartitionedCachedView(AttrLookup lookup, Context context, AttributeFamilyProxyDescriptor desc) {
if (desc.getTargetFamilyRead().getAccess().canReadCommitLog() && !desc.getTargetFamilyWrite().getAccess().isReadonly() && desc.getTargetFamilyRead().getAccess().canCreateCachedView()) {
Optional<CommitLogReader> maybeReader = getCommitLogReader(lookup, context, desc);
Optional<OnlineAttributeWriter> maybeWriter = getWriter(lookup, context, desc).map(AttributeWriterBase::online);
if (maybeReader.isPresent() && maybeWriter.isPresent()) {
return Optional.of(new LocalCachedPartitionedView(desc.getTargetFamilyRead().getEntity(), maybeReader.get(), maybeWriter.get()));
}
}
return Optional.empty();
}
use of cz.o2.proxima.direct.view.LocalCachedPartitionedView in project proxima-platform by O2-Czech-Republic.
the class InMemStorage method createAccessor.
@Override
public DataAccessor createAccessor(DirectDataOperator op, AttributeFamilyDescriptor familyDescriptor) {
final EntityDescriptor entity = familyDescriptor.getEntity();
final URI uri = familyDescriptor.getStorageUri();
final Map<String, Object> cfg = familyDescriptor.getCfg();
log.info("Creating accessor {} for URI {}", getClass(), uri);
holder().observers.computeIfAbsent(uri, k -> Collections.synchronizedNavigableMap(new TreeMap<>()));
final int numPartitions = Optional.ofNullable(cfg.get(NUM_PARTITIONS)).map(v -> Integer.parseInt(v.toString())).orElse(1);
final Partitioner partitioner = Optional.ofNullable(cfg.get(ConfigConstants.PARTITIONER)).map(name -> Classpath.newInstance(name.toString(), Partitioner.class)).orElseGet(KeyAttributePartitioner::new);
final Repository opRepo = op.getRepository();
final RepositoryFactory repositoryFactory = opRepo.asFactory();
final OnlineAttributeWriter.Factory<?> writerFactory = new Writer(entity, uri, numPartitions, partitioner).asFactory();
final CommitLogReader.Factory<?> commitLogReaderFactory = new InMemCommitLogReader(entity, uri, op.getContext().getExecutorFactory(), partitioner, numPartitions).asFactory();
final RandomAccessReader.Factory<Reader> randomAccessReaderFactory;
final BatchLogReader.Factory<Reader> batchLogReaderFactory;
final CachedView.Factory cachedViewFactory;
if (numPartitions > 1) {
randomAccessReaderFactory = null;
batchLogReaderFactory = null;
cachedViewFactory = null;
} else {
final ReaderFactory readerFactory = new Reader(entity, uri, op.getContext().getExecutorFactory()).asFactory();
randomAccessReaderFactory = readerFactory;
batchLogReaderFactory = readerFactory;
cachedViewFactory = new LocalCachedPartitionedView(entity, commitLogReaderFactory.apply(opRepo), writerFactory.apply(opRepo)).asFactory();
}
return new DataAccessor() {
private static final long serialVersionUID = 1L;
@Nullable
private transient Repository repo = opRepo;
@Override
public URI getUri() {
return uri;
}
@Override
public Optional<AttributeWriterBase> getWriter(Context context) {
Objects.requireNonNull(context);
return Optional.of(writerFactory.apply(repo()));
}
@Override
public Optional<CommitLogReader> getCommitLogReader(Context context) {
Objects.requireNonNull(context);
return Optional.of(commitLogReaderFactory.apply(repo()));
}
@Override
public Optional<RandomAccessReader> getRandomAccessReader(Context context) {
Objects.requireNonNull(context);
return Optional.ofNullable(randomAccessReaderFactory).map(item -> item.apply(repo()));
}
@Override
public Optional<CachedView> getCachedView(Context context) {
Objects.requireNonNull(context);
return Optional.ofNullable(cachedViewFactory).map(item -> item.apply(repo()));
}
@Override
public Optional<BatchLogReader> getBatchLogReader(Context context) {
Objects.requireNonNull(context);
return Optional.ofNullable(batchLogReaderFactory).map(item -> item.apply(repo()));
}
private Repository repo() {
if (this.repo == null) {
this.repo = repositoryFactory.apply();
}
return this.repo;
}
};
}
Aggregations