akka.stream.ActorMaterializer Java Examples

The following examples show how to use akka.stream.ActorMaterializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThingsSearchCursor.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Extract a cursor from a {@code QueryThings} command if any exists.
 *
 * @param queryThings the command.
 * @param materializer materializer of actors that will extract the cursor.
 * @return source of an optional cursor if the command has no cursor or has a valid cursor; a failed source if the
 * command has an invalid cursor.
 */
static Source<Optional<ThingsSearchCursor>, NotUsed> extractCursor(final QueryThings queryThings,
        final ActorMaterializer materializer) {

    return catchExceptions(queryThings.getDittoHeaders(), () -> {
        final List<Option> options = getOptions(queryThings);
        final List<CursorOption> cursorOptions = findAll(CursorOption.class, options);
        final List<LimitOption> limitOptions = findAll(LimitOption.class, options);
        final Optional<InvalidOptionException> sizeOptionError = checkSizeOption(options, queryThings);
        if (sizeOptionError.isPresent()) {
            return Source.failed(sizeOptionError.get());
        } else if (cursorOptions.isEmpty()) {
            return Source.single(Optional.empty());
        } else if (cursorOptions.size() > 1) {
            // there may not be 2 or more cursor options in 1 command.
            return Source.failed(invalidCursor("There may not be more than 1 'cursor' option.", queryThings));
        } else if (!limitOptions.isEmpty()) {
            return Source.failed(invalidCursor(LIMIT_OPTION_FORBIDDEN, queryThings));
        } else {
            return decode(cursorOptions.get(0).getCursor(), materializer)
                    .flatMapConcat(cursor -> cursor.checkCursorValidity(queryThings, options)
                            .<Source<Optional<ThingsSearchCursor>, NotUsed>>map(Source::failed)
                            .orElse(Source.single(Optional.of(cursor))));
        }
    });
}
 
Example #2
Source File: Kata3SearchAkkaStream.java    From ditto-examples with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void part1CreateAkkaSearchQuery() {
    final ActorSystem system = ActorSystem.create("thing-search");
    try {

        final String filter = "or(eq(attributes/counter,1), eq(attributes/counter,2))";


        // TODO create Akka source of publisher with above filter
        final Source<List<Thing>, NotUsed> things = null;


        // Verify Results
        things.flatMapConcat(Source::from)
                .toMat(Sink.seq(), Keep.right())
                .run(ActorMaterializer.create(system))
                .thenAccept(t -> Assertions.assertThat(t).containsAnyOf(thing1, thing2).doesNotContain(thing3))
                .toCompletableFuture()
                .join();
    } finally {
        system.terminate();
    }
}
 
Example #3
Source File: IndexInitializerIT.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void before() {
    system = ActorSystem.create("AkkaTestSystem");
    materializer = ActorMaterializer.create(system);

    requireNonNull(mongoResource);
    requireNonNull(materializer);

    mongoClient = MongoClientWrapper.getBuilder()
            .hostnameAndPort(mongoResource.getBindIp(), mongoResource.getPort())
            .defaultDatabaseName(getClass().getSimpleName() + "-" + UUID.randomUUID().toString())
            .connectionPoolMaxSize(CONNECTION_POOL_MAX_SIZE)
            .connectionPoolMaxWaitQueueSize(CONNECTION_POOL_MAX_WAIT_QUEUE_SIZE)
            .connectionPoolMaxWaitTime(Duration.ofSeconds(CONNECTION_POOL_MAX_WAIT_TIME_SECS))
            .build();

    indexInitializerUnderTest = IndexInitializer.of(mongoClient.getDefaultDatabase(), materializer);
    indexOperations = IndexOperations.of(mongoClient.getDefaultDatabase());
}
 
Example #4
Source File: AbstractPersistenceOperationsActor.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private AbstractPersistenceOperationsActor(final ActorRef pubSubMediator,
        final EntityType entityType,
        @Nullable final NamespacePersistenceOperations namespaceOps,
        @Nullable final EntityPersistenceOperations entitiesOps,
        final PersistenceOperationsConfig persistenceOperationsConfig,
        final Collection<Closeable> toCloseWhenStopped) {

    this.pubSubMediator = checkNotNull(pubSubMediator, "pub-sub mediator");
    this.entityType = checkNotNull(entityType, "entityType");
    if (namespaceOps == null && entitiesOps == null) {
        throw new IllegalArgumentException("At least one of namespaceOps or entitiesOps must be specified.");
    }
    this.namespaceOps = namespaceOps;
    this.entitiesOps = entitiesOps;
    this.toCloseWhenStopped = Collections.unmodifiableCollection(toCloseWhenStopped);
    materializer = ActorMaterializer.create(getContext());
    delayAfterPersistenceActorShutdown = persistenceOperationsConfig.getDelayAfterPersistenceActorShutdown();
    logger = DittoLoggerFactory.getDiagnosticLoggingAdapter(this);
}
 
Example #5
Source File: MongoReadJournal.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private <T> Source<List<T>, NotUsed> unfoldBatchedSource(
        final String lowerBound,
        final ActorMaterializer mat,
        final Function<T, String> seedCreator,
        final Function<String, Source<T, ?>> sourceCreator) {

    return Source.unfoldAsync("",
            start -> {
                final String actualStart = lowerBound.compareTo(start) >= 0 ? lowerBound : start;
                return sourceCreator.apply(actualStart)
                        .runWith(Sink.seq(), mat)
                        .thenApply(list -> {
                            if (list.isEmpty()) {
                                return Optional.empty();
                            } else {
                                return Optional.of(Pair.create(seedCreator.apply(list.get(list.size() - 1)), list));
                            }
                        });
            })
            .withAttributes(Attributes.inputBuffer(1, 1));
}
 
Example #6
Source File: AbstractGraphActor.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private SourceQueueWithComplete<T> getSourceQueue(final ActorMaterializer materializer) {
    // Log stream completion and failure at level ERROR because the stream is supposed to survive forever.
    final Attributes streamLogLevels =
            Attributes.logLevels(Attributes.logLevelDebug(), Attributes.logLevelError(),
                    Attributes.logLevelError());

    return Source.<T>queue(getBufferSize(), OverflowStrategy.dropNew())
            .map(this::incrementDequeueCounter)
            .log("graph-actor-stream-1-dequeued", logger)
            .withAttributes(streamLogLevels)
            .via(Flow.fromFunction(this::beforeProcessMessage))
            .log("graph-actor-stream-2-preprocessed", logger)
            .withAttributes(streamLogLevels)
            .via(processMessageFlow())
            .log("graph-actor-stream-3-processed", logger)
            .withAttributes(streamLogLevels)
            .to(processedMessageSink())
            .run(materializer);
}
 
Example #7
Source File: ConciergeRootActor.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private <C extends ConciergeConfig> ConciergeRootActor(final C conciergeConfig,
        final ActorRef pubSubMediator,
        final EnforcerActorFactory<C> enforcerActorFactory,
        final ActorMaterializer materializer) {

    pubSubMediator.tell(DistPubSubAccess.put(getSelf()), getSelf());

    final ActorContext context = getContext();
    final ShardRegions shardRegions = ShardRegions.of(getContext().getSystem(), conciergeConfig.getClusterConfig());

    enforcerActorFactory.startEnforcerActor(context, conciergeConfig, pubSubMediator, shardRegions);

    final ActorRef conciergeForwarder = context.findChild(ConciergeForwarderActor.ACTOR_NAME).orElseThrow(() ->
            new IllegalStateException("ConciergeForwarder could not be found"));

    final ActorRef cleanupCoordinator = startClusterSingletonActor(
            EventSnapshotCleanupCoordinator.ACTOR_NAME,
            EventSnapshotCleanupCoordinator.props(conciergeConfig.getPersistenceCleanupConfig(), pubSubMediator,
                    shardRegions));

    final ActorRef healthCheckingActor = startHealthCheckingActor(conciergeConfig, cleanupCoordinator);

    bindHttpStatusRoute(healthCheckingActor, conciergeConfig.getHttpConfig(), materializer);
}
 
Example #8
Source File: HealthService.java    From ari-proxy with GNU Affero General Public License v3.0 6 votes vote down vote up
private CompletionStage<ServerBinding> startHttpServer() {
	final ActorSystem system = getContext().getSystem();
	final Http http = Http.get(system);
	final ActorMaterializer materializer = ActorMaterializer.create(system);

	final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = createRoute().flow(system, materializer);

	final String address = "0.0.0.0";
	final CompletionStage<ServerBinding> binding = http.bindAndHandle(
			routeFlow,
			ConnectHttp.toHost(address, httpPort),
			materializer
	);

	log().info("HTTP server online at http://{}:{}/...", address, httpPort);

	return binding;
}
 
Example #9
Source File: ConciergeRootActor.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private void bindHttpStatusRoute(final ActorRef healthCheckingActor, final HttpConfig httpConfig,
        final ActorMaterializer materializer) {

    String hostname = httpConfig.getHostname();
    if (hostname.isEmpty()) {
        hostname = LocalHostAddressSupplier.getInstance().get();
        log.info("No explicit hostname configured, using HTTP hostname: {}", hostname);
    }

    final CompletionStage<ServerBinding> binding = Http.get(getContext().system())
            .bindAndHandle(createRoute(getContext().system(), healthCheckingActor).flow(getContext().system(),
                    materializer), ConnectHttp.toHost(hostname, httpConfig.getPort()), materializer);

    binding.thenAccept(theBinding -> CoordinatedShutdown.get(getContext().getSystem()).addTask(
            CoordinatedShutdown.PhaseServiceUnbind(), "shutdown_health_http_endpoint", () -> {
                log.info("Gracefully shutting down status/health HTTP endpoint..");
                return theBinding.terminate(Duration.ofSeconds(1))
                        .handle((httpTerminated, e) -> Done.getInstance());
            })
    ).exceptionally(failure -> {
        log.error(failure, "Something very bad happened: {}", failure.getMessage());
        getContext().system().terminate();
        return null;
    });
}
 
Example #10
Source File: HttpPublisherActor.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private HttpPublisherActor(final Connection connection, final HttpPushFactory factory) {
    super(connection);
    this.factory = factory;

    final ActorSystem system = getContext().getSystem();
    final ConnectionConfig connectionConfig =
            DittoConnectivityConfig.of(DefaultScopedConfig.dittoScoped(system.settings().config()))
                    .getConnectionConfig();
    config = connectionConfig.getHttpPushConfig();

    materializer = ActorMaterializer.create(getContext());
    sourceQueue =
            Source.<Pair<HttpRequest, HttpPushContext>>queue(config.getMaxQueueSize(), OverflowStrategy.dropNew())
                    .viaMat(factory.createFlow(system, log), Keep.left())
                    .toMat(Sink.foreach(this::processResponse), Keep.left())
                    .run(materializer);
}
 
Example #11
Source File: PlayWSITest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final ActorSystem system = ActorSystem.create();
  final Materializer materializer = ActorMaterializer.create(system);

  final AsyncHttpClientConfig asyncHttpClientConfig = new DefaultAsyncHttpClientConfig.Builder()
    .setMaxRequestRetry(0)
    .setShutdownQuietPeriod(0)
    .setShutdownTimeout(0)
    .build();

  final AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient(asyncHttpClientConfig);
  try (final StandaloneAhcWSClient wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer)) {
    final int status = wsClient.url("http://www.google.com").get()
      .whenComplete((response, throwable) -> TestUtil.checkActiveSpan())
      .toCompletableFuture().get(15, TimeUnit.SECONDS)
      .getStatus();

    if (200 != status)
      throw new AssertionError("Response: " + status);
  }
  finally {
    system.terminate();
    TestUtil.checkSpan(new ComponentSpanCount("play-ws", 1));
  }
}
 
Example #12
Source File: StreamingActor.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private StreamingActor(final DittoProtocolSub dittoProtocolSub,
        final ActorRef commandRouter,
        final JwtAuthenticationFactory jwtAuthenticationFactory,
        final StreamingConfig streamingConfig,
        final HeaderTranslator headerTranslator,
        final ActorRef pubSubMediator,
        final ActorRef conciergeForwarder) {

    this.dittoProtocolSub = dittoProtocolSub;
    this.commandRouter = commandRouter;
    this.streamingConfig = streamingConfig;
    this.headerTranslator = headerTranslator;
    streamingSessionsCounter = DittoMetrics.gauge("streaming_sessions_count");
    jwtValidator = jwtAuthenticationFactory.getJwtValidator();
    jwtAuthenticationResultProvider = jwtAuthenticationFactory.newJwtAuthenticationResultProvider();
    subscriptionManagerProps =
            SubscriptionManager.props(streamingConfig.getSearchIdleTimeout(), pubSubMediator, conciergeForwarder,
                    ActorMaterializer.create(getContext()));
    scheduleScrapeStreamSessionsCounter();
}
 
Example #13
Source File: HttpPushClientActorTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void createActorSystem() {
    // create actor system with deactivated hostname blacklist to connect to localhost
    actorSystem = ActorSystem.create(getClass().getSimpleName(),
            TestConstants.CONFIG.withValue("ditto.connectivity.connection.http-push.blacklisted-hostnames",
                    ConfigValueFactory.fromAnyRef("")));
    mat = ActorMaterializer.create(actorSystem);
    requestQueue = new LinkedBlockingQueue<>();
    responseQueue = new LinkedBlockingQueue<>();
    handler = Flow.fromFunction(request -> {
        requestQueue.offer(request);
        return responseQueue.take();
    });
    binding = Http.get(actorSystem)
            .bindAndHandle(handler, ConnectHttp.toHost("127.0.0.1", 0), mat)
            .toCompletableFuture()
            .join();
    connection = getHttpConnectionBuilderToLocalBinding(false, binding.localAddress().getPort()).build();
}
 
Example #14
Source File: PlayWSTest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Test
public void test(final MockTracer tracer) throws Exception {
  final Materializer materializer = ActorMaterializer.create(system);
  final AsyncHttpClientConfig asyncHttpClientConfig = new DefaultAsyncHttpClientConfig.Builder()
    .setMaxRequestRetry(0)
    .setShutdownQuietPeriod(0)
    .setShutdownTimeout(0)
    .build();

  final AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient(asyncHttpClientConfig);
  try (final StandaloneAhcWSClient wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer)) {
    wsClient.url("http://localhost:1234").get().toCompletableFuture().get(15, TimeUnit.SECONDS);
  }
  catch (final Exception ignore) {
  }

  await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(1));

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(1, spans.size());
  assertEquals(PlayWSAgentIntercept.COMPONENT_NAME, spans.get(0).tags().get(Tags.COMPONENT.getKey()));
}
 
Example #15
Source File: MongoHealthChecker.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private MongoHealthChecker() {

        final DefaultMongoDbConfig mongoDbConfig = DefaultMongoDbConfig.of(
                DefaultScopedConfig.dittoScoped(getContext().getSystem().settings().config()));
        mongoClient = MongoClientWrapper.getBuilder(mongoDbConfig)
                .connectionPoolMaxSize(HEALTH_CHECK_MAX_POOL_SIZE)
                .build();

        /*
         * It's important to have the read preferences to primary preferred because the replication is to slow to retrieve
         * the inserted document from a secondary directly after inserting it on the primary.
         */
        collection = mongoClient.getCollection(TEST_COLLECTION_NAME)
                .withReadPreference(ReadPreference.primaryPreferred());

        materializer = ActorMaterializer.create(getContext());
    }
 
Example #16
Source File: SnapshotStreamingActorTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void initActorSystem() {
    final Config config = ConfigFactory.load("test");
    actorSystem = ActorSystem.create("AkkaTestSystem", config);
    materializer = ActorMaterializer.create(actorSystem);
    mockClient = Mockito.mock(DittoMongoClient.class);
    mockReadJournal = Mockito.mock(MongoReadJournal.class);

}
 
Example #17
Source File: AbstractThingSearchPersistenceITBase.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void before() {
    final Config config = ConfigFactory.load("test");
    actorSystem = ActorSystem.create("AkkaTestSystem", config);
    log = actorSystem.log();
    actorMaterializer = ActorMaterializer.create(actorSystem);
    readPersistence = provideReadPersistence();
    writePersistence = provideWritePersistence();
    thingsCollection = mongoClient.getDefaultDatabase().getCollection(PersistenceConstants.THINGS_COLLECTION_NAME);
}
 
Example #18
Source File: ThingsService.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Props getMainRootActorProps(final ThingsConfig thingsConfig, final ActorRef pubSubMediator,
        final ActorMaterializer materializer) {

    return ThingsRootActor.props(thingsConfig, pubSubMediator, materializer,
            DefaultThingPersistenceActorPropsFactory.getInstance());
}
 
Example #19
Source File: SearchRootActor.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private SearchRootActor(final SearchConfig searchConfig, final ActorRef pubSubMediator,
        final ActorMaterializer materializer) {

    log = Logging.getLogger(getContext().system(), this);

    final MongoDbConfig mongoDbConfig = searchConfig.getMongoDbConfig();
    final MongoDbConfig.MonitoringConfig monitoringConfig = mongoDbConfig.getMonitoringConfig();

    final DittoMongoClient mongoDbClient = MongoClientWrapper.getBuilder(mongoDbConfig)
            .addCommandListener(getCommandListenerOrNull(monitoringConfig))
            .addConnectionPoolListener(getConnectionPoolListenerOrNull(monitoringConfig))
            .build();

    final ThingsSearchPersistence thingsSearchPersistence = getThingsSearchPersistence(searchConfig, mongoDbClient);
    final ActorRef searchActor = initializeSearchActor(searchConfig.getLimitsConfig(), thingsSearchPersistence);
    pubSubMediator.tell(DistPubSubAccess.put(searchActor), getSelf());

    final TimestampPersistence backgroundSyncPersistence =
            MongoTimestampPersistence.initializedInstance(BACKGROUND_SYNC_COLLECTION_NAME, mongoDbClient,
                    materializer);

    final ActorRef searchUpdaterRootActor = startChildActor(SearchUpdaterRootActor.ACTOR_NAME,
            SearchUpdaterRootActor.props(searchConfig, pubSubMediator, materializer, thingsSearchPersistence,
                    backgroundSyncPersistence));
    final ActorRef healthCheckingActor = initializeHealthCheckActor(searchConfig, searchUpdaterRootActor);

    createHealthCheckingActorHttpBinding(searchConfig.getHttpConfig(), healthCheckingActor, materializer);
}
 
Example #20
Source File: MongoThingsSearchPersistence.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Initializes the things search persistence with a passed in {@code persistence}.
 *
 * @param mongoClient the mongoDB persistence wrapper.
 * @param actorSystem the Akka ActorSystem.
 * @since 1.0.0
 */
public MongoThingsSearchPersistence(final DittoMongoClient mongoClient, final ActorSystem actorSystem) {
    final MongoDatabase database = mongoClient.getDefaultDatabase();
    // configure search persistence to stress the primary as little as possible and tolerate inconsistency
    collection = database
            .getCollection(PersistenceConstants.THINGS_COLLECTION_NAME)
            .withReadPreference(ReadPreference.secondaryPreferred());

    log = Logging.getLogger(actorSystem, getClass());
    final ActorMaterializer materializer = ActorMaterializer.create(actorSystem);
    indexInitializer = IndexInitializer.of(database, materializer);
    maxQueryTime = mongoClient.getDittoSettings().getMaxQueryTime();
    hints = MongoHints.empty();
}
 
Example #21
Source File: TransistorTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Connect a transistor to 2 test collectors and a test sink.
 */
@Before
public void init() {
    system = ActorSystem.create();
    final Source<Integer, TestPublisher.Probe<Integer>> collectorSource = TestSource.probe(system);
    final Source<Integer, TestPublisher.Probe<Integer>> baseSource = TestSource.probe(system);
    final Sink<Integer, TestSubscriber.Probe<Integer>> emitterSink = TestSink.probe(system);
    final Transistor<Integer> underTest = Transistor.of();

    final Graph<SourceShape<Integer>, Pair<TestPublisher.Probe<Integer>, TestPublisher.Probe<Integer>>>
            collectorGateTransistor =
            GraphDSL$.MODULE$.create3(
                    collectorSource, baseSource, underTest,
                    (collector, base, notUsed) -> Pair.create(collector, base),
                    (builder, collectorShape, baseShape, transistorShape) -> {
                        builder.from(collectorShape.out()).toInlet(transistorShape.in0());
                        builder.from(baseShape.out()).toInlet(transistorShape.in1());
                        return SourceShape.of(transistorShape.out());
                    });

    final Pair<Pair<TestPublisher.Probe<Integer>, TestPublisher.Probe<Integer>>, TestSubscriber.Probe<Integer>> m =
            Source.fromGraph(collectorGateTransistor)
                    .toMat(emitterSink, Keep.both())
                    .run(ActorMaterializer.create(system));

    collector = m.first().first();
    base = m.first().second();
    emitter = m.second();
}
 
Example #22
Source File: ResumeSourceTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void init() {
    system = ActorSystem.create();
    mat = ActorMaterializer.create(system);

    rematerializeSource();

    // materialize sink once - it never fails.
    final Sink<Integer, TestSubscriber.Probe<Integer>> sink = TestSink.probe(system);
    final Pair<TestSubscriber.Probe<Integer>, Sink<Integer, NotUsed>> sinkPair = sink.preMaterialize(mat);
    sinkProbe = sinkPair.first();
    testSink = sinkPair.second();
}
 
Example #23
Source File: DittoPublicKeyProviderTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() {
    actorSystem = ActorSystem.create(getClass().getSimpleName());
    when(httpClientMock.getActorMaterializer()).thenReturn(ActorMaterializer.create(actorSystem));
    final JwtSubjectIssuersConfig subjectIssuersConfig = JwtSubjectIssuersConfig.fromJwtSubjectIssuerConfigs(
            Collections.singleton(new JwtSubjectIssuerConfig("google.com", SubjectIssuer.GOOGLE)));
    when(cacheConfigMock.getMaximumSize()).thenReturn(100L);
    when(cacheConfigMock.getExpireAfterWrite()).thenReturn(Duration.ofMinutes(3));
    underTest = DittoPublicKeyProvider.of(subjectIssuersConfig, httpClientMock, cacheConfigMock,
            getClass().getSimpleName());
}
 
Example #24
Source File: SearchActor.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private SearchActor(
        final QueryParser queryParser,
        final ThingsSearchPersistence searchPersistence) {

    this.queryParser = queryParser;
    this.searchPersistence = searchPersistence;
    materializer = ActorMaterializer.create(getContext());
}
 
Example #25
Source File: MongoTimestampPersistenceIT.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    final Config config = ConfigFactory.load("test");
    actorSystem = ActorSystem.create("AkkaTestSystem", config);
    materializer = ActorMaterializer.create(actorSystem);
    syncPersistence = MongoTimestampPersistence.initializedInstance(KNOWN_COLLECTION, mongoClient, materializer);
}
 
Example #26
Source File: MongoReadJournal.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Retrieve all unique PIDs in journals above a lower bound. Does not limit database access in any way.
 *
 * @param lowerBoundPid the lower-bound PID.
 * @param batchSize how many events to read in 1 query.
 * @param mat the materializer.
 * @return all unique PIDs in journals above a lower bound.
 */
public Source<String, NotUsed> getJournalPidsAbove(final String lowerBoundPid, final int batchSize,
        final ActorMaterializer mat) {

    return getJournal()
            .withAttributes(Attributes.inputBuffer(1, 1))
            .flatMapConcat(journal ->
                    listPidsInJournal(journal, lowerBoundPid, batchSize, mat, MAX_BACK_OFF_DURATION, 0)
            )
            .mapConcat(pids -> pids);
}
 
Example #27
Source File: MongoReadJournal.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private Source<List<String>, NotUsed> listPidsInJournal(final MongoCollection<Document> journal,
        final String lowerBound, final int batchSize, final ActorMaterializer mat, final Duration maxBackOff,
        final int maxRestarts) {

    return unfoldBatchedSource(lowerBound, mat, Function.identity(), actualStart ->
            listJournalPidsAbove(journal, actualStart, batchSize, maxBackOff, maxRestarts)
    );
}
 
Example #28
Source File: MongoReadJournal.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private Source<List<Document>, NotUsed> listNewestSnapshots(final MongoCollection<Document> snapshotStore,
        final String lowerBound,
        final int batchSize,
        final ActorMaterializer mat,
        final String... snapshotFields) {

    return this.unfoldBatchedSource(lowerBound,
            mat,
            SnapshotBatch::getMaxPid,
            actualStart -> listNewestActiveSnapshotsByBatch(snapshotStore, actualStart, batchSize, snapshotFields))
            .mapConcat(x -> x)
            .map(SnapshotBatch::getItems);
}
 
Example #29
Source File: MongoReadJournal.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Retrieve all latest snapshots with unique PIDs in snapshot store above a lower bound.
 * Does not limit database access in any way.
 *
 * @param lowerBoundPid the lower-bound PID.
 * @param batchSize how many snapshots to read in 1 query.
 * @param mat the materializer.
 * @param snapshotFields snapshot fields to project out.
 * @return source of newest snapshots with unique PIDs.
 */
public Source<Document, NotUsed> getNewestSnapshotsAbove(final String lowerBoundPid,
        final int batchSize,
        final ActorMaterializer mat,
        final String... snapshotFields) {

    return getSnapshotStore()
            .withAttributes(Attributes.inputBuffer(1, 1))
            .flatMapConcat(snapshotStore ->
                    listNewestSnapshots(snapshotStore, lowerBoundPid, batchSize, mat,
                            snapshotFields)
            )
            .mapConcat(pids -> pids);
}
 
Example #30
Source File: ConnectivityRootActor.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private CompletionStage<ServerBinding> getHttpBinding(final HttpConfig httpConfig,
        final ActorSystem actorSystem,
        final ActorMaterializer materializer,
        final ActorRef healthCheckingActor) {

    String hostname = httpConfig.getHostname();
    if (hostname.isEmpty()) {
        hostname = LocalHostAddressSupplier.getInstance().get();
        log.info("No explicit hostname configured, using HTTP hostname <{}>.", hostname);
    }

    return Http.get(actorSystem)
            .bindAndHandle(createRoute(actorSystem, healthCheckingActor).flow(actorSystem, materializer),
                    ConnectHttp.toHost(hostname, httpConfig.getPort()), materializer);
}