Ejemplo n.º 1
0
 private String[] get(Number160 name) throws ClassNotFoundException, IOException {
   FutureDHT futureDHT = peer.get(name);
   futureDHT.awaitUninterruptibly();
   if (futureDHT.isSuccess()) {
     return (String[]) futureDHT.getData().values().iterator().next().getObject();
   } else return null;
 }
Ejemplo n.º 2
0
 private String get(String name) throws ClassNotFoundException, IOException {
   FutureDHT futureDHT = peer.get(Number160.createHash(name));
   futureDHT.awaitUninterruptibly();
   if (futureDHT.isSuccess()) {
     return futureDHT.getData().values().iterator().next().getObject().toString();
   } else return "Not Found";
 }
Ejemplo n.º 3
0
 public static void main(String[] args) throws Exception {
   Peer master = null;
   try {
     Peer[] peers = ExampleUtils.createAndAttachNodes(100, 4001);
     master = peers[0];
     MyPeer myPeer = new MyPeer(master);
     ExampleUtils.bootstrap(peers);
     myPeer
         .put(
             "This is my location key",
             "This is my domain",
             "This is my content key",
             "And here comes the data")
         .awaitUninterruptibly();
     FutureDHT futureDHT =
         myPeer.get("This is my location key", "This is my domain", "This is my content key");
     futureDHT.awaitUninterruptibly();
     System.err.println(futureDHT.getFailedReason());
     Map<Number160, Data> map = futureDHT.getDataMap();
     for (Data data : map.values()) {
       MyData myData = (MyData) data.getObject();
       System.out.println(
           "key: "
               + myData.getKey()
               + ", domain: "
               + myData.getDomain()
               + ", content: "
               + myData.getContent()
               + ", data: "
               + myData.getData());
     }
   } finally {
     master.halt();
   }
 }
Ejemplo n.º 4
0
 @SuppressWarnings("unchecked")
 private Vector<Number160> getPeerList(String name) throws ClassNotFoundException, IOException {
   FutureDHT futureDHT = peer.get(Number160.createHash(name));
   futureDHT.awaitUninterruptibly();
   if (futureDHT.isSuccess()) {
     return (Vector<Number160>) futureDHT.getData().values().iterator().next().getObject();
   } else return null;
 }