Java Code Examples for com.hazelcast.core.IMap#values()

The following examples show how to use com.hazelcast.core.IMap#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Oauth2RefreshTokenGetHandler.java    From light-oauth2 with Apache License 2.0 6 votes vote down vote up
@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));
    processAudit(exchange);
}
 
Example 2
Source File: Oauth2UserGetHandler.java    From light-oauth2 with Apache License 2.0 6 votes vote down vote up
@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(Headers.CONTENT_TYPE, "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values));
    processAudit(exchange);
}
 
Example 3
Source File: Oauth2ServiceGetHandler.java    From light-oauth2 with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    IMap<String, Service> services = CacheStartupHookProvider.hz.getMap("services");

    Deque<String> serviceIdDeque = exchange.getQueryParameters().get("serviceId");
    String serviceId = serviceIdDeque == null? "%" : serviceIdDeque.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("serviceId", serviceId);

    PagingPredicate pagingPredicate = new PagingPredicate(likePredicate, new ServiceComparator(), pageSize);
    pagingPredicate.setPage(page);
    Collection<Service> values = services.values(pagingPredicate);

    exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, "application/json");
    exchange.getResponseSender().send(Config.getInstance().getMapper().writeValueAsString(values));
    processAudit(exchange);
}
 
Example 4
Source File: Oauth2ClientGetHandler.java    From light-oauth2 with Apache License 2.0 6 votes vote down vote up
@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));
    processAudit(exchange);
}
 
Example 5
Source File: MatchDetailHandler.java    From match-trade with Apache License 2.0 4 votes vote down vote up
/**
 * @Title: outMatchDepth 保证了原子操作,无需事务
 * @Description: TODO(out订单处理)
 * @param @param order 入单
 * @return void 返回类型
 * @throws
 */
@Async
public void outMatchDepth(MatchOrder order) {
	List<LevelMatch> list = order.getList();
	try {
		if (null!=list&&list.size()>0) {
			Iterator<LevelMatch> itr = list.iterator();
			while (itr.hasNext()){
				LevelMatch lm = itr.next();
				itr.remove();
				BigDecimal dealNumber = lm.getNumber();
				while (dealNumber.compareTo(BigDecimal.ZERO)>0) {
					//对手盘
					IMap<Long, MatchOrder> order_map = hzInstance.getMap(HazelcastUtil.getOrderBookKey(order.getCoinTeam(), !order.getIsBuy()));
					@SuppressWarnings("rawtypes")
					Predicate pricePredicate = Predicates.equal("price", lm.getPrice());
					Collection<MatchOrder> orders = order_map.values(pricePredicate);
					for (MatchOrder mor : orders) {
						MatchOrder out = order_map.remove(mor.getId());
						if (null!=out) {
							int cpr = dealNumber.compareTo(out.getUnFinishNumber());
							if (cpr>0) {
								dealNumber=dealNumber.subtract(out.getUnFinishNumber());
								this.updateOutOder(out, OrderState.ALL, out.getUnFinishNumber());
							}else if (cpr==0) {
								this.updateOutOder(out, OrderState.ALL, dealNumber);
								dealNumber = BigDecimal.ZERO;
								break;
							}else {
								out = this.updateOutOder(out, OrderState.PART, dealNumber);
								order_map.put(out.getId(), out);
								dealNumber = BigDecimal.ZERO;
								break;
							}
						}
					}
				}
			}
		}
	} catch (Exception e) {
		log.error("===出单数据处理异常,数据原型:"+order.toJsonString()+"   本次异常:"+e);
	}
}
 
Example 6
Source File: Oauth2UserPostHandler.java    From light-oauth2 with Apache License 2.0 4 votes vote down vote up
@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 email = user.getEmail();
    IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users");
    // make sure that email is not duplicated in users.
    Predicate predicate = new SqlPredicate(String.format("email = %s", email));
    Set<User> set = (Set<User>) users.values(predicate);
    if(set != null && set.size() > 0) {
        setExchangeStatus(exchange, EMAIL_EXISTS, email);
        processAudit(exchange);
        return;
    }

    String password = user.getPassword();
    String passwordConfirm = user.getPasswordConfirm();
    if(password != null && password.length() > 0 && passwordConfirm != null && passwordConfirm.length() > 0) {
        // check if there are the same
        if(password.equals(passwordConfirm)) {
            // hash the password with salt.
            String hashedPass = HashUtil.generateStrongPasswordHash(password);
            user.setPassword(hashedPass);
            user.setPasswordConfirm(null);
            String userId = user.getUserId();
            if(users.get(userId) == null) {
                users.set(userId, user);
            } else {
                setExchangeStatus(exchange, USER_ID_EXISTS, userId);
            }
        } else {
            // password and passwordConfirm not match.
            setExchangeStatus(exchange, PASSWORD_PASSWORDCONFIRM_NOT_MATCH, password, passwordConfirm);
        }
    } else {
        // error password or passwordConform is empty
        setExchangeStatus(exchange, PASSWORD_OR_PASSWORDCONFIRM_EMPTY, password, passwordConfirm);
    }
    processAudit(exchange);
}
 
Example 7
Source File: InventoryItemsQuery.java    From cqrs-eventsourcing-kafka with Apache License 2.0 4 votes vote down vote up
public Iterable<InventoryItemListItem> getInventoryItems() {
    IMap<String, InventoryItemListItem> map = hazelcastInstance.getMap(INVENTORY_ITEMS_MAP);

    return map.values();
}
 
Example 8
Source File: InventoryItemsQuery.java    From cqrs-eventsourcing-kafka with Apache License 2.0 4 votes vote down vote up
public Collection<InventoryItemListItem> findInventoryItemsByName(String name) {
    IMap<String, InventoryItemListItem> map = hazelcastInstance.getMap(INVENTORY_ITEMS_MAP);

    return map.values(Predicates.like("name", name));
}
 
Example 9
Source File: CacheStartupHookProviderTest.java    From light-oauth2 with Apache License 2.0 3 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testUserCache() {
    CacheStartupHookProvider start = new CacheStartupHookProvider();
    start.onStartup();

    final IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users");

    User user = (User)users.get("admin");
    System.out.println("user = " + user);

    user.setUserType(User.UserTypeEnum.fromValue("customer"));

    users.put("admin", user);

    System.out.println("users size = " + users.size());

    // query email as it is indexed.
    String email = "adm%";
    Predicate predicate = new SqlPredicate(String.format("email like %s", email));
    Set<User> uSet = (Set<User>) users.values(predicate);

    System.out.println("uSet = " + uSet);

    users.delete("admin");

    System.out.println("users size = " + users.size());

    CacheShutdownHookProvider shutdown = new CacheShutdownHookProvider();
    shutdown.onShutdown();

}