This file contains 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
@Service | |
@Slf4j | |
@RequiredArgsConstructor | |
public class SspDefinitionenStore implements SspDefinitionConsumer { | |
private CacheMono<VersionedId, SspDefinition, SspDefinition> sspDefinitionCache; | |
private FluxSink<SspDefinition> sspDefinitionSink; | |
@PostConstruct | |
public void initialize() { |
This file contains 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
@Service | |
@Slf4j | |
@RequiredArgsConstructor | |
public class TopologyRepository { | |
private final CacheMono<TopologyRef, TopologyDto, TopologyDto> cache; | |
private final TopologyLoader topologyLoader; | |
private final TopologyCreator topologyCreator; | |
@Autowired |
This file contains 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
/** | |
* Gets cached values as Java Stream. Returned stream is not sorted. | |
*/ | |
public Stream<OVALUE> getValues() { | |
final Lock readLock = lock.readLock(); | |
readLock.lock(); | |
try { | |
return cache.values().stream().flatMap(cachedValue -> cachedValue.getValue().stream()); | |
} finally { | |
readLock.unlock(); |
This file contains 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
/** | |
* Finds a value by key in an in-memory cache or load it from a remote source. | |
* The loaded value will be cached. | |
*/ | |
public Mono<OVALUE> lookup(KEY key) { | |
return Mono.defer(() -> getValueAsMono(key) | |
.switchIfEmpty(Mono.defer(() -> onCacheMissResume(key))) | |
); | |
} |
This file contains 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 static class CacheMonoValue<VALUE> { | |
private Mono<VALUE> mono; | |
private Signal<VALUE> signal; | |
CacheMonoValue(Mono<VALUE> mono) { | |
this.mono = mono; | |
} | |
CacheMonoValue(Signal<VALUE> signal) { |
This file contains 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
@Slf4j | |
public class CacheMono<KEY, IVALUE, OVALUE> { | |
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); | |
private final Map<KEY, CacheMonoValue<OVALUE>> cache = new HashMap<>(); | |
/** | |
* External value supplier which should be provided if "valuePublisher" with "keyExtractor" | |
* are not set | |
*/ |
This file contains 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<String> cars = Flux.just("Fiat", "Audi", "BMW"); | |
Flux<String> years = Flux.just("2009", "2018", "2015"); | |
Flux.zip(cars, years) | |
.map(t -> t.getT1() + " " + t.getT2()) | |
.subscribe(System.out::println); | |
// Output | |
Fiat 2009 | |
Audi 2018 |
This file contains 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
CompletableFuture<Void> cf = CompletableFuture.supplyAsync(() -> 1 + 2) | |
.thenApply(i -> "1 + 2 = " + i) | |
.thenAccept(s -> System.out.println("Computation result: " + s)) | |
.thenRun(() -> System.out.println("Finished")); | |
cf.get(); | |
// Output | |
Computation result: 1 + 2 = 3 | |
Finished |
This file contains 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
@RestController | |
class TopologyController { | |
@GetMapping(path = "/uno", produces = {APPLICATION_JSON_VALUE}) | |
... | |
public Mono<UnoTopologyDto> getUnoTopology( | |
@RequestParam Set<String> stationNames, | |
@RequestParam(name = "replicationId", required = false) Long replicationId, | |
@RequestParam(name = "topoReferenceDate", required = false) | |
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate topoReferenceDate) { |
This file contains 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
Do something before task execution ... | |
21 | |
Do something after task execution ... | |
37 | |
87 | |
93 | |
23 |
NewerOlder