本文整理汇总了Java中io.reactivex.flowables.ConnectableFlowable类的典型用法代码示例。如果您正苦于以下问题:Java ConnectableFlowable类的具体用法?Java ConnectableFlowable怎么用?Java ConnectableFlowable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectableFlowable类属于io.reactivex.flowables包,在下文中一共展示了ConnectableFlowable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ifStartEmitsOnlyOnceBeforeDataStreamNeverEnds
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
@Test
public void ifStartEmitsOnlyOnceBeforeDataStreamNeverEnds() throws InterruptedException {
CountDownLatch sync = new CountDownLatch(1);
ConnectableFlowable<?> sourceStream = just(0L).publish();
ConnectableFlowable<?> startStream = just(new Object()).publish();
sourceStream.buffer(startStream, opening -> never()).doOnTerminate(sync::countDown)
.subscribe(System.out::println);
sourceStream.connect();
startStream.connect();
sync.await(5, SECONDS);
assertThat(sync.getCount()).isEqualTo(0L);
}
示例2: main
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
public static void main(String... args) throws IOException, InterruptedException {
//Create the rxRecorder but don't delete the cache that has been created.
ReactiveJournal reactiveJournal = new ReactiveJournal(HelloWorldApp_JounalAsObserver.FILE_NAME);
//Get the input from the remote process
RxJavaPlayer rxPlayer = new RxJavaPlayer(reactiveJournal);
PlayOptions options = new PlayOptions().filter(HelloWorldApp_JounalAsObserver.INPUT_FILTER)
.playFromNow(true).replayRate(PlayOptions.ReplayRate.FAST);
ConnectableFlowable<Byte> remoteInput = rxPlayer.play(options).publish();
BytesToWordsProcessor bytesToWords = new BytesToWordsProcessor();
Flowable<String> flowableOutput = bytesToWords.process(remoteInput);
flowableOutput.subscribe(
s->LOG.info("Remote input [{}]", s),
e-> LOG.error("Problem in remote [{}]", e),
()->{
LOG.info("Remote input ended");
System.exit(0);
});
remoteInput.connect();
}
示例3: main
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
ReactiveJournal reactiveJournal = new ReactiveJournal("src/main/java/org/reactivejournal/examples/fastproducerslowconsumer/resources/");
//Get the input from the recorder note that we have to set the replayRate to ACTUAL_TIME
//to replicate the conditions in the 'real world'.
PlayOptions options = new PlayOptions().filter("input").replayRate(ReplayRate.ACTUAL_TIME);
ConnectableFlowable journalInput = new RxJavaPlayer(reactiveJournal).play(options).publish();
//Reduce the latency of the consumer to 5ms - try reducing or increasing to study the effects.
Consumer onNextSlowConsumer = FastProducerSlowConsumer.createOnNextSlowConsumer(3);
long startTime = System.currentTimeMillis();
journalInput.observeOn(Schedulers.io()).subscribe(onNextSlowConsumer::accept,
e -> System.out.println("ReactiveRecorder " + " " + e),
() -> System.out.println("ReactiveRecorder complete [" + (System.currentTimeMillis()-startTime) + "ms]")
);
journalInput.connect();
DSUtil.sleep(1000);
}
示例4: create
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> ErrorStreamPair<T> create(StreamId<T> id, DiscoveryService discoveryService) {
if (!(id instanceof OverlapBufferStreamId)) {
return ErrorStreamPair.empty();
}
OverlapBufferStreamId<?> analysisId = (OverlapBufferStreamId<?>) id;
BufferSpecification bufferSpecification = analysisId.bufferSpecification();
StreamId<?> startId = bufferSpecification.startId();
StreamId<?> sourceId = analysisId.sourceId();
Flowable<?> timeout = bufferSpecification.timeout();
ConnectableFlowable<?> startStream = Flowable.fromPublisher(discoveryService.discover(startId)).publish();
ConnectableFlowable<?> sourceStream = Flowable.fromPublisher(discoveryService.discover(sourceId)).publish();
Set<EndStreamMatcher<?, ?>> matchers = bufferSpecification.endStreamMatchers();
Map<EndStreamMatcher<Object, Object>, ConnectableFlowable<?>> endStreams = matchers.stream()
.collect(Collectors.toMap(m -> (EndStreamMatcher<Object, Object>) m,
m -> Flowable.fromPublisher(discoveryService.discover(m.endStreamId())).publish()));
StreamConnector sourceStreamConnector = new StreamConnector(sourceStream);
Flowable<?> bufferStream = sourceStream
.compose(new DoAfterFirstSubscribe<>(() -> {
endStreams.values().forEach(ConnectableFlowable::connect);
startStream.connect();
}))
.buffer(startStream,
opening -> closingStreamFor(opening, endStreams, timeout, sourceStreamConnector));
return ErrorStreamPair.ofData((Publisher<T>) bufferStream);
}
示例5: closingStreamFor
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
private Flowable<?> closingStreamFor(Object opening,
Map<EndStreamMatcher<Object, Object>, ConnectableFlowable<?>> endStreams, Flowable<?> timeout,
StreamConnector sourceStreamConnector) {
Set<Flowable<?>> matchingEndStreams = endStreams.entrySet().stream()
.map(e -> e.getValue().filter(v -> e.getKey().matching().test(opening, v))).collect(Collectors.toSet());
matchingEndStreams.add(timeout);
return Flowable.merge(matchingEndStreams)
.compose(new DoAfterFirstSubscribe<>(sourceStreamConnector::connect))
.take(1);
}
示例6: main
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
ConnectableFlowable flowableInput =
Flowable.fromArray(new Byte[]{72,101,108,108,111,32,87,111,114,108,100,32}).map(
i->{
DSUtil.sleep(INTERVAL_MS);
return i;
}).publish();
//Create the reactiveRecorder and delete any previous content by clearing the cache
ReactiveJournal reactiveJournal = new ReactiveJournal(FILE_NAME);
reactiveJournal.clearCache();
//Pass the input stream into the reactiveRecorder which will subscribe to it and record all events.
//The subscription will not be activated until 'connect' is called on the input stream.
ReactiveRecorder reactiveRecorder = reactiveJournal.createReactiveRecorder();
reactiveRecorder.record(flowableInput, INPUT_FILTER);
BytesToWordsProcessor bytesToWords = new BytesToWordsProcessor();
//Pass the input Byte stream into the BytesToWordsProcessor class which subscribes to the stream and returns
//a stream of words.
//The subscription will not be activated until 'connect' is called on the input stream.
Flowable<String> flowableOutput = bytesToWords.process(flowableInput);
//Pass the output stream (of words) into the reactiveRecorder which will subscribe to it and record all events.
flowableOutput.subscribe(LOG::info);
reactiveRecorder.record(flowableOutput, OUTPUT_FILTER);
//Activate the subscriptions
flowableInput.connect();
reactiveJournal.writeToFile("/tmp/Demo/demo.txt",true);
}
示例7: main
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
//Create the reactiveRecorder and delete any previous content by clearing the cache
ReactiveJournal reactiveJournal = new ReactiveJournal(FILE_NAME);
reactiveJournal.clearCache();
//Pass the input stream into the reactiveRecorder which will subscribe to it and record all events.
//The subscription will not be activated on a new thread which will allow this program to continue.
ReactiveRecorder reactiveRecorder = reactiveJournal.createReactiveRecorder();
reactiveRecorder.recordAsync(observableInput, INPUT_FILTER);
BytesToWordsProcessor bytesToWords = new BytesToWordsProcessor();
//Retrieve a stream of
RxJavaPlayer rxPlayer = new RxJavaPlayer(reactiveJournal);
PlayOptions options = new PlayOptions().filter(INPUT_FILTER).playFromNow(true);
ConnectableFlowable recordedObservable = rxPlayer.play(options).publish();
//Pass the input Byte stream into the BytesToWordsProcessor class which subscribes to the stream and returns
//a stream of words.
Flowable<String> flowableOutput = bytesToWords.process(recordedObservable);
//Pass the output stream (of words) into the reactiveRecorder which will subscribe to it and record all events.
reactiveRecorder.record(flowableOutput, OUTPUT_FILTER);
flowableOutput.subscribe(s -> LOG.info("HelloWorldHot->" + s),
throwable -> LOG.error("", throwable),
()->LOG.info("HelloWorldHot Complete"));
//Only start the recording now because we want to make sure that the BytesToWordsProcessor and the reactiveRecorder
//are both setup up to receive subscriptions.
recordedObservable.connect();
//Sometimes useful to see the recording written to a file
reactiveJournal.writeToFile("/tmp/Demo/demo.txt",true);
}
示例8: main
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
ReactiveJournal reactiveJournal = new ReactiveJournal("/tmp/fastproducer");
reactiveJournal.clearCache();
Flowable<Long> fastProducer = FastProducerSlowConsumer.createFastProducer(BackpressureStrategy.MISSING, 2500);
ReactiveRecorder recorder = reactiveJournal.createReactiveRecorder();
recorder.recordAsync(fastProducer,"input");
//Set the replay strategy to ReplayRate.FAST as e want to process the event as soon as it is
//received from the publisher.
PlayOptions options = new PlayOptions().filter("input").replayRate(PlayOptions.ReplayRate.FAST);
ConnectableFlowable journalInput = new RxJavaPlayer(reactiveJournal).play(options).publish();
Consumer onNextSlowConsumer = FastProducerSlowConsumer.createOnNextSlowConsumer(10);
recorder.record(journalInput, "consumed");
long startTime = System.currentTimeMillis();
journalInput.observeOn(Schedulers.io()).subscribe(onNextSlowConsumer::accept,
e -> System.out.println("ReactiveRecorder " + " " + e),
() -> System.out.println("ReactiveRecorder complete [" + (System.currentTimeMillis()-startTime) + "]")
);
journalInput.connect();
DSUtil.sleep(3000);
}
示例9: FlowableRefCountTimeout
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
FlowableRefCountTimeout(ConnectableFlowable<T> source, int n, long timeout, TimeUnit unit,
Scheduler scheduler) {
this.source = source;
this.n = n;
this.timeout = timeout;
this.unit = unit;
this.scheduler = scheduler;
}
示例10: apply
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
@Override
public Publisher<T> apply(Flowable<T> upstream) {
if (upstream instanceof ConnectableFlowable) {
return new FlowableRefCountTimeout<T>((ConnectableFlowable<T>)upstream, n, timeout, unit, scheduler);
}
throw new IllegalArgumentException("This transformer requires an upstream ConnectableFlowable");
}
示例11: onCreate
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String githubToken = Constants.ETEST_API_KEY;
String urlx = "http:\\" + SettingsActivity.getServerName(getActivity());
String usicox = SettingsActivity.getUsIco(getActivity());
if( usicox.equals("44551142")) {
urlx = "http:\\" + Constants.EDCOM_url;
}
_rfetestService = RfEtestService.createGithubService(githubToken, urlx);
_disposables = new CompositeDisposable();
_rxBus = getRxBusSingleton();
ConnectableFlowable<Object> tapEventEmitter = _rxBus.asFlowable().publish();
_disposables
.add(tapEventEmitter.subscribe(event -> {
if (event instanceof ApproveListFragment.TapEvent) {
///_showTapText();
}
if (event instanceof Attendance) {
String keys = ((Attendance) event).getRok();
//Log.d("In FRGM longClick", keys);
getApproveDialog( keys, (Attendance) event);
}
}));
_disposables
.add(tapEventEmitter.publish(stream ->
stream.buffer(stream.debounce(1, TimeUnit.SECONDS)))
.observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
///_showTapCount(taps.size()); OK
}));
_disposables.add(tapEventEmitter.connect());
}
示例12: onCreate
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String githubToken = Constants.ETEST_API_KEY;
String urlx = SettingsActivity.getServerName(getActivity());
_disposables = new CompositeDisposable();
_rxBus = getRxBusSingleton();
ConnectableFlowable<Object> tapEventEmitter = _rxBus.asFlowable().publish();
_disposables
.add(tapEventEmitter.subscribe(event -> {
if (event instanceof AbsTypesListRxFragment.TapEvent) {
///_showTapText();
}
if (event instanceof Abstype) {
String keys = ((Abstype) event).getRok();
//Log.d("In FRGM longClick", keys);
getAbsTypesDialog( keys, (Abstype) event);
}
}));
_disposables
.add(tapEventEmitter.publish(stream ->
stream.buffer(stream.debounce(1, TimeUnit.SECONDS)))
.observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
///_showTapCount(taps.size()); OK
}));
_disposables.add(tapEventEmitter.connect());
}
示例13: onStart
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
@Override
public void onStart() {
super.onStart();
_disposables = new CompositeDisposable();
ConnectableFlowable<Object> tapEventEmitter = _rxBus.asFlowable().publish();
_disposables
.add(tapEventEmitter.subscribe(event -> {
if (event instanceof RxBusDemoFragment.TapEvent) {
_showTapText();
}
if (event instanceof EventRxBus.Message) {
tvContent = (TextView) getActivity().findViewById(R.id.tvContent);
tvContent.setText(((EventRxBus.Message) event).message);
}
}));
_disposables
.add(tapEventEmitter.publish(stream ->
stream.buffer(stream.debounce(1, TimeUnit.SECONDS)))
.observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
_showTapCount(taps.size());
}));
_disposables.add(tapEventEmitter.connect());
}
示例14: onCreate
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_rxBus = getRxBusSingleton();
_disposables = new CompositeDisposable();
ConnectableFlowable<Object> tapEventEmitter = _rxBus.asFlowable().publish();
_disposables
.add(tapEventEmitter.subscribe(event -> {
if (event instanceof PostsFragment.TapEvent) {
///_showTapText();
}
if (event instanceof BlogPostEntity) {
//saveAbsServer(((Attendance) event).daod + " / " + ((Attendance) event).dado, ((Attendance) event));
String keys = ((BlogPostEntity) event).getAuthor();
//blogPostsAdapter.remove(0);
showProgress(true);
Log.d("In FRGM shortClick", keys);
BlogPostEntity postx = new BlogPostEntity(null, null, null);
delBlogPostRx(postx,1, keys);
}
}));
_disposables
.add(tapEventEmitter.publish(stream ->
stream.buffer(stream.debounce(1, TimeUnit.SECONDS)))
.observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
///_showTapCount(taps.size()); OK
}));
_disposables.add(tapEventEmitter.connect());
}
示例15: send
import io.reactivex.flowables.ConnectableFlowable; //导入依赖的package包/类
public Flowable<Void> send(StompMessage stompMessage) {
Flowable<Void> flowable = mConnectionProvider.send(stompMessage.compile());
if (!mConnected) {
ConnectableFlowable<Void> deferred = flowable.publish();
mWaitConnectionFlowables.add(deferred);
return deferred;
} else {
return flowable;
}
}