*/
public FutureTask submit(final Number160 locationKey, final Map<Number160, Data> dataMap, final Worker worker,
final RoutingConfiguration routingConfiguration, final RequestP2PConfiguration requestP2PConfiguration,
final FutureChannelCreator futureChannelCreator, final boolean signMessage, final boolean isManualCleanup,
final ConnectionReservation connectionReservation) {
final FutureTask futureTask = new FutureTask();
futureChannelCreator.addListener(new BaseFutureAdapter<FutureChannelCreator>() {
@Override
public void operationComplete(FutureChannelCreator future) throws Exception {
if (future.isSuccess()) {
final ChannelCreator channelCreator = future.getChannelCreator();
// routing, find close peers
final FutureRouting futureRouting = createRouting(locationKey, null, null, routingConfiguration,
requestP2PConfiguration, Type.REQUEST_4, channelCreator);
futureRouting.addListener(new BaseFutureAdapter<FutureRouting>() {
@Override
public void operationComplete(FutureRouting future) throws Exception {
if (futureRouting.isSuccess()) {
// direct hits mean that there
// is a task scheduled
SortedMap<PeerAddress, DigestInfo> map = future.getDirectHitsDigest();
// potential hits means that no
// task is scheduled
NavigableSet<Pair> queue = findBest(map, future.getPotentialHits(), locationKey);
parallelRequests(futureTask, queue, requestP2PConfiguration, channelCreator,
locationKey, dataMap, worker, requestP2PConfiguration.isForceUPD(), signMessage);
} else {
futureTask.setFailed(futureRouting);
}
}
});
}
if (!isManualCleanup) {
Utils.addReleaseListenerAll(futureTask, connectionReservation, future.getChannelCreator());
} else {
futureTask.setFailed(future);
}
}
});
return futureTask;
}