Package net.sf.clairv.search.util

Examples of net.sf.clairv.search.util.Counter


  public ResponseMessage handleRequest(OverlayRequest request) {

    final Wrapper resp = new Wrapper();

    final Counter counter = new Counter(1);

    final KeywordQueryMessage kqm = (KeywordQueryMessage) request
        .getMessage();

    final DocList docList = reader.getMatchList(kqm.getKeywords()[kqm
        .getCurrentKeywordIndex()]);

    idf = reader.getIdf();

    final ScoreDocList sdList = new ScoreDocList(docList);

    if (kqm.getCurrentBloomFilter() != null) {
      SimpleBloomFilter receivedBloomFilter = kqm
          .getCurrentBloomFilter();
      // calculate F(a) intersects B
      sdList.intersects(receivedBloomFilter);
    }

    final SimpleBloomFilter currentBloomFilter = (new BloomFilterCreator())
        .createBloomFilter(sdList);
    try {
      OverlayNetwork network = PastryNetwork.getInstance();
      if (kqm.getCurrentKeywordIndex() < kqm.getKeywords().length - 1) {
        // if current node is NOT the last node of the message-chaining
        // process
        KeywordQueryMessage newKqm = new KeywordQueryMessage(kqm
            .getKeywords(), kqm.getCurrentKeywordIndex() + 1, currentBloomFilter);

        network.send(
            kqm.getKeywords()[kqm.getCurrentKeywordIndex() + 1],
            newKqm, new MessageCallback() {

              public void onResponse(ResponseMessage response) {

                if (response instanceof KeywordQueryRespMessage) {
                  ScoreDocList receivedSdList = ((KeywordQueryRespMessage) response)
                      .getSdList();

                  Scorer.calculateScore(docList,
                      receivedSdList, idf);
                  resp.value = new KeywordQueryRespMessage(
                      receivedSdList);

                  counter.decrement();
                }
              }
            });
      } else {
        // on the last node
        sdList.intersects(currentBloomFilter);
        Scorer.mutiplyIdf(sdList, idf);
        resp.value = new KeywordQueryRespMessage(sdList);
        counter.decrement();
      }

    } catch (OverlayNetworkException e) {
      log.error("Error in handling KeywordQueryMessage: ", e);
    }

    while (counter.getValue() != 0) {
     
    }

    return (ResponseMessage)resp.value;
  }
View Full Code Here


    }

  }

  public QueryResults search(String resourceName, String query, Object[] args) {
    final Counter finished = new Counter(1);
    final DHTQueryResults results = new DHTQueryResults(hitTextPattern);
    try {
      final OverlayNetwork network = PastryNetwork.getInstance();

      if (null == query) {
        return null;
      } else {
        String[] keywords = this.parseQuery(query);
        if (keywords.length == 0) {
          return null;
        }
        network.send(keywords[0], new KeywordQueryMessage(keywords, 0, null), new MessageCallback() {

          public void onResponse(ResponseMessage response) {
            if (response instanceof KeywordQueryRespMessage) {
              ScoreDocList sdList = ((KeywordQueryRespMessage) response)
                  .getSdList();

              sdList.sortList();
              final Counter counter = new Counter(sdList.size());
              for (Iterator itr = sdList.getSdList().iterator(); itr.hasNext(); ) {
                ScoreDoc sd = (ScoreDoc) itr.next();
                String nodeId = sd.getNodeId();
                Integer docId = new Integer(sd.getDocId());
                try {
                  network.sendDirect(nodeId,
                      new ResourceRequestMessage(docId),
                      new MessageCallback() {

                        public void onResponse(
                            ResponseMessage response) {

                          if (response instanceof ResourceRequestRespMessage) {
                            results
                                .add(((ResourceRequestRespMessage) response)
                                    .getResults());
                            counter.decrement();
                          }
                        }
                      });
                } catch (OverlayNetworkException e) {
                  e.printStackTrace();
                }
              }
              while (counter.getValue() != 0) {

              }
              finished.decrement();
            } else {
              log
View Full Code Here

TOP

Related Classes of net.sf.clairv.search.util.Counter

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.