Examples of FutureResponse


Examples of net.tomp2p.futures.FutureResponse

     
      FutureChannelCreator fcc = master.peer().connectionBean().reservation().create(0, 1);
            fcc.awaitUninterruptibly();
            cc = fcc.channelCreator();
     
      FutureResponse fr = master.storeRPC().put(slave.peerAddress(), pb, cc);
      fr.awaitUninterruptibly();
      Assert.assertEquals(true, fr.isSuccess());
     
      GetBuilder gb = master.get(new Number160("0x51")).domainKey(Number160.ZERO);

      fr = master.storeRPC().get(slave.peerAddress(), gb, cc);
      fr.awaitUninterruptibly();
      Assert.assertEquals(true, fr.isSuccess());

      System.err.println("done");
     
     
View Full Code Here

Examples of net.tomp2p.futures.FutureResponse

    // cache the original message until the connection is established
    cachedRequests.put(message.messageId(), futureResponse);

    // wait for response (whether the reverse connection setup was successful)
    final FutureResponse rconResponse = new FutureResponse(rconMessage);
   
    SimpleChannelInboundHandler<Message> rconInboundHandler = new SimpleChannelInboundHandler<Message>() {
      @Override
      protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
        if(msg.command() == Commands.RCON.getNr() && msg.type() == Type.OK) {
          LOG.debug("Successfully set up the reverse connection to peer {}", message.recipient().peerId());
          rconResponse.response(msg);
        } else {
          LOG.debug("Could not acquire a reverse connection to peer {}", message.recipient().peerId());
          rconResponse.failed("Could not acquire a reverse connection");
          futureResponse.failed(rconResponse.failedReason());
        }
      }
    };
   
    // send reverse connection request instead of normal message
View Full Code Here

Examples of net.tomp2p.futures.FutureResponse

     * @return The future response to keep track of future events
     */
    public FutureResponse sendTask(final PeerAddress remotePeer, ChannelCreator channelCreator, Number160 taskID,
            Map<Number160, Data> dataMap, Worker mapper, KeyPair keyPair, boolean forceUDP, boolean sign) {
        final Message message = createMessage(remotePeer, Command.TASK, Type.REQUEST_1);
        FutureResponse futureResponse = new FutureResponse(message);
        try {
            byte[] me = Utils.encodeJavaObject(mapper);
            ChannelBuffer payload = ChannelBuffers.wrappedBuffer(me);
            message.setPayload(payload);
            message.setDataMap(dataMap);
            message.setKey(taskID);
            if (sign) {
                message.setPublicKeyAndSign(keyPair);
            }
            if (forceUDP) {
                final RequestHandler<FutureResponse> requestHandler = new RequestHandler<FutureResponse>(
                        futureResponse, getPeerBean(), getConnectionBean(), message);
                if (logger.isDebugEnabled()) {
                    logger.debug("send Task " + message);
                }
                return requestHandler.sendUDP(channelCreator);
            } else {
                final RequestHandlerTCP<FutureResponse> requestHandler = new RequestHandlerTCP<FutureResponse>(
                        futureResponse, getPeerBean(), getConnectionBean(), message);
                if (logger.isDebugEnabled()) {
                    logger.debug("send Task " + message);
                }
                return requestHandler.sendTCP(channelCreator);
            }
        } catch (IOException ioe) {
            futureResponse.setFailed(ioe.toString());
            if (logger.isErrorEnabled()) {
                ioe.printStackTrace();
            }
            return futureResponse;
        }
View Full Code Here

Examples of net.tomp2p.futures.FutureResponse

    }

    public FutureResponse sendResult(final PeerAddress remotePeer, ChannelCreator channelCreator, Number160 taskID,
            Map<Number160, Data> dataMap, KeyPair keyPair, boolean forceUDP, boolean sign) {
        final Message message = createMessage(remotePeer, Command.TASK, Type.REQUEST_3);
        FutureResponse futureResponse = new FutureResponse(message);
        if (dataMap != null) {
            message.setDataMap(dataMap);
        }
        message.setKey(taskID);
        if (sign) {
View Full Code Here

Examples of net.tomp2p.futures.FutureResponse

    public FutureResponse taskStatus(final PeerAddress remotePeer, ChannelCreator channelCreator,
            Collection<Number160> taskIDs, boolean forceTCP) {
        final Message message = createMessage(remotePeer, Command.TASK, Type.REQUEST_2);
        message.setKeys(taskIDs);
        FutureResponse futureResponse = new FutureResponse(message);
        if (!forceTCP) {
            final RequestHandler<FutureResponse> requestHandler = new RequestHandler<FutureResponse>(
                    futureResponse, getPeerBean(), getConnectionBean(), message);
            return requestHandler.sendUDP(channelCreator);
        } else {
View Full Code Here

Examples of net.tomp2p.futures.FutureResponse

            FutureChannelCreator futureChannelCreator = connectionBean.getConnectionReservation().reserve(1);
            futureChannelCreator.addListener(new BaseFutureAdapter<FutureChannelCreator>() {
                @Override
                public void operationComplete(final FutureChannelCreator futureChannelCreator) throws Exception {
                    if (futureChannelCreator.isSuccess()) {
                        FutureResponse futureResponse = getTaskRPC().sendResult(senderAddress,
                                futureChannelCreator.getChannelCreator(), taskId, outputData2,
                                peer.getPeerBean().getKeyPair(), false, sign);
                        futureResponse.addListener(new BaseFutureAdapter<FutureResponse>() {
                            @Override
                            public void operationComplete(FutureResponse future) throws Exception {
                                if (future.isSuccess()) {
                                    synchronized (lock) {
                                        status.put(taskKey, Status.SUCCESS_RESULT_SENT);
View Full Code Here

Examples of net.tomp2p.futures.FutureResponse

            public void cancel() {
                taskFailed(taskKey);
            }
        });
        tasks.put(taskKey, futureAsyncTask);
        FutureResponse futureResponse = taskRPC.sendTask(remotePeer, channelCreator, taskId, dataMap, mapper,
                peerBean.getKeyPair(), forceUDP, sign);
        futureResponse.addListener(new BaseFutureAdapter<FutureResponse>() {
            @Override
            public void operationComplete(FutureResponse future) throws Exception {
                if (future.isSuccess()) {
                    // keep track of it and poll to see if its still alive
                    scheduler.keepTrack(remotePeer, taskId, (TaskResultListener) AsyncTask.this);
View Full Code Here

Examples of net.tomp2p.futures.FutureResponse

            FutureChannelCreator fcc = recv1.connectionBean().reservation().create(1, 0);
            fcc.awaitUninterruptibly();
            ChannelCreator cc = fcc.channelCreator();

            SearchValues v = new SearchValues(new Number160("0x1"), null);
            FutureResponse fr = neighbors2.closeNeighbors(sender.peerAddress(), v,
                    Type.REQUEST_2, cc, new DefaultConnectionConfiguration());

            fr.awaitUninterruptibly();
            // Thread.sleep(10000000);
            Assert.assertEquals(true, fr.isSuccess());
            NeighborSet pas = fr.responseMessage().neighborsSet(0);
            // we are able to fit 40 neighbors into 1400 bytes
            Assert.assertEquals(33, pas.size());
            Assert.assertEquals(new Number160("0x1"), pas.neighbors().iterator().next().peerId());
            Assert.assertEquals(PORT_TCP, pas.neighbors().iterator().next().tcpPort());
            Assert.assertEquals(PORT_UDP, pas.neighbors().iterator().next().udpPort());
View Full Code Here

Examples of net.tomp2p.futures.FutureResponse

            ChannelCreator cc = fcc.channelCreator();

            SearchValues v = new SearchValues(new Number160("0x1"), null);
            DefaultConnectionConfiguration d = new DefaultConnectionConfiguration();
            d.forceTCP();
            FutureResponse fr = neighbors2.closeNeighbors(sender.peerAddress(), v,
                    Type.REQUEST_2, cc, d);

            fr.awaitUninterruptibly();
            System.err.println(fr.failedReason());
            // Thread.sleep(10000000);
            Assert.assertEquals(true, fr.isSuccess());
            NeighborSet pas = fr.responseMessage().neighborsSet(0);
            // we are able to fit 40 neighbors into 1400 bytes
            Assert.assertEquals(33, pas.size());
            Assert.assertEquals(new Number160("0x1"), pas.neighbors().iterator().next().peerId());
            Assert.assertEquals(PORT_TCP, pas.neighbors().iterator().next().tcpPort());
            Assert.assertEquals(PORT_UDP, pas.neighbors().iterator().next().udpPort());
View Full Code Here

Examples of net.tomp2p.futures.FutureResponse

            FutureChannelCreator fcc = recv1.connectionBean().reservation().create(1, 0);
            fcc.awaitUninterruptibly();
            ChannelCreator cc = fcc.channelCreator();

            SearchValues v = new SearchValues(new Number160("0x30"), null);
            FutureResponse fr = neighbors2.closeNeighbors(sender.peerAddress(), v,
                    Type.REQUEST_2, cc, new DefaultConnectionConfiguration());
            fr.awaitUninterruptibly();
            Assert.assertEquals(true, fr.isSuccess());
            NeighborSet pas = fr.responseMessage().neighborsSet(0);

            // I see no one, not evenmyself. My peer was added in the overflow map
            Assert.assertEquals(0, pas.size());
            cc.shutdown();
        } finally {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.