本文整理汇总了Java中io.vertx.core.spi.cluster.ChoosableIterable类的典型用法代码示例。如果您正苦于以下问题:Java ChoosableIterable类的具体用法?Java ChoosableIterable怎么用?Java ChoosableIterable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChoosableIterable类属于io.vertx.core.spi.cluster包,在下文中一共展示了ChoosableIterable类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
@Override
public void get(K k, Handler<AsyncResult<ChoosableIterable<V>>> asyncResultHandler) {
if (!keyIsNull(k, asyncResultHandler)) {
vertx.runOnContext(event -> {
Map<String, ChildData> maps = curatorCache.getCurrentChildren(keyPath(k));
ChoosableSet<V> choosableSet = new ChoosableSet<>(0);
if (maps != null) {
for (ChildData childData : maps.values()) {
try {
if (childData != null && childData.getData() != null && childData.getData().length > 0)
choosableSet.add(asObject(childData.getData()));
} catch (Exception ex) {
asyncResultHandler.handle(Future.failedFuture(ex));
}
}
}
asyncResultHandler.handle(Future.succeededFuture(choosableSet));
});
}
}
示例2: get
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
@Override
public void get(K k, Handler<AsyncResult<ChoosableIterable<V>>> resultHandler) {
ContextImpl context = vertx.getOrCreateContext();
@SuppressWarnings("unchecked")
Queue<GetRequest<K, V>> getRequests = (Queue<GetRequest<K, V>>) context.contextData().computeIfAbsent(this, ctx -> new ArrayDeque<>());
synchronized (getRequests) {
ChoosableSet<V> entries = nearCache.get(k);
if (entries != null && entries.isInitialised() && getRequests.isEmpty()) {
context.runOnContext(v -> {
resultHandler.handle(Future.succeededFuture(entries));
});
} else {
getRequests.add(new GetRequest<>(k, resultHandler));
if (getRequests.size() == 1) {
dequeueGet(context, getRequests);
}
}
}
}
示例3: get
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
@Override
public void get(K k, Handler<AsyncResult<ChoosableIterable<V>>> resultHandler) {
ContextImpl context = vertx.getOrCreateContext();
@SuppressWarnings("unchecked")
Queue<GetRequest<K, V>> getRequests = (Queue<GetRequest<K, V>>) context.contextData().computeIfAbsent(this, ctx -> new ArrayDeque<>());
synchronized (getRequests) {
ChoosableSet<V> entries = cache.get(k);
if (entries != null && entries.isInitialised() && getRequests.isEmpty()) {
context.runOnContext(v -> {
resultHandler.handle(Future.succeededFuture(entries));
});
} else {
getRequests.add(new GetRequest<>(k, resultHandler));
if (getRequests.size() == 1) {
dequeueGet(context, getRequests);
}
}
}
}
示例4: get
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
@Override
public void get(final K k, final Handler<AsyncResult<ChoosableIterable<V>>> asyncResultHandler) {
final ContextInternal ctx = FakeClusterManager.this.vertx.getOrCreateContext();
ctx.executeBlocking(fut -> {
ChoosableIterable<V> it = this.map.get(k);
if (it == null) {
it = new ChoosableSet<>(0);
}
fut.complete(it);
}, this.taskQueue, asyncResultHandler);
}
示例5: get
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
@Override
public void get(K key, Handler<AsyncResult<ChoosableIterable<V>>> handler) {
execute(
cache -> cache.getAsync(marshal(key)),
(Set<V> items) -> {
Set<V> unmarshalledItems = null;
if (items != null) {
unmarshalledItems = items.stream().map(ClusterSerializationUtils::unmarshal).collect(toSet());
}
Set<V> items0 = unmarshalledItems;
ChoosableIterableImpl<V> it = subs.compute(key, (k, oldValue) -> {
if (items0 == null || items0.isEmpty()) {
return null;
}
if (oldValue == null) {
return new ChoosableIterableImpl<>(new ArrayList<>(items0));
}
else {
oldValue.update(new ArrayList<>(items0));
return oldValue;
}
});
return it == null ? ChoosableIterableImpl.empty() : it;
},
handler
);
}
示例6: get
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void get(K k, Handler<AsyncResult<ChoosableIterable<V>>> handler) {
map.get(k).whenComplete(VertxFutures.convertHandler(
handler,
collection -> collection != null
? new AtomixChoosableIterable(collection.value())
: new AtomixChoosableIterable<V>(Collections.emptyList()),
vertx.getOrCreateContext()));
}
示例7: shouldNotAddToMapCacheIfKeyDoesntAlreadyExist
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
@Test
public void shouldNotAddToMapCacheIfKeyDoesntAlreadyExist() throws Exception {
String nonexistentKey = "non-existent-key." + UUID.randomUUID();
map.get(nonexistentKey, ar -> {
if (ar.succeeded()) {
try {
ChoosableIterable<ServerID> s = ar.result();
Map<String, ChoosableIterable<ServerID>> cache = getCacheFromMap();
// System.err.println("CACHE CONTENTS: " + cache);
// check result
assertNotNull(s);
assertTrue(s.isEmpty());
// check cache
assertNotNull(cache);
assertFalse(
"Map cache should not contain key " + nonexistentKey,
cache.containsKey(nonexistentKey));
} catch (Exception e) {
fail(e.toString());
} finally {
testComplete();
}
} else {
fail(ar.cause().toString());
}
});
await();
}
示例8: empty
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
public static <T> ChoosableIterable<T> empty() {
return (ChoosableIterable<T>)EMPTY;
}
示例9: GetRequest
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
GetRequest(K key, Handler<AsyncResult<ChoosableIterable<V>>> handler) {
this.key = key;
this.handler = handler;
}
示例10: get
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
public void get(K k, Handler<AsyncResult<ChoosableIterable<V>>> handler) {
logTrace(() -> "get k = [" + k + "], handler = [" + handler + "]");
executorService.runAsync(() -> map.get(k), handler);
}
示例11: getCacheFromMap
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Map<String, ChoosableIterable<ServerID>> getCacheFromMap() throws Exception {
Field field = map.getClass().getDeclaredField("cache");
field.setAccessible(true);
return (Map<String, ChoosableIterable<ServerID>>) field.get(map);
}
示例12: get
import io.vertx.core.spi.cluster.ChoosableIterable; //导入依赖的package包/类
ChoosableIterable<V> get(K k);