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

The following examples show how to use com.hazelcast.core.IMap#containsKey() . 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: OrderData.java    From match-trade with Apache License 2.0 6 votes vote down vote up
/**
 * @Title: new_order
 * @Description: TODO(接收撤销订单数据)
 * @param  参数
 * @return void 返回类型
 * @throws
 */
@KafkaListener(id = "cancel_order", topics = "cancel_order")
public void cancel_order(String param) {
	log.info("===收到cancel_order:"+param);
	CancelOrderParam cancel = JSON.parseObject(param, CancelOrderParam.class);
	IMap<Long, MatchOrder> order_map = hzInstance.getMap(HazelcastUtil.getOrderBookKey(cancel.getCoinTeam(), cancel.getIsBuy()));
	if (order_map.containsKey(cancel.getId())) {
		TransactionOptions options = new TransactionOptions().setTransactionType(TransactionOptions.TransactionType.ONE_PHASE);
		TransactionContext context = hzInstance.newTransactionContext(options);
		context.beginTransaction();
		try {
			IMap<BigDecimal, BigDecimal> map = hzInstance.getMap(HazelcastUtil.getMatchKey(cancel.getCoinTeam(), cancel.getIsBuy()));
			MatchOrder cmo = order_map.remove(cancel.getId());
			map.compute(cmo.getPrice(), (k,v) -> v.subtract(cmo.getUnFinishNumber()));
			if (map.get(cmo.getPrice()).compareTo(BigDecimal.ZERO) >-1) {
				context.commitTransaction();
				pushData.updateOrder(cmo); //推送撤销成功结果
			}else {
				throw new Exception();
			}
		} catch (Exception e) {
			context.rollbackTransaction();
		}
	}
}
 
Example 2
Source File: DefaultAuthenticator.java    From light-oauth2 with Apache License 2.0 6 votes vote down vote up
private Account getAccount(final String id) {
    IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users");
    if (users.containsKey(id)) {
        return new Account() {
            private Set<String> roles = parseRoles(users.get(id).getRoles());
            private final Principal principal = () -> id;
            @Override
            public Principal getPrincipal() {
                return principal;
            }
            @Override
            public Set<String> getRoles() { return roles; }
        };
    }
    return null;
}
 
Example 3
Source File: TimeSeriesMiniCubeManagerHzImpl.java    From minicubes with Apache License 2.0 6 votes vote down vote up
private void handleNewMember(HazelcastInstance instance, Member member) {
    
    // Relationship between Member and MiniCube ID
    IMap<String, String> miniCubeManager = instance.getMap(MINICUBE_MANAGER);
    LOGGER.info("Minicube manager status {}", ObjectUtils.getDisplayString(miniCubeManager));
    
    String key = member.getSocketAddress().toString();
    // FIXME: load-pending status need refactor
    instance.getCluster().getLocalMember().setBooleanAttribute("load-pending", false);
    
    if (miniCubeManager.containsKey(key) && !miniCubeManager.get(key).startsWith("?")) {
        // Maybe node-restart
        LOGGER.info("A node{} restarted, so we need rebuild cube{}", key, miniCubeManager.get(key));
        // Reassign task.
        reassignRole(miniCubeManager.get(key), miniCubeManager.get(key).split("::")[0]);
    } else {
        // First time join into cluster
        String id = "?" + "::" + hzGroupName + "@" + key;
        miniCubeManager.put(key, id);
        
        member.setStringAttribute("cubeId", id);
        LOGGER.info("Add {} into cluster {}", id, hzGroupName);
    }
    LOGGER.info("Set load-pending status to false, enable reassign feature on {}", member);
}