本文整理了Java中com.hazelcast.core.IMap.set()
方法的一些代码示例,展示了IMap.set()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IMap.set()
方法的具体详情如下:
包路径:com.hazelcast.core.IMap
类名称:IMap
方法名:set
[英]Puts an entry into this map without returning the old value (which is more efficient than put()).
Warning 1:
This method breaks the contract of EntryListener. When an entry is updated by set(), it fires an EntryEvent with a null oldValue.
Warning 2:
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()更有效)。
警告1:
此方法打破了EntryListener的约定。当一个条目由set()更新时,它将触发一个具有null oldValue的EntryEvent。
警告2:
此方法使用密钥二进制形式的hashCode和equals,而不是密钥类中定义的hashCode和equals的实际实现。
与地图商店的交互
如果配置了直写持久化模式,则在将值存储在内存中之前,将调用MapStore#store(对象,对象)将值写入映射存储。存储引发的异常使操作失败,并传播到调用方。
如果将写后持久化模式配置为关闭写合并,则com。黑泽尔卡斯特。地图如果写后队列已达到其每个节点的最大容量,则可能引发ReacheMaxSizeException。
代码示例来源:origin: jooby-project/jooby
@Override
public void save(final Session session) {
Map<String, String> attrs = new HashMap<>(session.attributes());
attrs.put("_createdAt", Long.toString(session.createdAt()));
attrs.put("_accessedAt", Long.toString(session.accessedAt()));
attrs.put("_savedAt", Long.toString(session.savedAt()));
sessions.set(session.id(), attrs, timeout, TimeUnit.SECONDS);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveUpdatedMaxInactiveIntervalInSecondsFlushModeImmediate() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
HazelcastSession session = this.repository.createSession();
String sessionId = session.getId();
session.setMaxInactiveInterval(Duration.ofSeconds(1));
verify(this.sessions, times(1)).set(eq(sessionId),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verify(this.sessions).setTtl(eq(sessionId), anyLong(), any());
verify(this.sessions, times(1)).executeOnKey(eq(sessionId),
any(EntryProcessor.class));
this.repository.save(session);
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveUpdatedLastAccessedTimeFlushModeOnSave() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
HazelcastSession session = this.repository.createSession();
session.setLastAccessedTime(Instant.now());
verifyZeroInteractions(this.sessions);
this.repository.save(session);
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveUpdatedMaxInactiveIntervalInSecondsFlushModeOnSave() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
HazelcastSession session = this.repository.createSession();
session.setMaxInactiveInterval(Duration.ofSeconds(1));
verifyZeroInteractions(this.sessions);
this.repository.save(session);
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveNewFlushModeOnSave() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
HazelcastSession session = this.repository.createSession();
verifyZeroInteractions(this.sessions);
this.repository.save(session);
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void removeAttributeFlushModeOnSave() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
HazelcastSession session = this.repository.createSession();
session.removeAttribute("testName");
verifyZeroInteractions(this.sessions);
this.repository.save(session);
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveUpdatedAttributeFlushModeOnSave() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
HazelcastSession session = this.repository.createSession();
session.setAttribute("testName", "testValue");
verifyZeroInteractions(this.sessions);
this.repository.save(session);
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveNewFlushModeImmediate() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
HazelcastSession session = this.repository.createSession();
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveUnchangedFlushModeOnSave() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
HazelcastSession session = this.repository.createSession();
this.repository.save(session);
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
this.repository.save(session);
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveUnchangedFlushModeImmediate() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
HazelcastSession session = this.repository.createSession();
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
this.repository.save(session);
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveUpdatedLastAccessedTimeFlushModeImmediate() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
HazelcastSession session = this.repository.createSession();
session.setLastAccessedTime(Instant.now());
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verify(this.sessions, times(1)).executeOnKey(eq(session.getId()),
any(EntryProcessor.class));
this.repository.save(session);
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void saveUpdatedAttributeFlushModeImmediate() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
HazelcastSession session = this.repository.createSession();
session.setAttribute("testName", "testValue");
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verify(this.sessions, times(1)).executeOnKey(eq(session.getId()),
any(EntryProcessor.class));
this.repository.save(session);
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void removeAttributeFlushModeImmediate() {
verify(this.sessions, times(1)).addEntryListener(any(MapListener.class),
anyBoolean());
this.repository.setHazelcastFlushMode(HazelcastFlushMode.IMMEDIATE);
HazelcastSession session = this.repository.createSession();
session.removeAttribute("testName");
verify(this.sessions, times(1)).set(eq(session.getId()),
eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS));
verify(this.sessions, times(1)).executeOnKey(eq(session.getId()),
any(EntryProcessor.class));
this.repository.save(session);
verifyZeroInteractions(this.sessions);
}
代码示例来源:origin: spring-projects/spring-session
@Override
public void save(HazelcastSession session) {
if (session.isNew) {
this.sessions.set(session.getId(), session.getDelegate(),
session.getMaxInactiveInterval().getSeconds(), TimeUnit.SECONDS);
}
else if (session.sessionIdChanged) {
this.sessions.delete(session.originalId);
session.originalId = session.getId();
this.sessions.set(session.getId(), session.getDelegate(),
session.getMaxInactiveInterval().getSeconds(), TimeUnit.SECONDS);
}
else if (session.hasChanges()) {
SessionUpdateEntryProcessor entryProcessor = new SessionUpdateEntryProcessor();
if (session.lastAccessedTimeChanged) {
entryProcessor.setLastAccessedTime(session.getLastAccessedTime());
}
if (session.maxInactiveIntervalChanged) {
if (SUPPORTS_SET_TTL) {
updateTtl(session);
}
entryProcessor.setMaxInactiveInterval(session.getMaxInactiveInterval());
}
if (!session.delta.isEmpty()) {
entryProcessor.setDelta(session.delta);
}
this.sessions.executeOnKey(session.getId(), entryProcessor);
}
session.clearChangeFlags();
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
public static void main(String[] args) throws Exception {
Config config = new Config();
config.setProperty("hazelcast.rest.enabled", "true");
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
Person person = new Person("Joe");
IMap<String, String> hzSimpleMap = hz.getMap("simple");
hzSimpleMap.set("key1", "value1");
IMap<String, Person> hzObjectMap = hz.getMap("object");
hzObjectMap.set("key1", person);
}
}
代码示例来源:origin: com.hazelcast/hazelcast-all
@Override
public void put(Object key, Object value) {
if (key != null) {
map.set(key, toStoreValue(value));
}
}
代码示例来源:origin: com.hazelcast.simulator/tests-common
@TimeStep(prob = 0)
public void set(ThreadState state) {
String key = state.randomKey();
String value = state.randomValue();
map.set(key, value);
}
代码示例来源:origin: com.hazelcast.jet/hazelcast-jet-spring
@Override
public void put(Object key, Object value) {
if (key != null) {
map.set(key, toStoreValue(value));
}
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
@Override
public void run(String... arg0) throws Exception {
IMap<String, String> helloMap = this.hazelcastInstance.getMap("hello");
if (!helloMap.isEmpty()) {
LOGGER.info("Skip loading '{}', not empty", helloMap.getName());
} else {
Arrays.stream(GREETINGS).forEach(pair -> {
helloMap.set(pair[0], pair[1]);
});
LOGGER.info("Loaded {} into '{}'", GREETINGS.length, helloMap.getName());
}
}
代码示例来源:origin: hazelcast/hazelcast-code-samples
private static void populate(IMap<Integer, Person> personsMap) {
Person person1 = Person.newBuilder().setId(1).setEmail("dude@hazelcast.com").setName("Dude").build();
Person person2 = Person.newBuilder().setId(2).setEmail("sales@hazelcast.com").setName("John Appleseed").build();
Person person3 = Person.newBuilder().setId(3).setEmail("support@hazelcast.com").setName("John Support").build();
personsMap.set(person1.getId(), person1);
personsMap.set(person2.getId(), person2);
personsMap.set(person3.getId(), person3);
}
}
内容来源于网络,如有侵权,请联系作者删除!