Package jade.util.leap

Examples of jade.util.leap.ArrayList


        // Log the original error
        logger.log(Logger.SEVERE,"DB error during search operation.", sqle);
        try {invalidateConnectionWrapper();} catch(Exception e1) {}
      }
    }
    return new ArrayList();
  }
View Full Code Here



  protected abstract void clean();

  public List search(Object template, int maxResults) {
    List result = new ArrayList();
      Iterator it = facts.values().iterator();
    int found = 0;
      while(it.hasNext() && ((maxResults < 0) || (found < maxResults)) ) {
          Object fact = it.next();
        if(match(template, fact)){
        result.add(fact);
        found ++;
        }
        }
        return result;
  }
View Full Code Here

                logger.log(Logger.FINEST, "DF "+myAgent.getName()+": Iterated-search "+request.getConversationId()+". KBIterator correctly initialized");
              }
            }
           
            // Get the requested number of results
            List ll = new ArrayList();
            for (int i = 0; i < maxResult; ++i) {
              if (iterator.hasNext()) {
                ll.add(iterator.next());
              }
              else {
                if (logger.isLoggable(Logger.FINER)) {
                  logger.log(Logger.FINER, "DF "+myAgent.getName()+": Iterated-search "+request.getConversationId()+". Closing KBIterator");
                }
                iterator.close();
                // FIXME: properly handle recursive search
                closeSessionOnNextReply();
                break;
              }
            }
            if (logger.isLoggable(Logger.FINE)) {
              logger.log(Logger.FINE, "DF "+myAgent.getName()+": Iterated-search "+request.getConversationId()+". Sending back "+ll.size()+" results");
            }
           
            // Fill the reply
            reply = request.createReply();
            try {
View Full Code Here

    msg.setPerformative(performative);
    myAgent.send(msg);
  }
 
  protected void serveGetKeys(jade.lang.acl.ACLMessage request, Action aExpr, GetKeys action) throws Exception {
    List keys = new ArrayList();
    Method[] mm = myAgent.getClass().getMethods();
    for (int i = 0; i < mm.length; ++i) {
      Method method = mm[i];
      if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
        Class retType = method.getReturnType();
        if (retType.isPrimitive() || (serializableClass != null && serializableClass.isAssignableFrom(retType))) {
          String key = method.getName().substring(3);
          keys.add(key);
        }
      }
    }
    Result r = new Result(aExpr, keys);
    jade.lang.acl.ACLMessage reply = request.createReply();
View Full Code Here

    */
  public GuiEvent(Object eventSource, int eventType)
  {
    source = eventSource;
    type = eventType; 
    parameters = new ArrayList();
  }
View Full Code Here

     Scan the facts and remove those whose lease time has expired.
   */
  protected void clean(){

    if (entriesToDelete) {
      ArrayList toBeRemoved = new ArrayList();
      Iterator iter = facts.values().iterator();   
      while(iter.hasNext()){
        DFAgentDescription dfd = (DFAgentDescription) iter.next();
        if(dfd.checkLeaseTimeExpired()) {
          toBeRemoved.add(dfd.getName());
        }
      }
      iter = toBeRemoved.iterator();
      while (iter.hasNext()) {
        facts.remove((AID) iter.next());
      }
    }
  }
View Full Code Here

  /**
   * Returns all resolver AIDs for the given AID
   * @return <code>Collection</code> of aid strings
   */
  private Collection getResolverAIDs(String aid) throws SQLException {
    ArrayList res = new ArrayList();
    PreparedStatements pss = getPreparedStatements();

    pss.stm_selAgentResolverAIDs.setString(1, aid);
    ResultSet rs = pss.stm_selAgentResolverAIDs.executeQuery();
    while(rs.next()){
      res.add(rs.getString(1));
    }
    return res;
  }
View Full Code Here

  /**
   * Retrieve the DFDs matching the given template
   */
  protected List searchSingle(Object template, int maxResult) throws SQLException {
    List matchingAIDs = new ArrayList();
   
    // Get the names of all DFDs matching the template
    String select = null;
    ResultSet rs = null;
    Statement s = null;
   
    try {
      select = createSelect((DFAgentDescription) template);
         
      s = getConnectionWrapper().getConnection().createStatement();
      if (maxResult >= 0) {
        s.setMaxRows(maxResult);
        s.setFetchSize(maxResult);
      }
      rs = s.executeQuery(select);
     
      while(rs.next()) {
        String aidS = rs.getString("aid");
        matchingAIDs.add(aidS);
      }     
    }
    catch(SQLException sqle) {
      // Let it through
      throw sqle;
    }
    catch(Exception e) {
      logger.log(Logger.SEVERE, "Couldn't create the SQL SELECT statement.", e);
      throw new SQLException("Couldn't create the SQL SELECT statement. "+e.getMessage());
    }
    finally {
      closeResultSet(rs);
      closeStatement(s);
    }
   
    // For each matching AID reconstruct the complete DFD
    List dfds = new ArrayList(matchingAIDs.size());
    Iterator it = matchingAIDs.iterator();
    // FIXME: Define a proper constant and possibly a proper configuration option
    if (matchingAIDs.size() < 10) {
      while (it.hasNext()) {
        dfds.add(getDFD((String) it.next()));
      }
    }
    else {
      // If we found several matching agents we preload protocols languages and ontologies once for all
      // instead of making several queries one per agent.
      PreparedStatements pss = getPreparedStatements();
      Map allLanguages = preloadIdValueTable(pss.stm_selCountAllLanguages, pss.stm_selAllLanguages);
      Map allOntologies = preloadIdValueTable(pss.stm_selCountAllOntologies, pss.stm_selAllOntologies);
      Map allProtocols = preloadIdValueTable(pss.stm_selCountAllProtocols, pss.stm_selAllProtocols);
      while (it.hasNext()) {
        dfds.add(getDFD((String) it.next(), allLanguages, allOntologies, allProtocols));
      }
    }
   
    return dfds;
  }
View Full Code Here

        String currentId = null;
        List l = null;
        while(rs.next()){
          String id = rs.getString(1); // id (using the index is faster)
          if (!id.equals(currentId)) {
            l =  new ArrayList();
            m.put(id, l);
            currentId = id;
          }
          l.add(rs.getString(2)); // value (protocol, language, ontology ... depending on the passed statement)
        }
View Full Code Here

   */
  private String createSelect(DFAgentDescription dfdTemplate) throws Exception {
   
    StringBuffer select = new StringBuffer("SELECT dfagentdescr.aid FROM dfagentdescr");
   
    List lAs = new ArrayList();
    List lWhere = new ArrayList();
   
    // Name
    AID agentAID = dfdTemplate.getName();
    if(agentAID != null){
      lWhere.add(" dfagentdescr.aid = '"+agentAID.getName()+"'");
    }
    // Lease time
    Date lease = dfdTemplate.getLeaseTime();
    long currTime = System.currentTimeMillis();
    lWhere.add(" (dfagentdescr.lease = '-1' OR dfagentdescr.lease > '"+currTime+"')");
   
    // Languages
    Iterator iter = dfdTemplate.getAllLanguages();
    int i=0;
    while(iter.hasNext()){
      String tmp = LANGUAGE+i;
      lAs.add(", language "+tmp);
      lWhere.add(tmp+".language='"+(String)iter.next()+"'");
      lWhere.add(tmp+".descrid=dfagentdescr.id");
      i++;
    }
    // Ontologies
    iter = dfdTemplate.getAllOntologies();
    i = 0;
    while(iter.hasNext()){
      String tmp = ONTOLOGY+i;
      lAs.add(", ontology "+tmp);
      lWhere.add(tmp+".ontology='"+(String)iter.next()+"'");
      lWhere.add(tmp+".descrid=dfagentdescr.id");
      i++;
    }
    // Protocols
    iter = dfdTemplate.getAllProtocols();
    i = 0;
    while(iter.hasNext()){
      String tmp = PROTOCOL+i;
      lAs.add(", protocol "+tmp);
      lWhere.add(tmp+".protocol='"+(String)iter.next()+"'");
      lWhere.add(tmp+".descrid=dfagentdescr.id");
      i++;
    }
    // Services
    iter = dfdTemplate.getAllServices();
    i = 0;
    while(iter.hasNext()){
      ServiceDescription service = (ServiceDescription)iter.next();
      String serviceName = service.getName();
      String serviceType = service.getType();
      String serviceOwner = service.getOwnership();
      // Service name, type and ownership
      String tmp = SERVICE+i;
      lAs.add(", service "+tmp);
      if(serviceName != null){
        lWhere.add(tmp+".sname='"+serviceName+"'");
      }
      if(serviceType != null){
        lWhere.add(tmp+".stype='"+serviceType+"'");
      }
      if(serviceOwner != null){
        lWhere.add(tmp+".sownership='"+serviceOwner+"'");
      }
      lWhere.add(tmp+".descrid=dfagentdescr.id");
      i++;
     
      // Service languages
      Iterator iterS = service.getAllLanguages();
      int j = 0;
      while(iterS.hasNext()){
        String tmp1 = SERVICELANGUAGE+j;
        lAs.add(", servicelanguage "+tmp1);
        lWhere.add(tmp1+".language='"+(String)iterS.next()+"'");
        lWhere.add(tmp1+".serviceid="+tmp+".id");
        j++;
      }
      // Service ontologies
      iterS = service.getAllOntologies();
      j = 0;
      while(iterS.hasNext()){
        String tmp1 = SERVICEONTOLOGY+j;
        lAs.add(", serviceontology "+tmp1);
        lWhere.add(tmp1+".ontology='"+(String)iterS.next()+"'");
        lWhere.add(tmp1+".serviceid="+tmp+".id");
        j++;
      }
      // Service protocols
      iterS = service.getAllProtocols();
      j = 0;
      while(iterS.hasNext()){
        String tmp1 = SERVICEPROTOCOL+j;
        lAs.add(", serviceprotocol "+tmp1);
        lWhere.add(tmp1+".protocol='"+(String)iterS.next()+"'");
        lWhere.add(tmp1+".serviceid="+tmp+".id");
        j++;
      }
      // Service properties
      iterS = service.getAllProperties();
      j = 0;
      while(iterS.hasNext()){
        String tmp1 = SERVICEPROPERTY+j;
        lAs.add(", serviceproperty "+tmp1);
        Property prop = (Property) iterS.next()
       
        if (prop.getName() != null)
          lWhere.add(tmp1+".propkey='"+prop.getName()+"'");
       
        Object value = prop.getValue();
        if (value != null) {
          if (needSerialization(value)) {
            String hashStr = getHashValue(prop.getValue());
            lWhere.add(tmp1+".propvalhash='"+ hashStr +"'");
          }
          else {
            lWhere.add(tmp1+".propval_str='"+ value +"'");
          }
        }
        lWhere.add(tmp1+".serviceid="+tmp+".id")
        j++;
      }     
    }
   
    // Concatenate all the aliases
    iter = lAs.iterator();
    while (iter.hasNext()) {
      select.append((String) iter.next());
    }
    // Concatenate all WHERE
    if (lWhere.size() > 0) {
      select.append(" WHERE ");
    }
    iter = lWhere.iterator();
    i = 0;
    while (iter.hasNext()) {
      if(i > 0) {
        select.append(" and ");
      }
View Full Code Here

TOP

Related Classes of jade.util.leap.ArrayList

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.