コード例 #1
0
ファイル: PingBuilder.java プロジェクト: BenKoerber/TomP2P
  public BaseFuture start() {
    if (peer.isShutdown()) {
      return FUTURE_PING_SHUTDOWN;
    }

    if (connectionConfiguration == null) {
      connectionConfiguration = new DefaultConnectionConfiguration();
    }

    if (broadcast) {
      return pingBroadcast(port);
    } else {
      if (peerAddress != null) {
        if (tcpPing) {
          return ping(peerAddress, false);
        } else {
          return ping(peerAddress, true);
        }
      } else if (inetAddress != null) {
        if (tcpPing) {
          return ping(new InetSocketAddress(inetAddress, port), Number160.ZERO, false);
        } else {
          return ping(new InetSocketAddress(inetAddress, port), Number160.ZERO, true);
        }
      } else if (peerConnection != null) {
        return pingPeerConnection(peerConnection);
      } else {
        throw new IllegalArgumentException(
            "cannot ping, need to know peer address or inet address");
      }
    }
  }
コード例 #2
0
  public FutureBootstrap start() {
    if (peer.isShutdown()) {
      return FUTURE_BOOTSTRAP_SHUTDOWN;
    }

    if (routingConfiguration == null) {
      routingConfiguration = new RoutingConfiguration(5, 10, 2);
    }
    if (requestP2PConfiguration == null) {
      int size = peer.getPeerBean().peerMap().size() + 1;
      requestP2PConfiguration = new RequestP2PConfiguration(Math.min(size, 3), 5, 3);
    }
    //
    if (broadcast) {
      return broadcast();
    }
    if (peerAddress == null && inetAddress != null && bootstrapTo == null) {
      peerAddress = new PeerAddress(Number160.ZERO, inetAddress, portTCP, portUDP);
      return bootstrapPing(peerAddress);

    } else if (peerAddress != null && bootstrapTo == null) {
      bootstrapTo = new ArrayList<PeerAddress>(1);
      bootstrapTo.add(peerAddress);
      return bootstrap();
    } else if (bootstrapTo != null) {
      return bootstrap();
    } else {
      return FUTURE_BOOTSTRAP_NO_ADDRESS;
    }
  }
コード例 #3
0
  public FutureDirect start() {
    if (peer.isShutdown()) {
      return FUTURE_REQUEST_SHUTDOWN;
    }

    final boolean keepAlive;
    final PeerAddress remotePeer;
    if (recipientAddress != null && recipientConnection == null) {
      keepAlive = false;
      remotePeer = recipientAddress;
    } else if (recipientAddress == null && recipientConnection != null) {
      keepAlive = true;
      remotePeer = recipientConnection.remotePeer();
    } else if (peerConnection != null) {
      keepAlive = true;
      remotePeer = peerConnection.remotePeer();
    } else {
      throw new IllegalArgumentException("either remotePeer or connection has to be set");
    }

    if (futureChannelCreator == null) {
      futureChannelCreator =
          peer.connectionBean().reservation().create(isForceUDP() ? 1 : 0, isForceUDP() ? 0 : 1);
    }

    final RequestHandler<FutureResponse> request =
        peer.directDataRPC().sendInternal(remotePeer, this);
    if (keepAlive) {
      if (peerConnection != null) {
        sendDirectRequest(request, peerConnection);
      } else {
        recipientConnection.addListener(
            new BaseFutureAdapter<FuturePeerConnection>() {
              @Override
              public void operationComplete(final FuturePeerConnection future) throws Exception {
                if (future.isSuccess()) {
                  sendDirectRequest(request, future.peerConnection());
                } else {
                  request.futureResponse().failed("Could not acquire channel (1)", future);
                }
              }
            });
      }

    } else {
      futureChannelCreator.addListener(
          new BaseFutureAdapter<FutureChannelCreator>() {
            @Override
            public void operationComplete(final FutureChannelCreator future) throws Exception {
              if (future.isSuccess()) {
                final FutureResponse futureResponse = request.sendTCP(future.channelCreator());
                Utils.addReleaseListener(future.channelCreator(), futureResponse);
              } else {
                request.futureResponse().failed("could not create channel", future);
              }
            }
          });
    }

    return new FutureDirect(request.futureResponse());
  }