Package com.almende.eve.state

Examples of com.almende.eve.state.State


  }
 
  private void storeConnection(String agentId, String username,
      String password, String resource) throws Exception {
   
    State state = agentFactory.getStateFactory().get(agentId);
   
    String conns = (String) state.get("_XMPP_Connections");
    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("_XMPP_Connections", JOM.getInstance()
        .writeValueAsString(newConns), conns)) {
      // recursive retry
      storeConnection(agentId, username, password, resource);
    }
  }
View Full Code Here


      storeConnection(agentId, username, password, resource);
    }
  }
 
  private void delConnections(String agentId) throws Exception {
    State state = agentFactory.getStateFactory().get(agentId);
    state.remove("_XMPP_Connections");
  }
View Full Code Here

   */
  @Access(AccessType.UNAVAILABLE)
  final public void disconnect(String agentId) {
   
    try {
      State state = agentFactory.getStateFactory().get(agentId);
      ArrayNode conns = null;
      if (state.containsKey("_XMPP_Connections")) {
        conns = (ArrayNode) JOM.getInstance().readTree(
            (String) state.get("_XMPP_Connections"));
      }
      if (conns != null) {
        for (JsonNode conn : conns) {
          ObjectNode params = (ObjectNode) conn;
         
View Full Code Here

    return data.toString();
  }
 
  @Override
  public void reconnect(String agentId) throws Exception {
    State state = agentFactory.getStateFactory().get(agentId);
    ArrayNode conns = null;
    if (state.containsKey("_XMPP_Connections")) {
      conns = (ArrayNode) JOM.getInstance().readTree(
          (String) state.get("_XMPP_Connections"));
    }

    if (conns != null) {
      for (JsonNode conn : conns) {
        ObjectNode params = (ObjectNode) conn;
View Full Code Here

      return agent;
    }
    // No agent found, normal initialization:
   
    // load the State
    State state = null;
    if (getStateFactory() == null) {
      return null;
    }
    state = getStateFactory().get(agentId);
    if (state == null) {
      // agent does not exist
      return null;
    }
    state.init();
   
    // read the agents class name from state
    Class<?> agentType = state.getAgentType();
    if (agentType == null) {
      throw new JSONRPCException("Cannot instantiate agent. "
          + "Class information missing in the agents state "
          + "(agentId='" + agentId + "')");
    }
View Full Code Here

      LOG.warning("Validation error class: " + agentType.getName()
          + ", message: " + error);
    }
   
    // create the state
    State state = getStateFactory().create(agentId);
    state.setAgentType(agentType);
    state.init();
   
    // instantiate the agent
    T agent = (T) agentType.getConstructor().newInstance();
    agent.constr(this, state);
    agent.signalAgent(new AgentSignal<Void>("create"));
View Full Code Here

    init();
  }
 
  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(state.get(CONNKEY,String.class));
    }
    return conns;
  }
View Full Code Here

      IOException, InvalidKeyException,
      InvalidAlgorithmParameterException, NoSuchAlgorithmException,
      InvalidKeySpecException, NoSuchPaddingException,
      IllegalBlockSizeException, BadPaddingException {
   
    State state = agentHost.getStateFactory().get(agentId);
   
    String conns = state.get(CONNKEY,String.class);
    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);
    }
  }
View Full Code Here

      storeConnection(agentId, username, password, resource);
    }
  }
 
  private void delConnections(String agentId) throws JSONRPCException {
    State state = agentHost.getStateFactory().get(agentId);
    state.remove(CONNKEY);
  }
View Full Code Here

      @Name("token_type") String token_type,
      @Name("expires_in") Integer expires_in,
      @Name("refresh_token") String refresh_token) throws IOException {
    logger.info("setAuthorization");
   
    State state = getState();
   
    // retrieve user information
    String url = "https://www.googleapis.com/oauth2/v1/userinfo";
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Authorization", token_type + " " + access_token);
    String resp = HttpUtil.get(url, headers);
   
    ObjectNode info = JOM.getInstance().readValue(resp, ObjectNode.class);
    String email = info.has("email") ? info.get("email").asText() : null;
    String name = info.has("name") ? info.get("name").asText() : null;
   
    DateTime expires_at = calculateExpiresAt(expires_in);
    Authorization auth = new Authorization(access_token, token_type,
        expires_at, refresh_token);
   
    // store the tokens in the state
    state.put("auth", auth);
    state.put("email", email);
    state.put("name", name);
  }
View Full Code Here

TOP

Related Classes of com.almende.eve.state.State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.