reactor-lock

This library provides the way to perform any computations wrapped with reactor.core.publisher.Mono with exclusive locking in the reactive manner.

Лицензия

Лицензия

Категории

Категории

React Взаимодействие с пользователем Веб-фреймворки Reactor Контейнер Микросервисы Reactive libraries
Группа

Группа

com.github.alex-pumpkin
Идентификатор

Идентификатор

reactor-lock-core
Последняя версия

Последняя версия

0.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

reactor-lock
This library provides the way to perform any computations wrapped with reactor.core.publisher.Mono with exclusive locking in the reactive manner.
Ссылка на сайт

Ссылка на сайт

https://github.com/alex-pumpkin/reactor-lock
Система контроля версий

Система контроля версий

http://github.com/alex-pumpkin/reactor-lock/tree/master

Скачать reactor-lock-core

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.alex-pumpkin/reactor-lock-core/ -->
<dependency>
    <groupId>com.github.alex-pumpkin</groupId>
    <artifactId>reactor-lock-core</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.alex-pumpkin/reactor-lock-core/
implementation 'com.github.alex-pumpkin:reactor-lock-core:0.2.0'
// https://jarcasting.com/artifacts/com.github.alex-pumpkin/reactor-lock-core/
implementation ("com.github.alex-pumpkin:reactor-lock-core:0.2.0")
'com.github.alex-pumpkin:reactor-lock-core:jar:0.2.0'
<dependency org="com.github.alex-pumpkin" name="reactor-lock-core" rev="0.2.0">
  <artifact name="reactor-lock-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.alex-pumpkin', module='reactor-lock-core', version='0.2.0')
)
libraryDependencies += "com.github.alex-pumpkin" % "reactor-lock-core" % "0.2.0"
[com.github.alex-pumpkin/reactor-lock-core "0.2.0"]

Зависимости

runtime (3)

Идентификатор библиотеки Тип Версия
io.projectreactor : reactor-core jar 3.4.5
io.projectreactor.addons : reactor-extra jar 3.4.1
io.vavr : vavr jar 0.10.0

test (2)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
org.awaitility : awaitility jar 3.1.6

Модули Проекта

Данный проект не имеет модулей.

Exclusive locking for Mono and CacheMono in the reactive style

This library provides the way to perform any computations wrapped with Mono with exclusive locking in the reactive manner.

In most cases you should avoid to use it. But if you have the requirement to minimize concurrent calls of some services with or without caching, reactor-lock may be useful.

Usage

Dependencies

Maven

<dependency>
  <groupId>com.github.alex-pumpkin</groupId>
  <artifactId>reactor-lock-core</artifactId>
  <version>0.2.0</version>
</dependency>

Gradle

implementation 'com.github.alex-pumpkin:reactor-lock-core:0.2.0'

Exclusive subscription by key

public <K, V> Mono<V> callServiceByKeyWithLock(K key) {
    return LockMono.key(key)
            .lock(callServiceByKey(key));
}

private <K, V> Mono<V> callServiceByKey(K key) {
    return Mono.fromCallable(() -> {...});
}

Caching with exclusive subscription to the original Mono

Cache doesn’t implement Map interface

public <K, V> Mono<V> callServiceByKeyWithCache(K key) {
    return LockCacheMono.create(LockMono.key(key).build())
            .lookup(k -> Mono.justOrEmpty(CACHE.get(k)).map(Signal::next))
            .onCacheMissResume(() -> callServiceByKey(key))
            .andWriteWith((k, signal) -> Mono.fromRunnable(() -> Optional.ofNullable(signal.get())
                    .ifPresent(v -> CACHE.put(k, v))));
}

private <K, V> Mono<V> callServiceByKey(K key) {
    return Mono.fromCallable(() -> {...});
}

Cache implements Map interface

Map<K, Signal<V>> MAP_CACHE = ...;

public <K, V> Mono<V> callServiceByKeyWithCache(K key) {
    return LockCacheMono.create(LockMono.key(key).build())
            .lookup(MAP_CACHE)
            .onCacheMissResume(() -> callServiceByKey(key));
}

private <K, V> Mono<V> callServiceByKey(K key) {
    return Mono.fromCallable(() -> {...});
}

License

Copyright 2019 Alexander Pankin

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 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Версии библиотеки

Версия
0.2.0
0.1.0