return splitter.via(Flow.fromGraph(GraphDSL.<FlowShape<F.Either<FlowIn, Out>, Out>>create(builder -> {
return splitter.via(Flow.fromGraph(GraphDSL.<FlowShape<F.Either<FlowIn, Out>, Out>>create(builder -> {
return splitter.via(Flow.fromGraph(GraphDSL.<FlowShape<F.Either<FlowIn, Out>, Out>>create(builder -> {
private static <T> Graph<SinkShape<T>, NotUsed> createConsumerLoadBalancer(final Collection<ActorRef> routees) { return GraphDSL.create(builder -> { final UniformFanOutShape<T, T> loadBalancer = builder.add(Balance.create(routees.size())); int i = 0; for (final ActorRef routee : routees) { final Sink<Object, NotUsed> sink = Sink.actorRefWithAck(routee, ConsumerStreamMessage.STREAM_STARTED, ConsumerStreamMessage.STREAM_ACK, ConsumerStreamMessage.STREAM_ENDED, error -> ConsumerStreamMessage.STREAM_ENDED); final SinkShape<Object> sinkShape = builder.add(sink); final Outlet<T> outlet = loadBalancer.out(i++); builder.from(outlet).to(sinkShape); } return SinkShape.of(loadBalancer.in()); }); }
private static <T> Graph<SinkShape<T>, NotUsed> createConsumerLoadBalancer(final Collection<ActorRef> routees) { return GraphDSL.create(builder -> { final UniformFanOutShape<T, T> loadBalancer = builder.add(Balance.create(routees.size())); int i = 0; for (final ActorRef routee : routees) { final Sink<Object, NotUsed> sink = Sink.actorRefWithAck(routee, ConsumerStreamMessage.STREAM_STARTED, ConsumerStreamMessage.STREAM_ACK, ConsumerStreamMessage.STREAM_ENDED, error -> ConsumerStreamMessage.STREAM_ENDED); final SinkShape<Object> sinkShape = builder.add(sink); final Outlet<T> outlet = loadBalancer.out(i++); builder.from(outlet).to(sinkShape); } return SinkShape.of(loadBalancer.in()); }); }
/** * Join a flow into a sink. * * @param step1 the flow. * @param step2 the sink. * @param <A> type of input. * @param <B> type of intermediate messages. * @return joined sink. */ public static <A, B> Graph<SinkShape<A>, NotUsed> joinSink( final Graph<FlowShape<A, B>, NotUsed> step1, final Graph<SinkShape<B>, NotUsed> step2) { return GraphDSL.create(builder -> { final FlowShape<A, B> shape1 = builder.add(step1); final SinkShape<B> shape2 = builder.add(step2); builder.from(shape1.out()).to(shape2); return SinkShape.of(shape1.in()); }); }
/** * Join a flow into a sink. * * @param step1 the flow. * @param step2 the sink. * @param <A> type of input. * @param <B> type of intermediate messages. * @return joined sink. */ public static <A, B> Graph<SinkShape<A>, NotUsed> joinSink( final Graph<FlowShape<A, B>, NotUsed> step1, final Graph<SinkShape<B>, NotUsed> step2) { return GraphDSL.create(builder -> { final FlowShape<A, B> shape1 = builder.add(step1); final SinkShape<B> shape2 = builder.add(step2); builder.from(shape1.out()).to(shape2); return SinkShape.of(shape1.in()); }); }
/** * Attach a sink to the output port of a filter. * * @param filter the filter. * @param sink the sink. * @param <A> type of incoming and unhandled messages. * @param <B> type of messages that pass through the filter. * @return joined flow. */ public static <A, B> Graph<FlowShape<A, A>, NotUsed> joinFilteredSink( final Graph<FanOutShape2<A, B, A>, NotUsed> filter, final Graph<SinkShape<B>, NotUsed> sink) { return GraphDSL.create(builder -> { final FanOutShape2<A, B, A> filterShape = builder.add(filter); final SinkShape<B> sinkShape = builder.add(sink); builder.from(filterShape.out0()).to(sinkShape); return FlowShape.of(filterShape.in(), filterShape.out1()); }); }
/** * Attach a sink to the unhandled port of a filter. * * @param filter the filter. * @param unhandled the sink. * @param <A> type of incoming messages. * @param <B> type of messages that pass through the filter. * @return joined flow. */ public static <A, B> Graph<FlowShape<A, B>, NotUsed> joinUnhandledSink( final Graph<FanOutShape2<A, B, A>, NotUsed> filter, final Graph<SinkShape<A>, NotUsed> unhandled) { return GraphDSL.create(builder -> { final FanOutShape2<A, B, A> filterShape = builder.add(filter); final SinkShape<A> sinkShape = builder.add(unhandled); builder.from(filterShape.out1()).to(sinkShape); return FlowShape.of(filterShape.in(), filterShape.out0()); }); }
/** * Attach a sink to the output port of a filter. * * @param filter the filter. * @param sink the sink. * @param <A> type of incoming and unhandled messages. * @param <B> type of messages that pass through the filter. * @return joined flow. */ public static <A, B> Graph<FlowShape<A, A>, NotUsed> joinFilteredSink( final Graph<FanOutShape2<A, B, A>, NotUsed> filter, final Graph<SinkShape<B>, NotUsed> sink) { return GraphDSL.create(builder -> { final FanOutShape2<A, B, A> filterShape = builder.add(filter); final SinkShape<B> sinkShape = builder.add(sink); builder.from(filterShape.out0()).to(sinkShape); return FlowShape.of(filterShape.in(), filterShape.out1()); }); }
/** * Attach a sink to the unhandled port of a filter. * * @param filter the filter. * @param unhandled the sink. * @param <A> type of incoming messages. * @param <B> type of messages that pass through the filter. * @return joined flow. */ public static <A, B> Graph<FlowShape<A, B>, NotUsed> joinUnhandledSink( final Graph<FanOutShape2<A, B, A>, NotUsed> filter, final Graph<SinkShape<A>, NotUsed> unhandled) { return GraphDSL.create(builder -> { final FanOutShape2<A, B, A> filterShape = builder.add(filter); final SinkShape<A> sinkShape = builder.add(unhandled); builder.from(filterShape.out1()).to(sinkShape); return FlowShape.of(filterShape.in(), filterShape.out0()); }); }
/** * Attach a flow into the output port of a filter. * * @param filter the filter. * @param flow the flow. * @param <A> type of incoming and unhandled messages. * @param <B> type of messages that pass through the filter. * @param <C> output type of the flow. * @return joined filter. */ public static <A, B, C> Graph<FanOutShape2<A, C, A>, NotUsed> joinFilteredFlow( final Graph<FanOutShape2<A, B, A>, NotUsed> filter, final Graph<FlowShape<B, C>, NotUsed> flow) { return GraphDSL.create(builder -> { final FanOutShape2<A, B, A> filterShape = builder.add(filter); final FlowShape<B, C> flowShape = builder.add(flow); builder.from(filterShape.out0()).toInlet(flowShape.in()); return new FanOutShape2<>(filterShape.in(), flowShape.out(), filterShape.out1()); }); }
/** * Attach a flow into the output port of a filter. * * @param filter the filter. * @param flow the flow. * @param <A> type of incoming and unhandled messages. * @param <B> type of messages that pass through the filter. * @param <C> output type of the flow. * @return joined filter. */ public static <A, B, C> Graph<FanOutShape2<A, C, A>, NotUsed> joinFilteredFlow( final Graph<FanOutShape2<A, B, A>, NotUsed> filter, final Graph<FlowShape<B, C>, NotUsed> flow) { return GraphDSL.create(builder -> { final FanOutShape2<A, B, A> filterShape = builder.add(filter); final FlowShape<B, C> flowShape = builder.add(flow); builder.from(filterShape.out0()).toInlet(flowShape.in()); return new FanOutShape2<>(filterShape.in(), flowShape.out(), filterShape.out1()); }); }
/** * Create an Akka stream graph to terminate an actor after a period of inactivity. * * @param interval how often to check for activity. * @param self reference to the actor. * @param <A> type of messages that prevents actor termination. * @return an activity checker. */ public static <A> Graph<FlowShape<A, A>, NotUsed> of(final Duration interval, final ActorRef self) { return GraphDSL.create(builder -> { final SourceShape<Tick> ticker = builder.add(Source.tick(interval, interval, new Tick())); final FanInShape2<A, Tick, A> killer = builder.add(PipeWithIdleRoutine.of((tick, log) -> { log.debug("Terminating actor after <{}> of inactivity: <{}>", interval, self); self.tell(PoisonPill.getInstance(), ActorRef.noSender()); })); builder.from(ticker).toInlet(killer.in1()); return FlowShape.of(killer.in0(), killer.out()); }); }
/** * Create an Akka stream graph to terminate an actor after a period of inactivity. * * @param interval how often to check for activity. * @param self reference to the actor. * @param <A> type of messages that prevents actor termination. * @return an activity checker. */ public static <A> Graph<FlowShape<A, A>, NotUsed> of(final Duration interval, final ActorRef self) { return GraphDSL.create(builder -> { final SourceShape<Tick> ticker = builder.add(Source.tick(interval, interval, new Tick())); final FanInShape2<A, Tick, A> killer = builder.add(PipeWithIdleRoutine.of((tick, log) -> { log.debug("Terminating actor after <{}> of inactivity: <{}>", interval, self); self.tell(PoisonPill.getInstance(), ActorRef.noSender()); })); builder.from(ticker).toInlet(killer.in1()); return FlowShape.of(killer.in0(), killer.out()); }); }
final ActorRef thingsAggregatorActor = actorContext.actorOf(props, ThingsAggregatorActor.ACTOR_NAME); return GraphDSL.create(builder -> { final FanOutShape2<WithSender, WithSender<RetrieveThings>, WithSender> retrieveThingsFilter = builder.add(Filter.of(RetrieveThings.class));
final ActorRef pubSubMediator) { return GraphDSL.create(builder -> { final FanOutShape2<WithSender, WithSender<ThingSearchCommand>, WithSender> searchFilter = builder.add(Filter.of(ThingSearchCommand.class));