@Override public Source<ByteString, ?> dataStream() { return Source.<ByteString>single(data); }
@Override public Source<ByteString, ?> dataStream() { return Source.<ByteString>single(data); }
@Override public Source<ByteString, ?> dataStream() { return Source.<ByteString>single(data); }
public CompletionStage<A> run(E element, Materializer mat) { return run(Source.single(element), mat); }
private Source<ThingMetadata, NotUsed> defaultThingMetadata() { return Source.single(new ThingMetadata(-1L, null, -1L)); }
private Source<Optional<Instant>, NotUsed> retrieveLastSuccessfulStreamEndAsync() { return Source.fromPublisher(lastSuccessfulSearchSyncCollection.find()) .limit(1) .flatMapConcat(doc -> { final Date date = doc.getDate(FIELD_TIMESTAMP); final Instant timestamp = date.toInstant(); LOGGER.debug("Returning last timestamp of search synchronization: <{}>.", timestamp); return Source.single(Optional.of(timestamp)); }) .orElse(Source.single(Optional.empty())); }
private Source<Optional<Instant>, NotUsed> retrieveLastSuccessfulStreamEndAsync() { return Source.fromPublisher(lastSuccessfulSearchSyncCollection.find()) .limit(1) .flatMapConcat(doc -> { final Date date = doc.getDate(FIELD_TIMESTAMP); final Instant timestamp = date.toInstant(); LOGGER.debug("Returning last timestamp of search synchronization: <{}>.", timestamp); return Source.single(Optional.of(timestamp)); }) .orElse(Source.single(Optional.empty())); }
private static PartialFunction<Throwable, Source<Success, NotUsed>> buildDropIndexRecovery( final String indexDescription) { return new PFBuilder<Throwable, Source<Success, NotUsed>>() .match(MongoCommandException.class, IndexOperations::isIndexNotFound, throwable -> { LOGGER.debug("Index <{}> could not be dropped because it does not exist (anymore).", indexDescription); return Source.single(Success.SUCCESS); }) .build(); }
private static PartialFunction<Throwable, Source<Success, NotUsed>> buildDropIndexRecovery( final String indexDescription) { return new PFBuilder<Throwable, Source<Success, NotUsed>>() .match(MongoCommandException.class, IndexOperations::isIndexNotFound, throwable -> { LOGGER.debug("Index <{}> could not be dropped because it does not exist (anymore).", indexDescription); return Source.single(Success.SUCCESS); }) .build(); }
public <Event extends AggregateEvent<Event>> CompletionStage<Done> feed(Event e, Offset offset) { AggregateEventTagger<Event> tag = e.aggregateTag(); List<Pair<ReadSideHandler<?>, Offset>> list = processors.get(tag.eventType()); if (list == null) { throw new RuntimeException("No processor registered for Event " + tag.eventType().getCanonicalName()); } List<CompletionStage<?>> stages = list.stream().map(pHandlerOffset -> { @SuppressWarnings("unchecked") ReadSideHandler<Event> handler = (ReadSideHandler<Event>) pHandlerOffset.first(); Flow<Pair<Event, Offset>, Done, ?> flow = handler.handle(); return Source.single(Pair.create(e, offset)).via(flow).runWith(Sink.ignore(), materializer); } ).collect(Collectors.toList()); return doAll(stages); }
/** * Produces a flow of ByteString with a prepended block and a script wrapper. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<ByteString, ByteString, NotUsed> flow(String callbackName) { ByteString cb = ByteString.fromString(callbackName); return Flow.of(ByteString.class).map((msg) -> { return formatted(cb, msg); }).prepend(Source.single(initialChunk)); }
/** * Produces a flow of ByteString with a prepended block and a script wrapper. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<ByteString, ByteString, NotUsed> flow(String callbackName) { ByteString cb = ByteString.fromString(callbackName); return Flow.of(ByteString.class).map((msg) -> { return formatted(cb, msg); }).prepend(Source.single(initialChunk)); }
/** * Produces a flow of ByteString with a prepended block and a script wrapper. * * @param callbackName the javascript callback method. * @return a flow of ByteString elements. */ public static Flow<ByteString, ByteString, NotUsed> flow(String callbackName) { ByteString cb = ByteString.fromString(callbackName); return Flow.of(ByteString.class).map((msg) -> { return formatted(cb, msg); }).prepend(Source.single(initialChunk)); }
@Override public void emit(Object event) { Source.single(event).viaMat(busFlow, Keep.right()) .to(Sink.ignore()) .run(mat); }
public static TextMessage handleTextMessage(TextMessage msg) { if (msg.isStrict()) // optimization that directly creates a simple response... { return TextMessage.create("Hello " + msg.getStrictText()); } else // ... this would suffice to handle all text messages in a streaming fashion { return TextMessage.create(Source.single("Hello ").concat(msg.getStreamedText())); } } //#websocket-handler
@Override public Receive createReceive() { return ReceiveBuilder.create() .matchAny(message -> { if (message instanceof WithDittoHeaders) { LogUtil.enhanceLogWithCorrelationId(log, (WithDittoHeaders<?>) message); } log.debug("Received message: <{}>.", message); final WithSender wrapped = WithSender.of(message, getSender()); Source.single(wrapped).runWith(messageHandler, materializer); }) .build(); } }
private Source<Boolean, NotUsed> delete(final String thingId, final Bson filter, final Bson document) { return Source.fromPublisher(collection.updateOne(filter, document)) .flatMapConcat(deleteResult -> { if (deleteResult.getMatchedCount() <= 0) { return Source.single(Boolean.FALSE); } final PolicyUpdate deletePolicyEntries = PolicyUpdateFactory.createDeleteThingUpdate(thingId); final Bson policyIndexRemoveFilter = deletePolicyEntries.getPolicyIndexRemoveFilter(); return Source.fromPublisher(policiesCollection.deleteMany(policyIndexRemoveFilter)) .map(r -> true); }); }
private Source<Boolean, NotUsed> delete(final String thingId, final Bson filter, final Bson document) { return Source.fromPublisher(collection.updateOne(filter, document)) .flatMapConcat(deleteResult -> { if (deleteResult.getMatchedCount() <= 0) { return Source.single(Boolean.FALSE); } final PolicyUpdate deletePolicyEntries = PolicyUpdateFactory.createDeleteThingUpdate(thingId); final Bson policyIndexRemoveFilter = deletePolicyEntries.getPolicyIndexRemoveFilter(); return Source.fromPublisher(policiesCollection.deleteMany(policyIndexRemoveFilter)) .map(r -> true); }); }
@Override public Source<Long, NotUsed> count(final PolicyRestrictedSearchAggregation policyRestrictedSearchAggregation) { checkNotNull(policyRestrictedSearchAggregation, "policy restricted aggregation"); final Source<Document, NotUsed> source = policyRestrictedSearchAggregation.execute(collection, maxQueryTime); return source.map(doc -> doc.get(PersistenceConstants.COUNT_RESULT_NAME)) .map(countResult -> (Number) countResult) .map(Number::longValue) // use Number.longValue() to support both Integer and Long values .orElse(Source.<Long>single(0L)) .mapError(handleMongoExecutionTimeExceededException()) .log("count"); }
@Override public Source<Long, NotUsed> count(final PolicyRestrictedSearchAggregation policyRestrictedSearchAggregation) { checkNotNull(policyRestrictedSearchAggregation, "policy restricted aggregation"); final Source<Document, NotUsed> source = policyRestrictedSearchAggregation.execute(collection, maxQueryTime); return source.map(doc -> doc.get(PersistenceConstants.COUNT_RESULT_NAME)) .map(countResult -> (Number) countResult) .map(Number::longValue) // use Number.longValue() to support both Integer and Long values .orElse(Source.<Long>single(0L)) .mapError(handleMongoExecutionTimeExceededException()) .log("count"); }