Package com.almende.eve.state

Examples of com.almende.eve.state.State


     * @throws IOException
     */
    public void setAuthorization(@Name("access_token") String access_token,
            @Name("token_type") String token_type, @Name("expires_in") Integer expires_in,
            @Name("refresh_token") String refresh_token) throws IOException {
        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


    /**
     * Remove all stored data from this agent
     */
    @Override
    public void onDelete() {
        State state = getState();
        state.remove("auth");
        state.remove("email");
        state.remove("name");
        super.onDelete();
    }
View Full Code Here

   * @return the conns
   * @throws IOException
   *             Signals that an I/O exception has occurred.
   */
  private ArrayNode getConns(final String agentId) throws IOException {
    final 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

      InvalidKeyException, InvalidAlgorithmParameterException,
      NoSuchAlgorithmException, InvalidKeySpecException,
      NoSuchPaddingException, IllegalBlockSizeException,
      BadPaddingException {
   
    final State state = agentHost.getStateFactory().get(agentId);
   
    final String conns = state.get(CONNKEY, String.class);
    ArrayNode newConns;
    if (conns != null) {
      newConns = (ArrayNode) JOM.getInstance().readTree(conns);
    } else {
      newConns = JOM.createArrayNode();
    }
   
    final ObjectNode params = JOM.createObjectNode();
    params.put("username", EncryptionUtil.encrypt(username));
    params.put("password", EncryptionUtil.encrypt(password));
    if (resource != null && !resource.equals("")) {
      params.put("resource", EncryptionUtil.encrypt(resource));
    }
    for (final 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

   *
   * @param agentId
   *            the agent id
   */
  private void delConnections(final String agentId) {
    final State state = agentHost.getStateFactory().get(agentId);
    if (state != null) {
      state.remove(CONNKEY);
    }
  }
View Full Code Here

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

      final String agentId) throws InstantiationException,
      IllegalAccessException, InvocationTargetException,
      NoSuchMethodException, IOException {
   
    // create the state
    final State state = getStateFactory().create(agentId);
    state.setAgentType(agentType);
    state.init();
   
    // instantiate the agent
    final T agent = agentType.getConstructor().newInstance();
    agent.constr(this, state);
    agent.signalAgent(new AgentSignal<Void>(AgentSignal.CREATE));
View Full Code Here

      return agent;
    }
    //No agent found, normal initialization:
   
    // load the State
    State state = 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 Exception("Cannot instantiate agent. " +
          "Class information missing in the agents state " +
          "(agentId='" + agentId + "')");
    }
View Full Code Here

      logger.warning("Validation error class: " + agentType.getName() +
          ", message: " + error);
    }
   
    // create the state
    State state = getStateFactory().create(agentId);
    state.setAgentType(agentType);
    state.destroy();

    // instantiate the agent
    Agent agent = (Agent) agentType.getConstructor().newInstance();
    agent.setAgentFactory(this);
    agent.setState(state);
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.