コード例 #1
0
 /** Stop the network manager, closing all connections and cleaning up all resources. */
 public void stop() {
   started.set(false);
   logger.info("Network manager stopping!");
   ChannelGroupFuture future = allChannels.close();
   future.awaitUninterruptibly();
   channelFactory.releaseExternalResources();
 }
コード例 #2
0
  /** Shuts the AirReceiver down gracefully */
  public static void onShutdown() {
    /* Close channels */
    final ChannelGroupFuture allChannelsClosed = s_allChannels.close();

    /* Stop all mDNS responders */
    synchronized (s_jmDNSInstances) {
      for (final JmDNS jmDNS : s_jmDNSInstances) {
        try {
          jmDNS.unregisterAllServices();
          s_logger.info("Unregistered all services on " + jmDNS.getInterface());
        } catch (final IOException e) {
          s_logger.info("Failed to unregister some services");
        }
      }
    }

    /* Wait for all channels to finish closing */
    allChannelsClosed.awaitUninterruptibly();

    /* Stop the ExecutorService */
    ExecutorService.shutdown();

    /* Release the OrderedMemoryAwareThreadPoolExecutor */
    ChannelExecutionHandler.releaseExternalResources();
  }
コード例 #3
0
ファイル: DefaultNetServer.java プロジェクト: pkdevbox/vert.x
  private void actualClose(final Context closeContext, final Handler<Void> done) {
    if (id != null) {
      vertx.sharedNetServers().remove(id);
    }

    for (DefaultNetSocket sock : socketMap.values()) {
      sock.internalClose();
    }

    // We need to reset it since sock.internalClose() above can call into the close handlers of
    // sockets on the same thread
    // which can cause context id for the thread to change!

    Context.setContext(closeContext);

    ChannelGroupFuture fut = serverChannelGroup.close();
    if (done != null) {
      fut.addListener(
          new ChannelGroupFutureListener() {
            public void operationComplete(ChannelGroupFuture channelGroupFuture) throws Exception {
              executeCloseDone(closeContext, done);
            }
          });
    }
  }
コード例 #4
0
  public void stop() {
    log.info("Shutting down proxy");
    if (stopped.get()) {
      log.info("Already stopped");
      return;
    }
    stopped.set(true);

    log.info("Closing all channels...");

    // See http://static.netty.io/3.5/guide/#start.12

    final ChannelGroupFuture future = allChannels.close();
    future.awaitUninterruptibly(10 * 1000);

    if (!future.isCompleteSuccess()) {
      final Iterator<ChannelFuture> iter = future.iterator();
      while (iter.hasNext()) {
        final ChannelFuture cf = iter.next();
        if (!cf.isSuccess()) {
          log.warn("Cause of failure for {} is {}", cf.getChannel(), cf.getCause());
        }
      }
    }
    log.info("Stopping timer");
    timer.stop();
    serverChannelFactory.releaseExternalResources();
    clientChannelFactory.releaseExternalResources();

    log.info("Done shutting down proxy");
  }
コード例 #5
0
 public void stop() {
   log.info("Shutting down proxy");
   final ChannelGroupFuture future = allChannels.close();
   future.awaitUninterruptibly(6 * 1000);
   serverBootstrap.releaseExternalResources();
   log.info("Done shutting down proxy");
 }
コード例 #6
0
ファイル: Robot.java プロジェクト: NicoletaOita/k3po
  private void stopConfiguration() throws Exception {

    if (configuration == null) {
      // abort received but script not prepared, therefore entire script failed
      if (progress == null) {
        progress = new ScriptProgress(newSequential(0, 0), "");
      }
      RegionInfo scriptInfo = progress.getScriptInfo();
      progress.addScriptFailure(scriptInfo);
    } else {
      // stopping the configuration will implicitly trigger the script complete listener
      // to handle incomplete script that is being aborted by canceling the finish future

      // clear out the pipelines for new connections to avoid impacting the observed script
      for (ServerBootstrapResolver serverResolver : configuration.getServerResolvers()) {
        ServerBootstrap server = serverResolver.resolve();
        server.setPipelineFactory(pipelineFactory(pipeline(closeOnExceptionHandler)));
      }
      for (ClientBootstrapResolver clientResolver : configuration.getClientResolvers()) {
        ClientBootstrap client = clientResolver.resolve();
        client.setPipelineFactory(pipelineFactory(pipeline(closeOnExceptionHandler)));
      }

      // remove each handler from the configuration pipelines
      // this will trigger failures for any handlers on a pipeline for an incomplete stream
      // including pipelines not yet associated with any channel
      for (ChannelPipeline pipeline : configuration.getClientAndServerPipelines()) {
        stopStream(pipeline);
      }

      // cancel any pending binds and connects
      for (ChannelFuture bindFuture : bindFutures) {
        bindFuture.cancel();
      }

      for (ChannelFuture connectFuture : connectFutures) {
        connectFuture.cancel();
      }

      // close server and client channels
      final ChannelGroupFuture closeFuture = serverChannels.close();
      closeFuture.addListener(
          new ChannelGroupFutureListener() {
            @Override
            public void operationComplete(final ChannelGroupFuture future) {
              clientChannels.close();
            }
          });

      for (AutoCloseable resource : configuration.getResources()) {
        try {
          resource.close();
        } catch (Exception e) {
          // ignore
        }
      }
    }
  }
コード例 #7
0
ファイル: NeddyBenchmark.java プロジェクト: fbudassi/neddy
  /** Frees all the server resources. */
  @Override
  public void shutdown() {
    // Close all connections.
    ChannelGroupFuture groupFuture = NeddyBenchmark.getAllChannels().close();
    groupFuture.awaitUninterruptibly();

    // Shutdown the selector loop (boss and workers).
    getBootstrap().getFactory().releaseExternalResources();
  }
コード例 #8
0
 public void stop() {
   try {
     myScheduler.shutdown();
     myBuildsExecutor.shutdown();
     final ChannelGroupFuture closeFuture = myAllOpenChannels.close();
     closeFuture.awaitUninterruptibly();
   } finally {
     myChannelFactory.releaseExternalResources();
   }
 }
コード例 #9
0
ファイル: RedisClient.java プロジェクト: mDialog/lettuce
 /**
  * Shutdown this client and close all open connections. The client should be discarded after
  * calling shutdown.
  */
 public void shutdown() {
   for (Channel c : channels) {
     ChannelPipeline pipeline = c.getPipeline();
     RedisAsyncConnection<?, ?> connection = pipeline.get(RedisAsyncConnection.class);
     connection.close();
   }
   ChannelGroupFuture future = channels.close();
   future.awaitUninterruptibly();
   bootstrap.releaseExternalResources();
 }
コード例 #10
0
 public void close() throws IOException {
   ChannelGroupFuture f = group.close().awaitUninterruptibly();
   if (!f.isCompleteSuccess()) {
     for (ChannelFuture future : f) {
       if (!future.isSuccess()) {
         throw new IOException(future.getCause());
       }
     }
   }
   bootstrap.releaseExternalResources();
 }
コード例 #11
0
 /** Stop the Server */
 public void stop() {
   try {
     handler.destroy();
     final ChannelGroupFuture future = ALL_CHANNELS.close();
     future.awaitUninterruptibly();
     bootstrap.getFactory().releaseExternalResources();
     ALL_CHANNELS.clear();
   } finally {
     started.set(false);
   }
 }
コード例 #12
0
 @Override
 public final boolean isCompleteSuccess() {
   ensureConditionSet();
   if (condition) {
     return backedChannelGroupFuture.isCompleteSuccess();
   }
   return false;
 }
コード例 #13
0
 @Override
 public final boolean isPartialFailure() {
   ensureConditionSet();
   if (condition) {
     return backedChannelGroupFuture.isPartialFailure();
   }
   return false;
 }
コード例 #14
0
 @Override
 public boolean isSuccessful() {
   if (groupFuture != null) {
     return groupFuture.isCompleteSuccess();
   } else {
     return false;
   }
 }
コード例 #15
0
 @Override
 public final boolean isCompleteFailure() {
   ensureConditionSet();
   if (condition) {
     return backedChannelGroupFuture.isCompleteFailure();
   }
   return true;
 }
コード例 #16
0
 @Override
 public final ChannelGroupFuture awaitUninterruptibly() {
   waitForConditionSetUninterruptibly(-1, -1);
   if (condition) {
     backedChannelGroupFuture.awaitUninterruptibly();
   }
   return this;
 }
コード例 #17
0
 @Override
 public final Iterator<ChannelFuture> iterator() {
   ensureConditionSet();
   if (condition) {
     return backedChannelGroupFuture.iterator();
   } else {
     return null;
   }
 }
コード例 #18
0
 @Override
 public final ChannelGroup getGroup() {
   ensureConditionSet();
   if (condition) {
     return backedChannelGroupFuture.getGroup();
   } else {
     return EMPTY_GROUP;
   }
 }
コード例 #19
0
 @Override
 public final ChannelFuture find(final Integer channelId) {
   ensureConditionSet();
   if (condition) {
     return backedChannelGroupFuture.find(channelId);
   } else {
     return null;
   }
 }
コード例 #20
0
 @Override
 public final ChannelGroupFuture await() throws InterruptedException {
   if (Thread.interrupted()) {
     throw new InterruptedException();
   }
   waitForConditionSet(-1, -1);
   if (condition) {
     backedChannelGroupFuture.await();
   }
   return this;
 }
コード例 #21
0
 @Override
 public final boolean isDone() {
   if (!conditionSetFlag) {
     return false;
   } else {
     if (condition) {
       return backedChannelGroupFuture.isDone();
     } else {
       return true;
     }
   }
 }
コード例 #22
0
 @Override
 public final void removeListener(final ChannelGroupFutureListener listener) {
   synchronized (conditionSetLock) {
     if (!conditionSetFlag) {
       listeners.remove(listener);
     }
   }
   if (conditionSetFlag) {
     if (condition) {
       backedChannelGroupFuture.removeListener(listener);
     }
   }
 }
コード例 #23
0
  @Override
  public final boolean awaitUninterruptibly(final long timeout, final TimeUnit unit) {
    final long nano = unit.toNanos(timeout);
    final long milli = NANOSECONDS.toMillis(nano);
    final int nanoRemain = (int) (nano - MILLISECONDS.toNanos(milli));
    final long remain = nano - waitForConditionSetUninterruptibly(milli, nanoRemain);

    if (conditionSetFlag) {
      if (condition) {
        return backedChannelGroupFuture.awaitUninterruptibly(remain, NANOSECONDS);
      } else {
        return true;
      }
    } else {
      return false;
    }
  }
コード例 #24
0
 @Override
 public final void addListener(final ChannelGroupFutureListener listener) {
   synchronized (conditionSetLock) {
     if (!conditionSetFlag) {
       listeners.put(listener, listener);
       return;
     }
   }
   if (condition) {
     backedChannelGroupFuture.addListener(listener);
   } else {
     try {
       listener.operationComplete(this);
     } catch (final Throwable t) {
       LOGGER.warn("Exception occured when executing ChannelGroupFutureListener", t);
     }
   }
 }
コード例 #25
0
 /**
  * Set the condition value.
  *
  * @param conditionSatisfied if the condition is satisfied.
  */
 public final void setCondition(final boolean conditionSatisfied) {
   synchronized (conditionSetLock) {
     condition = conditionSatisfied;
     conditionSetFlag = true;
     if (condition) {
       for (final ChannelGroupFutureListener l : listeners.keySet()) {
         backedChannelGroupFuture.addListener(l);
       }
       listeners.clear();
     } else {
       for (final ChannelGroupFutureListener l : listeners.keySet()) {
         try {
           l.operationComplete(this);
         } catch (final Throwable t) {
           LOGGER.warn("Exception occured when executing ChannelGroupFutureListener", t);
         }
       }
     }
     conditionSetLock.notifyAll();
   }
 }
コード例 #26
0
ファイル: RestExpress.java プロジェクト: scalabin/RestExpress
 /**
  * Releases all resources associated with this server so the JVM can shutdown cleanly. Call this
  * method to finish using the server. To utilize the default shutdown hook in main() provided by
  * RestExpress, call awaitShutdown() instead.
  */
 public void shutdown() {
   ChannelGroupFuture future = allChannels.close();
   future.awaitUninterruptibly();
   shutdownPlugins();
   bootstrap.getFactory().releaseExternalResources();
 }
コード例 #27
0
 public void stopListening() {
   final ChannelGroupFuture closeFuture = myAllOpenChannels.close();
   closeFuture.awaitUninterruptibly();
 }