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


Java FluxSink类代码示例

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


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

示例1: test4

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
@Test
public void test4() {
    SomeFeed<PriceTick> feed = new SomeFeed<>();
    Flux<Object> priceFlux = Flux.create(emitter ->
    {
        SomeListener l = new SomeListener() {
            @Override
            public void priceTick(PriceTick event) {
                emitter.next(event);
            }

            @Override
            public void error(Throwable throwable) {
                emitter.error(throwable);
            }

        };
        feed.register(l);
    }, FluxSink.OverflowStrategy.LATEST);
    ConnectableFlux<Object> connectableFlux = priceFlux.publish();
    connectableFlux.connect();
    connectableFlux.subscribe(System.out::println);
}
 
开发者ID:vgrazi,项目名称:reactive-demo,代码行数:24,代码来源:Samples.java

示例2: CommentController

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
public CommentController(MeterRegistry meterRegistry) {
	this.meterRegistry = meterRegistry;
	this.flux = Flux.<Message<Comment>>create(
		emitter -> this.commentSink = emitter,
		FluxSink.OverflowStrategy.IGNORE)
		.publish()
		.autoConnect();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:9,代码来源:CommentController.java

示例3: test

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
@Test
public void test() throws InterruptedException {
    SomeFeed<PriceTick> feed = new SomeFeed<>();
    Flux<PriceTick> flux =
            Flux.create(emitter ->
            {
                SomeListener listener = new SomeListener() {
                    @Override
                    public void priceTick(PriceTick event) {
                        emitter.next(event);
                        if (event.isLast()) {
                            emitter.complete();
                        }
                    }

                    @Override
                    public void error(Throwable e) {
                        emitter.error(e);
                    }
                };
                        feed.register(listener);
    }, FluxSink.OverflowStrategy.LATEST);
    ConnectableFlux connectable = flux.publish();
    connectable.subscribe(x -> System.out.println("1st " + x));
    Thread.sleep(1000);
    connectable.subscribe(x -> System.out.println("2nd " + x));
    connectable.connect();

}
 
开发者ID:vgrazi,项目名称:reactive-demo,代码行数:30,代码来源:ReactorTests.java

示例4: accept

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
@Override public void accept(FluxSink<Response<T>> sink) {
  // Since Call is a one-shot type, clone it for each new subscriber.
  Call<T> call = originalCall.clone();

  sink.onDispose(call::cancel);

  Response<T> response;
  try {
    response = call.execute();
  } catch (IOException e) {
    sink.error(e);
    return;
  }
  sink.next(response);
  sink.complete();
}
 
开发者ID:JakeWharton,项目名称:retrofit2-reactor-adapter,代码行数:17,代码来源:ExecuteSinkConsumer.java

示例5: adapt

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
@Override public Object adapt(Call<R> call) {
  Consumer<FluxSink<Response<R>>> consumer = isAsync
      ? new EnqueueSinkConsumer<>(call)
      : new ExecuteSinkConsumer<>(call);
  Flux<Response<R>> responseFlux = Flux.create(consumer, LATEST);

  Flux<?> flux;
  if (isResult) {
    flux = new ResultFlux<>(responseFlux);
  } else if (isBody) {
    flux = new BodyFlux<>(responseFlux);
  } else {
    flux = responseFlux;
  }

  if (scheduler != null) {
    flux = flux.subscribeOn(scheduler);
  }

  if (isMono) {
    return flux.single();
  }
  return flux;
}
 
开发者ID:JakeWharton,项目名称:retrofit2-reactor-adapter,代码行数:25,代码来源:ReactorCallAdapter.java

示例6: burstyProducerRunnable

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
public Runnable burstyProducerRunnable(final FluxSink<Object> emitter, int count, int
		burstSize) {
	return () -> {

		// Let's start with some messages to keep the ringbuffer from going total empty
		for (int i = 0; i < INITAL_MESSAGES_COUNT; ++i) {
			emitter.next("initial" + i);
		}

		for (int outer=0; outer<count/burstSize; ++outer) {
			for (int inner=0; inner<burstSize; ++inner) {
				emitter.next(outer*burstSize+inner);
			}
			sleep(PRODUCER_LATENCY * burstSize);
		}
	};
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:18,代码来源:BurstyWorkQueueProcessorTests.java

示例7: toPublisher

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
/**
 * Return a Publisher of type T out of the the hystrix command.
 *
 * @param clazz the wanted stream type.
 * @param mapper the object mapper used to parse objects.
 * @param command the hystrix command to deal with.
 * @param <T> the type of objects to stream.
 * @return a Publisher<T></T> out of the hystrix command response body.
 */
public static <T> Publisher<T> toPublisher(final Class<T> clazz, final ObjectMapper mapper,
        final HystrixCommand<InputStream> command) {
    AtomicInteger count = new AtomicInteger(0);
    return Flux.create(sink -> {
        final Observable<InputStream> observable = command.toObservable();
        observable.map(i -> {
            try {
                return mapper.readerFor(clazz).<T> readValues(i);
            } catch (IOException e) {
                throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
            }
        }) //
        .doOnCompleted(() -> LOGGER.debug("Completed command '{}' (emits '{}') with '{}' records.", command.getClass().getName(), clazz.getName(), count.get())) //
        .toBlocking() //
        .forEach(s -> {
            while (s.hasNext()) {
                sink.next(s.next());
                count.incrementAndGet();
            }
            sink.complete();
        });
    }, FluxSink.OverflowStrategy.BUFFER);
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:33,代码来源:CommandHelper.java

示例8: CommentController

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
public CommentController(MeterRegistry meterRegistry) {
	this.meterRegistry = meterRegistry;
	this.flux = Flux.<Message<Comment>>create(
		emitter -> this.commentSink = emitter,
		FluxSink.OverflowStrategy.IGNORE)
			.publish()
			.autoConnect();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:9,代码来源:CommentController.java

示例9: CommentService

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
CommentService(ObjectMapper mapper) {
	this.mapper = mapper;
	this.flux = Flux.<Comment>create(
		emitter -> this.webSocketCommentSink = emitter,
		FluxSink.OverflowStrategy.IGNORE)
		.publish()
		.autoConnect();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:9,代码来源:CommentService.java

示例10: OutboundChatService

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
public OutboundChatService() {
	this.flux = Flux.<Message<String>>create(
		emitter -> this.chatMessageSink = emitter,
		FluxSink.OverflowStrategy.IGNORE)
		.publish()
		.autoConnect();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:8,代码来源:OutboundChatService.java

示例11: OutboundChatService

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
public OutboundChatService() {
	this.flux = Flux.<String>create(
		emitter -> this.chatMessageSink = emitter,
		FluxSink.OverflowStrategy.IGNORE)
		.publish()
		.autoConnect();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:8,代码来源:OutboundChatService.java

示例12: CommentService

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
CommentService(ObjectMapper mapper) {
	this.mapper = mapper;
	this.flux = Flux.<Comment>create(
		emitter -> this.webSocketCommentSink = emitter,
		FluxSink.OverflowStrategy.IGNORE)
			.publish()
			.autoConnect();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:9,代码来源:CommentService.java

示例13: emmit

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
private void emmit(FluxSink<Message> emitter, String roomId) {
    HttpClient
            .create()
            .get("https://stream.gitter.im/v1/rooms/" + roomId + "/chatMessages",
                    (r) -> r.addHeader("Authorization", "Bearer 3cd4820adf59b6a7116f99d92f68a1b786895ce7"))
            .flatMapMany(HttpClientResponse::receiveContent)
            .map(ByteBufHolder::content)
            .filter(bb -> bb.capacity() > 2)
            .map(MessageEncoder::mapToMessage)
            .doOnNext(m -> System.out.println("Log Emit: " + m))
            .subscribe(emitter::next, emitter::error, emitter::complete);
}
 
开发者ID:OlegDokuka,项目名称:reactive-playing,代码行数:13,代码来源:ReactorGitterClient.java

示例14: accept

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
@Override public void accept(FluxSink<Response<T>> sink) {
  // Since Call is a one-shot type, clone it for each new subscriber.
  Call<T> call = originalCall.clone();

  DisposableCallback<T> callback = new DisposableCallback<>(call, sink);
  sink.onDispose(callback);
  call.enqueue(callback);
}
 
开发者ID:JakeWharton,项目名称:retrofit2-reactor-adapter,代码行数:9,代码来源:EnqueueSinkConsumer.java

示例15: setUp

import reactor.core.publisher.FluxSink; //导入依赖的package包/类
@Before
public void setUp() {
    crazedFlux = Flux.create(new Consumer<FluxSink<Integer>>() {
        @Override
        public void accept(FluxSink<Integer> sink) {
            int i = 0;
            //noinspection InfiniteLoopStatement
            while (true) {
                sink.next(i);
                i++;
            }
        }
    }, FluxSink.OverflowStrategy.DROP);
}
 
开发者ID:dhinojosa,项目名称:intro_to_reactive,代码行数:15,代码来源:FluxBackpressureTest.java


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