本文整理汇总了Java中org.reactivestreams.Processor.onNext方法的典型用法代码示例。如果您正苦于以下问题:Java Processor.onNext方法的具体用法?Java Processor.onNext怎么用?Java Processor.onNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.reactivestreams.Processor
的用法示例。
在下文中一共展示了Processor.onNext方法的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: main
import org.reactivestreams.Processor; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Environment env = Environment.initialize();
Processor<String, String> p = RingBufferProcessor.create("testProcessor", 32);
Stream<String> s1 = Streams.wrap(p);
s1.consume(ev -> System.out.println(Thread.currentThread() + " data=" + ev));
s1.consume(ev -> System.out.println(Thread.currentThread() + " data=" + ev));
s1.consume(ev -> System.out.println(Thread.currentThread() + " data=" + ev));
p.onNext("One");
p.onNext("Two");
p.onNext("Three");
p.onComplete();
Environment.terminate();
}
示例13: main
import org.reactivestreams.Processor; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Environment env = Environment.initialize();
Processor<String, String> p = RingBufferWorkProcessor.create("testProcessor", 32);
Stream<String> s1 = Streams.wrap(p);
s1.consume(ev -> System.out.println(Thread.currentThread() + " data=" + ev));
s1.consume(ev -> System.out.println(Thread.currentThread() + " data=" + ev));
s1.consume(ev -> System.out.println(Thread.currentThread() + " data=" + ev));
p.onNext("One");
p.onNext("Two");
p.onNext("Three");
p.onNext("Four");
p.onNext("Five");
p.onComplete();
Environment.terminate();
}
示例14: sendToUnboundBus
import org.reactivestreams.Processor; //导入方法依赖的package包/类
private boolean sendToUnboundBus(RxQueueKey key, Object event)
{
boolean send = false;
Processor processor = RxBus.getInstance().getProcessor(key, 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;
}
示例15: itShouldIgnoreOlderValueFromReceivedCommands
import org.reactivestreams.Processor; //导入方法依赖的package包/类
@Test
public void itShouldIgnoreOlderValueFromReceivedCommands() {
// given
final TestSubscriber<MVRegister.SetCommand<String>> outCommands1 = TestSubscriber.create();
final TestSubscriber<MVRegister.SetCommand<String>> outCommands2 = TestSubscriber.create();
final Processor<MVRegister.SetCommand<String>, MVRegister.SetCommand<String>> inCommands3 = 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.subscribe(outCommands2);
register1.subscribeTo(register2);
register2.subscribeTo(register1);
final MVRegister<String> register3 = new MVRegister<>(NODE_ID_3, CRDT_ID);
register3.subscribeTo(inCommands3);
// when
register1.set("Hello World");
register2.set("Goodbye World");
final MVRegister.SetCommand<String> oldCommand = outCommands1.values().get(0);
final MVRegister.SetCommand<String> newCommand = outCommands2.values().get(1);
inCommands3.onNext(newCommand);
inCommands3.onNext(oldCommand);
// then
assertThat(register3.get(), contains("Goodbye World"));
}