• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Consumer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中reactor.function.Consumer的典型用法代码示例。如果您正苦于以下问题:Java Consumer类的具体用法?Java Consumer怎么用?Java Consumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: thumbnailImage

import reactor.function.Consumer; //导入依赖的package包/类
/**
 * Accept an image upload via POST and notify a Reactor that the image needs to be thumbnailed. Asynchronously respond
 * to the client when the thumbnailing has completed.
 *
 * @param channel
 *     the channel on which to send an HTTP response
 * @param thumbnail
 *     a reference to the shared thumbnail path
 * @param reactor
 *     the Reactor on which to publish events
 *
 * @return a consumer to handle HTTP requests
 */
public static Consumer<FullHttpRequest> thumbnailImage(NetChannel<FullHttpRequest, FullHttpResponse> channel,
                                                       AtomicReference<Path> thumbnail,
                                                       Reactor reactor) {
  return req -> {
    if (req.getMethod() != HttpMethod.POST) {
      channel.send(badRequest(req.getMethod() + " not supported for this URI"));
      return;
    }

    // write to a temp file
    Path imgIn = null;
    try {
      imgIn = readUpload(req.content());
    } catch (IOException e) {
      throw new IllegalStateException(e.getMessage(), e);
    }

    // Asynchronously thumbnail the image to 250px on the long side
    reactor.sendAndReceive("thumbnail", Event.wrap(imgIn), ev -> {
      thumbnail.set(ev.getData());
      channel.send(redirect());
    });
  };
}
 
开发者ID:danielyinanc,项目名称:spring-guides,代码行数:38,代码来源:ImageThumbnailerRestApi.java


示例2: AsyncAnnotationAuditOutputStream

import reactor.function.Consumer; //导入依赖的package包/类
/**
 * Instantiates a new annotation audit output stream.
 *
 * @param outputStream            the output stream
 * @param transformer the transformer
 */
public AsyncAnnotationAuditOutputStream(final AuditOutputStream<AuditEvent> outputStream, final AnnotationTransformer transformer) {
    ENV = new Environment();
    this.outputStream = outputStream;
    b = new Boundary();
    
    annotationDeferred = Streams.<AnnotationAuditEvent> defer().env(ENV).dispatcher(Environment.RING_BUFFER).get();
    Stream<AnnotationAuditEvent> annostream = annotationDeferred.compose();
    annostream.consume(b.bind(new Consumer<AnnotationAuditEvent>() {
        @Override
        public void accept(AnnotationAuditEvent annotationEvent) {
            AuditEvent event = transformer.transformToEvent(annotationEvent);
            // event is null if annotation is not found
            if (event != null) {
                outputStream.write(event);
            }
        }
    }));
}
 
开发者ID:audit4j,项目名称:audit4j-core,代码行数:25,代码来源:AsyncAnnotationAuditOutputStream.java


示例3: AsyncAuditOutputStream

import reactor.function.Consumer; //导入依赖的package包/类
/**
 * Instantiates a new async audit output stream.
 *
 * @param outputStream the output stream
 * @param annotationStream the annotation stream
 */
public AsyncAuditOutputStream(final AuditOutputStream<AuditEvent> outputStream, final AuditOutputStream<AnnotationAuditEvent> annotationStream) {
    this.outputStream = outputStream;
    this.annotationStream = annotationStream;
    
    ENV = new Environment();
    b = new Boundary();
    deferred = Streams.<AuditEvent> defer().env(ENV).dispatcher(Environment.RING_BUFFER).get();
    Stream<AuditEvent> stream = deferred.compose();
    stream.consume(b.bind(new Consumer<AuditEvent>() {
        @Override
        public void accept(AuditEvent event) {
            outputStream.write(event);
        }
    }));
    
    batchBoundry = new Boundary();
    batchDeferred = Streams.<EventBatch> defer().env(ENV).dispatcher(Environment.RING_BUFFER).get();
    Stream<EventBatch> batchStream = batchDeferred.compose();
    batchStream.consume(batchBoundry.bind(new Consumer<EventBatch>() {
        @Override
        public void accept(EventBatch batch) {
            outputStream.writeBatch(batch);
        }
    }));
}
 
开发者ID:audit4j,项目名称:audit4j-core,代码行数:32,代码来源:AsyncAuditOutputStream.java


示例4: main

import reactor.function.Consumer; //导入依赖的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


示例5: SubscriptionManager

import reactor.function.Consumer; //导入依赖的package包/类
/**
 * Creates a new SubscriptionManager
 * @param config The extracted configuration
 */
public SubscriptionManager(final Properties config) {
	reactor = SingletonEnvironment.getInstance().getDefaultReactor();
	reactor.on(Selectors.object("subscription-terminated"), new Consumer<Event<Subscription>>(){
		@Override
		public void accept(Event<Subscription> t) {
			final Subscription termSub = t.getData();
			log.info("Terminated Subscription: [{}]", termSub);				
			allSubscriptions.remove(termSub.pattern);				
		}
	});
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:16,代码来源:SubscriptionManager.java


示例6: serveThumbnailImage

import reactor.function.Consumer; //导入依赖的package包/类
/**
 * Respond to GET requests and serve the thumbnailed image, a reference to which is kept in the given {@literal
 * AtomicReference}.
 *
 * @param channel
 *     the channel on which to send an HTTP response
 * @param thumbnail
 *     a reference to the shared thumbnail path
 *
 * @return a consumer to handle HTTP requests
 */
public static Consumer<FullHttpRequest> serveThumbnailImage(NetChannel<FullHttpRequest, FullHttpResponse> channel,
                                                            AtomicReference<Path> thumbnail) {
  return req -> {
    if (req.getMethod() != HttpMethod.GET) {
      channel.send(badRequest(req.getMethod() + " not supported for this URI"));
    } else {
      try {
        channel.send(serveImage(thumbnail.get()));
      } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
      }
    }
  };
}
 
开发者ID:danielyinanc,项目名称:spring-guides,代码行数:26,代码来源:ImageThumbnailerRestApi.java


示例7: errorHandler

import reactor.function.Consumer; //导入依赖的package包/类
/**
 * Respond to errors occurring on a Reactor by redirecting them to the client via an HTTP 500 error response.
 *
 * @param channel
 *     the channel on which to send an HTTP response
 *
 * @return a consumer to handle HTTP requests
 */
public static Consumer<Throwable> errorHandler(NetChannel<FullHttpRequest, FullHttpResponse> channel) {
  return ev -> {
    DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
                                                               HttpResponseStatus.INTERNAL_SERVER_ERROR);
    resp.content().writeBytes(ev.getMessage().getBytes());
    resp.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
    resp.headers().set(HttpHeaders.Names.CONTENT_LENGTH, resp.content().readableBytes());
    channel.send(resp);
  };
}
 
开发者ID:danielyinanc,项目名称:spring-guides,代码行数:19,代码来源:ImageThumbnailerRestApi.java


示例8: serveThumbnailImage

import reactor.function.Consumer; //导入依赖的package包/类
/**
 * Respond to GET requests and serve the thumbnailed image, a reference to which is kept in the given {@literal
 * AtomicReference}.
 *
 * @param channel
 *     the channel on which to send an HTTP response
 *
 * @return a consumer to handle HTTP requests
 */
public static Consumer<FullHttpRequest> serveThumbnailImage(NetChannel<FullHttpRequest, FullHttpResponse> channel) {
  return req -> {
    channel.send(request("Hello World!"));
  };
}
 
开发者ID:greenlaw110,项目名称:simple-webframework-benchmark,代码行数:15,代码来源:ImageThumbnailerRestApi.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UIImage类代码示例发布时间:2022-05-23
下一篇:
Java ServiceDefinition类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap