Package net.tomp2p.futures

Examples of net.tomp2p.futures.FuturePeerConnection


                @Override
                public Object reply(PeerAddress sender, Object request) throws Exception {
                    return "yes";
                }
            });
            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) {
                sender.shutdown().await();
View Full Code Here


      List<BaseFuture> list1 = new ArrayList<BaseFuture>();
      List<BaseFuture> list2 = new ArrayList<BaseFuture>();
      List<FuturePeerConnection> list3 = new ArrayList<FuturePeerConnection>();
      for (int i = 0; i < 125; i++) {
        final byte[] b = new byte[10000];
        FuturePeerConnection pc = master.createPeerConnection(slave.peerAddress());
        list1.add(master.sendDirect(pc).buffer(new Buffer(Unpooled.wrappedBuffer(b))).start());
        list3.add(pc);
        // pc.close();
      }
      for (int i = 0; i < 20000; i++) {
        list2.add(master.discover().peerAddress(slave.peerAddress()).start());
        final byte[] b = new byte[10000];
        byte[] me = Utils.intToByteArray(i);
        System.arraycopy(me, 0, b, 0, 4);
        list2.add(master.sendDirect(slave.peerAddress()).buffer(new Buffer(Unpooled.wrappedBuffer(b)))
                .start());
      }
      for (BaseFuture bf : list1) {
        bf.awaitListenersUninterruptibly();
        if (bf.isFailed()) {
          System.err.println("WTF " + bf.failedReason());
        } else {
          System.err.print(",");
        }
        Assert.assertEquals(true, bf.isSuccess());
      }
      for (FuturePeerConnection pc : list3) {
        pc.close().awaitListenersUninterruptibly();
      }
      for (BaseFuture bf : list2) {
        bf.awaitListenersUninterruptibly();
        if (bf.isFailed()) {
          System.err.println("WTF " + bf.failedReason());
View Full Code Here

   */
  public FutureDone<PeerConnection> startSetupRcon(final PeerAddress relayPeerAddress, final PeerAddress unreachablePeerAddress) {
    checkRconPreconditions(relayPeerAddress, unreachablePeerAddress);

    final FutureDone<PeerConnection> futureDone = new FutureDone<PeerConnection>();
    final FuturePeerConnection fpc = peer.createPeerConnection(relayPeerAddress);
    fpc.addListener(new BaseFutureAdapter<FuturePeerConnection>() {
      // wait for the connection to the relay Peer
      @Override
      public void operationComplete(FuturePeerConnection future) throws Exception {
        if (fpc.isSuccess()) {
          final PeerConnection peerConnection = fpc.peerConnection();
          if (peerConnection != null) {
            // create the necessary messages
            final Message setUpMessage = createSetupMessage(relayPeerAddress, unreachablePeerAddress);

            // send the message to the relay so it forwards it to the unreachable peer
View Full Code Here

     *            the user closes the connection manually.
     * @return A class that needs to be passed to those methods that should use the already open connection. If the
     *         connection could not be reserved, maybe due to a shutdown, null is returned.
     */
    public FuturePeerConnection createPeerConnection(final PeerAddress destination, final int heartBeatMillis) {
        final FuturePeerConnection futureDone = new FuturePeerConnection(destination);
        final FutureChannelCreator fcc = connectionBean().reservation().createPermanent(1);
        fcc.addListener(new BaseFutureAdapter<FutureChannelCreator>() {
            @Override
            public void operationComplete(final FutureChannelCreator future) throws Exception {
                if (future.isSuccess()) {
                    final ChannelCreator cc = fcc.channelCreator();
                    final PeerConnection peerConnection = new PeerConnection(destination, cc, heartBeatMillis);
                    futureDone.done(peerConnection);
                } else {
                    futureDone.failed(future);
                }
            }
        });
        return futureDone;
    }
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.