Package com.google.code.twig

Examples of com.google.code.twig.ObjectDatastore


  public Map<String, Object> create(@Name("id") String id, @Name("type") String type)
      throws Exception {
    try {
      getAgentFactory().createAgent(type, id)
   
      ObjectDatastore datastore = new AnnotationObjectDatastore();
     
      // remove any old registration
      AgentMetaData meta = datastore.load(AgentMetaData.class, id);
      if (meta != null) {
        datastore.delete(meta);
      }
     
      // store new registration
      meta = new AgentMetaData(type, id);
      datastore.store(meta);
     
      try {
        trigger("create", toInfo(meta));
      }
      catch (Exception e) {}
View Full Code Here


   */
  public Map<String, Object> register(@Name("id") String id) throws Exception {
    AgentFactory factory = getAgentFactory();
    Agent agent = factory.getAgent(id);
    if (agent != null) {
      ObjectDatastore datastore = new AnnotationObjectDatastore();
     
      // remove any old registration
      AgentMetaData meta = datastore.load(AgentMetaData.class, id);
      if (meta != null) {
        datastore.delete(meta);
      }
     
      // store new registration
      meta = new AgentMetaData(agent.getClass().getName(), agent.getId());
      datastore.store(meta);
     
      try {
        trigger("register", toInfo(meta));
      }
      catch (Exception e) {}
View Full Code Here

   * Unregister an existing agent.
   * @param id
   * @throws Exception
   */
  public void unregister(@Name("id") String id) throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    AgentMetaData meta = datastore.load(AgentMetaData.class, id);
    if (meta != null) {
      try {
        trigger("unregister", toInfo(meta));
        datastore.delete(meta);
      }
      catch (Exception e) {}
    }
  }
View Full Code Here

   * @param id
   * @return
   * @throws Exception
   */
  public void delete(@Name("id") String id) throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    AgentMetaData meta = datastore.load(AgentMetaData.class, id);
    if (meta != null) {
      try {
        trigger("delete", toInfo(meta));
      }
      catch (Exception e) {}
     
      datastore.delete(meta);
    }   

    getAgentFactory().deleteAgent(id);
  }
View Full Code Here

   * @return agents     meta information of all agents: id, type, urls
   * @throws Exception
   */
  public List<Map<String, Object>> list(
      @Name("type") @Required(false) String type) throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    RootFindCommand<AgentMetaData> command = datastore.find()
      .type(AgentMetaData.class);
    if (type != null) {
      command = command.addFilter("type", FilterOperator.EQUAL, type);
    }

    List<Map<String, Object>> info = new ArrayList<Map<String,Object>>();
    QueryResultIterator<AgentMetaData> it = command.now();
    while (it.hasNext()) {
      AgentMetaData meta = it.next();
      Map<String, Object> i = toInfo(meta);
      if (i != null) {
        info.add(i);
      }
      else {
        // agent does not exist anymore. Delete meta information.
        datastore.delete(meta);
      }
    }   
   
    return info;
  }
View Full Code Here

   * @param id
   * @return info
   * @throws Exception
   */
  public Map<String, Object> get(@Name("id") String id) throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    AgentMetaData meta = datastore.load(AgentMetaData.class, id);
    if (meta != null) {
      return toInfo(meta);
    }
    else {
      Agent agent = getAgentFactory().getAgent(id);
View Full Code Here

   */
  public void onMessage(@Name("message") Message message) throws Exception {
    // store the message in the inbox
    message.setAgent(getFirstUrl());
    message.setBox("inbox");
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    datastore.store(message);
   
    // trigger receive event (not necessary)
    String event = "receive";
    ObjectNode params = JOM.createObjectNode();
    params.put("message", JOM.getInstance().convertValue(message, ObjectNode.class));
View Full Code Here

    message.setStatus("unread");

    // store the message in the outbox
    message.setAgent(getFirstUrl());
    message.setBox("outbox");
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    datastore.store(message);
   
    // send the message to all recipients
    Set<String> to = message.getTo();
    if (to != null) {
      for (String url : to) {
View Full Code Here

   * @return messages
   * @throws Exception
   */
  private List<Message> find (String box, String since, String status)
      throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
   
    RootFindCommand<Message> command = datastore.find()
      .type(Message.class)
      .addFilter("agent", FilterOperator.EQUAL, getFirstUrl());
    if (box != null) {
      command = command.addFilter("box", FilterOperator.EQUAL, box);
    }
View Full Code Here

  /**
   * Clear inbox and outbox and everything the agent has stored.
   */
  @Override
  public void clear() throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    QueryResultIterator<Message> it = datastore.find()
      .type(Message.class)
      .addFilter("agent", FilterOperator.EQUAL, getFirstUrl())
      .now();
   
    while (it.hasNext()) {
      Message message = it.next();
      datastore.delete(message);
      // TODO: bulk delete all messages instead of one by one
    }
  }
View Full Code Here

TOP

Related Classes of com.google.code.twig.ObjectDatastore

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.