/** * Creates a new instance of the ServiceBuilder class which is contained in memory. Any data added to this service will * be lost when the object is garbage collected or the process terminates. * * @param builderConfig The ServiceBuilderConfig to use. * @param executorBuilder A Function that, given a thread count and a pool name, creates a ScheduledExecutorService * with the given number of threads that have the given name as prefix. */ @VisibleForTesting public static ServiceBuilder newInMemoryBuilder(ServiceBuilderConfig builderConfig, ExecutorBuilder executorBuilder) { ServiceConfig serviceConfig = builderConfig.getConfig(ServiceConfig::builder); ServiceBuilder builder; if (serviceConfig.isReadOnlySegmentStore()) { // Only components required for ReadOnly SegmentStore. builder = new ReadOnlyServiceBuilder(builderConfig, serviceConfig, executorBuilder); } else { // Components that are required for general SegmentStore. builder = new ServiceBuilder(builderConfig, serviceConfig, executorBuilder) .withCacheFactory(setup -> new InMemoryCacheFactory()); } // Components that are required for all types of SegmentStore. return builder .withDataLogFactory(setup -> new InMemoryDurableDataLogFactory(setup.getCoreExecutor())) .withContainerManager(setup -> new LocalSegmentContainerManager( setup.getContainerRegistry(), setup.getSegmentToContainerMapper())) .withStorageFactory(setup -> new InMemoryStorageFactory(setup.getStorageExecutor())) .withStreamSegmentStore(setup -> new StreamSegmentService(setup.getContainerRegistry(), setup.getSegmentToContainerMapper())); }
@Override protected ServiceBuilder createBuilder(ServiceBuilderConfig.Builder builderConfig, int instanceId) { return super.createBuilder(builderConfig, instanceId) .withStreamSegmentStore(setup -> { StreamSegmentStore base = new StreamSegmentService(setup.getContainerRegistry(), setup.getSegmentToContainerMapper()); return new SynchronousStreamSegmentStore(base); }); } }
/** * Creates a new instance of TableStore using the components generated by this class. */ public TableStore createTableStoreService() { return getSingleton(this.tableStoreService, setup -> new TableService(setup.getContainerRegistry(), setup.getSegmentToContainerMapper())); }
private static ServiceBuilder newInlineExecutionInMemoryBuilder(ServiceBuilderConfig config) { return ServiceBuilder.newInMemoryBuilder(config, (size, name) -> new InlineExecutor()) .withStreamSegmentStore(setup -> new SynchronousStreamSegmentStore(new StreamSegmentService( setup.getContainerRegistry(), setup.getSegmentToContainerMapper()))); } }
private ReadOnlyServiceBuilder(ServiceBuilderConfig serviceBuilderConfig, ServiceConfig serviceConfig, ExecutorBuilder executorBuilder) { super(serviceBuilderConfig, serviceConfig, executorBuilder); // We attach a LocalSegmentContainerManager, since we only have one Container Running. // Note that withContainerManager() is disabled in ReadOnlyServiceBuilder, hence we must invoke the one on // the parent class. super.withContainerManager(setup -> new LocalSegmentContainerManager(setup.getContainerRegistry(), setup.getSegmentToContainerMapper())); }