Java Code Examples for org.apache.flink.util.ShutdownHookUtil#removeShutdownHook()

The following examples show how to use org.apache.flink.util.ShutdownHookUtil#removeShutdownHook() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskExecutorLocalStateStoresManager.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public void shutdown() {

		HashMap<AllocationID, Map<JobVertexSubtaskKey, OwnedTaskLocalStateStore>> toRelease;

		synchronized (lock) {

			if (closed) {
				return;
			}

			closed = true;
			toRelease = new HashMap<>(taskStateStoresByAllocationID);
			taskStateStoresByAllocationID.clear();
		}

		ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);

		LOG.info("Shutting down TaskExecutorLocalStateStoresManager.");

		for (Map.Entry<AllocationID, Map<JobVertexSubtaskKey, OwnedTaskLocalStateStore>> entry :
			toRelease.entrySet()) {

			doRelease(entry.getValue().values());
			cleanupAllocationBaseDirs(entry.getKey());
		}
	}
 
Example 2
Source File: AbstractBlobCache.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void close() throws IOException {
	cancelCleanupTask();

	if (shutdownRequested.compareAndSet(false, true)) {
		log.info("Shutting down BLOB cache");

		// Clean up the storage directory
		try {
			FileUtils.deleteDirectory(storageDir);
		} finally {
			// Remove shutdown hook to prevent resource leaks
			ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), log);
		}
	}
}
 
Example 3
Source File: AbstractBlobCache.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void close() throws IOException {
	cancelCleanupTask();

	if (shutdownRequested.compareAndSet(false, true)) {
		log.info("Shutting down BLOB cache");

		// Clean up the storage directory
		try {
			FileUtils.deleteDirectory(storageDir);
		} finally {
			// Remove shutdown hook to prevent resource leaks
			ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), log);
		}
	}
}
 
Example 4
Source File: TaskExecutorLocalStateStoresManager.java    From flink with Apache License 2.0 6 votes vote down vote up
public void shutdown() {

		HashMap<AllocationID, Map<JobVertexSubtaskKey, OwnedTaskLocalStateStore>> toRelease;

		synchronized (lock) {

			if (closed) {
				return;
			}

			closed = true;
			toRelease = new HashMap<>(taskStateStoresByAllocationID);
			taskStateStoresByAllocationID.clear();
		}

		ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);

		LOG.info("Shutting down TaskExecutorLocalStateStoresManager.");

		for (Map.Entry<AllocationID, Map<JobVertexSubtaskKey, OwnedTaskLocalStateStore>> entry :
			toRelease.entrySet()) {

			doRelease(entry.getValue().values());
			cleanupAllocationBaseDirs(entry.getKey());
		}
	}
 
Example 5
Source File: TaskExecutorLocalStateStoresManager.java    From flink with Apache License 2.0 6 votes vote down vote up
public void shutdown() {

		HashMap<AllocationID, Map<JobVertexSubtaskKey, OwnedTaskLocalStateStore>> toRelease;

		synchronized (lock) {

			if (closed) {
				return;
			}

			closed = true;
			toRelease = new HashMap<>(taskStateStoresByAllocationID);
			taskStateStoresByAllocationID.clear();
		}

		ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);

		LOG.info("Shutting down TaskExecutorLocalStateStoresManager.");

		for (Map.Entry<AllocationID, Map<JobVertexSubtaskKey, OwnedTaskLocalStateStore>> entry :
			toRelease.entrySet()) {

			doRelease(entry.getValue().values());
			cleanupAllocationBaseDirs(entry.getKey());
		}
	}
 
Example 6
Source File: AbstractBlobCache.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void close() throws IOException {
	cancelCleanupTask();

	if (shutdownRequested.compareAndSet(false, true)) {
		log.info("Shutting down BLOB cache");

		// Clean up the storage directory
		try {
			FileUtils.deleteDirectory(storageDir);
		} finally {
			// Remove shutdown hook to prevent resource leaks
			ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), log);
		}
	}
}
 
Example 7
Source File: FileChannelManagerImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Remove all the temp directories.
 */
@Override
public void close() throws Exception {
	// Marks shutdown and exits if it has already shutdown.
	if (!isShutdown.compareAndSet(false, true)) {
		return;
	}

	IOUtils.closeAll(Arrays.stream(paths)
		.filter(File::exists)
		.map(FileChannelManagerImpl::getFileCloser)
		.collect(Collectors.toList()));

	ShutdownHookUtil.removeShutdownHook(shutdownHook, String.format("%s-%s", getClass().getSimpleName(), prefix), LOG);
}
 
Example 8
Source File: RemoteEnvironment.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
protected void dispose() {
	// Remove shutdown hook to prevent resource leaks
	ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);

	try {
		PlanExecutor executor = this.executor;
		if (executor != null) {
			executor.endSession(jobID);
			executor.stop();
		}
	}
	catch (Exception e) {
		throw new RuntimeException("Failed to dispose the session shutdown hook.");
	}
}
 
Example 9
Source File: ClusterEntrypoint.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Clean up of temporary directories created by the {@link ClusterEntrypoint}.
 *
 * @throws IOException if the temporary directories could not be cleaned up
 */
private void cleanupDirectories() throws IOException {
	ShutdownHookUtil.removeShutdownHook(shutDownHook, getClass().getSimpleName(), LOG);

	final String webTmpDir = configuration.getString(WebOptions.TMP_DIR);

	FileUtils.deleteDirectory(new File(webTmpDir));
}
 
Example 10
Source File: FileArchivedExecutionGraphStore.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws IOException {
	cleanupFuture.cancel(false);

	jobDetailsCache.invalidateAll();

	// clean up the storage directory
	FileUtils.deleteFileOrDirectory(storageDir);

	// Remove shutdown hook to prevent resource leaks
	ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);
}
 
Example 11
Source File: ProcessPythonEnvironmentManager.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws Exception {
	try {
		int retries = 0;
		while (true) {
			try {
				FileUtils.deleteDirectory(new File(baseDirectory));
				break;
			} catch (Throwable t) {
				retries++;
				if (retries <= CHECK_TIMEOUT / CHECK_INTERVAL) {
					LOG.warn(
						String.format(
							"Failed to delete the working directory %s of the Python UDF worker. Retrying...",
							baseDirectory),
						t);
				} else {
					LOG.warn(
						String.format(
							"Failed to delete the working directory %s of the Python UDF worker.", baseDirectory),
						t);
					break;
				}
			}
		}
	} finally {
		if (shutdownHook != null) {
			ShutdownHookUtil.removeShutdownHook(
				shutdownHook, ProcessPythonEnvironmentManager.class.getSimpleName(), LOG);
			shutdownHook = null;
		}
	}
}
 
Example 12
Source File: ClusterEntrypoint.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Clean up of temporary directories created by the {@link ClusterEntrypoint}.
 *
 * @throws IOException if the temporary directories could not be cleaned up
 */
private void cleanupDirectories() throws IOException {
	ShutdownHookUtil.removeShutdownHook(shutDownHook, getClass().getSimpleName(), LOG);

	final String webTmpDir = configuration.getString(WebOptions.TMP_DIR);

	FileUtils.deleteDirectory(new File(webTmpDir));
}
 
Example 13
Source File: FileArchivedExecutionGraphStore.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws IOException {
	cleanupFuture.cancel(false);

	jobDetailsCache.invalidateAll();

	// clean up the storage directory
	FileUtils.deleteFileOrDirectory(storageDir);

	// Remove shutdown hook to prevent resource leaks
	ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);
}
 
Example 14
Source File: RemoteEnvironment.java    From flink with Apache License 2.0 5 votes vote down vote up
protected void dispose() {
	// Remove shutdown hook to prevent resource leaks
	ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);

	try {
		PlanExecutor executor = this.executor;
		if (executor != null) {
			executor.stop();
		}
	}
	catch (Exception e) {
		throw new RuntimeException("Failed to dispose the session shutdown hook.");
	}
}
 
Example 15
Source File: ClusterEntrypoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Clean up of temporary directories created by the {@link ClusterEntrypoint}.
 *
 * @throws IOException if the temporary directories could not be cleaned up
 */
private void cleanupDirectories() throws IOException {
	ShutdownHookUtil.removeShutdownHook(shutDownHook, getClass().getSimpleName(), LOG);

	final String webTmpDir = configuration.getString(WebOptions.TMP_DIR);

	FileUtils.deleteDirectory(new File(webTmpDir));
}
 
Example 16
Source File: FileArchivedExecutionGraphStore.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws IOException {
	cleanupFuture.cancel(false);

	jobDetailsCache.invalidateAll();

	// clean up the storage directory
	FileUtils.deleteFileOrDirectory(storageDir);

	// Remove shutdown hook to prevent resource leaks
	ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);
}
 
Example 17
Source File: BlobServer.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Shuts down the BLOB server.
 */
@Override
public void close() throws IOException {
	cleanupTimer.cancel();

	if (shutdownRequested.compareAndSet(false, true)) {
		Exception exception = null;

		try {
			this.serverSocket.close();
		}
		catch (IOException ioe) {
			exception = ioe;
		}

		// wake the thread up, in case it is waiting on some operation
		interrupt();

		try {
			join();
		}
		catch (InterruptedException ie) {
			Thread.currentThread().interrupt();

			LOG.debug("Error while waiting for this thread to die.", ie);
		}

		synchronized (activeConnections) {
			if (!activeConnections.isEmpty()) {
				for (BlobServerConnection conn : activeConnections) {
					LOG.debug("Shutting down connection {}.", conn.getName());
					conn.close();
				}
				activeConnections.clear();
			}
		}

		// Clean up the storage directory
		try {
			FileUtils.deleteDirectory(storageDir);
		}
		catch (IOException e) {
			exception = ExceptionUtils.firstOrSuppressed(e, exception);
		}

		// Remove shutdown hook to prevent resource leaks
		ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);

		if (LOG.isInfoEnabled()) {
			LOG.info("Stopped BLOB server at {}:{}", serverSocket.getInetAddress().getHostAddress(), getPort());
		}

		ExceptionUtils.tryRethrowIOException(exception);
	}
}
 
Example 18
Source File: BlobServer.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Shuts down the BLOB server.
 */
@Override
public void close() throws IOException {
	cleanupTimer.cancel();

	if (shutdownRequested.compareAndSet(false, true)) {
		Exception exception = null;

		try {
			this.serverSocket.close();
		}
		catch (IOException ioe) {
			exception = ioe;
		}

		// wake the thread up, in case it is waiting on some operation
		interrupt();

		try {
			join();
		}
		catch (InterruptedException ie) {
			Thread.currentThread().interrupt();

			LOG.debug("Error while waiting for this thread to die.", ie);
		}

		synchronized (activeConnections) {
			if (!activeConnections.isEmpty()) {
				for (BlobServerConnection conn : activeConnections) {
					LOG.debug("Shutting down connection {}.", conn.getName());
					conn.close();
				}
				activeConnections.clear();
			}
		}

		// Clean up the storage directory
		try {
			FileUtils.deleteDirectory(storageDir);
		}
		catch (IOException e) {
			exception = ExceptionUtils.firstOrSuppressed(e, exception);
		}

		// Remove shutdown hook to prevent resource leaks
		ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);

		if (LOG.isInfoEnabled()) {
			LOG.info("Stopped BLOB server at {}:{}", serverSocket.getInetAddress().getHostAddress(), getPort());
		}

		ExceptionUtils.tryRethrowIOException(exception);
	}
}
 
Example 19
Source File: BlobServer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Shuts down the BLOB server.
 */
@Override
public void close() throws IOException {
	cleanupTimer.cancel();

	if (shutdownRequested.compareAndSet(false, true)) {
		Exception exception = null;

		try {
			this.serverSocket.close();
		}
		catch (IOException ioe) {
			exception = ioe;
		}

		// wake the thread up, in case it is waiting on some operation
		interrupt();

		try {
			join();
		}
		catch (InterruptedException ie) {
			Thread.currentThread().interrupt();

			LOG.debug("Error while waiting for this thread to die.", ie);
		}

		synchronized (activeConnections) {
			if (!activeConnections.isEmpty()) {
				for (BlobServerConnection conn : activeConnections) {
					LOG.debug("Shutting down connection {}.", conn.getName());
					conn.close();
				}
				activeConnections.clear();
			}
		}

		// Clean up the storage directory
		try {
			FileUtils.deleteDirectory(storageDir);
		}
		catch (IOException e) {
			exception = ExceptionUtils.firstOrSuppressed(e, exception);
		}

		// Remove shutdown hook to prevent resource leaks
		ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);

		if (LOG.isInfoEnabled()) {
			LOG.info("Stopped BLOB server at {}:{}", serverSocket.getInetAddress().getHostAddress(), getPort());
		}

		ExceptionUtils.tryRethrowIOException(exception);
	}
}