本文整理了Java中com.hazelcast.core.IMap.getAsync()
方法的一些代码示例,展示了IMap.getAsync()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IMap.getAsync()
方法的具体详情如下:
包路径:com.hazelcast.core.IMap
类名称:IMap
方法名:getAsync
[英]Asynchronously gets the given key.
ICompletableFuture future = map.getAsync(key);
// do some other stuff, when ready get the result.
Object value = future.get();
ICompletableFuture#get() will block until the actual map.get() completes. If the application requires timely response, then ICompletableFuture#get(long,TimeUnit) can be used.
try {
ICompletableFuture future = map.getAsync(key);
Object value = future.get(40, TimeUnit.MILLISECOND);
} catch (TimeoutException t) {
// time wasn't enough
}
Additionally, the client can schedule an ExecutionCallback to be invoked upon completion of the ICompletableFuture via ICompletableFuture#andThen(ExecutionCallback) or ICompletableFuture#andThen(ExecutionCallback,Executor):
// assuming an IMappublic void onFailure(Throwable t)
// handle failure
}
});
}
ExecutionException is never thrown.
Warning:
This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equalsdefined in the key's class.
Interactions with the map store
If value with key is not found in memory MapLoader#load(Object) is invoked to load the value from the map store backing the map. Exceptions thrown by load fail the operation and are propagated to the caller.
[中]异步获取给定的密钥
ICompletableFuture future = map.getAsync(key);
// do some other stuff, when ready get the result.
Object value = future.get();
ICompletableFuture#get()将被阻止,直到实际映射。get()完成。如果应用程序需要及时响应,则可以使用ICompletableFuture#get(long,TimeUnit)
try {
ICompletableFuture future = map.getAsync(key);
Object value = future.get(40, TimeUnit.MILLISECOND);
} catch (TimeoutException t) {
// time wasn't enough
}
此外,客户端可以通过ICompletableFuture和ICompletableFuture(ExecutionCallback)或ICompletableFuture(ExecutionCallback,Executor)计划在ICompletableFuture完成后调用ExecutionCallback:
// assuming an IMappublic void onFailure(Throwable t)
// handle failure
}
});
}
永远不会引发ExecutionException。
警告:
此方法使用密钥二进制形式的hashCode和equals,而不是密钥类中定义的hashCode和equals的实际实现。
与地图商店的交互
如果在内存中找不到带键的值,则会调用MapLoader#load(对象)从支持映射的映射存储中加载值。load引发的异常使操作失败,并传播到调用方。
代码示例来源:origin: hazelcast/hazelcast-jet
@Override
public ICompletableFuture<V> getAsync(K key) {
return map.getAsync(key);
}
代码示例来源:origin: hazelcast/hazelcast-jet
@Override
public ICompletableFuture<V> getAsync(K key) {
return map.getAsync(key);
}
代码示例来源:origin: com.hazelcast/hazelcast-all
@Override
public ICompletableFuture<V> getAsync(K key) {
return map.getAsync(key);
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public void run() {
IMap map = hazelcast.getMap("myMap");
try {
map.getAsync(random.nextInt(SIZE)).get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
}, 1);
代码示例来源:origin: hazelcast/hazelcast-jet
protected void handleMapGetAsync(String[] args) {
try {
println(getMap().getAsync(args[1]).get());
} catch (InterruptedException e) {
currentThread().interrupt();
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
代码示例来源:origin: hazelcast/hazelcast-jet
protected void handleMapGetAsync(String[] args) {
try {
println(getMap().getAsync(args[1]).get());
} catch (InterruptedException e) {
currentThread().interrupt();
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
代码示例来源:origin: com.hazelcast/hazelcast-all
protected void handleMapGetAsync(String[] args) {
try {
println(getMap().getAsync(args[1]).get());
} catch (InterruptedException e) {
currentThread().interrupt();
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
代码示例来源:origin: com.hazelcast.simulator/tests-hz36
@TimeStep(prob = 0.2)
public void getAsync(BaseThreadState state) {
int key = state.randomInt(keyCount);
map.getAsync(key);
count.getAsyncCount.incrementAndGet();
}
代码示例来源:origin: com.hazelcast/hazelcast-all
protected void handleMapGetAsync(String[] args) {
try {
println(getMap().getAsync(args[1]).get());
} catch (InterruptedException e) {
currentThread().interrupt();
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
代码示例来源:origin: com.hazelcast.simulator/tests-common
@TimeStep(prob = 0.2)
public void getAsync(ThreadState state) {
int key = state.randomInt(keyCount);
map.getAsync(key);
count.getAsyncCount.incrementAndGet();
}
代码示例来源:origin: com.hazelcast.simulator/tests-common
@TimeStep(prob = 0.1)
public void getAsync(ThreadState state) {
try {
int key = state.randomInt(keyCount);
map.getAsync(key);
state.count.getAsyncCount.incrementAndGet();
} catch (DistributedObjectDestroyedException e) {
EmptyStatement.ignore(e);
}
}
代码示例来源:origin: com.hazelcast.simulator/tests-hz36
@TimeStep(prob = 0.1)
public void getAsync(ThreadState state) {
try {
int key = state.randomInt(keyCount);
map.getAsync(key);
state.count.getAsyncCount.incrementAndGet();
} catch (DistributedObjectDestroyedException e) {
EmptyStatement.ignore(e);
}
}
代码示例来源:origin: com.hazelcast.stabilizer/stabilizer
map.getAsync(key);
count.getAsyncCount.incrementAndGet();
代码示例来源:origin: com.hazelcast.stabilizer/stabilizer
map.getAsync(key);
count.getAsyncCount.incrementAndGet();
代码示例来源:origin: com.hazelcast.simulator/tests-common
@Override
public void timeStep(MapOperation mapOperation) {
Integer key = randomInt(keyCount);
switch (mapOperation) {
case LOAD_ALL:
map.loadAll(true);
break;
case PUT:
putOperation(key);
break;
case GET:
map.get(key);
operationCounter.getCount.incrementAndGet();
break;
case GET_ASYNC:
map.getAsync(key);
operationCounter.getAsyncCount.incrementAndGet();
break;
case DELETE:
map.delete(key);
operationCounter.deleteCount.incrementAndGet();
break;
case DESTROY:
map.destroy();
operationCounter.destroyCount.incrementAndGet();
break;
default:
throw new UnsupportedOperationException();
}
}
代码示例来源:origin: com.hazelcast.simulator/tests-hz36
@Override
public void timeStep(MapOperation mapOperation) {
Integer key = randomInt(keyCount);
switch (mapOperation) {
case LOAD_ALL:
map.loadAll(true);
break;
case PUT:
putOperation(key);
break;
case GET:
map.get(key);
operationCounter.getCount.incrementAndGet();
break;
case GET_ASYNC:
map.getAsync(key);
operationCounter.getAsyncCount.incrementAndGet();
break;
case DELETE:
map.delete(key);
operationCounter.deleteCount.incrementAndGet();
break;
case DESTROY:
map.destroy();
operationCounter.destroyCount.incrementAndGet();
break;
default:
throw new UnsupportedOperationException();
}
}
代码示例来源:origin: com.hazelcast.jet/hazelcast-jet-spring
private Object lookup(Object key) {
if (readTimeout > 0) {
try {
return this.map.getAsync(key).get(readTimeout, TimeUnit.MILLISECONDS);
} catch (TimeoutException te) {
throw new OperationTimeoutException(te.getMessage());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw ExceptionUtil.rethrow(e);
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
return this.map.get(key);
}
代码示例来源:origin: hazelcast/hazelcast-jet
private Object lookup(Object key) {
if (readTimeout > 0) {
try {
return this.map.getAsync(key).get(readTimeout, TimeUnit.MILLISECONDS);
} catch (TimeoutException te) {
throw new OperationTimeoutException(te.getMessage());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw ExceptionUtil.rethrow(e);
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
return this.map.get(key);
}
代码示例来源:origin: com.hazelcast/hazelcast-all
private Object lookup(Object key) {
if (readTimeout > 0) {
try {
return this.map.getAsync(key).get(readTimeout, TimeUnit.MILLISECONDS);
} catch (TimeoutException te) {
throw new OperationTimeoutException(te.getMessage());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw ExceptionUtil.rethrow(e);
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
return this.map.get(key);
}
代码示例来源:origin: com.hazelcast.stabilizer/stabilizer
map.getAsync(key);
count.getAsyncCount.incrementAndGet();
内容来源于网络,如有侵权,请联系作者删除!