Package net.tomp2p.futures

Examples of net.tomp2p.futures.FutureDirect


          Assert.assertEquals(request.toString(), request);
          return response;
        }
      });

      FutureDirect fd = unreachablePeer.sendDirect(receiver.peerAddress()).object(request).start()
          .awaitUninterruptibly();
      Assert.assertEquals(response, fd.object());
     
      // make sure we did receive it from the unreachable peer with id
      Assert.assertEquals(receiver.peerID(), fd.wrappedFuture().responseMessage().sender().peerId());
    } finally {
      if (unreachablePeer != null) {
        unreachablePeer.shutdown().await();
      }
      if (master != null) {
View Full Code Here


          System.err.println(sender.inetAddress());
          return "yes";
        }
      });
     
      FutureDirect fd = sender.sendDirect(recv1.peerAddress()).object("test").start().awaitUninterruptibly();
      Assert.assertTrue(fd.isSuccess());
     
    } finally {

      if (sender != null) {
        sender.shutdown().await();
View Full Code Here

            });
            FuturePeerConnection peerConnection = sender.createPeerConnection(recv1.peerAddress());
            ccohTCP.reset();
            ccohUDP.reset();

            FutureDirect fd1 = sender.sendDirect(peerConnection).object("test")
                    .connectionTimeoutTCPMillis(2000).idleTCPSeconds(10 * 1000).start();
            fd1.awaitListenersUninterruptibly();
            Assert.assertEquals(true, fd1.isSuccess());
            Assert.assertEquals(1, ccohTCP.total());
            Assert.assertEquals(0, ccohUDP.total());
            Thread.sleep(2000);
            System.err.println("send second with the same connection");
            FutureDirect fd2 = sender.sendDirect(peerConnection).object("test").start();
            fd2.awaitUninterruptibly();
            Assert.assertEquals(1, ccohTCP.total());
            Assert.assertEquals(0, ccohUDP.total());
            Assert.assertEquals(true, fd2.isSuccess());
            peerConnection.close().await();
            System.err.println("done");
        } finally {
            if (sender != null) {
                sender.shutdown().await();
View Full Code Here

            });
            FuturePeerConnection peerConnection = sender.createPeerConnection(recv1.peerAddress(), 8000);
            ccohTCP.reset();
            ccohUDP.reset();

            FutureDirect fd1 = sender.sendDirect(peerConnection).object("test")
                    .connectionTimeoutTCPMillis(2000).idleTCPSeconds(5).start();
            fd1.awaitUninterruptibly();

            Assert.assertEquals(1, ccohTCP.total());

            Thread.sleep(7000);

            FutureDirect fd2 = sender.sendDirect(peerConnection).object("test").start();
            fd2.awaitUninterruptibly();
            peerConnection.close().await();
            Assert.assertEquals(2, ccohTCP.total());
            System.out.println("done");
        } finally {
            if (sender != null) {
View Full Code Here

          c.writeInt(88);
          Buffer ret = new Buffer(c);
          return ret;
        }
      });
      FutureDirect fd = master.peer().sendDirect(peers[50].peerAddress()).buffer(b).start();
      fd.await();
      if (fd.buffer() == null) {
        System.err.println("damm");
        Assert.fail();
      }
      int read = fd.buffer().buffer().readInt();
      Assert.assertEquals(88, read);
      System.err.println("done");
      // for(FutureBootstrap fb:tmp)
      // fb.awaitUninterruptibly();
    } finally {
View Full Code Here

        public Buffer reply(PeerAddress sender, Buffer requestBuffer, boolean complete) {
          System.err.println("got it");
          return requestBuffer;
        }
      });
      FutureDirect fd = master.peer().sendDirect(peers[50].peerAddress()).buffer(b).start();
      fd.await();
      System.err.println("done1");
      Assert.assertEquals(true, fd.isSuccess());
      Assert.assertNull(fd.buffer());
      // int read = fd.getBuffer().readInt();
      // Assert.assertEquals(88, read);
      System.err.println("done2");
    } finally {
      if (master != null) {
View Full Code Here

        public Object reply(PeerAddress sender, Object request) throws Exception {
          System.out.println("request [" + request + "]");
          return "world";
        }
      });
      FutureDirect futureData = p1.sendDirect(p2.peerAddress()).object("hello").start();
      futureData.awaitUninterruptibly();
      System.out.println("reply [" + futureData.object() + "]");
    } finally {
      if (p1 != null) {
        p1.shutdown().await();
      }
      if (p2 != null) {
View Full Code Here

  private void send2(final PeerDHT p1, final PeerDHT p2, final ByteBuf toStore1, final int count) throws IOException {
    if (count == 0) {
      return;
    }
    Buffer b = new Buffer(toStore1);
    FutureDirect fd = p1.peer().sendDirect(p2.peerAddress()).buffer(b).start();
    fd.addListener(new BaseFutureAdapter<FutureDirect>() {
      @Override
      public void operationComplete(FutureDirect future) throws Exception {
        if (future.isFailed()) {
          // System.err.println(future.getFailedReason());
          send2(p1, p2, toStore1, count - 1);
View Full Code Here

  private void send1(final PeerDHT p1, final PeerDHT p2, final byte[] toStore1, final int count) throws IOException {
    if (count == 0) {
      return;
    }
    FutureDirect fd = p1.peer().sendDirect(p2.peerAddress()).object(toStore1).start();
    fd.addListener(new BaseFutureAdapter<FutureDirect>() {
      @Override
      public void operationComplete(FutureDirect future) throws Exception {
        if (future.isFailed()) {
          //System.err.println(future.getFailedReason());
          send1(p1, p2, toStore1, count - 1);
View Full Code Here

          }
        }
      });
    }

    return new FutureDirect(request.futureResponse());
  }
View Full Code Here

TOP

Related Classes of net.tomp2p.futures.FutureDirect

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.