/** * Adds shutdown hook with default priority (10) * @param shutdownHook - shutdown hook */ public static void addShutdownHook(Runnable shutdownHook) { addShutdownHook(shutdownHook, FileSystem.SHUTDOWN_HOOK_PRIORITY); }
@Override public void destroy() { lDrvState.stateLock.lock(); try { // in the cancel case where the driver state is INTERRUPTED, destroy will be deferred to // the query process if (lDrvState.driverState == DriverState.DESTROYED) { return; } else { lDrvState.driverState = DriverState.DESTROYED; } } finally { lDrvState.stateLock.unlock(); } if (!hiveLocks.isEmpty()) { try { releaseLocksAndCommitOrRollback(false); } catch (LockException e) { LOG.warn("Exception when releasing locking in destroy: " + e.getMessage()); } } ShutdownHookManager.removeShutdownHook(shutdownRunner); }
/** * Close connection */ @Override public void close() { if (isConnectionClosed.get()) { return; } isConnectionClosed.set(true); try { if (currentTransactionBatch != null) { currentTransactionBatch.close(); } } catch (StreamingException e) { LOG.warn("Unable to close current transaction batch: " + currentTransactionBatch, e); } finally { if (manageTransactions) { getMSC().close(); getHeatbeatMSC().close(); } //remove shutdown hook entry added while creating this connection via HiveStreamingConnection.Builder#connect() if (!ShutdownHookManager.isShutdownInProgress()) { ShutdownHookManager.removeShutdownHook(this.onShutdownRunner); } } if (LOG.isInfoEnabled()) { LOG.info("Closed streaming connection. Agent: {} Stats: {}", getAgentInfo(), getConnectionStats()); } }
ShutdownHookManager.removeShutdownHook(shutdownRunner); shutdownRunner = new Runnable() { @Override ShutdownHookManager.addShutdownHook(shutdownRunner, SHUTDOWN_HOOK_PRIORITY);
/** * Returns the list of shutdownHooks in order of execution, * Highest priority first. * * @return the list of shutdownHooks in order of execution. */ static List<Runnable> getShutdownHooksInOrder() { return MGR.getShutdownHooksInOrderInternal(); }
/** * Adds a shutdownHook with a priority, the higher the priority * the earlier will run. ShutdownHooks with same priority run * in a non-deterministic order. * * @param shutdownHook shutdownHook <code>Runnable</code> * @param priority priority of the shutdownHook. */ public static void addShutdownHook(Runnable shutdownHook, int priority) { MGR.addShutdownHookInternal(shutdownHook, priority); }
/** * Indicates if a shutdownHook is registered or not. * * @param shutdownHook shutdownHook to check if registered. * @return TRUE/FALSE depending if the shutdownHook is is registered. */ public static boolean hasShutdownHook(Runnable shutdownHook) { return MGR.hasShutdownHookInternal(shutdownHook); }
@Override public void run() { MGR.shutdownInProgress.set(true); for (Runnable hook: MGR.getShutdownHooksInOrder()) { try { hook.run(); } catch (Throwable ex) { LOG.warn("ShutdownHook '" + hook.getClass().getSimpleName() + "' failed, " + ex.toString(), ex); } } } }
ShutdownHookManager.removeShutdownHook(shutdownRunner); final HiveTxnManager txnMgr = queryTxnMgr; shutdownRunner = new Runnable() { ShutdownHookManager.addShutdownHook(shutdownRunner, SHUTDOWN_HOOK_PRIORITY);
/** * Returns the list of shutdownHooks in order of execution, * Highest priority first. * * @return the list of shutdownHooks in order of execution. */ static List<Runnable> getShutdownHooksInOrder() { return MGR.getShutdownHooksInOrderInternal(); }
/** * Adds a shutdownHook with a priority, the higher the priority * the earlier will run. ShutdownHooks with same priority run * in a non-deterministic order. * * @param shutdownHook shutdownHook <code>Runnable</code> * @param priority priority of the shutdownHook. */ public static void addShutdownHook(Runnable shutdownHook, int priority) { MGR.addShutdownHookInternal(shutdownHook, priority); }
/** * Indicates if a shutdownHook is registered or not. * * @param shutdownHook shutdownHook to check if registered. * @return TRUE/FALSE depending if the shutdownHook is is registered. */ public static boolean hasShutdownHook(Runnable shutdownHook) { return MGR.hasShutdownHookInternal(shutdownHook); }
@Override public void run() { MGR.shutdownInProgress.set(true); for (Runnable hook: MGR.getShutdownHooksInOrder()) { try { hook.run(); } catch (Throwable ex) { LOG.warn("ShutdownHook '" + hook.getClass().getSimpleName() + "' failed, " + ex.toString(), ex); } } } }
DbTxnManager() { shutdownRunner = new Runnable() { @Override public void run() { if (heartbeatExecutorService != null && !heartbeatExecutorService.isShutdown() && !heartbeatExecutorService.isTerminated()) { LOG.info("Shutting down Heartbeater thread pool."); heartbeatExecutorService.shutdown(); } } }; ShutdownHookManager.addShutdownHook(shutdownRunner, SHUTDOWN_HOOK_PRIORITY); }
public void destroy() { lDrvState.stateLock.lock(); try { // in the cancel case where the driver state is INTERRUPTED, destroy will be deferred to // the query process if (lDrvState.driverState == DriverState.DESTROYED || lDrvState.driverState == DriverState.INTERRUPT) { return; } else { lDrvState.driverState = DriverState.DESTROYED; } } finally { lDrvState.stateLock.unlock(); } if (!hiveLocks.isEmpty()) { try { releaseLocksAndCommitOrRollback(false, null); } catch (LockException e) { LOG.warn("Exception when releasing locking in destroy: " + e.getMessage()); } } ShutdownHookManager.removeShutdownHook(shutdownRunner); }
private void createShutdownHook() { // Add a shutdown hook for cleanup, if there are elements remaining in the cache which were not cleaned up. // This is the best effort approach. Ignore any error while doing so. Notice that most of the clients // would get cleaned up via either the removalListener or the close() call, only the active clients // that are in the cache or expired but being used in other threads wont get cleaned. The following code will only // clean the active cache ones. The ones expired from cache but being hold by other threads are in the mercy // of finalize() being called. Thread cleanupHiveClientShutdownThread = new Thread() { @Override public void run() { LOG.debug("Cleaning up hive client cache in ShutDown hook"); cleanupHandle.cancel(false); // Cancel the maintenance thread. closeAllClientsQuietly(); } }; ShutdownHookManager.addShutdownHook(cleanupHiveClientShutdownThread); }
@Override protected void destruct() { try { stopHeartbeat(); if (shutdownRunner != null) { ShutdownHookManager.removeShutdownHook(shutdownRunner); } if (isTxnOpen()) rollbackTxn(); if (lockMgr != null) lockMgr.close(); } catch (Exception e) { LOG.error("Caught exception " + e.getClass().getName() + " with message <" + e.getMessage() + ">, swallowing as there is nothing we can do with it."); // Not much we can do about it here. } }
private void createShutdownHook() { // Add a shutdown hook for cleanup, if there are elements remaining in the cache which were not cleaned up. // This is the best effort approach. Ignore any error while doing so. Notice that most of the clients // would get cleaned up via either the removalListener or the close() call, only the active clients // that are in the cache or expired but being used in other threads wont get cleaned. The following code will only // clean the active cache ones. The ones expired from cache but being hold by other threads are in the mercy // of finalize() being called. Thread cleanupHiveClientShutdownThread = new Thread() { @Override public void run() { LOG.debug("Cleaning up hive client cache in ShutDown hook"); cleanupHandle.cancel(false); // Cancel the maintenance thread. closeAllClientsQuietly(); } }; ShutdownHookManager.addShutdownHook(cleanupHiveClientShutdownThread); }
@Override protected void destruct() { try { stopHeartbeat(); if (shutdownRunner != null) { ShutdownHookManager.removeShutdownHook(shutdownRunner); } if (isTxnOpen()) rollbackTxn(); if (lockMgr != null) lockMgr.close(); } catch (Exception e) { LOG.error("Caught exception " + e.getClass().getName() + " with message <" + e.getMessage() + ">, swallowing as there is nothing we can do with it."); // Not much we can do about it here. } }
DbTxnManager() { shutdownRunner = new Runnable() { @Override public void run() { if (heartbeatExecutorService != null && !heartbeatExecutorService.isShutdown() && !heartbeatExecutorService.isTerminated()) { LOG.info("Shutting down Heartbeater thread pool."); heartbeatExecutorService.shutdown(); } } }; ShutdownHookManager.addShutdownHook(shutdownRunner, SHUTDOWN_HOOK_PRIORITY); }