当前位置: 首页>>代码示例>>Java>>正文


Java Reactor.on方法代码示例

本文整理汇总了Java中reactor.core.Reactor.on方法的典型用法代码示例。如果您正苦于以下问题:Java Reactor.on方法的具体用法?Java Reactor.on怎么用?Java Reactor.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reactor.core.Reactor的用法示例。


在下文中一共展示了Reactor.on方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import reactor.core.Reactor; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
	Environment env = new Environment();
	Reactor reactor = Reactors.reactor().env(env).dispatcher(Environment.THREAD_POOL).get();

	// topic: parse
	reactor.on($("parse"), App::handleEvent1);
	reactor.on($("parse"), App::handleEvent2);

	// Notify consumers of the 'parse' topic that data is ready
	// by passing a Supplier<Event<T>> in the form of a lambda

	for (long l = 0; true; l++) {
		String obj = "Test-" + l;
		reactor.notify("parse", Event.wrap(new ObjectEvent().setObject(obj)));
		Thread.sleep(1000);
	}

}
 
开发者ID:smallnest,项目名称:DisruptorBootstrap,代码行数:19,代码来源:App.java

示例2: main

import reactor.core.Reactor; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    Environment env = new Environment();
    final TradeServer server = new TradeServer();

    // Use a Reactor to dispatch events using the default Dispatcher
    Reactor reactor = Reactors.reactor()
            .env(env)
            .dispatcher("ringBuffer")
            .get();

    String topic = "trade.execute";

    // For each Trade event, execute that on the server
    reactor.on($(topic), new Consumer<Event<Trade>>() {
        @Override
        public void accept(Event<Trade> tradeEvent) {
            server.execute(tradeEvent.getData());

            // Since we're async, for this test, use a latch to tell when we're done
            latch.countDown();
        }
    });

    // Start a throughput timer
    startTimer();

    // Publish one event per trade
    for (int i = 0; i < totalTrades; i++) {
        // Pull next randomly-generated Trade from server
        Trade t = server.nextTrade();

        // Notify the Reactor the event is ready to be handled
        reactor.notify(topic, Event.wrap(t));
    }

    // Stop throughput timer and output metrics
    endTimer();

    server.stop();
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:41,代码来源:TradeServerExample.java

示例3: reactor

import reactor.core.Reactor; //导入方法依赖的package包/类
@Bean
public Reactor reactor(Environment env, MailServer mailServer) {
    Logger log = LoggerFactory.getLogger("mail.server");
    Reactor r = Reactors.reactor(env);

    // Wire an event handler to execute messages
    r.on($("mail.execute"), (Event<MessageDescriptor> ev) -> {
        mailServer.execute(ev.getData());
        log.info("Executed message: {}", ev.getData());
    });

    return r;
}
 
开发者ID:mdarapour,项目名称:microservice-workshop,代码行数:14,代码来源:BootMailServer.java


注:本文中的reactor.core.Reactor.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。