Examples of FutureAsyncTask


Examples of net.tomp2p.futures.FutureAsyncTask

        for (int i = 0; i < min + parallelDiff; i++) {
            if (futures.get(i) == null) {
                PeerAddress next = queue.pollFirst().peerAddress;
                if (next != null) {
                    active++;
                    FutureAsyncTask futureAsyncTask = asyncTask.submit(next, channelCreator, taskId, dataMap, mapper,
                            forceUDP, sign);
                    futures.set(i, futureAsyncTask);
                    futureTask.addRequests(futureAsyncTask);
                }
            } else {
View Full Code Here

Examples of net.tomp2p.futures.FutureAsyncTask

    }

    public FutureAsyncTask submit(final PeerAddress remotePeer, ChannelCreator channelCreator, final Number160 taskId,
            Map<Number160, Data> dataMap, Worker mapper, boolean forceUDP, boolean sign) {
        final Number320 taskKey = new Number320(taskId, remotePeer.getPeerId());
        final FutureAsyncTask futureAsyncTask = new FutureAsyncTask(remotePeer);
        futureAsyncTask.addCancellation(new Cancel() {
            @Override
            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);
                } else {
                    futureAsyncTask.setFailed(future);
                }
            }
        });
        return futureAsyncTask;
    }
View Full Code Here

Examples of net.tomp2p.futures.FutureAsyncTask

    public void taskReceived(Number320 taskKey, Map<Number160, Data> dataMap) {
        if (logger.isDebugEnabled()) {
            logger.debug("Task received " + taskKey);
        }
        scheduler.stopKeepTrack(taskKey);
        FutureAsyncTask futureAsyncTask = tasks.remove(taskKey);
        if (futureAsyncTask == null) {
            logger.error("Task that was completed was not in the tracking list: " + taskKey);
            return;
        }
        futureAsyncTask.setDataMap(dataMap);
    }
View Full Code Here

Examples of net.tomp2p.futures.FutureAsyncTask

    public void taskFailed(Number320 taskKey) {
        if (logger.isDebugEnabled()) {
            logger.debug("Task failed " + taskKey);
        }
        // this comes from the scheduler
        FutureAsyncTask futureAsyncTask = tasks.remove(taskKey);
        if (futureAsyncTask == null) {
            return;
        }
        futureAsyncTask.setFailed("polling faild, maybe peer died");
    }
View Full Code Here

Examples of net.tomp2p.futures.FutureAsyncTask

            FutureChannelCreator futureChannelCreator = peer1.getConnectionBean().getConnectionReservation().reserve(1);
            futureChannelCreator.awaitUninterruptibly();
            Number160 taskId = new Number160(11);
            Map<Number160, Data> dataMap = new HashMap<Number160, Data>();
            dataMap.put(new Number160(22), new Data("testme"));
            FutureAsyncTask futureAsyncTask = peer1.getAsyncTask().submit(peer2.getPeerAddress(),
                    futureChannelCreator.getChannelCreator(), taskId, dataMap, new MyWorker3(), false, false);
            Utils.addReleaseListenerAll(futureAsyncTask, peer1.getConnectionBean().getConnectionReservation(),
                    futureChannelCreator.getChannelCreator());
            futureAsyncTask.awaitUninterruptibly();
            Assert.assertEquals(true, futureAsyncTask.isSuccess());
            Assert.assertEquals("yup", futureAsyncTask.getDataMap().get(Number160.ONE).getObject());
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            if (peer1 != null) {
                peer1.halt();
View Full Code Here

Examples of net.tomp2p.futures.FutureAsyncTask

            FutureChannelCreator futureChannelCreator = peer1.getConnectionBean().getConnectionReservation().reserve(1);
            futureChannelCreator.awaitUninterruptibly();
            Number160 taskId = new Number160(11);
            Map<Number160, Data> dataMap = new HashMap<Number160, Data>();
            dataMap.put(new Number160(22), new Data("testme"));
            FutureAsyncTask futureAsyncTask = peer1.getAsyncTask().submit(peer2.getPeerAddress(),
                    futureChannelCreator.getChannelCreator(), taskId, dataMap, new MyWorker3(), false, false);
            Utils.addReleaseListenerAll(futureAsyncTask, peer1.getConnectionBean().getConnectionReservation(),
                    futureChannelCreator.getChannelCreator());
            peer2.halt();
            futureAsyncTask.awaitUninterruptibly();
            Assert.assertEquals(false, futureAsyncTask.isSuccess());
        } finally {
            if (peer1 != null) {
                peer1.halt();
            }
        }
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.