private void storeConnection(String agentId, String username, String password, String resource) throws JSONRPCException, IOException, InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { State state = agentHost.getStateFactory().get(agentId); String conns = (String) state.get(CONNKEY); ArrayNode newConns; if (conns != null) { newConns = (ArrayNode) JOM.getInstance().readTree(conns); } else { newConns = JOM.createArrayNode(); } ObjectNode params = JOM.createObjectNode(); params.put("username", EncryptionUtil.encrypt(username)); params.put("password", EncryptionUtil.encrypt(password)); if (resource != null && !resource.isEmpty()) { params.put("resource", EncryptionUtil.encrypt(resource)); } for (JsonNode item : newConns) { if (item.get("username").equals(params.get("username"))) { return; } } newConns.add(params); if (!state.putIfUnchanged(CONNKEY, JOM.getInstance().writeValueAsString(newConns), conns)) { // recursive retry storeConnection(agentId, username, password, resource); } }
private ArrayNode getConns(String agentId) throws IOException, JSONRPCException { State state = agentHost.getStateFactory().get(agentId); ArrayNode conns = null; if (state.containsKey(CONNKEY)) { conns = (ArrayNode) JOM.getInstance().readTree((String) state.get(CONNKEY)); } return conns; }
@SuppressWarnings("unchecked") @Namespace("aspect") public T getAspect() { if (aspect == null) { String AspectType = myState.get("_aspectType", String.class); try { aspect = (T) Class.forName(AspectType).getConstructor().newInstance(); } catch (Exception e) { LOG.log(Level.WARNING, "", e); } } return aspect; }