com.hazelcast.core.IMap.setAsync()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中com.hazelcast.core.IMap.setAsync()方法的一些代码示例,展示了IMap.setAsync()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IMap.setAsync()方法的具体详情如下:
包路径:com.hazelcast.core.IMap
类名称:IMap
方法名:setAsync

IMap.setAsync介绍

[英]Asynchronously puts the given key and value. The entry lives forever. Similar to the put operation except that set doesn't return the old value, which is more efficient.

ICompletableFuture future = map.setAsync(key, value);

ICompletableFuture.get() will block until the actual map.set() operation completes. If your application requires a timely response, then you can use ICompletableFuture.get(timeout, timeunit).

try catch (TimeoutException t)  
// time wasn't enough 
} 
}

You can also schedule an ExecutionCallback to be invoked upon completion of the ICompletableFuture via ICompletableFuture#andThen(ExecutionCallback) or ICompletableFuture#andThen(ExecutionCallback,Executor):

ICompletableFuture future = map.setAsync("a", "b");public 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 write-through persistence mode is configured, before the value is stored in memory, MapStore#store(Object,Object) is called to write the value into the map store. Exceptions thrown by the store fail the operation and are propagated to the caller.

If write-behind persistence mode is configured with write-coalescing turned off, com.hazelcast.map.ReachedMaxSizeException may be thrown if the write-behind queue has reached its per-node maximum capacity.
[中]异步放置给定的键和值。入口永远存在。与put操作类似,只是set不返回旧值,这更有效

ICompletableFuture future = map.setAsync(key, value);

ICompletableFuture。get()将一直阻止,直到生成实际贴图为止。set()操作完成。如果您的应用程序需要及时响应,那么您可以在将来使用ICompleTable。获取(超时,时间单位)

try catch (TimeoutException t)  
// time wasn't enough 
} 
}

您还可以计划在ICompletableFuture完成后通过ICompletableFuture调用ExecutionCallback,然后通过ICompletableFuture(ExecutionCallback)或ICompletableFuture(ExecutionCallback,Executor):永远不会引发ExecutionException。
警告:
此方法使用密钥二进制形式的hashCode和equals,而不是密钥类中定义的hashCode和equals的实际实现。
与地图商店的交互
如果配置了直写持久化模式,则在将值存储在内存中之前,将调用MapStore#store(对象,对象)将值写入映射存储。存储引发的异常使操作失败,并传播到调用方。
如果将写后持久化模式配置为关闭写合并,则com。黑泽尔卡斯特。地图如果写后队列已达到其每个节点的最大容量,则可能引发ReacheMaxSizeException。

代码示例

代码示例来源:origin: hazelcast/hazelcast-jet

@Override
public ICompletableFuture<Void> setAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdle,
                     TimeUnit maxIdleUnit) {
  return map.setAsync(key, value, ttl, ttlUnit, maxIdle, maxIdleUnit);
}

代码示例来源:origin: hazelcast/hazelcast-jet

@Override
public ICompletableFuture<Void> setAsync(K key, V value) {
  return map.setAsync(key, value);
}

代码示例来源:origin: hazelcast/hazelcast-jet

@Override
public ICompletableFuture<Void> setAsync(K key, V value, long ttl, TimeUnit timeunit) {
  return map.setAsync(key, value, ttl, timeunit);
}

代码示例来源:origin: hazelcast/hazelcast-jet

@Override
public ICompletableFuture<Void> setAsync(K key, V value) {
  return map.setAsync(key, value);
}

代码示例来源:origin: hazelcast/hazelcast-jet

@Override
public ICompletableFuture<Void> setAsync(K key, V value, long ttl, TimeUnit timeunit) {
  return map.setAsync(key, value, ttl, timeunit);
}

代码示例来源:origin: com.hazelcast/hazelcast-all

@Override
public ICompletableFuture<Void> setAsync(K key, V value, long ttl, TimeUnit timeunit) {
  return map.setAsync(key, value, ttl, timeunit);
}

代码示例来源:origin: com.hazelcast/hazelcast-all

@Override
public ICompletableFuture<Void> setAsync(K key, V value) {
  return map.setAsync(key, value);
}

相关文章