List of usage examples for org.apache.hadoop.util ServicePlugin stop
void stop();
From source file:common.DataNode.java
License:Apache License
/** * Shut down this instance of the datanode. * Returns only after shutdown is complete. * This method can only be called by the offerService thread. * Otherwise, deadlock might occur./* ww w . ja v a 2s .co m*/ */ public void shutdown() { if (plugins != null) { for (ServicePlugin p : plugins) { try { p.stop(); LOG.info("Stopped plug-in " + p); } catch (Throwable t) { LOG.warn("ServicePlugin " + p + " could not be stopped", t); } } } if (infoServer != null) { try { infoServer.stop(); } catch (Exception e) { LOG.warn("Exception shutting down DataNode", e); } } if (ipcServer != null) { ipcServer.stop(); } this.shouldRun = false; if (dataXceiverServer != null) { ((DataXceiverServer) this.dataXceiverServer.getRunnable()).kill(); this.dataXceiverServer.interrupt(); // wait for all data receiver threads to exit if (this.threadGroup != null) { int sleepMs = 2; while (true) { this.threadGroup.interrupt(); LOG.info( "Waiting for threadgroup to exit, active threads is " + this.threadGroup.activeCount()); if (this.threadGroup.activeCount() == 0) { break; } try { Thread.sleep(sleepMs); } catch (InterruptedException e) { } sleepMs = sleepMs * 3 / 2; // exponential backoff if (sleepMs > 1000) { sleepMs = 1000; } } } // wait for dataXceiveServer to terminate try { this.dataXceiverServer.join(); } catch (InterruptedException ie) { } } RPC.stopProxy(namenode); // stop the RPC threads if (upgradeManager != null) upgradeManager.shutdownUpgrade(); if (blockScannerThread != null) { blockScannerThread.interrupt(); try { blockScannerThread.join(3600000L); // wait for at most 1 hour } catch (InterruptedException ie) { } } if (storage != null) { try { this.storage.unlockAll(); } catch (IOException ie) { LOG.warn("Exception when unlocking storage: " + ie, ie); } } if (dataNodeThread != null) { dataNodeThread.interrupt(); try { dataNodeThread.join(); } catch (InterruptedException ie) { } } if (data != null) { data.shutdown(); } if (myMetrics != null) { myMetrics.shutdown(); } }
From source file:common.NameNode.java
License:Apache License
/** * Stop all NameNode threads and wait for all to finish. *//* ww w . j a v a 2 s .com*/ public void stop() { synchronized (this) { if (stopRequested) return; stopRequested = true; } if (plugins != null) { for (ServicePlugin p : plugins) { try { p.stop(); } catch (Throwable t) { LOG.warn("ServicePlugin " + p + " could not be stopped", t); } } } try { if (httpServer != null) httpServer.stop(); } catch (Exception e) { LOG.error(StringUtils.stringifyException(e)); } if (namesystem != null) namesystem.close(); if (emptier != null) emptier.interrupt(); if (server != null) server.stop(); if (myMetrics != null) { myMetrics.shutdown(); } if (namesystem != null) { namesystem.shutdown(); } }