本文整理匯總了Java中com.hazelcast.core.IMap.get方法的典型用法代碼示例。如果您正苦於以下問題:Java IMap.get方法的具體用法?Java IMap.get怎麽用?Java IMap.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hazelcast.core.IMap
的用法示例。
在下文中一共展示了IMap.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleRequest
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
String refreshToken = exchange.getQueryParameters().get("refreshToken").getFirst();
if(logger.isDebugEnabled()) logger.debug("refreshToken = " + refreshToken);
IMap<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
RefreshToken token = tokens.get(refreshToken);
if(token == null) {
Status status = new Status(REFRESH_TOKEN_NOT_FOUND, refreshToken);
exchange.setStatusCode(status.getStatusCode());
exchange.getResponseSender().send(status.toString());
return;
}
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(token));
}
示例2: validateClientSecret
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
private Client validateClientSecret(String clientId, String clientSecret) throws ApiException {
IMap<String, Client> clients = CacheStartupHookProvider.hz.getMap("clients");
Client client = clients.get(clientId);
if(client == null) {
throw new ApiException(new Status(CLIENT_NOT_FOUND, clientId));
} else {
try {
if(HashUtil.validatePassword(clientSecret.toCharArray(), client.getClientSecret())) {
return client;
} else {
throw new ApiException(new Status(UNAUTHORIZED_CLIENT));
}
} catch ( NoSuchAlgorithmException | InvalidKeySpecException e) {
logger.error("Exception:", e);
throw new ApiException(new Status(RUNTIME_EXCEPTION));
}
}
}
示例3: handleRequest
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
Map<String, Object> body = (Map)exchange.getAttachment(BodyHandler.REQUEST_BODY);
User user = Config.getInstance().getMapper().convertValue(body, User.class);
String userId = user.getUserId();
IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users");
User u = users.get(userId);
if(u == null) {
Status status = new Status(USER_NOT_FOUND, userId);
exchange.setStatusCode(status.getStatusCode());
exchange.getResponseSender().send(status.toString());
} else {
// as password is not in the return value, chances are password is not in the user object
user.setPassword(u.getPassword());
user.setUpdateDt(new Date(System.currentTimeMillis()));
users.set(userId, user);
}
}
示例4: testGlobalCustomDelegateSerializationConfiguredProgrammaticallyForClientConfig
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Test
public void testGlobalCustomDelegateSerializationConfiguredProgrammaticallyForClientConfig() {
Config memberConfig = new Config();
SubZero.useAsGlobalSerializer(memberConfig);
hazelcastFactory.newHazelcastInstance(memberConfig);
String mapName = randomMapName();
ClientConfig config = new ClientConfig();
SubZero.useAsGlobalSerializer(config, MyGlobalDelegateSerlizationConfig.class);
HazelcastInstance member = hazelcastFactory.newHazelcastClient(config);
IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName);
myMap.put(0, new AnotherNonSerializableObject());
AnotherNonSerializableObject fromCache = myMap.get(0);
assertEquals("deserialized", fromCache.name);
}
示例5: handleRequest
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
String clientId = exchange.getQueryParameters().get("clientId").getFirst();
IMap<String, Client> clients = CacheStartupHookProvider.hz.getMap("clients");
Client client = clients.get(clientId);
if(client == null) {
Status status = new Status(CLIENT_NOT_FOUND, clientId);
exchange.setStatusCode(status.getStatusCode());
exchange.getResponseSender().send(status.toString());
return;
}
Client c = Client.copyClient(client);
c.setClientSecret(null);
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(c));
}
示例6: testClientCache
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testClientCache() {
CacheStartupHookProvider start = new CacheStartupHookProvider();
start.onStartup();
final IMap<String, Client> clients = CacheStartupHookProvider.hz.getMap("clients");
Client client = clients.get("f7d42348-c647-4efb-a52d-4c5787421e72");
System.out.println("client = " + client);
client.setClientType(Client.ClientTypeEnum.fromValue("trusted"));
clients.put("f7d42348-c647-4efb-a52d-4c5787421e72", client);
System.out.println("clients size = " + clients.size());
clients.delete("f7d42348-c647-4efb-a52d-4c5787421e72");
System.out.println("clients size = " + clients.size());
CacheShutdownHookProvider shutdown = new CacheShutdownHookProvider();
shutdown.onShutdown();
}
示例7: onEntryChange
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
private void onEntryChange(RefreshableConfiguration refreshableConfiguration,
EntryEvent<String, String> entry,
IMap<String, String> configMap) {
String entryKey = entry.getKey();
String configContent = configMap.get(entryKey);
if (refreshableConfiguration.isListeningConfiguration(entryKey)) {
refreshableConfiguration.onRefresh(entryKey, configContent);
log.info(
"Process config update event: "
+ "[key = {}, evtType = {}, size = {}, newHash = {}, oldHash = {}] in bean: [{}]",
entryKey,
entry.getEventType(),
StringUtils.length(configContent),
getValueHash(configContent),
getValueHash(entry.getOldValue()),
getBeanName(refreshableConfiguration));
} else {
log.debug("Ignored config update event: [key = {}, evtType = {}, configSize = {} in bean [{}]",
entryKey,
entry.getEventType(),
StringUtils.length(configContent),
getBeanName(refreshableConfiguration));
}
}
示例8: simpleTest
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Test
public void simpleTest() throws Exception {
final IMap<Integer, String> testMapFromMember = member.getMap("testMap");
testMapFromMember.set(1, "test1");
final IMap<Integer, String> testMap = client.getMap("testMap");
final String value = testMap.get(1);
assertEquals("member puts, client gets", value, "test1");
}
示例9: cacheMetrics
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Test
void cacheMetrics() {
IMap<String, String> map = h.getMap("my-distributed-map");
SimpleMeterRegistry registry = new SimpleMeterRegistry();
HazelcastCacheMetrics.monitor(registry, map, "cache",emptyList());
map.put("key", "value");
map.get("key");
assertThat(registry.mustFind("cache.gets").functionTimer().count()).isEqualTo(1L);
assertThat(registry.mustFind("cache.puts").functionTimer().count()).isEqualTo(1L);
}
示例10: handleRequest
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
String refreshToken = exchange.getQueryParameters().get("refreshToken").getFirst();
if(logger.isDebugEnabled()) logger.debug("refreshToken = " + refreshToken);
IMap<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
if(tokens.get(refreshToken) == null) {
Status status = new Status(REFRESH_TOKEN_NOT_FOUND, refreshToken);
exchange.setStatusCode(status.getStatusCode());
exchange.getResponseSender().send(status.toString());
} else {
tokens.delete(refreshToken);
}
}
示例11: handle
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Override
public void handle(InventoryItemRenamed event) {
IMap<String, InventoryItemListItem> inventoryItems = getInventoryItemsMap();
String id = event.id.toString();
InventoryItemListItem item = inventoryItems.get(id);
if (item != null) {
item.name = event.getNewName();
item.version = event.version;
inventoryItems.put(id, item);
}
}
示例12: testGlobalCustomDelegateSerializationConfiguredProgrammaticallyForHzConfig
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Test
public void testGlobalCustomDelegateSerializationConfiguredProgrammaticallyForHzConfig() {
String mapName = randomMapName();
Config config = new Config();
SubZero.useAsGlobalSerializer(config, MyGlobalDelegateSerlizationConfig.class);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
IMap<Integer, AnotherNonSerializableObject> myMap = member.getMap(mapName);
myMap.put(0, new AnotherNonSerializableObject());
AnotherNonSerializableObject fromCache = myMap.get(0);
assertEquals("deserialized", fromCache.name);
}
示例13: testMapName
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Test
public void testMapName() throws Exception {
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
instance1 = getWebContainerConfigurator();
instance1.port(SERVER_PORT_1).sticky(true).clientOnly(true).mapName(SESSION_REPLICATION_MAP_NAME).sessionTimeout(10).start();
instance2 = getWebContainerConfigurator();
instance2.port(SERVER_PORT_2).sticky(true).clientOnly(true).mapName(SESSION_REPLICATION_MAP_NAME).sessionTimeout(10).start();
CookieStore cookieStore = new BasicCookieStore();
executeRequest("write", SERVER_PORT_1, cookieStore);
Cookie cookie = cookieStore.getCookies().get(0);
String sessionId = cookie.getValue();
IMap<String, HazelcastSession> map = hz.getMap(SESSION_REPLICATION_MAP_NAME);
assertEquals(1, map.size());
HazelcastSession session = map.get(sessionId);
assertFalse(session.getAttributes().isEmpty());
executeRequest("remove", SERVER_PORT_1, cookieStore);
cookie = cookieStore.getCookies().get(0);
String newSessionId = cookie.getValue();
session = map.get(newSessionId);
assertTrue(session.getAttributes().isEmpty());
}
示例14: test_setAttribute
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Test(timeout = 20000)
public void test_setAttribute() throws Exception {
CookieStore cookieStore = new BasicCookieStore();
executeRequest("setAttribute?key=value&key2=value2&key2=value22", serverPort1, cookieStore);
IMap<Object, Object> map = hz.getMap(DEFAULT_MAP_NAME);
assertEquals(1, map.size());
String hazelcastSessionId = getHazelcastSessionId(cookieStore);
SessionState sessionState = (SessionState) map.get(hazelcastSessionId);
assertEquals(2, sessionState.getAttributes().size());
assertEquals("value", executeRequest("read", serverPort1, cookieStore));
assertEquals("value", executeRequest("read", serverPort2, cookieStore));
assertEquals(1, map.size());
server1.stop();
assertEquals(1, map.size());
sessionState = (SessionState) map.get(hazelcastSessionId);
assertEquals(2, sessionState.getAttributes().size());
assertEquals("value", executeRequest("read", serverPort2, cookieStore));
server2.stop();
assertEquals(1, map.size());
sessionState = (SessionState) map.get(hazelcastSessionId);
assertNotNull(sessionState);
server1.start();
assertEquals("true", executeRequest("write", serverPort1, cookieStore));
server2.start();
assertEquals("value", executeRequest("read", serverPort2, cookieStore));
executeRequest("invalidate", serverPort2, cookieStore);
assertEquals(0, map.size());
assertNull(map.get(hazelcastSessionId));
assertEquals("null", executeRequest("read", serverPort2, cookieStore));
assertEquals("null", executeRequest("read", serverPort1, cookieStore));
}
示例15: test_setAttribute
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Test(timeout = 20000)
public void test_setAttribute() throws Exception {
CookieStore cookieStore = new BasicCookieStore();
executeRequest("setAttribute?key=value&key2=value2&key2=value22", serverPort1, cookieStore);
IMap<Object, Object> map = hz.getMap(DEFAULT_MAP_NAME);
assertEquals(1, map.size());
SessionState sessionState = (SessionState) map.get(getHazelcastSessionId(cookieStore));
assertEquals(2, sessionState.getAttributes().size());
assertEquals("value", executeRequest("read", serverPort1, cookieStore));
assertEquals("value", executeRequest("read", serverPort2, cookieStore));
assertEquals(1, map.size());
assertEquals("value", executeRequest("read", serverPort2, cookieStore));
assertEquals("true", executeRequest("update", serverPort2, cookieStore));
assertEquals("value-updated", executeRequest("read", serverPort2, cookieStore));
assertEquals("value-updated", executeRequest("read", serverPort1, cookieStore));
}