本文整理匯總了Java中com.hazelcast.core.IMap類的典型用法代碼示例。如果您正苦於以下問題:Java IMap類的具體用法?Java IMap怎麽用?Java IMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IMap類屬於com.hazelcast.core包,在下文中一共展示了IMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createFutureEvent
import com.hazelcast.core.IMap; //導入依賴的package包/類
/**
* Set up an event to hang the bets off
*/
public default void createFutureEvent() {
// Grab some horses to use as runners in races
final IMap<Horse, Object> fromHC = getClient().getMap("winners");
final Set<Horse> horses = fromHC.keySet();
// Now set up some future-dated events for next Sat
final LocalDate nextSat = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.SATURDAY));
LocalTime raceTime = LocalTime.of(11, 0); // 1100 start
final Event e = CentralFactory.eventOf("Racing from Epsom", nextSat);
final Set<Horse> runners = makeRunners(horses, 10);
for (int i = 0; i < 18; i++) {
final Map<Horse, Double> runnersWithOdds = makeSimulatedOdds(runners);
final Race r = CentralFactory.raceOf(LocalDateTime.of(nextSat, raceTime), runnersWithOdds);
e.addRace(r);
raceTime = raceTime.plusMinutes(10);
}
final IMap<Long, Event> events = getClient().getMap("events");
events.put(e.getID(), e);
}
示例2: setValue
import com.hazelcast.core.IMap; //導入依賴的package包/類
public void setValue(String map, String key, String contentType,
int length, final InputStream in) throws IOException
{
verifyBucket(map);
byte type = mapContentType(contentType);
IMap<String, byte[]> m = hazelcast.getMap(map);
int offset = 1;
byte[] data = new byte[length + offset];
data[0] = type;
int num;
while ((num = in.read(data, offset, length)) > 0) {
offset += num;
if (offset >= data.length) {
break;
}
}
m.set(key, data);
}
示例3: addTicket
import com.hazelcast.core.IMap; //導入依賴的package包/類
@Override
public void addTicket(final Ticket ticket) {
final long ttl = ticket.getExpirationPolicy().getTimeToLive();
if (ttl < 0) {
throw new IllegalArgumentException("The expiration policy of ticket "
+ ticket.getId() + "is set to use a negative ttl");
}
LOGGER.debug("Adding ticket [{}] with ttl [{}s]", ticket.getId(), ttl);
final Ticket encTicket = encodeTicket(ticket);
final TicketDefinition metadata = this.ticketCatalog.find(ticket);
final IMap<String, Ticket> ticketMap = getTicketMapInstanceByMetadata(metadata);
ticketMap.set(encTicket.getId(), encTicket, ttl, TimeUnit.SECONDS);
LOGGER.debug("Added ticket [{}] with ttl [{}s]", encTicket.getId(), ttl);
}
示例4: lock
import com.hazelcast.core.IMap; //導入依賴的package包/類
private boolean lock(int hash, long waitTime) {
if (rateRecordMap instanceof IMap) {
if (logger.isDebugEnabled())
logger.debug("Getting distributed lock for hash " + hash);
return ((IMap) rateRecordMap).tryLock(hash, waitTime, LOCK_TIME_UNIT);
} else {
try {
if (logger.isDebugEnabled())
logger.debug("Getting local lock for hash " + hash);
return lock.tryLock(waitTime, LOCK_TIME_UNIT);
} catch (InterruptedException e) {
logger.error("Failed to acquire lock for hash " + hash + ": " + e.getMessage());
return false;
}
}
}
示例5: handleRequest
import com.hazelcast.core.IMap; //導入依賴的package包/類
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
IMap<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
Deque<String> userIdDeque = exchange.getQueryParameters().get("userId");
String userId = userIdDeque == null? "%" : userIdDeque.getFirst() + "%";
int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1;
Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize");
int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst());
if(logger.isDebugEnabled()) logger.debug("userId = " + userId + " page = " + page + " pageSize = " + pageSize);
LikePredicate likePredicate = new LikePredicate("userId", userId);
PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new RefreshTokenComparator(), pageSize);
pagingPredicate.setPage(page);
Collection<RefreshToken> values = tokens.values(pagingPredicate);
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values));
}
示例6: testWhenClusterIsDownAtBeginningInDeferedMode
import com.hazelcast.core.IMap; //導入依賴的package包/類
@Test
public void testWhenClusterIsDownAtBeginningInDeferedMode() throws Exception {
if (!testName.equals("client - not deferred")) {
return;
}
hz.shutdown();
CookieStore cookieStore = new BasicCookieStore();
assertEquals("true", executeRequest("write", serverPort1, cookieStore));
assertEquals("value", executeRequest("read", serverPort1, cookieStore));
hz = Hazelcast.newHazelcastInstance(
new FileSystemXmlConfig(new File(sourceDir + "/WEB-INF/", "hazelcast.xml")));
assertClusterSizeEventually(1, hz);
assertEquals("value", executeRequest("read", serverPort1, cookieStore));
IMap<String, Object> map = hz.getMap(DEFAULT_MAP_NAME);
assertEquals(0, map.size());
}
示例7: 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);
}
}
示例8: handleRequest
import com.hazelcast.core.IMap; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
String userId = exchange.getQueryParameters().get("userId").getFirst();
IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users");
User user = users.get(userId);
if(user == null) {
Status status = new Status(USER_NOT_FOUND, userId);
exchange.setStatusCode(status.getStatusCode());
exchange.getResponseSender().send(status.toString());
return;
}
// remove password here
user.setPassword(null);
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(user));
}
示例9: handleRequest
import com.hazelcast.core.IMap; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users");
Deque<String> userIdDeque = exchange.getQueryParameters().get("userId");
String userId = userIdDeque == null? "%" : userIdDeque.getFirst() + "%";
int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1;
Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize");
int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst());
LikePredicate likePredicate = new LikePredicate("userId", userId);
PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new UserComparator(), pageSize);
pagingPredicate.setPage(page);
Collection<User> values = users.values(pagingPredicate);
for (User value : values) {
value.setPassword(null);
}
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values));
}
示例10: handleRequest
import com.hazelcast.core.IMap; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
String serviceId = exchange.getQueryParameters().get("serviceId").getFirst();
IMap<String, Service> services = CacheStartupHookProvider.hz.getMap("services");
Service service = services.get(serviceId);
if(service == null) {
Status status = new Status(SERVICE_NOT_FOUND, serviceId);
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(service));
}
示例11: 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));
}
示例12: handleRequest
import com.hazelcast.core.IMap; //導入依賴的package包/類
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
IMap<String, Client> clients = CacheStartupHookProvider.hz.getMap("clients");
Deque<String> clientNameDeque = exchange.getQueryParameters().get("clientName");
String clientName = clientNameDeque == null? "%" : clientNameDeque.getFirst() + "%";
int page = Integer.valueOf(exchange.getQueryParameters().get("page").getFirst()) - 1;
Deque<String> pageSizeDeque = exchange.getQueryParameters().get("pageSize");
int pageSize = pageSizeDeque == null? 10 : Integer.valueOf(pageSizeDeque.getFirst());
LikePredicate likePredicate = new LikePredicate("clientName", clientName);
PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new ClientComparator(), pageSize);
pagingPredicate.setPage(page);
Collection<Client> values = clients.values(pagingPredicate);
List results = new ArrayList();
for (Client value : values) {
Client c = Client.copyClient(value);
c.setClientSecret(null);
results.add(c);
}
exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json");
exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(results));
}
示例13: 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();
}
示例14: shouldEventuallyCleanUpExpiredKeys
import com.hazelcast.core.IMap; //導入依賴的package包/類
@Test
void shouldEventuallyCleanUpExpiredKeys() throws Exception {
ImmutableSet<RequestLimitRule> rules = ImmutableSet.of(RequestLimitRule.of(2, TimeUnit.SECONDS, 5));
RequestRateLimiter requestRateLimiter = getRateLimiter(rules, timeBandit);
String key = "ip:127.0.0.5";
IntStream.rangeClosed(1, 5).forEach(value -> {
timeBandit.addUnixTimeMilliSeconds(100L);
assertThat(requestRateLimiter.overLimitWhenIncremented(key)).isFalse();
});
IMap<Object, Object> map = hz.getMap(key);
while (map.size() != 0) {
Thread.sleep(10);
}
assertThat(map.size()).isZero();
}
示例15: main
import com.hazelcast.core.IMap; //導入依賴的package包/類
public static void main(String[] args) {
HazelcastInstance ins = Hazelcast.newHazelcastInstance();
IMap<Integer, String> map = ins.getMap("");
map.addEntryListener(new ListenerExample(), true);//添加自定義監聽器
map.put(1, "Grand Theft Auto");
map.put(1, "Final Fantasy");
map.put(2, "World Of Warcraft");
HazelcastInstance insex = Hazelcast.newHazelcastInstance();
IMap<Integer, String> mapex = insex.getMap("");
System.out.println(mapex.get(1));
System.out.println(mapex.get(2));
mapex.remove(1);
mapex.remove(2);
System.exit(0);
}