Package net.tomp2p.futures

Examples of net.tomp2p.futures.FutureDHT


  @Override
  public List<Triple> get(String locationKey) {
    l.log(TYPE_RETRIEVE,
        String.format("Peer %s: get keys: %s", p, locationKey), 10);
    final Number160 hash = Number160.createHash(locationKey);
    FutureDHT request;
    try {
      request = p.get(hash).setRequestP2PConfiguration(reqParam).setAll()
          .start();
      request.awaitUninterruptibly();
      Data f = request.getData();
      if (!request.isSuccess() || f == null) {
        logger.debug(String.format("Got no triple in key \"%s\" (%s)",
            locationKey, hash));
        return new ArrayList<Triple>(0);
      }

      List<Triple> result = new ArrayList<Triple>();
      for (Data d : request.getDataMap().values()) {
        logger.debug(String.format(
            "Got triple \"%s\" in key \"%s\" (%s) at peer \"%s\"",
            d.getObject(), locationKey, hash, d.getPeerId()));
        try {
          Triple t;
View Full Code Here


  }

  @Override
  public void remove(String locationKey, Triple item) {
    final Number160 hash = Number160.createHash(locationKey);
    FutureDHT request;
    l.log(TYPE_REMOVE, String.format("Peer %s: remove item %s in key: %s",
        p, item, locationKey), 10);
    final Number160 contentKey = Number160.createHash(item.toString());
    request = p.remove(hash).setContentKey(contentKey)
        .setReturnResults(false).start();
    request.awaitUninterruptibly();
    logger.debug(String.format("Remove triple in key %s (%s)", locationKey,
        hash));
  }
View Full Code Here

  }

  @Override
  public void removeAll(String locationKey, Triple... item) {
    final Number160 hash = Number160.createHash(locationKey);
    FutureDHT request;
    Set<Number160> contentKeys = new HashSet<Number160>();
    for (Triple t : item) {
      final Number160 contentKey = Number160.createHash(t.toString());
      contentKeys.add(contentKey);
    }
    l.log(TYPE_REMOVE, String.format(
        "Peer %s: removed %d  item in key: %s", p, contentKeys.size(),
        locationKey), 10);
    request = p.remove(hash).setContentKeys(contentKeys)
        .setReturnResults(false).start();
    request.awaitUninterruptibly();
    logger.debug(String.format("Remove %d triples in key %s (%s)",
        contentKeys.size(), locationKey, hash));
  }
View Full Code Here

  public void add(String locationKey, Triple t) {
    l.log(TYPE_ADD, String.format("Peer %s: add item %s in key: %s", p, t,
        locationKey), 10);
    final Number160 hash = Number160.createHash(locationKey);
    final Number160 contentKey = Number160.createHash(t.toString());
    FutureDHT request;
    try {
      Data valueToAdd;
      if (usingDebugObject)
        valueToAdd = new Data(new TomP2P_Item<Triple>(locationKey, t));
      else
        valueToAdd = new Data(t);
      request = p.put(hash).setData(contentKey, valueToAdd)
          .setRequestP2PConfiguration(reqParam).start();
      request.awaitUninterruptibly();
      logger.debug(String.format("Insert triple %s in key %s (%s)", t,
          locationKey, hash));
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

      } catch (IOException e) {
        e.printStackTrace();
      }
      map.put(contentKey, valueToAdd);
    }
    FutureDHT request = p.put(hash).setDataMap(map)
        .setRequestP2PConfiguration(reqParam).start();
    request.awaitUninterruptibly();
    logger.debug(String.format("Insert %d triple(s) in key %s (%s)",
        map.size(), locationKey, hash));
  }
View Full Code Here

      } catch (IOException e) {
        e.printStackTrace();
      }
      list.add(valueToAdd);
    }
    FutureDHT request = p.add(hash).setDataSet(list)
        .setRequestP2PConfiguration(reqParam).start();
    request.awaitUninterruptibly();
    logger.debug(String.format("Insert %d triple(s) in key %s (%s)",
        list.size(), locationKey, hash));
  }
View Full Code Here

TOP

Related Classes of net.tomp2p.futures.FutureDHT

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.