本文整理汇总了Java中io.vertx.core.shareddata.AsyncMap类的典型用法代码示例。如果您正苦于以下问题:Java AsyncMap类的具体用法?Java AsyncMap怎么用?Java AsyncMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsyncMap类属于io.vertx.core.shareddata包,在下文中一共展示了AsyncMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
/**
* Create a AsyncMap
*
* @param <K> Key type
* @param <V> Value type
* @param vertx
* @param mapName name of the map. If null, will always create a local map
* @param fut
*/
public static <K, V> void create(Vertx vertx, String mapName, Handler<ExtendedAsyncResult<AsyncMap<K, V>>> fut) {
if (vertx.isClustered() && mapName != null) {
SharedData shared = vertx.sharedData();
shared.<K, V>getClusterWideMap(mapName, res -> {
if (res.succeeded()) {
fut.handle(new Success<>(res.result()));
} else {
fut.handle(new Failure<>(INTERNAL, res.cause()));
}
});
} else {
// Dirty trickery to make sure we can run two verticles in our tests,
// without them sharing the 'shared' memory. Only when running in non-
// clustered mode, of course.
// Also used in deploy-only nodes, where we want local-only tenant and
// module lists with only the hard-coded supertenant and internalModule.
Random r = new Random();
String newid = String.format("%09d", r.nextInt(1000000000));
if (mapName != null) {
newid = mapName + newid;
}
AsyncLocalmap<K, V> l = new AsyncLocalmap<>(vertx, newid);
fut.handle(new Success<>(l));
}
}
示例2: retrieveRegistry
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
private synchronized void retrieveRegistry(Handler<AsyncResult<AsyncMap<String, String>>> handler) {
if (registry != null) {
handler.handle(Future.succeededFuture(registry));
} else {
vertx.sharedData().<String, String>getClusterWideMap("service.registry", ar -> {
synchronized (DefaultServiceDiscoveryBackend.class) {
if (ar.failed()) {
handler.handle(ar);
} else {
registry = ar.result();
handler.handle(Future.succeededFuture(registry));
}
}
});
}
}
示例3: getStore
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
private void getStore(Handler<AsyncResult<AsyncMap<String, Buffer>>> handler) {
if (store != null) {
handler.handle(Future.succeededFuture(store));
return;
}
String name = getClass().getName() + ".STORE";
if (vertx.isClustered()) {
vertx.sharedData().<String, Buffer>getClusterWideMap(name, ar -> {
if (ar.succeeded()) {
store = ar.result();
}
handler.handle(ar);
});
} else {
LocalMap<String, Buffer> lm = vertx.sharedData().getLocalMap(name);
store = new AsyncLocalMap<String, Buffer>(lm);
handler.handle(Future.succeededFuture(store));
}
}
示例4: doDeleteChunks
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
private void doDeleteChunks(Queue<String> paths, AsyncMap<String, Buffer> store,
Handler<AsyncResult<Void>> handler) {
if (paths.isEmpty()) {
handler.handle(Future.succeededFuture());
return;
}
String path = PathUtils.normalize(paths.poll());
store.remove(path, ar -> {
if (ar.failed()) {
handler.handle(Future.failedFuture(ar.cause()));
} else {
doDeleteChunks(paths, store, handler);
}
});
}
示例5: getAsyncMap
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
@Override
public <K, V> void getAsyncMap(final String name, final Handler<AsyncResult<AsyncMap<K, V>>> resultHandler) {
ConcurrentMap map = asyncMaps.get(name);
if (map == null) {
map = new ConcurrentHashMap<>();
final ConcurrentMap prevMap = asyncMaps.putIfAbsent(name, map);
if (prevMap != null) {
map = prevMap;
}
}
@SuppressWarnings("unchecked") final ConcurrentMap<K, V> theMap = map;
this.vertx.runOnContext(v -> resultHandler.handle(Future.succeededFuture(new FakeAsyncMap<>(theMap))));
}
示例6: adaptListener
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private synchronized void adaptListener() {
if (listenerCleaner == null) {
// TODO - move in separated jar as some sort of provider
AsyncMap<String, Session> map = Reflection.field("sessionMap").ofType(AsyncMap.class).in(sessionStore).get();
String listenerId = tryGetHazelcastMap(map)
.map(imap -> imap.addEntryListener(new MapListenerAdapter<String, Session>() {
@Override
public void entryExpired(EntryEvent<String, Session> event) {
sessionExpiredProducer.send(event.getKey());
}
}, true)).orElse(null);
listenerCleaner = () -> tryGetHazelcastMap(map).ifPresent(imap -> imap.removeEntryListener(listenerId));
}
}
示例7: tryGetHazelcastMap
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
private Optional<IMap> tryGetHazelcastMap(AsyncMap<String, Session> map) {
return Optional.ofNullable(map)
.map( m -> Reflection.field("delegate").ofType(AsyncMap.class).in(m).get())
.filter(HazelcastAsyncMap.class::isInstance)
.map(HazelcastAsyncMap.class::cast)
.map(h -> Reflection.field("map").ofType(IMap.class).in(h).get());
}
示例8: getAsyncMap
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
@Override
public <K, V> void getAsyncMap(String name, Handler<AsyncResult<AsyncMap<K, V>>> resultHandler) {
vertx.executeBlocking(future -> {
Cache<Object, Object> cache = cacheManager.getCache(name);
future.complete(new InfinispanAsyncMapImpl<>(vertx, cache));
}, false, resultHandler);
}
示例9: unwrap
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
/**
* Unwraps a generic {@link AsyncMap} to an {@link InfinispanAsyncMap}.
*
* @throws IllegalArgumentException if underlying implementation is not Infinispan
*/
@SuppressWarnings("unchecked")
static <K, V> InfinispanAsyncMap<K, V> unwrap(AsyncMap asyncMap) {
if (asyncMap instanceof WrappedAsyncMap) {
WrappedAsyncMap wrappedAsyncMap = (WrappedAsyncMap) asyncMap;
AsyncMap delegate = wrappedAsyncMap.getDelegate();
if (delegate instanceof InfinispanAsyncMap) {
return (InfinispanAsyncMap<K, V>) delegate;
}
}
throw new IllegalArgumentException(String.valueOf(asyncMap != null ? asyncMap.getClass() : null));
}
示例10: getAsyncMap
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
@Override
public <K, V> void getAsyncMap(String name, Handler<AsyncResult<AsyncMap<K, V>>> handler) {
atomix.<K, V>consistentMapBuilder(name)
.withSerializer(createSerializer())
.withConsistency(Consistency.LINEARIZABLE)
.withPersistence(Persistence.PERSISTENT)
.withReplication(Replication.SYNCHRONOUS)
.withRecovery(Recovery.RECOVER)
.withMaxRetries(5)
.buildAsync()
.whenComplete(VertxFutures.convertHandler(
handler, map -> new AtomixAsyncMap<>(vertx, map.async()), vertx.getOrCreateContext()));
}
示例11: getAsyncMap
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
@Override
public <K, V> void getAsyncMap(String name, Handler<AsyncResult<AsyncMap<K, V>>> handler) {
logTrace(() -> String.format("Create new AsyncMap [%s] on address [%s]", name, address));
vertx.executeBlocking((future) -> {
checkCluster();
AsyncMap<K, V> map = cacheManager.<K, V>createAsyncMap(name);
future.complete(map);
}, handler);
}
示例12: getEndpointHolderAndAdd
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
private void getEndpointHolderAndAdd(ServerWebSocket serverSocket, AsyncMap<String, WSEndpointHolder> registryMap) {
registryMap.get(WS_ENDPOINT_HOLDER, wsEndpointHolder -> {
if (wsEndpointHolder.succeeded()) {
updateWSEndpointHolder(serverSocket, registryMap, wsEndpointHolder);
}
});
}
示例13: updateWSEndpointHolder
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
private void updateWSEndpointHolder(ServerWebSocket serverSocket, AsyncMap<String, WSEndpointHolder> registryMap, AsyncResult<WSEndpointHolder> wsEndpointHolder) {
log("add entry: " + Thread.currentThread());
final String binaryHandlerId = serverSocket.binaryHandlerID();
final String textHandlerId = serverSocket.textHandlerID();
final String path = serverSocket.path();
final EventBus eventBus = vertx.eventBus();
final WSEndpoint endpoint = new WSEndpoint(binaryHandlerId, textHandlerId, path);
final WSEndpointHolder result = wsEndpointHolder.result();
if (result != null) {
addDefinitionToRegistry(serverSocket, eventBus, path, endpoint, registryMap, result);
} else {
createEntryAndAddDefinition(serverSocket, eventBus, path, endpoint, registryMap);
}
}
示例14: createEntryAndAddDefinition
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
private void createEntryAndAddDefinition(ServerWebSocket serverSocket, EventBus eventBus, String path, WSEndpoint endpoint, AsyncMap<String, WSEndpointHolder> registryMap) {
final WSEndpointHolder holder = new WSEndpointHolder();
holder.add(endpoint);
registryMap.put(WS_ENDPOINT_HOLDER, holder, s -> {
if (s.succeeded()) {
log("OK ADD: " + serverSocket.binaryHandlerID() + " Thread" + Thread.currentThread());
sendToWSService(serverSocket, eventBus, path, endpoint);
}
}
);
}
示例15: addDefinitionToRegistry
import io.vertx.core.shareddata.AsyncMap; //导入依赖的package包/类
private void addDefinitionToRegistry(ServerWebSocket serverSocket, EventBus eventBus, String path, WSEndpoint endpoint, AsyncMap<String, WSEndpointHolder> registryMap, WSEndpointHolder wsEndpointHolder) {
wsEndpointHolder.add(endpoint);
registryMap.replace(WS_ENDPOINT_HOLDER, wsEndpointHolder, s -> {
if (s.succeeded()) {
log("OK REPLACE: " + serverSocket.binaryHandlerID() + " Thread" + Thread.currentThread());
sendToWSService(serverSocket, eventBus, path, endpoint);
}
}
);
}