This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright (c) 2022 VMware Inc. or its affiliates, All Rights Reserved. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * https://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Flux.create(new Consumer<FluxSink<Map<String, Object>>>() { | |
| @Override | |
| public void accept(FluxSink<Map<String, Object>> fluxSink) { | |
| // here we should have our subscription to resource | |
| Socket socket; | |
| try { | |
| socket = IO.socket("https://streamer.cryptocompare.com"); | |
| logger.info("[EXTERNAL-SERVICE] Connecting to CryptoCompare.com ..."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright 2015-2019 the original author or authors. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright 2015-2018 the original author or authors. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright (c) 2017, salesforce.com, inc. | |
| * All rights reserved. | |
| * Licensed under the BSD 3-Clause license. | |
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | |
| */ | |
| package com.salesforce.rxgrpc; | |
| import com.google.common.collect.Lists; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for (;;) { | |
| long currentDemand = demand.getAcquire(); // (1) | |
| if (currentDemand == Long.MAX_VALUE) { // (2) | |
| return; | |
| } | |
| long adjustedDemand = currentDemand + n; | |
| if (adjustedDemand < 0L) { // (3) | |
| adjustedDemand = Long.MAX_VALUE; | |
| } | |
| if (demand.compareAndSet(currentDemand, adjustedDemand)) { // (4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| new StreamPublisher(...) | |
| .subscribe(new Subscriber() { | |
| public void onSubscribe(Subscription s) { | |
| new Thread(() -> s.request(Long.MAX_VALUE)).start(); | |
| new Thread(() -> s.request(Long.MAX_VALUE)).start(); | |
| } | |
| ... | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| @Override | |
| public void request(long n) { | |
| ... | |
| if (demand.getAndAdd(n) > 0) { | |
| return; | |
| } | |
| for (... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //---------Thread A---------|-----------------------Thread B-------------------------- | |
| if (demand.get() > 0) { // | demand -> 1 | |
| // | for(; ... ; executing --> demand.decrementAndGet()) | |
| // | demand -> 0 | |
| // | for(; executing --> demand.get() > 0 && ...) | |
| // | exiting loop | |
| demand.getAndAdd(n); // | <-- executing | |
| // | demand -> n | |
| return; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private class StreamSubscription implements Flow.Subscription { | |
| private final Flow.Subscriber<? super T> subscriber; | |
| private final Iterator<? extends T> iterator; | |
| private final AtomicBoolean isTerminated = new AtomicBoolean(false); | |
| private final AtomicLong demand = new AtomicLong(); | |
| private final AtomicReference<Throwable> error = new AtomicReference<>(); | |
| StreamSubscription(Flow.Subscriber<? super T> subscriber) { | |
| this.subscriber = subscriber; | |
| Iterator<? extends T> iterator = null; |
NewerOlder