本文整理汇总了Java中akka.stream.ActorMaterializer类的典型用法代码示例。如果您正苦于以下问题:Java ActorMaterializer类的具体用法?Java ActorMaterializer怎么用?Java ActorMaterializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActorMaterializer类属于akka.stream包,在下文中一共展示了ActorMaterializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
ActorSystem system = ActorSystem.create("ServiceB");
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Main app = new Main();
final ActorRef serviceBackendActor = system.actorOf(BackendActor.props(), "backendActor");
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(serviceBackendActor).flow(system, materializer);
final CompletionStage<ServerBinding> binding =
http.bindAndHandle(
routeFlow,
ConnectHttp.toHost("localhost", 8081),
materializer);
System.out.println("Server online at http://localhost:8081/\nPress RETURN to stop...");
System.in.read(); // let it run until user presses return
binding
.thenCompose(ServerBinding::unbind) // trigger unbinding from the port
.thenAccept(unbound -> system.terminate()); // and shutdown when done
}
示例2: main
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
final ActorSystem system = ActorSystem.create("ServiceA");
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
final StreamMain app = new StreamMain();
final ActorRef streamActor = system.actorOf(StreamActor.props());
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(streamActor).flow(system, materializer);
final CompletionStage<ServerBinding> binding =
http.bindAndHandle(
routeFlow,
ConnectHttp.toHost("localhost", 8080),
materializer);
System.out.println("Server online at http://localhost:8080/\nPress RETURN to stop...");
System.in.read(); // let it run until user presses return
System.in.read(); // let it run until user presses return
binding
.thenCompose(ServerBinding::unbind) // trigger unbinding from the port
.thenAccept(unbound -> system.terminate()); // and shutdown when done
}
示例3: run
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public void run() {
final Config conf = parseString("akka.remote.netty.tcp.hostname=" + config.hostname())
.withFallback(parseString("akka.remote.netty.tcp.port=" + config.actorPort()))
.withFallback(ConfigFactory.load("remote"));
final ActorSystem system = ActorSystem.create("concierge", conf);
kv = system.actorOf(LinearizableStorage.props(new Cluster(config.cluster().paths(), "kv")), "kv");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Flow<HttpRequest, HttpResponse, NotUsed> theFlow = createRoute().flow(system, materializer);
final ConnectHttp host = ConnectHttp.toHost(config.hostname(), config.clientPort());
Http.get(system).bindAndHandle(theFlow, host, materializer);
LOG.info("Ama up");
}
示例4: main
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public static void main(String[] args) {
final ActorSystem system = ActorSystem.create("KafkaProducerSystem");
final Materializer materializer = ActorMaterializer.create(system);
final ProducerSettings<byte[], String> producerSettings =
ProducerSettings
.create(system, new ByteArraySerializer(), new StringSerializer())
.withBootstrapServers("localhost:9092");
CompletionStage<Done> done =
Source.range(1, 100)
.map(n -> n.toString())
.map(elem ->
new ProducerRecord<byte[], String>(
"topic1-ts",
0,
Instant.now().getEpochSecond(),
null,
elem))
.runWith(Producer.plainSink(producerSettings), materializer);
done.whenComplete((d, ex) -> System.out.println("sent"));
}
示例5: main
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
final ActorSystem system = ActorSystem.create();
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Route route = InfillionRoutes.routes();
final Flow<HttpRequest, HttpResponse, NotUsed> flow = route.flow(system, materializer);
final Http http = Http.get(system);
final CompletionStage<ServerBinding> bindings = http.bindAndHandle(flow, ConnectHttp.toHost("127.0.0.1", 8080), materializer);
System.out.println("Type RETURN to exit");
System.in.read();
bindings
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例6: testReactiveStream
import akka.stream.ActorMaterializer; //导入依赖的package包/类
@Test
public void testReactiveStream() throws InterruptedException, TimeoutException {
final ActorSystem system =
ActorSystem.create("MySystem");
final Materializer mat =
ActorMaterializer.create(system);
Source<Integer, NotUsed> source = Source.range(1, 5);
Flow<Integer, Integer, NotUsed> flow = Flow
.fromFunction(x -> x + 1);
Source<Integer, NotUsed> source2 = source.via(flow);
Sink<Integer, CompletionStage<Integer>> fold =
Sink.<Integer, Integer>fold(0, (next, total) -> total + next);
CompletionStage<Integer> integerCompletionStage = source2.runWith(fold, mat);
integerCompletionStage.thenAccept(System.out::println);
Thread.sleep(3000);
Await.ready(system.terminate(), Duration.apply(10, TimeUnit.SECONDS));
}
示例7: testReactiveStreamRefined
import akka.stream.ActorMaterializer; //导入依赖的package包/类
@Test
public void testReactiveStreamRefined() throws InterruptedException, TimeoutException {
final ActorSystem system =
ActorSystem.create("MySystem");
final Materializer mat =
ActorMaterializer.create(system);
Source<Integer, NotUsed> source = Source.range(1, 5).map(x -> x + 1)
.fold(0, (next, total) -> total + next);
CompletionStage<Integer> integerCompletionStage =
source.runWith(Sink.head(), mat);
integerCompletionStage.thenAccept(System.out::println);
Thread.sleep(3000);
Await.ready(system.terminate(), Duration.apply(10, TimeUnit.SECONDS));
}
示例8: SharedActorSystemSpec
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public SharedActorSystemSpec(Config additionalConfig) {
synchronized (SharedActorSystemSpec.class) {
if (!configs.containsKey(additionalConfig)) {
Config config = additionalConfig
.withFallback(ConfigFactory.parseResources("com/tradeshift/reaktive/testkit/SharedActorSystemSpec.conf"))
.withFallback(ConfigFactory.defaultReference())
.resolve();
configs = configs.put(additionalConfig, config);
ActorSystem system = ActorSystem.create(config.getString("akka.name"), config);
systems = systems.put(additionalConfig, system);
materializers = materializers.put(additionalConfig, ActorMaterializer.create(system));
journals = journals.put(additionalConfig, PersistenceQuery.get(system).getReadJournalFor(InMemoryReadJournal.class, InMemoryReadJournal.Identifier()));
}
}
this.config = configs.apply(additionalConfig);
this.system = systems.apply(additionalConfig);
this.materializer = materializers.apply(additionalConfig);
this.journal = journals.apply(additionalConfig);
}
示例9: importAll
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public CompletableFuture<Done> importAll() {
AtomicLong batch = new AtomicLong(0);
long start = System.currentTimeMillis();
final Materializer materializer = ActorMaterializer.create(ActorSystem.create("actor-system", ConfigFactory.load()));
Source<Page, NotUsed> channelSource = Source.fromIterator(() -> reader);
Flow<Page, List<Page>, NotUsed> processing = Flow.of(Page.class)
.filter(x -> x != null && x.getNamespace() == 0)
.buffer(cores * 100, OverflowStrategy.backpressure())
.mapAsyncUnordered(cores, x -> cleaner.clean(x))
.groupedWithin(BATCH_SIZE,
FiniteDuration.apply(1, TimeUnit.SECONDS))
.mapAsyncUnordered(cores, x -> datastore.save(x));
final CompletionStage<Done> promise = channelSource.via(processing).runForeach(x -> {
System.out.printf("Inserted: %d, Time: %d sec\n",
batch.incrementAndGet() * BATCH_SIZE,
(System.currentTimeMillis() - start) / 1000);
}, materializer);
return promise.toCompletableFuture();
}
示例10: setup
import akka.stream.ActorMaterializer; //导入依赖的package包/类
@Setup
public void setup() throws Exception {
Config cfg = ConfigFactory.parseResources(AkkaStreamsFlatMapPerf.class, "/akka-streams.conf");
actorSystem = ActorSystem.create("sys", cfg);
materializer = ActorMaterializer.create(actorSystem);
akRangeFlatMapJust = s ->
Source.range(1, times)
.flatMapMerge(maxConcurrent, v -> Source.single(v))
.runWith(Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), materializer)
.subscribe(s)
;
akRangeConcatMapJust = s ->
Source.range(1, times)
.flatMapConcat(v -> Source.single(v))
.runWith(Sink.asPublisher(AsPublisher.WITHOUT_FANOUT), materializer)
.subscribe(s)
;
}
示例11: start
import akka.stream.ActorMaterializer; //导入依赖的package包/类
@BeforeClass
public void start() throws Exception {
executorService = Executors.newCachedThreadPool();
actorSystem = ActorSystem.create();
materializer = ActorMaterializer.create(actorSystem);
helper = new HttpHelper(materializer);
eventLoop = new NioEventLoopGroup();
ProcessorHttpServer server = new ProcessorHttpServer(eventLoop);
// A flow that echos HttpRequest bodies in HttpResponse bodies
final Flow<HttpRequest, HttpResponse, NotUsed> flow = Flow.<HttpRequest>create().map(
new Function<HttpRequest, HttpResponse>() {
public HttpResponse apply(HttpRequest request) throws Exception {
return helper.echo(request);
}
}
);
serverBindChannel = server.bind(new InetSocketAddress("127.0.0.1", 0), new Callable<Processor<HttpRequest, HttpResponse>>() {
@Override
public Processor<HttpRequest, HttpResponse> call() throws Exception {
return AkkaStreamsUtil.flowToProcessor(flow, materializer);
}
}).await().channel();
}
开发者ID:playframework,项目名称:netty-reactive-streams,代码行数:26,代码来源:FullStackHttpIdentityProcessorVerificationTest.java
示例12: main
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
final ActorSystem system = ActorSystem.create("example");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Http http = Http.get(system);
final MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
final SetSessionJava app = new SetSessionJava(dispatcher);
final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server started, press enter to stop");
System.in.read();
binding
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例13: main
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
final ActorSystem system = ActorSystem.create("example");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Http http = Http.get(system);
final MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
final VariousSessionsJava app = new VariousSessionsJava(dispatcher);
final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server started, press enter to stop");
System.in.read();
binding
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例14: main
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
// ** akka-http boiler plate **
ActorSystem system = ActorSystem.create("example");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Http http = Http.get(system);
// ** akka-http-session setup **
MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
final SessionInvalidationJava app = new SessionInvalidationJava(dispatcher);
// ** akka-http boiler plate continued **
final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server started, press enter to stop");
System.in.read();
binding
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}
示例15: main
import akka.stream.ActorMaterializer; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
// ** akka-http boiler plate **
ActorSystem system = ActorSystem.create("example");
final ActorMaterializer materializer = ActorMaterializer.create(system);
final Http http = Http.get(system);
// ** akka-http-session setup **
MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
final JavaJwtExample app = new JavaJwtExample(dispatcher);
// ** akka-http boiler plate continued **
final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);
System.out.println("Server started, press enter to stop");
System.in.read();
binding
.thenCompose(ServerBinding::unbind)
.thenAccept(unbound -> system.terminate());
}