Ejemplo n.º 1
0
 private FutureChannelCreator acquire(
     final FutureChannelCreator futureChannelCreator, final FutureResponse futureResponse) {
   if (oneConnection.tryAcquire()) {
     futureResponse.addListener(
         new BaseFutureAdapter<FutureResponse>() {
           @Override
           public void operationComplete(FutureResponse future) throws Exception {
             oneConnection.release();
             synchronized (map) {
               Iterator<Map.Entry<FutureChannelCreator, FutureResponse>> iterator =
                   map.entrySet().iterator();
               if (iterator.hasNext()) {
                 Map.Entry<FutureChannelCreator, FutureResponse> entry = iterator.next();
                 iterator.remove();
                 acquire(entry.getKey(), entry.getValue());
               }
             }
           }
         });
     futureChannelCreator.reserved(cc);
     return futureChannelCreator;
   } else {
     synchronized (map) {
       map.put(futureChannelCreator, futureResponse);
     }
   }
   return futureChannelCreator;
 }
Ejemplo n.º 2
0
 private FutureWrappedBootstrap<FutureBootstrap> bootstrapPing(PeerAddress address) {
   final FutureWrappedBootstrap<FutureBootstrap> result =
       new FutureWrappedBootstrap<FutureBootstrap>();
   final FutureResponse tmp =
       (FutureResponse) peer.ping().setPeerAddress(address).setTcpPing().start();
   tmp.addListener(
       new BaseFutureAdapter<FutureResponse>() {
         @Override
         public void operationComplete(final FutureResponse future) throws Exception {
           if (future.isSuccess()) {
             peerAddress = future.getResponse().getSender();
             bootstrapTo = new ArrayList<PeerAddress>(1);
             bootstrapTo.add(peerAddress);
             result.setBootstrapTo(bootstrapTo);
             result.waitFor(bootstrap());
           } else {
             result.setFailed("could not reach anyone with bootstrap");
           }
         }
       });
   return result;
 }