Comments (3)
It looks like rxExecuteBlocking now returns a Maybe instead of a Single. Using toSingle().ignoreElement() seems to address this for all methods but get(K key) when a Singe<Optional > needs to be returned.
from vertx-cache-example.
It's a bit more complicated because it depends on what do we do with the result.
If we expect a Completable
, using ignoreElement()
is fine
If we expect a Single
, using toSingle
is fine. However, in case of absence, it propagates an error (which is fine in our case).
The resulting class is:
public class Cache<K, V> {
private final Vertx vertx;
private final RemoteCache<K, V> cache;
public static <K, V> Single<Cache<K, V>> create(Vertx vertx) {
Configuration config = new ConfigurationBuilder().addServer().host("cache-server").port(11222).build();
return vertx.
<RemoteCache<K, V>>rxExecuteBlocking(
future -> {
RemoteCache<K, V> cache = new RemoteCacheManager(config).getCache();
future.complete(cache);
}
)
.toSingle()
.map(rc -> new Cache<>(vertx, rc));
}
private Cache(Vertx vertx, RemoteCache<K, V> rc) {
this.vertx = vertx;
this.cache = rc;
}
public Completable remove(K key) {
return vertx.rxExecuteBlocking(
future -> {
cache.remove(key);
future.complete();
}
).ignoreElement();
}
public Single<Optional<V>> get(K key) {
// While this method can use the Maybe type, I found easier to use an Optional.
return vertx.<Optional<V>>rxExecuteBlocking(future -> {
V value = cache.get(key);
future.complete(Optional.ofNullable(value));
}).toSingle();
}
public Completable put(K key, V value, long ttl) {
return vertx.rxExecuteBlocking(future -> {
cache.put(key, value, ttl, TimeUnit.SECONDS);
future.complete();
}).ignoreElement();
}
}
from vertx-cache-example.
I've pushed the fix in the update-to-vertx-3.6.0
branch.
from vertx-cache-example.
Related Issues (11)
- upgrade vert.x maven plugin version HOT 1
- Can't find snapshots when running test.sh HOT 1
- too many `.openshiftio` directories HOT 3
- Should the dependency on infinispan use community bits
- Cannot manually deploy to OpenShift with mvn fabric8:deploy -Popenshift HOT 1
- Is there a community based image that this booster should use? HOT 1
- Upgrade to the latest infinispan/rh-sso
- Display duration in the result
- Extract cache interaction into a Cache class
- Add support for JKube (ocmp)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vertx-cache-example.