Package net.tomp2p.futures

Examples of net.tomp2p.futures.FuturePeerConnection


                        result.append(String.valueOf(request));
                        return "pong";
                    }
                });

                FuturePeerConnection futurePeerConnection = peer1DHT.peer().createPeerConnection(peer2DHT.peer()
                                                                                                         .peerAddress(), 500);
                FutureDirect futureDirect = peer1DHT.peer().sendDirect(futurePeerConnection).object("hallo").start();
                futureDirect.awaitUninterruptibly();

View Full Code Here


            configure();
            peer1DHT = getDHTPeer("node_1", client1Port);
            PeerAddress reachablePeerAddress = new PeerAddress(Number160.createHash(seedId), seedIP, seedPort,
                                                               seedPort);

            FuturePeerConnection futurePeerConnection = peer1DHT.peer().createPeerConnection
                    (reachablePeerAddress, 500);
            FutureDirect futureDirect = peer1DHT.peer().sendDirect(futurePeerConnection).object("hallo").start();
            futureDirect.awaitUninterruptibly();
            assertTrue(futureDirect.isSuccess());
            assertEquals("pong", futureDirect.object());
View Full Code Here

        master = Utils2.createNodes(1, rnd, 4001, null, false)[0];
        slave = Utils2.createNodes(1, rnd, 4002, null, false)[0];
        System.err.println("master is " + master.peerAddress());
        System.err.println("slave is " + slave.peerAddress());
       
        FuturePeerConnection pcMaster = master.createPeerConnection(slave.peerAddress());
        MyDirectDataRPC myDirectDataRPC = new MyDirectDataRPC(slave.peerBean(), slave.connectionBean());
        slave.directDataRPC(myDirectDataRPC);
       
        slave.objectDataReply(new ObjectDataReply() {
            @Override
            public Object reply(PeerAddress sender, Object request) throws Exception {
                return "yoo!";
            }
        });
       
        master.objectDataReply(new ObjectDataReply() {
            @Override
            public Object reply(PeerAddress sender, Object request) throws Exception {
                return "world!";
            }
        });
       
        FutureDirect futureResponse = master.sendDirect(pcMaster).object("test").start().awaitUninterruptibly();
        Assert.assertEquals("yoo!", futureResponse.object());
       
        FuturePeerConnection pcSlave = myDirectDataRPC.peerConnection();
       
        futureResponse = slave.sendDirect(pcSlave).object("hello").start().awaitUninterruptibly();
        System.err.println(futureResponse.failedReason());
        Assert.assertEquals("world!", futureResponse.object());
       
        Thread.sleep(1000);
        pcSlave.close();
        pcMaster.close();
        System.err.println("done");
       
        } finally {
            if (master != null) {
View Full Code Here

            super(peerBean, connectionBean);
        }
        @Override
        public void handleResponse(Message message, PeerConnection peerConnection, boolean sign, Responder responder)
                throws Exception {
            futurePeerConnection = new FuturePeerConnection(message.sender());
            futurePeerConnection.done(peerConnection);
            super.handleResponse(message, peerConnection, sign, responder);
        }
View Full Code Here

           
            System.out.println("received " + fd.object() + " connections: "
                    + ccohTCP.total()+ "/"+ccohUDP.total());
           
            // keep the connection for 20s alive. Setting -1 means to keep it open as long as possible
            FuturePeerConnection futurePeerConnection = peer1.createPeerConnection(peer2.peerAddress(), timeout);
           
            fd = peer1.sendDirect(futurePeerConnection).object(sentObject).start();
            System.out.println("send " + sentObject);
            fd.awaitUninterruptibly();
            System.out.println("received " + fd.object() + " connections: "
                    + ccohTCP.total()+ "/"+ccohUDP.total());
            // we reuse the connection
            fd = peer1.sendDirect(futurePeerConnection).object(sentObject).start();
            System.out.println("send " + sentObject);
            fd.awaitUninterruptibly();
            System.out.println("received " + fd.object() + " connections: "
                    + ccohTCP.total()+ "/"+ccohUDP.total());
            // now we don't want to keep the connection open anymore:
            futurePeerConnection.close();
        } finally {
            if (peer1 != null) {
                peer1.shutdown();
            }
            if (peer2 != null) {
View Full Code Here

  private void handleRconSetup(final Message message, final Responder responder) throws TimeoutException {
    if (!message.neighborsSetList().isEmpty()) {
      // extract the PeerAddress from the reachable peer
      final PeerAddress originalSender = (PeerAddress) message.neighborsSetList().get(0).neighbors().toArray()[0];
      // create new PeerConnectin to the reachable peer
      final FuturePeerConnection fpc = peer.createPeerConnection(originalSender);
      fpc.addListener(new BaseFutureAdapter<FuturePeerConnection>() {
        @Override
        public void operationComplete(final FuturePeerConnection future) throws Exception {
          if (future.isSuccess() && future.peerConnection() != null) {
            // successfully created a connection from unreachable to the requester
            final PeerConnection peerConnection = future.peerConnection();
View Full Code Here

            // open as long as possible
            FutureBootstrap masterAnother = peer1.bootstrap().peerAddress(peer2.peerAddress()).start();
            FutureBootstrap anotherMaster = peer2.bootstrap().peerAddress(peer1.peerAddress()).start();
            masterAnother.awaitUninterruptibly();
            anotherMaster.awaitUninterruptibly();
            FuturePeerConnection fpc = peer1.createPeerConnection(peer2.peerAddress());
            // fpc.awaitUninterruptibly();
            // PeerConnection peerConnection = fpc.peerConnection();
            String sentObject = "Hello";
            FutureDirect fd = peer1.sendDirect(fpc).object(sentObject).start();
            System.out.println("send " + sentObject);
            fd.awaitUninterruptibly();
            Assert.assertEquals(true, fd.isSuccess());
            System.out.println("received " + fd.object() + " connections: "
                    + ccohTCP.total());
            // we reuse the connection
            long start = System.currentTimeMillis();
            System.out.println("send " + sentObject);
            fd = peer1.sendDirect(fpc).object(sentObject).start();
            fd.awaitUninterruptibly();
            System.err.println(fd.failedReason());
            Assert.assertEquals(true, fd.isSuccess());
            System.err.println(fd.failedReason());
            System.out.println("received " + fd.object() + " connections: "
                    + ccohTCP.total());
            // now we don't want to keep the connection open anymore:
            double duration = (System.currentTimeMillis() - start) / 1000d;
            System.out.println("Send and get in s:" + duration);
            fpc.close().await();
            System.out.println("done");
        } finally {
            if (peer1 != null) {
                peer1.shutdown().await();
                System.out.println("done1");
View Full Code Here

        message.intValue(mapUpdateInterval);
      }
    }

    LOG.debug("Setting up relay connection to peer {}, message {}", candidate, message);
    final FuturePeerConnection fpc = peer.createPeerConnection(candidate);
    fpc.addListener(new BaseFutureAdapter<FuturePeerConnection>() {
      public void operationComplete(final FuturePeerConnection futurePeerConnection) throws Exception {
        if (futurePeerConnection.isSuccess()) {
          // successfully created a connection to the relay peer
          final PeerConnection peerConnection = futurePeerConnection.object();
View Full Code Here

   * @param config
   * @return
   */
  public static FutureResponse connectAndSend(final Peer peer, final Message message, final ConnectionConfiguration config) {
    final FutureResponse futureResponse = new FutureResponse(message);
    final FuturePeerConnection fpc = peer.createPeerConnection(message.recipient());
    fpc.addListener(new BaseFutureAdapter<FuturePeerConnection>() {
            public void operationComplete(final FuturePeerConnection futurePeerConnection) throws Exception {
                if (futurePeerConnection.isSuccess()) {
                  // successfully created a connection to the other peer
                  final PeerConnection peerConnection = futurePeerConnection.object();
                 
View Full Code Here

                @Override
                public Object reply(PeerAddress sender, Object request) throws Exception {
                    return "yes";
                }
            });
            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

TOP

Related Classes of net.tomp2p.futures.FuturePeerConnection

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.