also fix FlowInterleaveSpec
Also-by: Johan Andrén <johan@markatta.com> Also-by: Roland Kuhn <rk@rkuhn.info> Also-by: Martynas Mickevičius <mmartynas@gmail.com>
This commit is contained in:
parent
ef77b56e66
commit
60497f6561
195 changed files with 1110 additions and 857 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package docs.http.javadsl.server;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.dispatch.OnFailure;
|
||||
import akka.http.impl.util.Util;
|
||||
|
|
@ -98,7 +99,7 @@ public class HttpServerExampleDocTest {
|
|||
Source<IncomingConnection, Future<ServerBinding>> serverSource =
|
||||
Http.get(system).bind("localhost", 8080, materializer);
|
||||
|
||||
Flow<IncomingConnection, IncomingConnection, BoxedUnit> failureDetection =
|
||||
Flow<IncomingConnection, IncomingConnection, NotUsed> failureDetection =
|
||||
Flow.of(IncomingConnection.class).transform(() ->
|
||||
new PushStage<IncomingConnection, IncomingConnection>() {
|
||||
@Override
|
||||
|
|
@ -136,7 +137,7 @@ public class HttpServerExampleDocTest {
|
|||
Source<IncomingConnection, Future<ServerBinding>> serverSource =
|
||||
Http.get(system).bind("localhost", 8080, materializer);
|
||||
|
||||
Flow<HttpRequest, HttpRequest, BoxedUnit> failureDetection =
|
||||
Flow<HttpRequest, HttpRequest, NotUsed> failureDetection =
|
||||
Flow.of(HttpRequest.class).transform(() ->
|
||||
new PushStage<HttpRequest, HttpRequest>() {
|
||||
@Override
|
||||
|
|
@ -151,7 +152,7 @@ public class HttpServerExampleDocTest {
|
|||
}
|
||||
});
|
||||
|
||||
Flow<HttpRequest, HttpResponse, BoxedUnit> httpEcho =
|
||||
Flow<HttpRequest, HttpResponse, NotUsed> httpEcho =
|
||||
Flow.of(HttpRequest.class)
|
||||
.via(failureDetection)
|
||||
.map(request -> {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.io.BufferedReader;
|
|||
import java.io.InputStreamReader;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.NotUsed;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
|
|
@ -71,7 +72,7 @@ public class WebsocketCoreExample {
|
|||
* A handler that treats incoming messages as a name,
|
||||
* and responds with a greeting to that name
|
||||
*/
|
||||
public static Flow<Message, Message, BoxedUnit> greeter() {
|
||||
public static Flow<Message, Message, NotUsed> greeter() {
|
||||
return
|
||||
Flow.<Message>create()
|
||||
.collect(new JavaPartialFunction<Message, Message>() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import static akka.pattern.Patterns.ask;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Iterator;
|
||||
|
||||
import akka.NotUsed;
|
||||
import com.typesafe.config.Config;
|
||||
|
||||
import akka.actor.*;
|
||||
|
|
@ -113,27 +115,27 @@ public class PersistenceQueryDocTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Source<EventEnvelope, BoxedUnit> eventsByTag(String tag, long offset) {
|
||||
public Source<EventEnvelope, NotUsed> eventsByTag(String tag, long offset) {
|
||||
final Props props = MyEventsByTagPublisher.props(tag, offset, refreshInterval);
|
||||
return Source.<EventEnvelope>actorPublisher(props).
|
||||
mapMaterializedValue(m -> BoxedUnit.UNIT);
|
||||
mapMaterializedValue(m -> NotUsed.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source<EventEnvelope, BoxedUnit> eventsByPersistenceId(String persistenceId,
|
||||
public Source<EventEnvelope, NotUsed> eventsByPersistenceId(String persistenceId,
|
||||
long fromSequenceNr, long toSequenceNr) {
|
||||
// implement in a similar way as eventsByTag
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source<String, BoxedUnit> allPersistenceIds() {
|
||||
public Source<String, NotUsed> allPersistenceIds() {
|
||||
// implement in a similar way as eventsByTag
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Source<String, BoxedUnit> currentPersistenceIds() {
|
||||
public Source<String, NotUsed> currentPersistenceIds() {
|
||||
// implement in a similar way as eventsByTag
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
|
@ -166,25 +168,25 @@ public class PersistenceQueryDocTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public akka.stream.scaladsl.Source<EventEnvelope, BoxedUnit> eventsByTag(
|
||||
public akka.stream.scaladsl.Source<EventEnvelope, NotUsed> eventsByTag(
|
||||
String tag, long offset) {
|
||||
return javadslReadJournal.eventsByTag(tag, offset).asScala();
|
||||
}
|
||||
|
||||
@Override
|
||||
public akka.stream.scaladsl.Source<EventEnvelope, BoxedUnit> eventsByPersistenceId(
|
||||
public akka.stream.scaladsl.Source<EventEnvelope, NotUsed> eventsByPersistenceId(
|
||||
String persistenceId, long fromSequenceNr, long toSequenceNr) {
|
||||
return javadslReadJournal.eventsByPersistenceId(persistenceId, fromSequenceNr,
|
||||
toSequenceNr).asScala();
|
||||
}
|
||||
|
||||
@Override
|
||||
public akka.stream.scaladsl.Source<String, BoxedUnit> allPersistenceIds() {
|
||||
public akka.stream.scaladsl.Source<String, NotUsed> allPersistenceIds() {
|
||||
return javadslReadJournal.allPersistenceIds().asScala();
|
||||
}
|
||||
|
||||
@Override
|
||||
public akka.stream.scaladsl.Source<String, BoxedUnit> currentPersistenceIds() {
|
||||
public akka.stream.scaladsl.Source<String, NotUsed> currentPersistenceIds() {
|
||||
return javadslReadJournal.currentPersistenceIds().asScala();
|
||||
}
|
||||
|
||||
|
|
@ -209,7 +211,7 @@ public class PersistenceQueryDocTest {
|
|||
"akka.persistence.query.my-read-journal");
|
||||
|
||||
// issue query to journal
|
||||
Source<EventEnvelope, BoxedUnit> source =
|
||||
Source<EventEnvelope, NotUsed> source =
|
||||
readJournal.eventsByPersistenceId("user-1337", 0, Long.MAX_VALUE);
|
||||
|
||||
// materialize stream, consuming events
|
||||
|
|
@ -262,7 +264,7 @@ public class PersistenceQueryDocTest {
|
|||
|
||||
//#events-by-tag
|
||||
// assuming journal is able to work with numeric offsets we can:
|
||||
final Source<EventEnvelope, BoxedUnit> blueThings =
|
||||
final Source<EventEnvelope, NotUsed> blueThings =
|
||||
readJournal.eventsByTag("blue", 0L);
|
||||
|
||||
// find top 10 blue things:
|
||||
|
|
@ -276,7 +278,7 @@ public class PersistenceQueryDocTest {
|
|||
}, mat);
|
||||
|
||||
// start another query, from the known offset
|
||||
Source<EventEnvelope, BoxedUnit> blue = readJournal.eventsByTag("blue", 10);
|
||||
Source<EventEnvelope, NotUsed> blue = readJournal.eventsByTag("blue", 10);
|
||||
//#events-by-tag
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ package docs.persistence.query;
|
|||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.persistence.journal.WriteEventAdapter;
|
||||
import akka.persistence.journal.Tagged;
|
||||
|
|
@ -37,7 +37,7 @@ public class LeveldbPersistenceQueryDocTest {
|
|||
PersistenceQuery.get(system).getReadJournalFor(LeveldbReadJournal.class,
|
||||
LeveldbReadJournal.Identifier());
|
||||
|
||||
Source<EventEnvelope, BoxedUnit> source =
|
||||
Source<EventEnvelope, NotUsed> source =
|
||||
queries.eventsByPersistenceId("some-persistence-id", 0, Long.MAX_VALUE);
|
||||
//#EventsByPersistenceId
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ public class LeveldbPersistenceQueryDocTest {
|
|||
PersistenceQuery.get(system).getReadJournalFor(LeveldbReadJournal.class,
|
||||
LeveldbReadJournal.Identifier());
|
||||
|
||||
Source<String, BoxedUnit> source = queries.allPersistenceIds();
|
||||
Source<String, NotUsed> source = queries.allPersistenceIds();
|
||||
//#AllPersistenceIds
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ public class LeveldbPersistenceQueryDocTest {
|
|||
PersistenceQuery.get(system).getReadJournalFor(LeveldbReadJournal.class,
|
||||
LeveldbReadJournal.Identifier());
|
||||
|
||||
Source<EventEnvelope, BoxedUnit> source =
|
||||
Source<EventEnvelope, NotUsed> source =
|
||||
queries.eventsByTag("green", 0);
|
||||
//#EventsByTag
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.stream.javadsl.GraphDSL;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
|
@ -26,7 +27,6 @@ import scala.concurrent.Await;
|
|||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class BidiFlowDocTest {
|
||||
|
|
@ -110,7 +110,7 @@ public class BidiFlowDocTest {
|
|||
//#codec
|
||||
@SuppressWarnings("unused")
|
||||
//#codec
|
||||
public final BidiFlow<Message, ByteString, ByteString, Message, BoxedUnit> codecVerbose =
|
||||
public final BidiFlow<Message, ByteString, ByteString, Message, NotUsed> codecVerbose =
|
||||
BidiFlow.fromGraph(GraphDSL.create(b -> {
|
||||
final FlowShape<Message, ByteString> top =
|
||||
b.add(Flow.of(Message.class).map(BidiFlowDocTest::toBytes));
|
||||
|
|
@ -119,7 +119,7 @@ public class BidiFlowDocTest {
|
|||
return BidiShape.fromFlows(top, bottom);
|
||||
}));
|
||||
|
||||
public final BidiFlow<Message, ByteString, ByteString, Message, BoxedUnit> codec =
|
||||
public final BidiFlow<Message, ByteString, ByteString, Message, NotUsed> codec =
|
||||
BidiFlow.fromFunctions(BidiFlowDocTest::toBytes, BidiFlowDocTest::fromBytes);
|
||||
//#codec
|
||||
|
||||
|
|
@ -186,7 +186,7 @@ public class BidiFlowDocTest {
|
|||
}
|
||||
}
|
||||
|
||||
public final BidiFlow<ByteString, ByteString, ByteString, ByteString, BoxedUnit> framing =
|
||||
public final BidiFlow<ByteString, ByteString, ByteString, ByteString, NotUsed> framing =
|
||||
BidiFlow.fromGraph(GraphDSL.create(b -> {
|
||||
final FlowShape<ByteString, ByteString> top =
|
||||
b.add(Flow.of(ByteString.class).map(BidiFlowDocTest::addLengthHeader));
|
||||
|
|
@ -210,16 +210,16 @@ public class BidiFlowDocTest {
|
|||
* | +-------+ +---------+ |
|
||||
* +------------------------------------+
|
||||
*/
|
||||
final BidiFlow<Message, ByteString, ByteString, Message, BoxedUnit> stack =
|
||||
final BidiFlow<Message, ByteString, ByteString, Message, NotUsed> stack =
|
||||
codec.atop(framing);
|
||||
|
||||
// test it by plugging it into its own inverse and closing the right end
|
||||
final Flow<Message, Message, BoxedUnit> pingpong =
|
||||
final Flow<Message, Message, NotUsed> pingpong =
|
||||
Flow.of(Message.class).collect(new PFBuilder<Message, Message>()
|
||||
.match(Ping.class, p -> new Pong(p.id))
|
||||
.build()
|
||||
);
|
||||
final Flow<Message, Message, BoxedUnit> flow =
|
||||
final Flow<Message, Message, NotUsed> flow =
|
||||
stack.atop(stack.reversed()).join(pingpong);
|
||||
final Future<List<Message>> result = Source
|
||||
.from(Arrays.asList(0, 1, 2))
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package docs.stream;
|
|||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.stream.ClosedShape;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
|
@ -20,7 +21,7 @@ import akka.stream.javadsl.Tcp.OutgoingConnection;
|
|||
import akka.testkit.JavaTestKit;
|
||||
import akka.util.ByteString;
|
||||
import scala.concurrent.*;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import scala.Option;
|
||||
|
||||
public class CompositionDocTest {
|
||||
|
|
@ -56,47 +57,47 @@ public class CompositionDocTest {
|
|||
@Test
|
||||
public void nestedFlow() throws Exception {
|
||||
//#nested-flow
|
||||
final Source<Integer, BoxedUnit> nestedSource =
|
||||
final Source<Integer, NotUsed> nestedSource =
|
||||
Source.single(0) // An atomic source
|
||||
.map(i -> i + 1) // an atomic processing stage
|
||||
.named("nestedSource"); // wraps up the current Source and gives it a name
|
||||
|
||||
final Flow<Integer, Integer, BoxedUnit> nestedFlow =
|
||||
final Flow<Integer, Integer, NotUsed> nestedFlow =
|
||||
Flow.of(Integer.class).filter(i -> i != 0) // an atomic processing stage
|
||||
.map(i -> i - 2) // another atomic processing stage
|
||||
.named("nestedFlow"); // wraps up the Flow, and gives it a name
|
||||
|
||||
final Sink<Integer, BoxedUnit> nestedSink =
|
||||
final Sink<Integer, NotUsed> nestedSink =
|
||||
nestedFlow.to(Sink.fold(0, (acc, i) -> acc + i)) // wire an atomic sink to the nestedFlow
|
||||
.named("nestedSink"); // wrap it up
|
||||
|
||||
// Create a RunnableGraph
|
||||
final RunnableGraph<BoxedUnit> runnableGraph = nestedSource.to(nestedSink);
|
||||
final RunnableGraph<NotUsed> runnableGraph = nestedSource.to(nestedSink);
|
||||
//#nested-flow
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reusingComponents() throws Exception {
|
||||
final Source<Integer, BoxedUnit> nestedSource =
|
||||
final Source<Integer, NotUsed> nestedSource =
|
||||
Source.single(0) // An atomic source
|
||||
.map(i -> i + 1) // an atomic processing stage
|
||||
.named("nestedSource"); // wraps up the current Source and gives it a name
|
||||
|
||||
final Flow<Integer, Integer, BoxedUnit> nestedFlow =
|
||||
final Flow<Integer, Integer, NotUsed> nestedFlow =
|
||||
Flow.of(Integer.class).filter(i -> i != 0) // an atomic processing stage
|
||||
.map(i -> i - 2) // another atomic processing stage
|
||||
.named("nestedFlow"); // wraps up the Flow, and gives it a name
|
||||
|
||||
final Sink<Integer, BoxedUnit> nestedSink =
|
||||
final Sink<Integer, NotUsed> nestedSink =
|
||||
nestedFlow.to(Sink.fold(0, (acc, i) -> acc + i)) // wire an atomic sink to the nestedFlow
|
||||
.named("nestedSink"); // wrap it up
|
||||
|
||||
//#reuse
|
||||
// Create a RunnableGraph from our components
|
||||
final RunnableGraph<BoxedUnit> runnableGraph = nestedSource.to(nestedSink);
|
||||
final RunnableGraph<NotUsed> runnableGraph = nestedSource.to(nestedSink);
|
||||
|
||||
// Usage is uniform, no matter if modules are composite or atomic
|
||||
final RunnableGraph<BoxedUnit> runnableGraph2 =
|
||||
final RunnableGraph<NotUsed> runnableGraph2 =
|
||||
Source.single(0).to(Sink.fold(0, (acc, i) -> acc + i));
|
||||
//#reuse
|
||||
}
|
||||
|
|
@ -150,7 +151,7 @@ public class CompositionDocTest {
|
|||
@Test
|
||||
public void partialGraph() throws Exception {
|
||||
//#partial-graph
|
||||
final Graph<FlowShape<Integer, Integer>, BoxedUnit> partial =
|
||||
final Graph<FlowShape<Integer, Integer>, NotUsed> partial =
|
||||
GraphDSL.create(builder -> {
|
||||
final UniformFanOutShape<Integer, Integer> B = builder.add(Broadcast.create(2));
|
||||
final UniformFanInShape<Integer, Integer> C = builder.add(Merge.create(2));
|
||||
|
|
@ -173,10 +174,10 @@ public class CompositionDocTest {
|
|||
//#partial-flow-dsl
|
||||
// Convert the partial graph of FlowShape to a Flow to get
|
||||
// access to the fluid DSL (for example to be able to call .filter())
|
||||
final Flow<Integer, Integer, BoxedUnit> flow = Flow.fromGraph(partial);
|
||||
final Flow<Integer, Integer, NotUsed> flow = Flow.fromGraph(partial);
|
||||
|
||||
// Simple way to create a graph backed Source
|
||||
final Source<Integer, BoxedUnit> source = Source.fromGraph(
|
||||
final Source<Integer, NotUsed> source = Source.fromGraph(
|
||||
GraphDSL.create(builder -> {
|
||||
final UniformFanInShape<Integer, Integer> merge = builder.add(Merge.create(2));
|
||||
builder.from(builder.add(Source.single(0))).toFanIn(merge);
|
||||
|
|
@ -187,23 +188,23 @@ public class CompositionDocTest {
|
|||
);
|
||||
|
||||
// Building a Sink with a nested Flow, using the fluid DSL
|
||||
final Sink<Integer, BoxedUnit> sink = Flow.of(Integer.class)
|
||||
final Sink<Integer, NotUsed> sink = Flow.of(Integer.class)
|
||||
.map(i -> i * 2)
|
||||
.drop(10)
|
||||
.named("nestedFlow")
|
||||
.to(Sink.head());
|
||||
|
||||
// Putting all together
|
||||
final RunnableGraph<BoxedUnit> closed = source.via(flow.filter(i -> i > 1)).to(sink);
|
||||
final RunnableGraph<NotUsed> closed = source.via(flow.filter(i -> i > 1)).to(sink);
|
||||
//#partial-flow-dsl
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closedGraph() throws Exception {
|
||||
//#embed-closed
|
||||
final RunnableGraph<BoxedUnit> closed1 =
|
||||
final RunnableGraph<NotUsed> closed1 =
|
||||
Source.single(0).to(Sink.foreach(System.out::println));
|
||||
final RunnableGraph<BoxedUnit> closed2 =
|
||||
final RunnableGraph<NotUsed> closed2 =
|
||||
RunnableGraph.fromGraph(
|
||||
GraphDSL.create(builder -> {
|
||||
final ClosedShape embeddedClosed = builder.add(closed1);
|
||||
|
|
@ -246,7 +247,7 @@ public class CompositionDocTest {
|
|||
final Source<Integer, Promise<Optional<Integer>>> source = Source.<Integer>maybe();
|
||||
|
||||
// Materializes to BoxedUnit (black)
|
||||
final Flow<Integer, Integer, BoxedUnit> flow1 = Flow.of(Integer.class).take(100);
|
||||
final Flow<Integer, Integer, NotUsed> flow1 = Flow.of(Integer.class).take(100);
|
||||
|
||||
// Materializes to Promise<Option<>> (red)
|
||||
final Source<Integer, Promise<Optional<Integer>>> nestedSource =
|
||||
|
|
@ -255,7 +256,7 @@ public class CompositionDocTest {
|
|||
|
||||
//#mat-combine-2
|
||||
// Materializes to BoxedUnit (orange)
|
||||
final Flow<Integer, ByteString, BoxedUnit> flow2 = Flow.of(Integer.class)
|
||||
final Flow<Integer, ByteString, NotUsed> flow2 = Flow.of(Integer.class)
|
||||
.map(i -> ByteString.fromString(i.toString()));
|
||||
|
||||
// Materializes to Future<OutgoingConnection> (yellow)
|
||||
|
|
@ -287,19 +288,19 @@ public class CompositionDocTest {
|
|||
@Test
|
||||
public void attributes() throws Exception {
|
||||
//#attributes-inheritance
|
||||
final Source<Integer, BoxedUnit> nestedSource =
|
||||
final Source<Integer, NotUsed> nestedSource =
|
||||
Source.single(0)
|
||||
.map(i -> i + 1)
|
||||
.named("nestedSource"); // Wrap, no inputBuffer set
|
||||
|
||||
final Flow<Integer, Integer, BoxedUnit> nestedFlow =
|
||||
final Flow<Integer, Integer, NotUsed> nestedFlow =
|
||||
Flow.of(Integer.class).filter(i -> i != 0)
|
||||
.via(Flow.of(Integer.class)
|
||||
.map(i -> i - 2)
|
||||
.withAttributes(Attributes.inputBuffer(4, 4))) // override
|
||||
.named("nestedFlow"); // Wrap, no inputBuffer set
|
||||
|
||||
final Sink<Integer, BoxedUnit> nestedSink =
|
||||
final Sink<Integer, NotUsed> nestedSink =
|
||||
nestedFlow.to(Sink.fold(0, (acc, i) -> acc + i)) // wire an atomic sink to the nestedFlow
|
||||
.withAttributes(Attributes.name("nestedSink")
|
||||
.and(Attributes.inputBuffer(3, 3))); // override
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.util.*;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.japi.Pair;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
|
@ -19,7 +20,6 @@ import scala.concurrent.Future;
|
|||
import scala.concurrent.Promise;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
import scala.Option;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.Cancellable;
|
||||
|
|
@ -48,13 +48,13 @@ public class FlowDocTest {
|
|||
@Test
|
||||
public void sourceIsImmutable() throws Exception {
|
||||
//#source-immutable
|
||||
final Source<Integer, BoxedUnit> source =
|
||||
final Source<Integer, NotUsed> source =
|
||||
Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||
source.map(x -> 0); // has no effect on source, since it's immutable
|
||||
source.runWith(Sink.fold(0, (agg, next) -> agg + next), mat); // 55
|
||||
|
||||
// returns new Source<Integer>, with `map()` appended
|
||||
final Source<Integer, BoxedUnit> zeroes = source.map(x -> 0);
|
||||
final Source<Integer, NotUsed> zeroes = source.map(x -> 0);
|
||||
final Sink<Integer, Future<Integer>> fold =
|
||||
Sink.fold(0, (agg, next) -> agg + next);
|
||||
zeroes.runWith(fold, mat); // 0
|
||||
|
|
@ -70,7 +70,7 @@ public class FlowDocTest {
|
|||
@Test
|
||||
public void materializationInSteps() throws Exception {
|
||||
//#materialization-in-steps
|
||||
final Source<Integer, BoxedUnit> source =
|
||||
final Source<Integer, NotUsed> source =
|
||||
Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||
// note that the Future is scala.concurrent.Future
|
||||
final Sink<Integer, Future<Integer>> sink =
|
||||
|
|
@ -91,7 +91,7 @@ public class FlowDocTest {
|
|||
@Test
|
||||
public void materializationRunWith() throws Exception {
|
||||
//#materialization-runWith
|
||||
final Source<Integer, BoxedUnit> source =
|
||||
final Source<Integer, NotUsed> source =
|
||||
Source.from(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||
final Sink<Integer, Future<Integer>> sink =
|
||||
Sink.fold(0, (aggr, next) -> aggr + next);
|
||||
|
|
@ -195,12 +195,12 @@ public class FlowDocTest {
|
|||
.to(Sink.foreach(System.out::println));
|
||||
|
||||
// Starting from a Source
|
||||
final Source<Integer, BoxedUnit> source = Source.from(Arrays.asList(1, 2, 3, 4))
|
||||
final Source<Integer, NotUsed> source = Source.from(Arrays.asList(1, 2, 3, 4))
|
||||
.map(elem -> elem * 2);
|
||||
source.to(Sink.foreach(System.out::println));
|
||||
|
||||
// Starting from a Sink
|
||||
final Sink<Integer, BoxedUnit> sink = Flow.of(Integer.class)
|
||||
final Sink<Integer, NotUsed> sink = Flow.of(Integer.class)
|
||||
.map(elem -> elem * 2).to(Sink.foreach(System.out::println));
|
||||
Source.from(Arrays.asList(1, 2, 3, 4)).to(sink);
|
||||
//#flow-connecting
|
||||
|
|
@ -276,9 +276,9 @@ public class FlowDocTest {
|
|||
|
||||
public void fusingAndAsync() {
|
||||
//#explicit-fusing
|
||||
Flow<Integer, Integer, BoxedUnit> flow =
|
||||
Flow<Integer, Integer, NotUsed> flow =
|
||||
Flow.of(Integer.class).map(x -> x * 2).filter(x -> x > 500);
|
||||
Graph<FlowShape<Integer, Integer>, BoxedUnit> fused =
|
||||
Graph<FlowShape<Integer, Integer>, NotUsed> fused =
|
||||
akka.stream.Fusing.aggressive(flow);
|
||||
|
||||
Source.fromIterator(() -> Stream.iterate(0, x -> x + 1).iterator())
|
||||
|
|
|
|||
|
|
@ -7,13 +7,14 @@ import static org.junit.Assert.assertEquals;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.NotUsed;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.ActorMaterializer;
|
||||
|
|
@ -46,7 +47,7 @@ public class FlowErrorDocTest {
|
|||
public void demonstrateFailStream() throws Exception {
|
||||
//#stop
|
||||
final Materializer mat = ActorMaterializer.create(system);
|
||||
final Source<Integer, BoxedUnit> source = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5))
|
||||
final Source<Integer, NotUsed> source = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5))
|
||||
.map(elem -> 100 / elem);
|
||||
final Sink<Integer, Future<Integer>> fold =
|
||||
Sink.fold(0, (acc, elem) -> acc + elem);
|
||||
|
|
@ -70,7 +71,7 @@ public class FlowErrorDocTest {
|
|||
final Materializer mat = ActorMaterializer.create(
|
||||
ActorMaterializerSettings.create(system).withSupervisionStrategy(decider),
|
||||
system);
|
||||
final Source<Integer, BoxedUnit> source = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5))
|
||||
final Source<Integer, NotUsed> source = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5))
|
||||
.map(elem -> 100 / elem);
|
||||
final Sink<Integer, Future<Integer>> fold =
|
||||
Sink.fold(0, (acc, elem) -> acc + elem);
|
||||
|
|
@ -92,10 +93,10 @@ public class FlowErrorDocTest {
|
|||
else
|
||||
return Supervision.stop();
|
||||
};
|
||||
final Flow<Integer, Integer, BoxedUnit> flow =
|
||||
final Flow<Integer, Integer, NotUsed> flow =
|
||||
Flow.of(Integer.class).filter(elem -> 100 / elem < 50).map(elem -> 100 / (5 - elem))
|
||||
.withAttributes(ActorAttributes.withSupervisionStrategy(decider));
|
||||
final Source<Integer, BoxedUnit> source = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5))
|
||||
final Source<Integer, NotUsed> source = Source.from(Arrays.asList(0, 1, 2, 3, 4, 5))
|
||||
.via(flow);
|
||||
final Sink<Integer, Future<Integer>> fold =
|
||||
Sink.fold(0, (acc, elem) -> acc + elem);
|
||||
|
|
@ -117,13 +118,13 @@ public class FlowErrorDocTest {
|
|||
else
|
||||
return Supervision.stop();
|
||||
};
|
||||
final Flow<Integer, Integer, BoxedUnit> flow =
|
||||
final Flow<Integer, Integer, NotUsed> flow =
|
||||
Flow.of(Integer.class).scan(0, (acc, elem) -> {
|
||||
if (elem < 0) throw new IllegalArgumentException("negative not allowed");
|
||||
else return acc + elem;
|
||||
})
|
||||
.withAttributes(ActorAttributes.withSupervisionStrategy(decider));
|
||||
final Source<Integer, BoxedUnit> source = Source.from(Arrays.asList(1, 3, -1, 5, 7))
|
||||
final Source<Integer, NotUsed> source = Source.from(Arrays.asList(1, 3, -1, 5, 7))
|
||||
.via(flow);
|
||||
final Future<List<Integer>> result = source.grouped(1000)
|
||||
.runWith(Sink.<List<Integer>>head(), mat);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.stream.ClosedShape;
|
||||
import akka.stream.SourceShape;
|
||||
import org.junit.AfterClass;
|
||||
|
|
@ -18,7 +19,6 @@ import org.junit.Test;
|
|||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.japi.Pair;
|
||||
import akka.stream.*;
|
||||
|
|
@ -45,13 +45,13 @@ public class FlowGraphDocTest {
|
|||
@Test
|
||||
public void demonstrateBuildSimpleGraph() throws Exception {
|
||||
//#simple-flow-graph
|
||||
final Source<Integer, BoxedUnit> in = Source.from(Arrays.asList(1, 2, 3, 4, 5));
|
||||
final Source<Integer, NotUsed> in = Source.from(Arrays.asList(1, 2, 3, 4, 5));
|
||||
final Sink<List<String>, Future<List<String>>> sink = Sink.head();
|
||||
final Sink<List<Integer>, Future<List<Integer>>> sink2 = Sink.head();
|
||||
final Flow<Integer, Integer, BoxedUnit> f1 = Flow.of(Integer.class).map(elem -> elem + 10);
|
||||
final Flow<Integer, Integer, BoxedUnit> f2 = Flow.of(Integer.class).map(elem -> elem + 20);
|
||||
final Flow<Integer, String, BoxedUnit> f3 = Flow.of(Integer.class).map(elem -> elem.toString());
|
||||
final Flow<Integer, Integer, BoxedUnit> f4 = Flow.of(Integer.class).map(elem -> elem + 30);
|
||||
final Flow<Integer, Integer, NotUsed> f1 = Flow.of(Integer.class).map(elem -> elem + 10);
|
||||
final Flow<Integer, Integer, NotUsed> f2 = Flow.of(Integer.class).map(elem -> elem + 20);
|
||||
final Flow<Integer, String, NotUsed> f3 = Flow.of(Integer.class).map(elem -> elem.toString());
|
||||
final Flow<Integer, Integer, NotUsed> f4 = Flow.of(Integer.class).map(elem -> elem + 30);
|
||||
|
||||
final RunnableGraph<Future<List<String>>> result =
|
||||
RunnableGraph.<Future<List<String>>>fromGraph(
|
||||
|
|
@ -81,8 +81,8 @@ public class FlowGraphDocTest {
|
|||
public void demonstrateConnectErrors() {
|
||||
try {
|
||||
//#simple-graph
|
||||
final RunnableGraph<BoxedUnit> g =
|
||||
RunnableGraph.<BoxedUnit>fromGraph(
|
||||
final RunnableGraph<NotUsed> g =
|
||||
RunnableGraph.<NotUsed>fromGraph(
|
||||
GraphDSL
|
||||
.create((b) -> {
|
||||
final SourceShape<Integer> source1 = b.add(Source.from(Arrays.asList(1, 2, 3, 4, 5)));
|
||||
|
|
@ -107,7 +107,7 @@ public class FlowGraphDocTest {
|
|||
//#flow-graph-reusing-a-flow
|
||||
final Sink<Integer, Future<Integer>> topHeadSink = Sink.head();
|
||||
final Sink<Integer, Future<Integer>> bottomHeadSink = Sink.head();
|
||||
final Flow<Integer, Integer, BoxedUnit> sharedDoubler = Flow.of(Integer.class).map(elem -> elem * 2);
|
||||
final Flow<Integer, Integer, NotUsed> sharedDoubler = Flow.of(Integer.class).map(elem -> elem * 2);
|
||||
|
||||
final RunnableGraph<Pair<Future<Integer>, Future<Integer>>> g =
|
||||
RunnableGraph.<Pair<Future<Integer>, Future<Integer>>>fromGraph(
|
||||
|
|
@ -139,7 +139,7 @@ public class FlowGraphDocTest {
|
|||
return a + b;
|
||||
});
|
||||
|
||||
final Flow<Future<Integer>, Integer, BoxedUnit> flatten = Flow.<Future<Integer>>create()
|
||||
final Flow<Future<Integer>, Integer, NotUsed> flatten = Flow.<Future<Integer>>create()
|
||||
.mapAsync(4, x -> {
|
||||
return x;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
*/
|
||||
package docs.stream;
|
||||
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import akka.NotUsed;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -37,10 +37,10 @@ public class FlowParallelismDocTest {
|
|||
static class Pancake {}
|
||||
|
||||
//#pipelining
|
||||
Flow<ScoopOfBatter, HalfCookedPancake, BoxedUnit> fryingPan1 =
|
||||
Flow<ScoopOfBatter, HalfCookedPancake, NotUsed> fryingPan1 =
|
||||
Flow.of(ScoopOfBatter.class).map(batter -> new HalfCookedPancake());
|
||||
|
||||
Flow<HalfCookedPancake, Pancake, BoxedUnit> fryingPan2 =
|
||||
Flow<HalfCookedPancake, Pancake, NotUsed> fryingPan2 =
|
||||
Flow.of(HalfCookedPancake.class).map(halfCooked -> new Pancake());
|
||||
//#pipelining
|
||||
|
||||
|
|
@ -49,17 +49,17 @@ public class FlowParallelismDocTest {
|
|||
//#pipelining
|
||||
|
||||
// With the two frying pans we can fully cook pancakes
|
||||
Flow<ScoopOfBatter, Pancake, BoxedUnit> pancakeChef = fryingPan1.via(fryingPan2);
|
||||
Flow<ScoopOfBatter, Pancake, NotUsed> pancakeChef = fryingPan1.via(fryingPan2);
|
||||
//#pipelining
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demonstrateParallelism() {
|
||||
//#parallelism
|
||||
Flow<ScoopOfBatter, Pancake, BoxedUnit> fryingPan =
|
||||
Flow<ScoopOfBatter, Pancake, NotUsed> fryingPan =
|
||||
Flow.of(ScoopOfBatter.class).map(batter -> new Pancake());
|
||||
|
||||
Flow<ScoopOfBatter, Pancake, BoxedUnit> pancakeChef =
|
||||
Flow<ScoopOfBatter, Pancake, NotUsed> pancakeChef =
|
||||
Flow.fromGraph(GraphDSL.create(b -> {
|
||||
final UniformFanInShape<Pancake, Pancake> mergePancakes =
|
||||
b.add(Merge.create(2));
|
||||
|
|
@ -82,7 +82,7 @@ public class FlowParallelismDocTest {
|
|||
@Test
|
||||
public void parallelPipeline() {
|
||||
//#parallel-pipeline
|
||||
Flow<ScoopOfBatter, Pancake, BoxedUnit> pancakeChef =
|
||||
Flow<ScoopOfBatter, Pancake, NotUsed> pancakeChef =
|
||||
Flow.fromGraph(GraphDSL.create(b -> {
|
||||
final UniformFanInShape<Pancake, Pancake> mergePancakes =
|
||||
b.add(Merge.create(2));
|
||||
|
|
@ -109,7 +109,7 @@ public class FlowParallelismDocTest {
|
|||
@Test
|
||||
public void pipelinedParallel() {
|
||||
//#pipelined-parallel
|
||||
Flow<ScoopOfBatter, HalfCookedPancake, BoxedUnit> pancakeChefs1 =
|
||||
Flow<ScoopOfBatter, HalfCookedPancake, NotUsed> pancakeChefs1 =
|
||||
Flow.fromGraph(GraphDSL.create(b -> {
|
||||
final UniformFanInShape<HalfCookedPancake, HalfCookedPancake> mergeHalfCooked =
|
||||
b.add(Merge.create(2));
|
||||
|
|
@ -124,7 +124,7 @@ public class FlowParallelismDocTest {
|
|||
return FlowShape.of(dispatchBatter.in(), mergeHalfCooked.out());
|
||||
}));
|
||||
|
||||
Flow<HalfCookedPancake, Pancake, BoxedUnit> pancakeChefs2 =
|
||||
Flow<HalfCookedPancake, Pancake, NotUsed> pancakeChefs2 =
|
||||
Flow.fromGraph(GraphDSL.create(b -> {
|
||||
final UniformFanInShape<Pancake, Pancake> mergePancakes =
|
||||
b.add(Merge.create(2));
|
||||
|
|
@ -139,7 +139,7 @@ public class FlowParallelismDocTest {
|
|||
return FlowShape.of(dispatchHalfCooked.in(), mergePancakes.out());
|
||||
}));
|
||||
|
||||
Flow<ScoopOfBatter, Pancake, BoxedUnit> kitchen =
|
||||
Flow<ScoopOfBatter, Pancake, NotUsed> kitchen =
|
||||
pancakeChefs1.via(pancakeChefs2);
|
||||
//#pipelined-parallel
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ package docs.stream;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import akka.NotUsed;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import scala.runtime.BoxedUnit;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.*;
|
||||
import akka.stream.javadsl.*;
|
||||
|
|
@ -34,13 +34,13 @@ public class GraphCyclesDocTest {
|
|||
|
||||
final static SilenceSystemOut.System System = SilenceSystemOut.get();
|
||||
|
||||
final Source<Integer, BoxedUnit> source = Source.from(Arrays.asList(1, 2, 3, 4, 5));
|
||||
final Source<Integer, NotUsed> source = Source.from(Arrays.asList(1, 2, 3, 4, 5));
|
||||
|
||||
@Test
|
||||
public void demonstrateDeadlockedCycle() {
|
||||
//#deadlocked
|
||||
// WARNING! The graph below deadlocks!
|
||||
final Flow<Integer, Integer, BoxedUnit> printFlow =
|
||||
final Flow<Integer, Integer, NotUsed> printFlow =
|
||||
Flow.of(Integer.class).map(s -> {
|
||||
System.out.println(s);
|
||||
return s;
|
||||
|
|
@ -62,7 +62,7 @@ public class GraphCyclesDocTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateUnfairCycle() {
|
||||
final Flow<Integer, Integer, BoxedUnit> printFlow =
|
||||
final Flow<Integer, Integer, NotUsed> printFlow =
|
||||
Flow.of(Integer.class).map(s -> {
|
||||
System.out.println(s);
|
||||
return s;
|
||||
|
|
@ -85,7 +85,7 @@ public class GraphCyclesDocTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateDroppingCycle() {
|
||||
final Flow<Integer, Integer, BoxedUnit> printFlow =
|
||||
final Flow<Integer, Integer, NotUsed> printFlow =
|
||||
Flow.of(Integer.class).map(s -> {
|
||||
System.out.println(s);
|
||||
return s;
|
||||
|
|
@ -109,7 +109,7 @@ public class GraphCyclesDocTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateZippingCycle() {
|
||||
final Flow<Integer, Integer, BoxedUnit> printFlow =
|
||||
final Flow<Integer, Integer, NotUsed> printFlow =
|
||||
Flow.of(Integer.class).map(s -> {
|
||||
System.out.println(s);
|
||||
return s;
|
||||
|
|
@ -133,7 +133,7 @@ public class GraphCyclesDocTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateLiveZippingCycle() {
|
||||
final Flow<Integer, Integer, BoxedUnit> printFlow =
|
||||
final Flow<Integer, Integer, NotUsed> printFlow =
|
||||
Flow.of(Integer.class).map(s -> {
|
||||
System.out.println(s);
|
||||
return s;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package docs.stream;
|
||||
|
||||
import akka.Done;
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
//#imports
|
||||
import akka.dispatch.Futures;
|
||||
|
|
@ -7,7 +9,6 @@ import akka.dispatch.Mapper;
|
|||
import akka.dispatch.OnSuccess;
|
||||
import akka.japi.Option;
|
||||
import akka.japi.Predicate;
|
||||
import akka.japi.function.Effect;
|
||||
import akka.japi.function.Procedure;
|
||||
import akka.stream.*;
|
||||
import akka.stream.javadsl.*;
|
||||
|
|
@ -20,7 +21,6 @@ import akka.japi.Function;
|
|||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.reactivestreams.Subscriber;
|
||||
import org.reactivestreams.Subscription;
|
||||
import scala.Tuple2;
|
||||
import scala.concurrent.Await;
|
||||
|
|
@ -29,7 +29,6 @@ import scala.concurrent.Future;
|
|||
import scala.concurrent.Promise;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -96,10 +95,10 @@ public class GraphStageDocTest {
|
|||
public void demonstrateCustomSourceUsage() throws Exception {
|
||||
//#simple-source-usage
|
||||
// A GraphStage is a proper Graph, just like what GraphDSL.create would return
|
||||
Graph<SourceShape<Integer>, BoxedUnit> sourceGraph = new NumbersSource();
|
||||
Graph<SourceShape<Integer>, NotUsed> sourceGraph = new NumbersSource();
|
||||
|
||||
// Create a Source from the Graph to access the DSL
|
||||
Source<Integer, BoxedUnit> mySource = Source.fromGraph(sourceGraph);
|
||||
Source<Integer, NotUsed> mySource = Source.fromGraph(sourceGraph);
|
||||
|
||||
// Returns 55
|
||||
Future<Integer> result1 = mySource.take(10).runFold(0, (sum, next) -> sum + next, mat);
|
||||
|
|
@ -162,7 +161,7 @@ public class GraphStageDocTest {
|
|||
@Test
|
||||
public void demonstrateOneToOne() throws Exception {
|
||||
// tests:
|
||||
final Graph<FlowShape<String, Integer>, BoxedUnit> stringLength =
|
||||
final Graph<FlowShape<String, Integer>, NotUsed> stringLength =
|
||||
Flow.fromGraph(new Map<String, Integer>(new Function<String, Integer>() {
|
||||
@Override
|
||||
public Integer apply(String str) {
|
||||
|
|
@ -229,7 +228,7 @@ public class GraphStageDocTest {
|
|||
public void demonstrateAManyToOneElementGraphStage() throws Exception {
|
||||
|
||||
// tests:
|
||||
Graph<FlowShape<Integer, Integer>, BoxedUnit> evenFilter =
|
||||
Graph<FlowShape<Integer, Integer>, NotUsed> evenFilter =
|
||||
Flow.fromGraph(new Filter<Integer>(n -> n % 2 == 0));
|
||||
|
||||
Future<Integer> result =
|
||||
|
|
@ -298,7 +297,7 @@ public class GraphStageDocTest {
|
|||
@Test
|
||||
public void demonstrateAOneToManyElementGraphStage() throws Exception {
|
||||
// tests:
|
||||
Graph<FlowShape<Integer, Integer>, BoxedUnit> duplicator =
|
||||
Graph<FlowShape<Integer, Integer>, NotUsed> duplicator =
|
||||
Flow.fromGraph(new Duplicator<Integer>());
|
||||
|
||||
Future<Integer> result =
|
||||
|
|
@ -355,7 +354,7 @@ public class GraphStageDocTest {
|
|||
@Test
|
||||
public void demonstrateASimplerOneToManyStage() throws Exception {
|
||||
// tests:
|
||||
Graph<FlowShape<Integer, Integer>, BoxedUnit> duplicator =
|
||||
Graph<FlowShape<Integer, Integer>, NotUsed> duplicator =
|
||||
Flow.fromGraph(new Duplicator2<Integer>());
|
||||
|
||||
Future<Integer> result =
|
||||
|
|
@ -387,9 +386,9 @@ public class GraphStageDocTest {
|
|||
// will close upstream when the future completes
|
||||
public class KillSwitch<A> extends GraphStage<FlowShape<A, A>> {
|
||||
|
||||
private final Future<BoxedUnit> switchF;
|
||||
private final Future<Done> switchF;
|
||||
|
||||
public KillSwitch(Future<BoxedUnit> switchF) {
|
||||
public KillSwitch(Future<Done> switchF) {
|
||||
this.switchF = switchF;
|
||||
}
|
||||
|
||||
|
|
@ -423,18 +422,18 @@ public class GraphStageDocTest {
|
|||
|
||||
@Override
|
||||
public void preStart() {
|
||||
AsyncCallback<BoxedUnit> callback = createAsyncCallback(new Procedure<BoxedUnit>() {
|
||||
AsyncCallback<Done> callback = createAsyncCallback(new Procedure<Done>() {
|
||||
@Override
|
||||
public void apply(BoxedUnit param) throws Exception {
|
||||
public void apply(Done param) throws Exception {
|
||||
completeStage();
|
||||
}
|
||||
});
|
||||
|
||||
ExecutionContext ec = system.dispatcher();
|
||||
switchF.onSuccess(new OnSuccess<BoxedUnit>() {
|
||||
switchF.onSuccess(new OnSuccess<Done>() {
|
||||
@Override
|
||||
public void onSuccess(BoxedUnit result) throws Throwable {
|
||||
callback.invoke(BoxedUnit.UNIT);
|
||||
public void onSuccess(Done result) throws Throwable {
|
||||
callback.invoke(Done.getInstance());
|
||||
}
|
||||
}, ec);
|
||||
}
|
||||
|
|
@ -447,16 +446,16 @@ public class GraphStageDocTest {
|
|||
public void demonstrateAnAsynchronousSideChannel() throws Exception{
|
||||
|
||||
// tests:
|
||||
Promise<BoxedUnit> switchF = Futures.promise();
|
||||
Graph<FlowShape<Integer, Integer>, BoxedUnit> killSwitch =
|
||||
Promise<Done> switchF = Futures.promise();
|
||||
Graph<FlowShape<Integer, Integer>, NotUsed> killSwitch =
|
||||
Flow.fromGraph(new KillSwitch<>(switchF.future()));
|
||||
|
||||
ExecutionContext ec = system.dispatcher();
|
||||
|
||||
// TODO this is probably racey, is there a way to make sure it happens after?
|
||||
Future<Integer> valueAfterKill = switchF.future().flatMap(new Mapper<BoxedUnit, Future<Integer>>() {
|
||||
Future<Integer> valueAfterKill = switchF.future().flatMap(new Mapper<Done, Future<Integer>>() {
|
||||
@Override
|
||||
public Future<Integer> apply(BoxedUnit parameter) {
|
||||
public Future<Integer> apply(Done parameter) {
|
||||
return Futures.successful(4);
|
||||
}
|
||||
}, ec);
|
||||
|
|
@ -467,7 +466,7 @@ public class GraphStageDocTest {
|
|||
.via(killSwitch)
|
||||
.runFold(0, (n, sum) -> n + sum, mat);
|
||||
|
||||
switchF.success(BoxedUnit.UNIT);
|
||||
switchF.success(Done.getInstance());
|
||||
|
||||
assertEquals(new Integer(6), Await.result(result, Duration.create(3, "seconds")));
|
||||
}
|
||||
|
|
@ -694,7 +693,7 @@ public class GraphStageDocTest {
|
|||
|
||||
TestSubscriber.ManualProbe<Integer> subscriber = TestSubscriber.manualProbe(system);
|
||||
TestPublisher.Probe<Integer> publisher = TestPublisher.probe(0, system);
|
||||
RunnableGraph<BoxedUnit> flow2 =
|
||||
RunnableGraph<NotUsed> flow2 =
|
||||
Source.fromPublisher(publisher)
|
||||
.via(new TwoBuffer<>())
|
||||
.to(Sink.fromSubscriber(subscriber));
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package docs.stream;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.*;
|
||||
import akka.dispatch.Futures;
|
||||
import akka.dispatch.MessageDispatcher;
|
||||
|
|
@ -22,7 +23,6 @@ import org.junit.BeforeClass;
|
|||
import org.junit.Test;
|
||||
import scala.concurrent.ExecutionContext;
|
||||
import scala.concurrent.Future;
|
||||
import scala.runtime.BoxedUnit;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
|
|
@ -290,14 +290,14 @@ public class IntegrationDocTest {
|
|||
|
||||
{
|
||||
//#tweet-authors
|
||||
final Source<Author, BoxedUnit> authors = tweets
|
||||
final Source<Author, NotUsed> authors = tweets
|
||||
.filter(t -> t.hashtags().contains(AKKA))
|
||||
.map(t -> t.author);
|
||||
|
||||
//#tweet-authors
|
||||
|
||||
//#email-addresses-mapAsync
|
||||
final Source<String, BoxedUnit> emailAddresses = authors
|
||||
final Source<String, NotUsed> emailAddresses = authors
|
||||
.mapAsync(4, author -> addressSystem.lookupEmail(author.handle))
|
||||
.filter(o -> o.isPresent())
|
||||
.map(o -> o.get());
|
||||
|
|
@ -305,7 +305,7 @@ public class IntegrationDocTest {
|
|||
//#email-addresses-mapAsync
|
||||
|
||||
//#send-emails
|
||||
final RunnableGraph<BoxedUnit> sendEmails = emailAddresses
|
||||
final RunnableGraph<NotUsed> sendEmails = emailAddresses
|
||||
.mapAsync(4, address ->
|
||||
emailServer.send(new Email(address, "Akka", "I like your tweet")))
|
||||
.to(Sink.ignore());
|
||||
|
|
@ -331,18 +331,18 @@ public class IntegrationDocTest {
|
|||
final AddressSystem2 addressSystem = new AddressSystem2();
|
||||
|
||||
{
|
||||
final Source<Author, BoxedUnit> authors = tweets
|
||||
final Source<Author, NotUsed> authors = tweets
|
||||
.filter(t -> t.hashtags().contains(AKKA))
|
||||
.map(t -> t.author);
|
||||
|
||||
//#email-addresses-mapAsync-supervision
|
||||
final Attributes resumeAttrib =
|
||||
ActorAttributes.withSupervisionStrategy(Supervision.getResumingDecider());
|
||||
final Flow<Author, String, BoxedUnit> lookupEmail =
|
||||
final Flow<Author, String, NotUsed> lookupEmail =
|
||||
Flow.of(Author.class)
|
||||
.mapAsync(4, author -> addressSystem.lookupEmail(author.handle))
|
||||
.withAttributes(resumeAttrib);
|
||||
final Source<String, BoxedUnit> emailAddresses = authors.via(lookupEmail);
|
||||
final Source<String, NotUsed> emailAddresses = authors.via(lookupEmail);
|
||||
|
||||
//#email-addresses-mapAsync-supervision
|
||||
}
|
||||
|
|
@ -358,18 +358,18 @@ public class IntegrationDocTest {
|
|||
|
||||
{
|
||||
//#external-service-mapAsyncUnordered
|
||||
final Source<Author, BoxedUnit> authors =
|
||||
final Source<Author, NotUsed> authors =
|
||||
tweets
|
||||
.filter(t -> t.hashtags().contains(AKKA))
|
||||
.map(t -> t.author);
|
||||
|
||||
final Source<String, BoxedUnit> emailAddresses =
|
||||
final Source<String, NotUsed> emailAddresses =
|
||||
authors
|
||||
.mapAsyncUnordered(4, author -> addressSystem.lookupEmail(author.handle))
|
||||
.filter(o -> o.isPresent())
|
||||
.map(o -> o.get());
|
||||
|
||||
final RunnableGraph<BoxedUnit> sendEmails =
|
||||
final RunnableGraph<NotUsed> sendEmails =
|
||||
emailAddresses
|
||||
.mapAsyncUnordered(4, address ->
|
||||
emailServer.send(new Email(address, "Akka", "I like your tweet")))
|
||||
|
|
@ -389,19 +389,19 @@ public class IntegrationDocTest {
|
|||
final SmsServer smsServer = new SmsServer(getRef());
|
||||
|
||||
{
|
||||
final Source<Author, BoxedUnit> authors =
|
||||
final Source<Author, NotUsed> authors =
|
||||
tweets
|
||||
.filter(t -> t.hashtags().contains(AKKA))
|
||||
.map(t -> t.author);
|
||||
|
||||
final Source<String, BoxedUnit> phoneNumbers = authors.mapAsync(4, author -> addressSystem.lookupPhoneNumber(author.handle))
|
||||
final Source<String, NotUsed> phoneNumbers = authors.mapAsync(4, author -> addressSystem.lookupPhoneNumber(author.handle))
|
||||
.filter(o -> o.isPresent())
|
||||
.map(o -> o.get());
|
||||
|
||||
//#blocking-mapAsync
|
||||
final MessageDispatcher blockingEc = system.dispatchers().lookup("blocking-dispatcher");
|
||||
|
||||
final RunnableGraph<BoxedUnit> sendTextMessages =
|
||||
final RunnableGraph<NotUsed> sendTextMessages =
|
||||
phoneNumbers
|
||||
.mapAsync(4, phoneNo ->
|
||||
Futures.future(() ->
|
||||
|
|
@ -436,17 +436,17 @@ public class IntegrationDocTest {
|
|||
final SmsServer smsServer = new SmsServer(probe.ref());
|
||||
|
||||
{
|
||||
final Source<Author, BoxedUnit> authors =
|
||||
final Source<Author, NotUsed> authors =
|
||||
tweets
|
||||
.filter(t -> t.hashtags().contains(AKKA))
|
||||
.map(t -> t.author);
|
||||
|
||||
final Source<String, BoxedUnit> phoneNumbers = authors.mapAsync(4, author -> addressSystem.lookupPhoneNumber(author.handle))
|
||||
final Source<String, NotUsed> phoneNumbers = authors.mapAsync(4, author -> addressSystem.lookupPhoneNumber(author.handle))
|
||||
.filter(o -> o.isPresent())
|
||||
.map(o -> o.get());
|
||||
|
||||
//#blocking-map
|
||||
final Flow<String, Boolean, BoxedUnit> send =
|
||||
final Flow<String, Boolean, NotUsed> send =
|
||||
Flow.of(String.class)
|
||||
.map(phoneNo -> smsServer.send(new TextMessage(phoneNo, "I like your tweet")))
|
||||
.withAttributes(ActorAttributes.dispatcher("blocking-dispatcher"));
|
||||
|
|
@ -477,9 +477,9 @@ public class IntegrationDocTest {
|
|||
|
||||
{
|
||||
//#save-tweets
|
||||
final Source<Tweet, BoxedUnit> akkaTweets = tweets.filter(t -> t.hashtags().contains(AKKA));
|
||||
final Source<Tweet, NotUsed> akkaTweets = tweets.filter(t -> t.hashtags().contains(AKKA));
|
||||
|
||||
final RunnableGraph<BoxedUnit> saveTweets =
|
||||
final RunnableGraph<NotUsed> saveTweets =
|
||||
akkaTweets
|
||||
.mapAsync(4, tweet -> ask(database, new Save(tweet), 300))
|
||||
.to(Sink.ignore());
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.Cancellable;
|
||||
import akka.http.javadsl.model.Uri;
|
||||
|
|
@ -19,7 +20,6 @@ import scala.Option;
|
|||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.concurrent.Promise;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.reactivestreams.Subscriber;
|
||||
|
|
@ -67,30 +67,30 @@ public class MigrationsJava {
|
|||
Inlet<Integer> inlet1 = null;
|
||||
Inlet<Integer> inlet2 = null;
|
||||
|
||||
Flow<Integer, Integer, BoxedUnit> flow = Flow.of(Integer.class);
|
||||
Flow<Integer, Integer, BoxedUnit> flow1 = Flow.of(Integer.class);
|
||||
Flow<Integer, Integer, BoxedUnit> flow2 = Flow.of(Integer.class);
|
||||
Flow<Integer, Integer, NotUsed> flow = Flow.of(Integer.class);
|
||||
Flow<Integer, Integer, NotUsed> flow1 = Flow.of(Integer.class);
|
||||
Flow<Integer, Integer, NotUsed> flow2 = Flow.of(Integer.class);
|
||||
|
||||
Promise<Option<Integer>> promise = null;
|
||||
|
||||
|
||||
{
|
||||
Graph<SourceShape<Integer>, BoxedUnit> graphSource = null;
|
||||
Graph<SinkShape<Integer>, BoxedUnit> graphSink = null;
|
||||
Graph<FlowShape<Integer, Integer>, BoxedUnit> graphFlow = null;
|
||||
Graph<SourceShape<Integer>, NotUsed> graphSource = null;
|
||||
Graph<SinkShape<Integer>, NotUsed> graphSink = null;
|
||||
Graph<FlowShape<Integer, Integer>, NotUsed> graphFlow = null;
|
||||
|
||||
//#flow-wrap
|
||||
Source<Integer, BoxedUnit> source = Source.fromGraph(graphSource);
|
||||
Sink<Integer, BoxedUnit> sink = Sink.fromGraph(graphSink);
|
||||
Flow<Integer, Integer, BoxedUnit> aflow = Flow.fromGraph(graphFlow);
|
||||
Source<Integer, NotUsed> source = Source.fromGraph(graphSource);
|
||||
Sink<Integer, NotUsed> sink = Sink.fromGraph(graphSink);
|
||||
Flow<Integer, Integer, NotUsed> aflow = Flow.fromGraph(graphFlow);
|
||||
Flow.fromSinkAndSource(Sink.<Integer>head(), Source.single(0));
|
||||
Flow.fromSinkAndSourceMat(Sink.<Integer>head(), Source.single(0), Keep.left());
|
||||
//#flow-wrap
|
||||
|
||||
Graph<BidiShape<Integer, Integer, Integer, Integer>, BoxedUnit> bidiGraph = null;
|
||||
Graph<BidiShape<Integer, Integer, Integer, Integer>, NotUsed> bidiGraph = null;
|
||||
|
||||
//#bidi-wrap
|
||||
BidiFlow<Integer, Integer, Integer, Integer, BoxedUnit> bidiFlow =
|
||||
BidiFlow<Integer, Integer, Integer, Integer, NotUsed> bidiFlow =
|
||||
BidiFlow.fromGraph(bidiGraph);
|
||||
BidiFlow.fromFlows(flow1, flow2);
|
||||
BidiFlow.fromFlowsMat(flow1, flow2, Keep.both());
|
||||
|
|
@ -158,10 +158,10 @@ public class MigrationsJava {
|
|||
FiniteDuration.create(200, TimeUnit.MILLISECONDS),
|
||||
"tick");
|
||||
|
||||
final Source<Integer, BoxedUnit> pubSource =
|
||||
final Source<Integer, NotUsed> pubSource =
|
||||
Source.fromPublisher(TestPublisher.<Integer>manualProbe(true, sys));
|
||||
|
||||
final Source<Integer, BoxedUnit> futSource =
|
||||
final Source<Integer, NotUsed> futSource =
|
||||
Source.fromFuture(Futures.successful(42));
|
||||
|
||||
final Source<Integer, Subscriber<Integer>> subSource =
|
||||
|
|
@ -169,7 +169,7 @@ public class MigrationsJava {
|
|||
//#source-creators
|
||||
|
||||
//#sink-creators
|
||||
final Sink<Integer, BoxedUnit> subSink =
|
||||
final Sink<Integer, NotUsed> subSink =
|
||||
Sink.fromSubscriber(TestSubscriber.<Integer>manualProbe(sys));
|
||||
//#sink-creators
|
||||
|
||||
|
|
@ -182,14 +182,14 @@ public class MigrationsJava {
|
|||
//#sink-as-publisher
|
||||
|
||||
//#empty-flow
|
||||
Flow<Integer, Integer, BoxedUnit> emptyFlow = Flow.<Integer>create();
|
||||
Flow<Integer, Integer, NotUsed> emptyFlow = Flow.<Integer>create();
|
||||
// or
|
||||
Flow<Integer, Integer, BoxedUnit> emptyFlow2 = Flow.of(Integer.class);
|
||||
Flow<Integer, Integer, NotUsed> emptyFlow2 = Flow.of(Integer.class);
|
||||
//#empty-flow
|
||||
|
||||
//#flatMapConcat
|
||||
Flow.<Source<Integer, BoxedUnit>>create().
|
||||
<Integer, BoxedUnit>flatMapConcat(i -> i);
|
||||
Flow.<Source<Integer, NotUsed>>create().
|
||||
<Integer, NotUsed>flatMapConcat(i -> i);
|
||||
//#flatMapConcat
|
||||
|
||||
//#group-flatten
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import java.util.stream.Collectors;
|
|||
import java.util.stream.DoubleStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import akka.NotUsed;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -32,7 +33,6 @@ import scala.collection.Iterator;
|
|||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
import scala.util.Random;
|
||||
|
||||
public class RateTransformationDocTest {
|
||||
|
|
@ -57,7 +57,7 @@ public class RateTransformationDocTest {
|
|||
@Test
|
||||
public void conflateShouldSummarize() throws Exception {
|
||||
//#conflate-summarize
|
||||
final Flow<Double, Tuple3<Double, Double, Integer>, BoxedUnit> statsFlow =
|
||||
final Flow<Double, Tuple3<Double, Double, Integer>, NotUsed> statsFlow =
|
||||
Flow.of(Double.class)
|
||||
.conflate(elem -> Collections.singletonList(elem), (acc, elem) -> {
|
||||
return Stream
|
||||
|
|
@ -85,7 +85,7 @@ public class RateTransformationDocTest {
|
|||
public void conflateShouldSample() throws Exception {
|
||||
//#conflate-sample
|
||||
final Double p = 0.01;
|
||||
final Flow<Double, Double, BoxedUnit> sampleFlow = Flow.of(Double.class)
|
||||
final Flow<Double, Double, NotUsed> sampleFlow = Flow.of(Double.class)
|
||||
.conflate(elem -> Collections.singletonList(elem), (acc, elem) -> {
|
||||
if (r.nextDouble() < p) {
|
||||
return Stream
|
||||
|
|
@ -108,7 +108,7 @@ public class RateTransformationDocTest {
|
|||
@Test
|
||||
public void expandShouldRepeatLast() throws Exception {
|
||||
//#expand-last
|
||||
final Flow<Double, Double, BoxedUnit> lastFlow = Flow.of(Double.class)
|
||||
final Flow<Double, Double, NotUsed> lastFlow = Flow.of(Double.class)
|
||||
.expand(d -> d, s -> new Pair<>(s, s));
|
||||
//#expand-last
|
||||
|
||||
|
|
@ -131,13 +131,13 @@ public class RateTransformationDocTest {
|
|||
public void expandShouldTrackDrift() throws Exception {
|
||||
@SuppressWarnings("unused")
|
||||
//#expand-drift
|
||||
final Flow<Double, Pair<Double, Integer>, BoxedUnit> driftFlow = Flow.of(Double.class)
|
||||
final Flow<Double, Pair<Double, Integer>, NotUsed> driftFlow = Flow.of(Double.class)
|
||||
.expand(d -> new Pair<Double, Integer>(d, 0), t -> {
|
||||
return new Pair<>(t, new Pair<>(t.first(), t.second() + 1));
|
||||
});
|
||||
//#expand-drift
|
||||
final TestLatch latch = new TestLatch(2, system);
|
||||
final Flow<Double, Pair<Double, Integer>, BoxedUnit> realDriftFlow = Flow.of(Double.class)
|
||||
final Flow<Double, Pair<Double, Integer>, NotUsed> realDriftFlow = Flow.of(Double.class)
|
||||
.expand(d -> { latch.countDown(); return new Pair<Double, Integer>(d, 0); }, t -> {
|
||||
return new Pair<>(t, new Pair<>(t.first(), t.second() + 1));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package docs.stream;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.japi.Pair;
|
||||
|
|
@ -25,7 +26,6 @@ import org.reactivestreams.Processor;
|
|||
//#imports
|
||||
import org.reactivestreams.Subscription;
|
||||
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.lang.Exception;
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ public class ReactiveStreamsDocTest {
|
|||
static class Data {
|
||||
|
||||
static //#authors
|
||||
final Flow<Tweet, Author, BoxedUnit> authors = Flow.of(Tweet.class)
|
||||
final Flow<Tweet, Author, NotUsed> authors = Flow.of(Tweet.class)
|
||||
.filter(t -> t.hashtags().contains(AKKA))
|
||||
.map(t -> t.author);
|
||||
|
||||
|
|
@ -243,7 +243,7 @@ public class ReactiveStreamsDocTest {
|
|||
}
|
||||
};
|
||||
|
||||
final Flow<Integer, Integer, BoxedUnit> flow = Flow.fromProcessor(factory);
|
||||
final Flow<Integer, Integer, NotUsed> flow = Flow.fromProcessor(factory);
|
||||
|
||||
//#use-processor
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ package docs.stream;
|
|||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.NotUsed;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.Cancellable;
|
||||
import akka.stream.*;
|
||||
|
|
@ -60,11 +60,11 @@ public class StreamBuffersRateDocTest {
|
|||
//#materializer-buffer
|
||||
|
||||
//#section-buffer
|
||||
final Flow<Integer, Integer, BoxedUnit> flow1 =
|
||||
final Flow<Integer, Integer, NotUsed> flow1 =
|
||||
Flow.of(Integer.class)
|
||||
.map(elem -> elem * 2) // the buffer size of this map is 1
|
||||
.withAttributes(Attributes.inputBuffer(1, 1));
|
||||
final Flow<Integer, Integer, BoxedUnit> flow2 =
|
||||
final Flow<Integer, Integer, NotUsed> flow2 =
|
||||
flow1.via(
|
||||
Flow.of(Integer.class)
|
||||
.map(elem -> elem / 2)); // the buffer size of this map is the default
|
||||
|
|
@ -80,7 +80,7 @@ public class StreamBuffersRateDocTest {
|
|||
Source.tick(oneSecond, oneSecond, "message!");
|
||||
final Source<String, Cancellable> tickSource =
|
||||
Source.tick(oneSecond.mul(3), oneSecond.mul(3), "tick");
|
||||
final Flow<String, Integer, BoxedUnit> conflate =
|
||||
final Flow<String, Integer, NotUsed> conflate =
|
||||
Flow.of(String.class).conflate(
|
||||
first -> 1, (count, elem) -> count + 1);
|
||||
|
||||
|
|
@ -97,10 +97,10 @@ public class StreamBuffersRateDocTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateExplicitBuffers() {
|
||||
final Source<Job, BoxedUnit> inboundJobsConnector = Source.empty();
|
||||
final Source<Job, NotUsed> inboundJobsConnector = Source.empty();
|
||||
//#explicit-buffers-backpressure
|
||||
// Getting a stream of jobs from an imaginary external system as a Source
|
||||
final Source<Job, BoxedUnit> jobs = inboundJobsConnector;
|
||||
final Source<Job, NotUsed> jobs = inboundJobsConnector;
|
||||
jobs.buffer(1000, OverflowStrategy.backpressure());
|
||||
//#explicit-buffers-backpressure
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import static org.junit.Assert.assertEquals;
|
|||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.Done;
|
||||
import akka.NotUsed;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -15,7 +17,6 @@ import org.junit.Test;
|
|||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
import akka.actor.*;
|
||||
import akka.japi.Pair;
|
||||
import akka.stream.*;
|
||||
|
|
@ -43,10 +44,10 @@ public class StreamPartialFlowGraphDocTest {
|
|||
@Test
|
||||
public void demonstrateBuildWithOpenPorts() throws Exception {
|
||||
//#simple-partial-flow-graph
|
||||
final Graph<FanInShape2<Integer, Integer, Integer>, BoxedUnit> zip =
|
||||
final Graph<FanInShape2<Integer, Integer, Integer>, NotUsed> zip =
|
||||
ZipWith.create((Integer left, Integer right) -> Math.max(left, right));
|
||||
|
||||
final Graph<UniformFanInShape<Integer, Integer>, BoxedUnit> pickMaxOfThree =
|
||||
final Graph<UniformFanInShape<Integer, Integer>, NotUsed> pickMaxOfThree =
|
||||
GraphDSL.create(builder -> {
|
||||
final FanInShape2<Integer, Integer, Integer> zip1 = builder.add(zip);
|
||||
final FanInShape2<Integer, Integer, Integer> zip2 = builder.add(zip);
|
||||
|
|
@ -95,9 +96,9 @@ public class StreamPartialFlowGraphDocTest {
|
|||
@Test
|
||||
public void demonstrateBuildSourceFromPartialFlowGraphCreate() throws Exception {
|
||||
//#source-from-partial-flow-graph
|
||||
final Source<Integer, BoxedUnit> ints = Source.fromIterator(() -> new Ints());
|
||||
final Source<Integer, NotUsed> ints = Source.fromIterator(() -> new Ints());
|
||||
|
||||
final Source<Pair<Integer, Integer>, BoxedUnit> pairs = Source.fromGraph(
|
||||
final Source<Pair<Integer, Integer>, NotUsed> pairs = Source.fromGraph(
|
||||
GraphDSL.create(
|
||||
builder -> {
|
||||
final FanInShape2<Integer, Integer, Pair<Integer, Integer>> zip =
|
||||
|
|
@ -118,7 +119,7 @@ public class StreamPartialFlowGraphDocTest {
|
|||
@Test
|
||||
public void demonstrateBuildFlowFromPartialFlowGraphCreate() throws Exception {
|
||||
//#flow-from-partial-flow-graph
|
||||
final Flow<Integer, Pair<Integer, String>, BoxedUnit> pairs = Flow.fromGraph(GraphDSL.create(
|
||||
final Flow<Integer, Pair<Integer, String>, NotUsed> pairs = Flow.fromGraph(GraphDSL.create(
|
||||
b -> {
|
||||
final UniformFanOutShape<Integer, Integer> bcast = b.add(Broadcast.create(2));
|
||||
final FanInShape2<Integer, String, Pair<Integer, String>> zip =
|
||||
|
|
@ -143,10 +144,10 @@ public class StreamPartialFlowGraphDocTest {
|
|||
@Test
|
||||
public void demonstrateBuildSourceWithCombine() throws Exception {
|
||||
//#source-combine
|
||||
Source<Integer, BoxedUnit> source1 = Source.single(1);
|
||||
Source<Integer, BoxedUnit> source2 = Source.single(2);
|
||||
Source<Integer, NotUsed> source1 = Source.single(1);
|
||||
Source<Integer, NotUsed> source2 = Source.single(2);
|
||||
|
||||
final Source<Integer, BoxedUnit> sources = Source.combine(source1, source2, new ArrayList<>(),
|
||||
final Source<Integer, NotUsed> sources = Source.combine(source1, source2, new ArrayList<>(),
|
||||
i -> Merge.<Integer>create(i));
|
||||
//#source-combine
|
||||
final Future<Integer> result=
|
||||
|
|
@ -163,9 +164,9 @@ public class StreamPartialFlowGraphDocTest {
|
|||
ActorRef actorRef = probe.getRef();
|
||||
|
||||
//#sink-combine
|
||||
Sink<Integer, BoxedUnit> sendRmotely = Sink.actorRef(actorRef, "Done");
|
||||
Sink<Integer, Future<BoxedUnit>> localProcessing = Sink.<Integer>foreach(a -> { /*do something useful*/ } );
|
||||
Sink<Integer, BoxedUnit> sinks = Sink.combine(sendRmotely,localProcessing, new ArrayList<>(), a -> Broadcast.create(a));
|
||||
Sink<Integer, NotUsed> sendRemotely = Sink.actorRef(actorRef, "Done");
|
||||
Sink<Integer, Future<Done>> localProcessing = Sink.<Integer>foreach(a -> { /*do something useful*/ } );
|
||||
Sink<Integer, NotUsed> sinks = Sink.combine(sendRemotely,localProcessing, new ArrayList<>(), a -> Broadcast.create(a));
|
||||
|
||||
Source.<Integer>from(Arrays.asList(new Integer[]{0, 1, 2})).runWith(sinks, mat);
|
||||
//#sink-combine
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.NotUsed;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
|
@ -26,7 +27,6 @@ import scala.concurrent.Future;
|
|||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
public class StreamTestKitDocTest {
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ public class StreamTestKitDocTest {
|
|||
@Test
|
||||
public void groupedPartOfInfiniteStream() throws Exception {
|
||||
//#grouped-infinite
|
||||
final Source<Integer, BoxedUnit> sourceUnderTest = Source.repeat(1)
|
||||
final Source<Integer, NotUsed> sourceUnderTest = Source.repeat(1)
|
||||
.map(i -> i * 2);
|
||||
|
||||
final Future<List<Integer>> future = sourceUnderTest
|
||||
|
|
@ -77,7 +77,7 @@ public class StreamTestKitDocTest {
|
|||
@Test
|
||||
public void foldedStream() throws Exception {
|
||||
//#folded-stream
|
||||
final Flow<Integer, Integer, BoxedUnit> flowUnderTest = Flow.of(Integer.class)
|
||||
final Flow<Integer, Integer, NotUsed> flowUnderTest = Flow.of(Integer.class)
|
||||
.takeWhile(i -> i < 5);
|
||||
|
||||
final Future<Integer> future = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6))
|
||||
|
|
@ -90,7 +90,7 @@ public class StreamTestKitDocTest {
|
|||
@Test
|
||||
public void pipeToTestProbe() throws Exception {
|
||||
//#pipeto-testprobe
|
||||
final Source<List<Integer>, BoxedUnit> sourceUnderTest = Source
|
||||
final Source<List<Integer>, NotUsed> sourceUnderTest = Source
|
||||
.from(Arrays.asList(1, 2, 3, 4))
|
||||
.grouped(2);
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ public class StreamTestKitDocTest {
|
|||
@Test
|
||||
public void testSinkProbe() {
|
||||
//#test-sink-probe
|
||||
final Source<Integer, BoxedUnit> sourceUnderTest = Source.from(Arrays.asList(1, 2, 3, 4))
|
||||
final Source<Integer, NotUsed> sourceUnderTest = Source.from(Arrays.asList(1, 2, 3, 4))
|
||||
.filter(elem -> elem % 2 == 0)
|
||||
.map(elem -> elem * 2);
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ public class StreamTestKitDocTest {
|
|||
@Test
|
||||
public void testSourceProbe() {
|
||||
//#test-source-probe
|
||||
final Sink<Integer, BoxedUnit> sinkUnderTest = Sink.cancelled();
|
||||
final Sink<Integer, NotUsed> sinkUnderTest = Sink.cancelled();
|
||||
|
||||
TestSource.<Integer>probe(system)
|
||||
.toMat(sinkUnderTest, Keep.left())
|
||||
|
|
@ -199,7 +199,7 @@ public class StreamTestKitDocTest {
|
|||
@Test
|
||||
public void testSourceAndTestSink() throws Exception {
|
||||
//#test-source-and-sink
|
||||
final Flow<Integer, Integer, BoxedUnit> flowUnderTest = Flow.of(Integer.class)
|
||||
final Flow<Integer, Integer, NotUsed> flowUnderTest = Flow.of(Integer.class)
|
||||
.mapAsyncUnordered(2, sleep -> akka.pattern.Patterns.after(
|
||||
Duration.create(10, TimeUnit.MILLISECONDS),
|
||||
system.scheduler(),
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
package docs.stream;
|
||||
|
||||
import akka.Done;
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.dispatch.Foreach;
|
||||
import akka.japi.JavaPartialFunction;
|
||||
|
|
@ -20,7 +22,6 @@ import org.junit.Test;
|
|||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -167,7 +168,7 @@ public class TwitterStreamQuickstartDocTest {
|
|||
public static final Hashtag AKKA = new Hashtag("#akka");
|
||||
//#model
|
||||
|
||||
public static final Source<Tweet, BoxedUnit> tweets = Source.from(
|
||||
public static final Source<Tweet, NotUsed> tweets = Source.from(
|
||||
Arrays.asList(new Tweet[] {
|
||||
new Tweet(new Author("rolandkuhn"), System.currentTimeMillis(), "#akka rocks!"),
|
||||
new Tweet(new Author("patriknw"), System.currentTimeMillis(), "#akka !"),
|
||||
|
|
@ -184,7 +185,7 @@ public class TwitterStreamQuickstartDocTest {
|
|||
|
||||
static abstract class Example0 {
|
||||
//#tweet-source
|
||||
Source<Tweet, BoxedUnit> tweets;
|
||||
Source<Tweet, NotUsed> tweets;
|
||||
//#tweet-source
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +221,7 @@ public class TwitterStreamQuickstartDocTest {
|
|||
//#first-sample
|
||||
|
||||
//#authors-filter-map
|
||||
final Source<Author, BoxedUnit> authors =
|
||||
final Source<Author, NotUsed> authors =
|
||||
tweets
|
||||
.filter(t -> t.hashtags().contains(AKKA))
|
||||
.map(t -> t.author);
|
||||
|
|
@ -241,7 +242,7 @@ public class TwitterStreamQuickstartDocTest {
|
|||
}
|
||||
};
|
||||
|
||||
final Source<Author, BoxedUnit> authors =
|
||||
final Source<Author, NotUsed> authors =
|
||||
tweets.collect(collectFunction);
|
||||
//#authors-collect
|
||||
};
|
||||
|
|
@ -261,22 +262,22 @@ public class TwitterStreamQuickstartDocTest {
|
|||
@Test
|
||||
public void demonstrateMapConcat() {
|
||||
//#hashtags-mapConcat
|
||||
final Source<Hashtag, BoxedUnit> hashtags =
|
||||
final Source<Hashtag, NotUsed> hashtags =
|
||||
tweets.mapConcat(t -> new ArrayList<Hashtag>(t.hashtags()));
|
||||
//#hashtags-mapConcat
|
||||
}
|
||||
|
||||
static abstract class HiddenDefinitions {
|
||||
//#flow-graph-broadcast
|
||||
Sink<Author, BoxedUnit> writeAuthors;
|
||||
Sink<Hashtag, BoxedUnit> writeHashtags;
|
||||
Sink<Author, NotUsed> writeAuthors;
|
||||
Sink<Hashtag, NotUsed> writeHashtags;
|
||||
//#flow-graph-broadcast
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demonstrateBroadcast() {
|
||||
final Sink<Author, Future<BoxedUnit>> writeAuthors = Sink.ignore();
|
||||
final Sink<Hashtag, Future<BoxedUnit>> writeHashtags = Sink.ignore();
|
||||
final Sink<Author, Future<Done>> writeAuthors = Sink.ignore();
|
||||
final Sink<Hashtag, Future<Done>> writeHashtags = Sink.ignore();
|
||||
|
||||
//#flow-graph-broadcast
|
||||
RunnableGraph.fromGraph(GraphDSL.create(b -> {
|
||||
|
|
@ -340,7 +341,7 @@ public class TwitterStreamQuickstartDocTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateMaterializeMultipleTimes() {
|
||||
final Source<Tweet, BoxedUnit> tweetsInMinuteFromNow = tweets; // not really in second, just acting as if
|
||||
final Source<Tweet, NotUsed> tweetsInMinuteFromNow = tweets; // not really in second, just acting as if
|
||||
|
||||
//#tweets-runnable-flow-materialized-twice
|
||||
final Sink<Integer, Future<Integer>> sumSink =
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import akka.Done;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.ActorAttributes;
|
||||
import akka.stream.javadsl.Sink;
|
||||
|
|
@ -18,7 +19,6 @@ import org.junit.AfterClass;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import scala.concurrent.Future;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import akka.stream.*;
|
||||
import akka.testkit.JavaTestKit;
|
||||
|
|
@ -55,7 +55,7 @@ public class StreamFileDocTest {
|
|||
|
||||
try {
|
||||
//#file-source
|
||||
Sink<ByteString, Future<BoxedUnit>> printlnSink =
|
||||
Sink<ByteString, Future<Done>> printlnSink =
|
||||
Sink.foreach(chunk -> System.out.println(chunk.utf8String()));
|
||||
|
||||
Future<Long> bytesWritten =
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package docs.stream.io;
|
|||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.stream.io.Framing;
|
||||
import docs.stream.SilenceSystemOut;
|
||||
import java.net.InetSocketAddress;
|
||||
|
|
@ -14,7 +15,6 @@ import org.junit.AfterClass;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import scala.concurrent.Future;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.*;
|
||||
|
|
@ -74,7 +74,7 @@ public class StreamTcpDocTest {
|
|||
connections.runForeach(connection -> {
|
||||
System.out.println("New connection from: " + connection.remoteAddress());
|
||||
|
||||
final Flow<ByteString, ByteString, BoxedUnit> echo = Flow.of(ByteString.class)
|
||||
final Flow<ByteString, ByteString, NotUsed> echo = Flow.of(ByteString.class)
|
||||
.via(Framing.delimiter(ByteString.fromString("\n"), 256, false))
|
||||
.map(bytes -> bytes.utf8String())
|
||||
.map(s -> s + "!!!\n")
|
||||
|
|
@ -110,9 +110,9 @@ public class StreamTcpDocTest {
|
|||
final String welcomeMsg = "Welcome to: " + connection.localAddress() +
|
||||
" you are: " + connection.remoteAddress() + "!\n";
|
||||
|
||||
final Source<ByteString, BoxedUnit> welcome =
|
||||
final Source<ByteString, NotUsed> welcome =
|
||||
Source.single(ByteString.fromString(welcomeMsg));
|
||||
final Flow<ByteString, ByteString, BoxedUnit> echoFlow =
|
||||
final Flow<ByteString, ByteString, NotUsed> echoFlow =
|
||||
Flow.of(ByteString.class)
|
||||
.via(Framing.delimiter(ByteString.fromString("\n"), 256, false))
|
||||
.map(bytes -> bytes.utf8String())
|
||||
|
|
@ -126,7 +126,7 @@ public class StreamTcpDocTest {
|
|||
.map(s -> s + "\n")
|
||||
.map(s -> ByteString.fromString(s));
|
||||
|
||||
final Flow<ByteString, ByteString, BoxedUnit> serverLogic =
|
||||
final Flow<ByteString, ByteString, NotUsed> serverLogic =
|
||||
Flow.fromGraph(GraphDSL.create(builder -> {
|
||||
final UniformFanInShape<ByteString, ByteString> concat =
|
||||
builder.add(Concat.create());
|
||||
|
|
@ -165,7 +165,7 @@ public class StreamTcpDocTest {
|
|||
}
|
||||
};
|
||||
|
||||
final Flow<ByteString, ByteString, BoxedUnit> repl = Flow.of(ByteString.class)
|
||||
final Flow<ByteString, ByteString, NotUsed> repl = Flow.of(ByteString.class)
|
||||
.via(Framing.delimiter(ByteString.fromString("\n"), 256, false))
|
||||
.map(bytes -> bytes.utf8String())
|
||||
.map(text -> {System.out.println("Server: " + text); return "next";})
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.ActorMaterializer;
|
||||
import akka.stream.Materializer;
|
||||
|
|
@ -22,7 +23,6 @@ import scala.Tuple2;
|
|||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
|
@ -47,7 +47,7 @@ public class RecipeByteStrings extends RecipeTest {
|
|||
|
||||
final Materializer mat = ActorMaterializer.create(system);
|
||||
|
||||
final Source<ByteString, BoxedUnit> rawBytes = Source.from(Arrays.asList(
|
||||
final Source<ByteString, NotUsed> rawBytes = Source.from(Arrays.asList(
|
||||
ByteString.fromArray(new byte[] { 1, 2 }),
|
||||
ByteString.fromArray(new byte[] { 3 }),
|
||||
ByteString.fromArray(new byte[] { 4, 5, 6 }),
|
||||
|
|
@ -93,7 +93,7 @@ public class RecipeByteStrings extends RecipeTest {
|
|||
|
||||
{
|
||||
//#bytestring-chunker2
|
||||
Source<ByteString, BoxedUnit> chunksStream =
|
||||
Source<ByteString, NotUsed> chunksStream =
|
||||
rawBytes.transform(() -> new Chunker(CHUNK_LIMIT));
|
||||
//#bytestring-chunker2
|
||||
|
||||
|
|
@ -143,17 +143,17 @@ public class RecipeByteStrings extends RecipeTest {
|
|||
|
||||
{
|
||||
//#bytes-limiter2
|
||||
Flow<ByteString, ByteString, BoxedUnit> limiter =
|
||||
Flow<ByteString, ByteString, NotUsed> limiter =
|
||||
Flow.of(ByteString.class).transform(() -> new ByteLimiter(SIZE_LIMIT));
|
||||
//#bytes-limiter2
|
||||
|
||||
final Source<ByteString, BoxedUnit> bytes1 = Source.from(Arrays.asList(
|
||||
final Source<ByteString, NotUsed> bytes1 = Source.from(Arrays.asList(
|
||||
ByteString.fromArray(new byte[] { 1, 2 }),
|
||||
ByteString.fromArray(new byte[] { 3 }),
|
||||
ByteString.fromArray(new byte[] { 4, 5, 6 }),
|
||||
ByteString.fromArray(new byte[] { 7, 8, 9 })));
|
||||
|
||||
final Source<ByteString, BoxedUnit> bytes2 = Source.from(Arrays.asList(
|
||||
final Source<ByteString, NotUsed> bytes2 = Source.from(Arrays.asList(
|
||||
ByteString.fromArray(new byte[] { 1, 2 }),
|
||||
ByteString.fromArray(new byte[] { 3 }),
|
||||
ByteString.fromArray(new byte[] { 4, 5, 6 }),
|
||||
|
|
@ -184,14 +184,14 @@ public class RecipeByteStrings extends RecipeTest {
|
|||
public void compacting() throws Exception {
|
||||
new JavaTestKit(system) {
|
||||
{
|
||||
final Source<ByteString, BoxedUnit> rawBytes = Source.from(Arrays.asList(
|
||||
final Source<ByteString, NotUsed> rawBytes = Source.from(Arrays.asList(
|
||||
ByteString.fromArray(new byte[] { 1, 2 }),
|
||||
ByteString.fromArray(new byte[] { 3 }),
|
||||
ByteString.fromArray(new byte[] { 4, 5, 6 }),
|
||||
ByteString.fromArray(new byte[] { 7, 8, 9 })));
|
||||
|
||||
//#compacting-bytestrings
|
||||
Source<ByteString, BoxedUnit> compacted = rawBytes.map(bs -> bs.compact());
|
||||
Source<ByteString, NotUsed> compacted = rawBytes.map(bs -> bs.compact());
|
||||
//#compacting-bytestrings
|
||||
|
||||
FiniteDuration timeout = FiniteDuration.create(3, TimeUnit.SECONDS);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.ActorMaterializer;
|
||||
import akka.stream.Materializer;
|
||||
|
|
@ -19,7 +20,6 @@ import org.junit.BeforeClass;
|
|||
import org.junit.Test;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
|
@ -80,12 +80,12 @@ public class RecipeDigest extends RecipeTest {
|
|||
//#calculating-digest
|
||||
|
||||
{
|
||||
Source<ByteString, BoxedUnit> data = Source.from(Arrays.asList(
|
||||
Source<ByteString, NotUsed> data = Source.from(Arrays.asList(
|
||||
ByteString.fromString("abcdbcdecdef"),
|
||||
ByteString.fromString("defgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
|
||||
|
||||
//#calculating-digest2
|
||||
final Source<ByteString, BoxedUnit> digest = data
|
||||
final Source<ByteString, NotUsed> digest = data
|
||||
.transform(() -> digestCalculator("SHA-256"));
|
||||
//#calculating-digest2
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.Done;
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.*;
|
||||
import akka.stream.javadsl.*;
|
||||
|
|
@ -11,7 +13,6 @@ import org.junit.AfterClass;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import scala.concurrent.Future;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -37,7 +38,7 @@ public class RecipeDroppyBroadcast extends RecipeTest {
|
|||
new JavaTestKit(system) {
|
||||
//#droppy-bcast
|
||||
// Makes a sink drop elements if too slow
|
||||
public <T> Sink<T, Future<BoxedUnit>> droppySink(Sink<T, Future<BoxedUnit>> sink, int size) {
|
||||
public <T> Sink<T, Future<Done>> droppySink(Sink<T, Future<Done>> sink, int size) {
|
||||
return Flow.<T> create()
|
||||
.buffer(size, OverflowStrategy.dropHead())
|
||||
.toMat(sink, Keep.right());
|
||||
|
|
@ -50,11 +51,11 @@ public class RecipeDroppyBroadcast extends RecipeTest {
|
|||
nums.add(i + 1);
|
||||
}
|
||||
|
||||
final Sink<Integer, Future<BoxedUnit>> mySink1 = Sink.ignore();
|
||||
final Sink<Integer, Future<BoxedUnit>> mySink2 = Sink.ignore();
|
||||
final Sink<Integer, Future<BoxedUnit>> mySink3 = Sink.ignore();
|
||||
final Sink<Integer, Future<Done>> mySink1 = Sink.ignore();
|
||||
final Sink<Integer, Future<Done>> mySink2 = Sink.ignore();
|
||||
final Sink<Integer, Future<Done>> mySink3 = Sink.ignore();
|
||||
|
||||
final Source<Integer, BoxedUnit> myData = Source.from(nums);
|
||||
final Source<Integer, NotUsed> myData = Source.from(nums);
|
||||
|
||||
//#droppy-bcast2
|
||||
RunnableGraph.fromGraph(GraphDSL.create(builder -> {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.ActorMaterializer;
|
||||
import akka.stream.Materializer;
|
||||
|
|
@ -14,7 +15,6 @@ import org.junit.BeforeClass;
|
|||
import org.junit.Test;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
|
@ -42,12 +42,12 @@ public class RecipeFlattenList extends RecipeTest {
|
|||
public void workWithMapConcat() throws Exception {
|
||||
new JavaTestKit(system) {
|
||||
{
|
||||
Source<List<Message>, BoxedUnit> someDataSource = Source
|
||||
Source<List<Message>, NotUsed> someDataSource = Source
|
||||
.from(Arrays.asList(Arrays.asList(new Message("1")), Arrays.asList(new Message("2"), new Message("3"))));
|
||||
|
||||
//#flattening-lists
|
||||
Source<List<Message>, BoxedUnit> myData = someDataSource;
|
||||
Source<Message, BoxedUnit> flattened = myData.mapConcat(i -> i);
|
||||
Source<List<Message>, NotUsed> myData = someDataSource;
|
||||
Source<Message, NotUsed> flattened = myData.mapConcat(i -> i);
|
||||
//#flattening-lists
|
||||
|
||||
List<Message> got = Await.result(flattened.grouped(10).runWith(Sink.head(), mat),
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.*;
|
||||
import akka.dispatch.Mapper;
|
||||
import akka.japi.pf.ReceiveBuilder;
|
||||
|
|
@ -22,6 +23,7 @@ import scala.concurrent.duration.Duration;
|
|||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
|
@ -142,9 +144,9 @@ public class RecipeGlobalRateLimit extends RecipeTest {
|
|||
public void work() throws Exception {
|
||||
new JavaTestKit(system) {
|
||||
//#global-limiter-flow
|
||||
public <T> Flow<T, T, BoxedUnit> limitGlobal(ActorRef limiter, FiniteDuration maxAllowedWait) {
|
||||
public <T> Flow<T, T, NotUsed> limitGlobal(ActorRef limiter, FiniteDuration maxAllowedWait) {
|
||||
final int parallelism = 4;
|
||||
final Flow<T, T, BoxedUnit> f = Flow.create();
|
||||
final Flow<T, T, NotUsed> f = Flow.create();
|
||||
|
||||
return f.mapAsync(parallelism, element -> {
|
||||
final Timeout triggerTimeout = new Timeout(maxAllowedWait);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.ActorMaterializer;
|
||||
import akka.stream.Materializer;
|
||||
|
|
@ -12,7 +13,6 @@ import akka.util.ByteString;
|
|||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ public class RecipeKeepAlive extends RecipeTest {
|
|||
|
||||
//@formatter:off
|
||||
//#inject-keepalive
|
||||
Flow<ByteString, ByteString, BoxedUnit> keepAliveInject =
|
||||
Flow<ByteString, ByteString, NotUsed> keepAliveInject =
|
||||
Flow.of(ByteString.class).keepAlive(
|
||||
scala.concurrent.duration.Duration.create(1, TimeUnit.SECONDS),
|
||||
() -> keepAliveMessage);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
|
|
@ -19,7 +20,6 @@ import org.junit.AfterClass;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import scala.runtime.AbstractFunction0;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ public class RecipeLoggingElements extends RecipeTest {
|
|||
final SilenceSystemOut.System System = SilenceSystemOut.get(getTestActor());
|
||||
|
||||
{
|
||||
final Source<String, BoxedUnit> mySource = Source.from(Arrays.asList("1", "2", "3"));
|
||||
final Source<String, NotUsed> mySource = Source.from(Arrays.asList("1", "2", "3"));
|
||||
|
||||
//#println-debug
|
||||
mySource.map(elem -> {
|
||||
|
|
@ -65,7 +65,7 @@ public class RecipeLoggingElements extends RecipeTest {
|
|||
}
|
||||
|
||||
{
|
||||
final Source<String, BoxedUnit> mySource = Source.from(Arrays.asList("1", "2", "3"));
|
||||
final Source<String, NotUsed> mySource = Source.from(Arrays.asList("1", "2", "3"));
|
||||
|
||||
final int onElement = Logging.WarningLevel();
|
||||
final int onFinish = Logging.ErrorLevel();
|
||||
|
|
@ -82,7 +82,8 @@ public class RecipeLoggingElements extends RecipeTest {
|
|||
mySource.log("custom", adapter);
|
||||
//#log-custom
|
||||
|
||||
new DebugFilter("customLogger", "[custom] Element: ", false, false, 3).intercept(new AbstractFunction0 () {
|
||||
|
||||
new DebugFilter("customLogger", "[custom] Element: ", false, false, 3).intercept(new AbstractFunction0<Object> () {
|
||||
public Void apply() {
|
||||
mySource.log("custom", adapter).runWith(Sink.ignore(), mat);
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.japi.Pair;
|
||||
import akka.stream.ActorMaterializer;
|
||||
|
|
@ -23,7 +24,6 @@ import org.junit.Test;
|
|||
import scala.concurrent.Await;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
|
@ -57,11 +57,11 @@ public class RecipeMissedTicks extends RecipeTest {
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
//#missed-ticks
|
||||
final Flow<Tick, Integer, BoxedUnit> missedTicks =
|
||||
final Flow<Tick, Integer, NotUsed> missedTicks =
|
||||
Flow.of(Tick.class).conflate(tick -> 0, (missed, tick) -> missed + 1);
|
||||
//#missed-ticks
|
||||
final TestLatch latch = new TestLatch(3, system);
|
||||
final Flow<Tick, Integer, BoxedUnit> realMissedTicks =
|
||||
final Flow<Tick, Integer, NotUsed> realMissedTicks =
|
||||
Flow.of(Tick.class).conflate(tick -> 0, (missed, tick) -> { latch.countDown(); return missed + 1; });
|
||||
|
||||
Pair<TestPublisher.Probe<Tick>, TestSubscriber.Probe<Integer>> pubSub =
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.japi.Function;
|
||||
import akka.japi.Pair;
|
||||
|
|
@ -18,7 +19,6 @@ import org.junit.Test;
|
|||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -93,14 +93,14 @@ public class RecipeMultiGroupByTest extends RecipeTest {
|
|||
|
||||
{
|
||||
|
||||
final Source<Message, BoxedUnit> elems = Source
|
||||
final Source<Message, NotUsed> elems = Source
|
||||
.from(Arrays.asList("1: a", "1: b", "all: c", "all: d", "1: e"))
|
||||
.map(s -> new Message(s));
|
||||
|
||||
//#multi-groupby
|
||||
final Function<Message, List<Topic>> topicMapper = m -> extractTopics(m);
|
||||
|
||||
final Source<Pair<Message, Topic>, BoxedUnit> messageAndTopic = elems
|
||||
final Source<Pair<Message, Topic>, NotUsed> messageAndTopic = elems
|
||||
.mapConcat((Message msg) -> {
|
||||
List<Topic> topicsForMessage = topicMapper.apply(msg);
|
||||
// Create a (Msg, Topic) pair for each of the topics
|
||||
|
|
@ -112,7 +112,7 @@ public class RecipeMultiGroupByTest extends RecipeTest {
|
|||
.collect(toList());
|
||||
});
|
||||
|
||||
SubSource<Pair<Message, Topic>, BoxedUnit> multiGroups = messageAndTopic
|
||||
SubSource<Pair<Message, Topic>, NotUsed> multiGroups = messageAndTopic
|
||||
.groupBy(2, pair -> pair.second())
|
||||
.map(pair -> {
|
||||
Message message = pair.first();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.ActorMaterializer;
|
||||
import akka.stream.Materializer;
|
||||
|
|
@ -16,7 +17,6 @@ import org.junit.BeforeClass;
|
|||
import org.junit.Test;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -40,7 +40,7 @@ public class RecipeParseLines extends RecipeTest {
|
|||
|
||||
@Test
|
||||
public void parseLines() throws Exception {
|
||||
final Source<ByteString, BoxedUnit> rawData = Source.from(Arrays.asList(
|
||||
final Source<ByteString, NotUsed> rawData = Source.from(Arrays.asList(
|
||||
ByteString.fromString("Hello World"),
|
||||
ByteString.fromString("\r"),
|
||||
ByteString.fromString("!\r"),
|
||||
|
|
@ -48,7 +48,7 @@ public class RecipeParseLines extends RecipeTest {
|
|||
ByteString.fromString("\r\n\r\n")));
|
||||
|
||||
//#parse-lines
|
||||
final Source<String, BoxedUnit> lines = rawData
|
||||
final Source<String, NotUsed> lines = rawData
|
||||
.via(Framing.delimiter(ByteString.fromString("\r\n"), 100, true))
|
||||
.map(b -> b.utf8String());
|
||||
//#parse-lines
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.japi.Pair;
|
||||
import akka.japi.function.Function;
|
||||
|
|
@ -19,7 +20,6 @@ import org.junit.BeforeClass;
|
|||
import org.junit.Test;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -47,12 +47,12 @@ public class RecipeReduceByKeyTest extends RecipeTest {
|
|||
public void work() throws Exception {
|
||||
new JavaTestKit(system) {
|
||||
{
|
||||
final Source<String, BoxedUnit> words = Source.from(Arrays.asList("hello", "world", "and", "hello", "akka"));
|
||||
final Source<String, NotUsed> words = Source.from(Arrays.asList("hello", "world", "and", "hello", "akka"));
|
||||
|
||||
//#word-count
|
||||
final int MAXIMUM_DISTINCT_WORDS = 1000;
|
||||
|
||||
final Source<Pair<String, Integer>, BoxedUnit> counts = words
|
||||
final Source<Pair<String, Integer>, NotUsed> counts = words
|
||||
// split the words into separate streams first
|
||||
.groupBy(MAXIMUM_DISTINCT_WORDS, i -> i)
|
||||
// add counting logic to the streams
|
||||
|
|
@ -74,7 +74,7 @@ public class RecipeReduceByKeyTest extends RecipeTest {
|
|||
}
|
||||
|
||||
//#reduce-by-key-general
|
||||
static public <In, K, Out> Flow<In, Pair<K, Out>, BoxedUnit> reduceByKey(
|
||||
static public <In, K, Out> Flow<In, Pair<K, Out>, NotUsed> reduceByKey(
|
||||
int maximumGroupSize,
|
||||
Function<In, K> groupKey,
|
||||
Function<K, Out> foldZero,
|
||||
|
|
@ -96,12 +96,12 @@ public class RecipeReduceByKeyTest extends RecipeTest {
|
|||
public void workGeneralised() throws Exception {
|
||||
new JavaTestKit(system) {
|
||||
{
|
||||
final Source<String, BoxedUnit> words = Source.from(Arrays.asList("hello", "world", "and", "hello", "akka"));
|
||||
final Source<String, NotUsed> words = Source.from(Arrays.asList("hello", "world", "and", "hello", "akka"));
|
||||
|
||||
//#reduce-by-key-general2
|
||||
final int MAXIMUM_DISTINCT_WORDS = 1000;
|
||||
|
||||
Source<Pair<String, Integer>, BoxedUnit> counts = words.via(reduceByKey(
|
||||
Source<Pair<String, Integer>, NotUsed> counts = words.via(reduceByKey(
|
||||
MAXIMUM_DISTINCT_WORDS,
|
||||
word -> word,
|
||||
key -> 0,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.japi.Pair;
|
||||
import akka.stream.ActorMaterializer;
|
||||
|
|
@ -19,7 +20,6 @@ import org.junit.BeforeClass;
|
|||
import org.junit.Test;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
|
@ -45,11 +45,11 @@ public class RecipeSimpleDrop extends RecipeTest {
|
|||
{
|
||||
@SuppressWarnings("unused")
|
||||
//#simple-drop
|
||||
final Flow<Message, Message, BoxedUnit> droppyStream =
|
||||
final Flow<Message, Message, NotUsed> droppyStream =
|
||||
Flow.of(Message.class).conflate(i -> i, (lastMessage, newMessage) -> newMessage);
|
||||
//#simple-drop
|
||||
final TestLatch latch = new TestLatch(2, system);
|
||||
final Flow<Message, Message, BoxedUnit> realDroppyStream =
|
||||
final Flow<Message, Message, NotUsed> realDroppyStream =
|
||||
Flow.of(Message.class).conflate(i -> i, (lastMessage, newMessage) -> { latch.countDown(); return newMessage; });
|
||||
|
||||
final Pair<TestPublisher.Probe<Message>, TestSubscriber.Probe<Message>> pubSub = TestSource
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.ActorMaterializer;
|
||||
import akka.stream.Materializer;
|
||||
|
|
@ -15,7 +16,6 @@ import org.junit.Test;
|
|||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
|
@ -41,7 +41,7 @@ public class RecipeToStrict extends RecipeTest {
|
|||
public void workWithPrintln() throws Exception {
|
||||
new JavaTestKit(system) {
|
||||
{
|
||||
final Source<String, BoxedUnit> myData = Source.from(Arrays.asList("1", "2", "3"));
|
||||
final Source<String, NotUsed> myData = Source.from(Arrays.asList("1", "2", "3"));
|
||||
final int MAX_ALLOWED_SIZE = 100;
|
||||
|
||||
//#draining-to-list
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.stream.javadsl.cookbook;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.stream.*;
|
||||
import akka.stream.javadsl.*;
|
||||
|
|
@ -13,7 +14,6 @@ import org.junit.Test;
|
|||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
|
@ -38,8 +38,8 @@ public class RecipeWorkerPool extends RecipeTest {
|
|||
final Materializer mat = ActorMaterializer.create(system);
|
||||
|
||||
//#worker-pool
|
||||
public static <In, Out> Flow<In, Out, BoxedUnit> balancer(
|
||||
Flow<In, Out, BoxedUnit> worker, int workerCount) {
|
||||
public static <In, Out> Flow<In, Out, NotUsed> balancer(
|
||||
Flow<In, Out, NotUsed> worker, int workerCount) {
|
||||
return Flow.fromGraph(GraphDSL.create(b -> {
|
||||
boolean waitForAllDownstreams = true;
|
||||
final UniformFanOutShape<In, In> balance =
|
||||
|
|
@ -60,16 +60,16 @@ public class RecipeWorkerPool extends RecipeTest {
|
|||
public void workForVersion1() throws Exception {
|
||||
new JavaTestKit(system) {
|
||||
{
|
||||
Source<Message, BoxedUnit> data =
|
||||
Source<Message, NotUsed> data =
|
||||
Source
|
||||
.from(Arrays.asList("1", "2", "3", "4", "5"))
|
||||
.map(t -> new Message(t));
|
||||
|
||||
Flow<Message, Message, BoxedUnit> worker = Flow.of(Message.class).map(m -> new Message(m.msg + " done"));
|
||||
Flow<Message, Message, NotUsed> worker = Flow.of(Message.class).map(m -> new Message(m.msg + " done"));
|
||||
|
||||
//#worker-pool2
|
||||
Flow<Message, Message, BoxedUnit> balancer = balancer(worker, 3);
|
||||
Source<Message, BoxedUnit> processedJobs = data.via(balancer);
|
||||
Flow<Message, Message, NotUsed> balancer = balancer(worker, 3);
|
||||
Source<Message, NotUsed> processedJobs = data.via(balancer);
|
||||
//#worker-pool2
|
||||
|
||||
FiniteDuration timeout = FiniteDuration.create(200, TimeUnit.MILLISECONDS);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue