Package net.tomp2p.dht

Examples of net.tomp2p.dht.FuturePut


      RequestP2PConfiguration rp = new RequestP2PConfiguration(1, 1, 0);

      System.err.println(unreachablePeer1.peerID()); // f1
      System.err.println(unreachablePeer2.peerID()); // e7

      FuturePut futurePut = unreachablePeer1.put(unreachablePeer2.peerID()).data(new Data("hello"))
          .routingConfiguration(r).requestP2PConfiguration(rp).start().awaitUninterruptibly();
      // the relayed one is the slowest, so we need to wait for it!
      futurePut.futureRequests().awaitUninterruptibly();
      System.err.println(futurePut.failedReason());

      Assert.assertTrue(futurePut.isSuccess());
      Assert.assertTrue(unreachablePeer2.storageLayer().contains(
          new Number640(unreachablePeer2.peerID(), Number160.ZERO, Number160.ZERO, Number160.ZERO)));

      FutureGet futureGet = unreachablePeer1.get(unreachablePeer2.peerID()).routingConfiguration(r)
          .requestP2PConfiguration(rp).fastGet(false).start().awaitUninterruptibly();
View Full Code Here


             RequestP2PConfiguration rp = new RequestP2PConfiguration(1, 1, 0);
            
             System.err.println(unreachablePeer1.peerID()); //f1
             System.err.println(unreachablePeer2.peerID()); //e7
            
             FuturePut futurePut = unreachablePeer1.put(unreachablePeer2.peerID()).data(new Data("hello")).sign().routingConfiguration(r).requestP2PConfiguration(rp).start().awaitUninterruptibly();
             //the relayed one is the slowest, so we need to wait for it!
             futurePut.awaitUninterruptibly();
             futurePut.futureRequests().awaitUninterruptibly();
             System.err.println(futurePut.failedReason());
            
             Assert.assertTrue(futurePut.isSuccess());
             Assert.assertTrue(unreachablePeer2.storageLayer().contains(new Number640(unreachablePeer2.peerID(), Number160.ZERO, Number160.ZERO, Number160.ZERO)));
            
             FutureGet futureGet = unreachablePeer1.get(unreachablePeer2.peerID()).routingConfiguration(r).sign().requestP2PConfiguration(rp).fastGet(false).start().awaitUninterruptibly();
             //TODO: try peers even if no data found with fastget
             System.err.println(futureGet.failedReason());
View Full Code Here

  }

  public boolean put(Number640 key) {
    Data data = generateRandomData();
    putStats.start();
    FuturePut futurePut = peerDHT.put(key.locationKey()).domainKey(key.domainKey()).versionKey(key.versionKey())
        .data(key.contentKey(), data).routingConfiguration(routingConfig).requestP2PConfiguration(requestConfig)
        .start().awaitUninterruptibly();
    putStats.finished(futurePut.isSuccess());
   
    LOG.debug("Put of {} bytes is success = {}. Reason: {}", data.length(), futurePut.isSuccess(),
        futurePut.failedReason());
    return futurePut.isSuccess();
  }
View Full Code Here

        peers[peerOffline1].shutdown().awaitListenersUninterruptibly();
        peers[peerOffline2].shutdown().awaitListenersUninterruptibly();
        peers[peerOffline3].shutdown().awaitListenersUninterruptibly();
        // now lets store something else with the same key
        final int peerGet = 33;
        FuturePut futurePut = peers[peerStore1].put(key1).requestP2PConfiguration(REQUEST_3)
                .data(new Data("Test 2")).start();
        futurePut.awaitUninterruptibly();
        System.out.println("stored [Test 2] on " + futurePut.rawResult().keySet());

        FutureGet futureGet = peers[peerGet].get(key1).all().start();
        futureGet.awaitUninterruptibly();
        System.out.println("peer[" + peerGet + "] got [" + futureGet.data().object() + "] should be [Test 2]");
        // peer 11 and 8 joins again
View Full Code Here

     * @throws IOException e.
     * @throws ClassNotFoundException .
     */
    private static void examplePutGet(final PeerDHT[] peers, final Number160 nr)
            throws IOException, ClassNotFoundException {
        FuturePut futurePut = peers[PEER_NR_1].put(nr).data(new Data("hallo")).start();
        futurePut.awaitUninterruptibly();
        System.out.println("peer " + PEER_NR_1 + " stored [key: " + nr + ", value: \"hallo\"]");
        FutureGet futureGet = peers[PEER_NR_2].get(nr).start();
        futureGet.awaitUninterruptibly();
        System.out.println("peer " + PEER_NR_2 + " got: \"" + futureGet.data().object() + "\" for the key " + nr);
        // the output should look like this:
View Full Code Here

    private static void examplePutGetConfig( PeerDHT[] peers, Number160 nr2 )
        throws IOException, ClassNotFoundException
    {
        Number160 nr = new Number160( RND );
        FuturePut futurePut =
            peers[30].put( nr ).data( new Number160( 11 ), new Data( "hallo" ) ).domainKey( Number160.createHash( "my_domain" ) ).start();
        futurePut.awaitUninterruptibly();
        System.out.println( "peer 30 stored [key: " + nr + ", value: \"hallo\"]" );
        // this will fail, since we did not specify the domain
        FutureGet futureGet = peers[77].get( nr ).all().start();
        futureGet.awaitUninterruptibly();
        System.out.println( "peer 77 got: \"" + futureGet.data() + "\" for the key " + nr );
View Full Code Here

        Number160 nr = new Number160( RND );
        String toStore1 = "hallo1";
        String toStore2 = "hallo2";
        Data data1 = new Data( toStore1 );
        Data data2 = new Data( toStore2 );
        FuturePut futurePut = peers[30].add( nr ).data( data1 ).start();
        futurePut.awaitUninterruptibly();
        System.out.println( "added: " + toStore1 + " (" + futurePut.isSuccess() + ")" );
        futurePut = peers[50].add( nr ).data( data2 ).start();
        futurePut.awaitUninterruptibly();
        System.out.println( "added: " + toStore2 + " (" + futurePut.isSuccess() + ")" );
        FutureGet futureGet = peers[77].get( nr ).all().start();
        futureGet.awaitUninterruptibly();
        System.out.println( "size" + futureGet.dataMap().size() );
        Iterator<Data> iterator = futureGet.dataMap().values().iterator();
        System.out.println( "got: " + iterator.next().object() + " (" + futureGet.isSuccess() + ")" );
View Full Code Here

        final int peer30 = 30;
        final int peer60 = 60;

        Number160 key = Number160.createHash(TERM);

        FuturePut futurePut = peers[peer60].put(key).object(TERM).start();
        futurePut.awaitUninterruptibly();

        FutureGet futureGet = peers[peer30].get(key).start();
        futureGet.awaitUninterruptibly();

        System.out.println("got: " + key + " = " + futureGet.data().object());
View Full Code Here

        PeerDHT peer3 = new PeerBuilderDHT(new PeerBuilder( pair3 ).ports( 4003 ).start()).start();
        PeerDHT[] peers = new PeerDHT[] { peer1, peer2, peer3 };
        ExampleUtils.bootstrap( peers );
        setProtection( peers, ProtectionEnable.ALL, ProtectionMode.MASTER_PUBLIC_KEY );
        // peer 1 stores "test" in the domain key of owner peer 2
        FuturePut futurePut =
            peer1.put( Number160.ONE ).data( new Data( "test" ) ).domainKey( peer2Owner ).protectDomain().start();
        futurePut.awaitUninterruptibly();
        // peer 2 did not claim this domain, so we stored it
        System.out.println( "stored: " + futurePut.isSuccess() + " -> because no one claimed this domain" );
        // peer 3 want to store something
        futurePut =
            peer3.put( Number160.ONE ).data( new Data( "hello" ) ).domainKey( peer2Owner ).protectDomain().start();
        futurePut.awaitUninterruptibly();
        System.out.println( "stored: " + futurePut.isSuccess() + " -> becaues peer1 already claimed this domain" );
        // peer 2 claims this domain
        futurePut =
            peer2.put( Number160.ONE ).data( new Data( "MINE!" ) ).domainKey( peer2Owner ).protectDomain().start();
        futurePut.awaitUninterruptibly();
        System.out.println( "stored: " + futurePut.isSuccess() + " -> becaues peer2 is the owner" );
        // get the data!
        FutureGet futureGet = peer1.get( Number160.ONE ).domainKey( peer2Owner ).start();
        futureGet.awaitUninterruptibly();
        System.out.println( "we got " + futureGet.data().object() );
        shutdown( peers );
View Full Code Here

        PeerDHT peer3 = new PeerBuilderDHT(new PeerBuilder( pair3 ).ports( 4003 ).start()).start();
        PeerDHT[] peers = new PeerDHT[] { peer1, peer2, peer3 };
        ExampleUtils.bootstrap( peers );
        setProtection( peers, ProtectionEnable.NONE, ProtectionMode.MASTER_PUBLIC_KEY );
        // peer 1 stores "test" in the domain key of owner peer 2
        FuturePut futurePut =
            peer1.put( Number160.ONE ).data( new Data( "test" ) ).protectDomain().domainKey( peer2Owner ).start();
        futurePut.awaitUninterruptibly();
        // peer 2 did not claim this domain, so we stored it
        System.out.println( "stored: " + futurePut.isSuccess()
            + " -> because no one can claim domains except the owner, storage ok but no protection" );
        // peer 3 want to store something
        futurePut =
            peer3.put( Number160.ONE ).data( new Data( "hello" ) ).protectDomain().domainKey( peer2Owner ).start();
        futurePut.awaitUninterruptibly();
        System.out.println( "stored: " + futurePut.isSuccess()
            + " -> because no one can claim domains except the owner, storage ok but no protection" );
        // peer 2 claims this domain
        futurePut =
            peer2.put( Number160.ONE ).data( new Data( "MINE!" ) ).protectDomain().domainKey( peer2Owner ).start();
        futurePut.awaitUninterruptibly();
        System.out.println( "stored: " + futurePut.isSuccess() + " -> becaues peer2 is the owner" );
        // get the data!
        FutureGet futureGet = peer1.get( Number160.ONE ).domainKey( peer2Owner ).start();
        futureGet.awaitUninterruptibly();
        System.out.println( "we got " + futureGet.data().object() );
        futurePut = peer3.put( Number160.ONE ).domainKey( peer2Owner ).data( new Data( "hello" ) ).start();
        futurePut.awaitUninterruptibly();
        System.out.println( "stored: " + futurePut.isSuccess() + " -> because this domain is claimed by peer2" );
        shutdown( peers );
    }
View Full Code Here

TOP

Related Classes of net.tomp2p.dht.FuturePut

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.