本文整理汇总了Java中org.reactivestreams.Processor类的典型用法代码示例。如果您正苦于以下问题:Java Processor类的具体用法?Java Processor怎么用?Java Processor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Processor类属于org.reactivestreams包,在下文中一共展示了Processor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendToKeyBoundBus
import org.reactivestreams.Processor; //导入依赖的package包/类
private boolean sendToKeyBoundBus(RxQueueKey key, Object event)
{
RxQueueKey keyToUse = key.clone();
boolean send = false;
Processor processor;
if (mKey instanceof String)
keyToUse.withId((String)mKey);
else if (mKey instanceof Integer)
keyToUse.withId((Integer)mKey);
processor = RxBus.getInstance().getProcessor(keyToUse, false);
// only send event, if processor exists => this means someone has at least once subscribed to it
if (processor != null)
{
if (mCast == null)
processor.onNext(event);
else
processor.onNext(mCast.cast(event));
send = true;
}
return send;
}
示例2: shouldHandleAddCommands
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void shouldHandleAddCommands() {
// given:
final UUID uuid1 = UUID.randomUUID();
final UUID uuid2 = UUID.randomUUID();
final Processor<USet.USetCommand<UUID>, USet.USetCommand<UUID>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final USet<UUID> set = new USet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final USet.AddCommand<UUID> command1 = new USet.AddCommand<>(set.getCrdtId(), uuid1);
final USet.AddCommand<UUID> command2 = new USet.AddCommand<>(set.getCrdtId(), uuid2);
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
// then:
assertThat(set, hasSize(2));
assertThat(subscriber.valueCount(), is(2));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例3: shouldHandleRemoveCommands
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void shouldHandleRemoveCommands() {
// given:
final UUID uuid1 = UUID.randomUUID();
final Processor<USet.USetCommand<UUID>, USet.USetCommand<UUID>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final USet<UUID> set = new USet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final USet.AddCommand<UUID> command1 = new USet.AddCommand<>(set.getCrdtId(), uuid1);
final USet.RemoveCommand<UUID> command2 = new USet.RemoveCommand<>(set.getCrdtId(), uuid1);
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
// then:
assertThat(set, empty());
assertThat(subscriber.valueCount(), is(2));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例4: itShouldOverwriteOnlyPartialCommandsFromReceivedCommand
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void itShouldOverwriteOnlyPartialCommandsFromReceivedCommand() {
// given
final TestSubscriber<MVRegister.SetCommand<String>> outCommands1 = TestSubscriber.create();
final Processor<MVRegister.SetCommand<String>, MVRegister.SetCommand<String>> inCommands2 = ReplayProcessor.create();
final MVRegister<String> register1 = new MVRegister<>(NODE_ID_1, CRDT_ID);
register1.subscribe(outCommands1);
final MVRegister<String> register2 = new MVRegister<>(NODE_ID_2, CRDT_ID);
register2.subscribeTo(inCommands2);
register1.set("Hello World");
register2.set("Goodbye World");
inCommands2.onNext(outCommands1.values().get(0));
// when
register1.set("42");
inCommands2.onNext(outCommands1.values().get(1));
// then
assertThat(register1.get(), containsInAnyOrder("42"));
assertThat(register2.get(), containsInAnyOrder("42", "Goodbye World"));
}
示例5: shouldHandleAddCommands
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void shouldHandleAddCommands() {
// given:
final Processor<ORSet.ORSetCommand<String>, ORSet.ORSetCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final ORSet<String> set = new ORSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final ORSet.AddCommand<String> command1 = new ORSet.AddCommand<>(set.getCrdtId(), new ORSet.Element<>("1", UUID.randomUUID()));
final ORSet.AddCommand<String> command2 = new ORSet.AddCommand<>(set.getCrdtId(), new ORSet.Element<>("2", UUID.randomUUID()));
final ORSet.AddCommand<String> command3 = new ORSet.AddCommand<>(set.getCrdtId(), new ORSet.Element<>("1", UUID.randomUUID()));
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
inputStream.onNext(command3);
// then:
assertThat(set, hasSize(2));
assertThat(subscriber.valueCount(), is(3));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例6: shouldHandleDuplicateCommands
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void shouldHandleDuplicateCommands() {
// given:
final Processor<ORSet.ORSetCommand<String>, ORSet.ORSetCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final ORSet<String> set = new ORSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final ORSet.AddCommand<String> command = new ORSet.AddCommand<>(set.getCrdtId(), new ORSet.Element<>("1", UUID.randomUUID()));
// when:
inputStream.onNext(command);
inputStream.onNext(command);
// then:
assertThat(set, hasSize(1));
assertThat(subscriber.valueCount(), is(1));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例7: shouldHandleAddCommands
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void shouldHandleAddCommands() {
// given:
final Processor<GSet.AddCommand<String>, GSet.AddCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final GSet<String> set = new GSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final GSet.AddCommand<String> command1 = new GSet.AddCommand<>(set.getCrdtId(), "1");
final GSet.AddCommand<String> command2 = new GSet.AddCommand<>(set.getCrdtId(), "2");
final GSet.AddCommand<String> command3 = new GSet.AddCommand<>(set.getCrdtId(), "1");
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
inputStream.onNext(command3);
// then:
assertThat(set, hasSize(2));
assertThat(subscriber.valueCount(), is(2));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例8: shouldHandleDuplicateCommands
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void shouldHandleDuplicateCommands() {
// given:
final Processor<GSet.AddCommand<String>, GSet.AddCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final GSet<String> set = new GSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final GSet.AddCommand<String> command = new GSet.AddCommand<>(set.getCrdtId(), "1");
// when:
inputStream.onNext(command);
inputStream.onNext(command);
// then:
assertThat(set, hasSize(1));
assertThat(subscriber.valueCount(), is(1));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例9: shouldHandleAddCommands
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void shouldHandleAddCommands() {
// given:
final Processor<TwoPSet.TwoPSetCommand<String>, TwoPSet.TwoPSetCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final TwoPSet<String> set = new TwoPSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final TwoPSet.AddCommand<String> command1 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
final TwoPSet.AddCommand<String> command2 = new TwoPSet.AddCommand<>(set.getCrdtId(), "2");
final TwoPSet.AddCommand<String> command3 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
inputStream.onNext(command3);
// then:
assertThat(set, hasSize(2));
assertThat(subscriber.valueCount(), is(2));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例10: shouldHandleRemoveCommands
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void shouldHandleRemoveCommands() {
// given:
final Processor<TwoPSet.TwoPSetCommand<String>, TwoPSet.TwoPSetCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final TwoPSet<String> set = new TwoPSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final TwoPSet.AddCommand<String> command1 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
final TwoPSet.AddCommand<String> command2 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
final TwoPSet.RemoveCommand<String> command3 = new TwoPSet.RemoveCommand<>(set.getCrdtId(), "1");
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
inputStream.onNext(command3);
// then:
assertThat(set, empty());
assertThat(subscriber.valueCount(), is(2));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例11: shouldHandleRemoveCommandArrivesBeforeAddCommand
import org.reactivestreams.Processor; //导入依赖的package包/类
@Test
public void shouldHandleRemoveCommandArrivesBeforeAddCommand() {
// given:
final Processor<TwoPSet.TwoPSetCommand<String>, TwoPSet.TwoPSetCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final TwoPSet<String> set = new TwoPSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final TwoPSet.RemoveCommand<String> command1 = new TwoPSet.RemoveCommand<>(set.getCrdtId(), "1");
final TwoPSet.AddCommand<String> command2 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
final TwoPSet.AddCommand<String> command3 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
inputStream.onNext(command3);
// then:
assertThat(set, empty());
assertThat(subscriber.valueCount(), is(1));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例12: onNext
import org.reactivestreams.Processor; //导入依赖的package包/类
/**
* Emits the specified value from the observable associated with the specified key
* if there is an associated observable. If no observable has subscribed to the key,
* this operation is a noop. If no value is not emitted it will be faulted in later
* should another query request it
*
* @param key key with which the specified value is to be associated
* @param valueProvider the method to be called to create the new value in the case of a hit
* @param missHandler the callback for when a subscriber has not been bound
*/
public void onNext(K key, final Callable<V> valueProvider, Action missHandler)
{
emitUpdate(key, new Consumer<Processor<V, V>>() {
@Override
public void accept(Processor<V, V> subject)
{
try {
subject.onNext(valueProvider.call());
}
catch (Exception error) {
subject.onError(error);
}
}
}, missHandler);
}
示例13: setupFakeProtocolListener
import org.reactivestreams.Processor; //导入依赖的package包/类
private void setupFakeProtocolListener() throws Exception {
broadcaster = TopicProcessor.create();
final Processor<List<String>, List<String>> processor =
WorkQueueProcessor.<List<String>>builder().autoCancel(false).build();
Flux.from(broadcaster)
.buffer(5)
.subscribe(processor);
httpServer = HttpServer.create(0)
.newRouter(r -> r.get("/data",
(req, resp) -> resp.options(NettyPipeline.SendOptions::flushOnEach)
.send(Flux.from(processor)
.log("server")
.timeout(Duration.ofSeconds(
2),
Flux.empty())
.concatWith(Flux.just(
new ArrayList<>()))
.map(new DummyListEncoder(
resp.alloc()
)))))
.block(Duration.ofSeconds(30));
}
示例14: start
import org.reactivestreams.Processor; //导入依赖的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
示例15: onError
import org.reactivestreams.Processor; //导入依赖的package包/类
@Override
public void onError(Throwable t) {
if (done) {
Operators.onErrorDropped(t, actual.currentContext());
return;
}
done = true;
Processor<T, T> w = window;
if (w != null) {
window = null;
w.onError(t);
}
actual.onError(t);
}