All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.swirlds.common.io.utility.RecycleBin Maven / Gradle / Ivy

Go to download

Swirlds is a software platform designed to build fully-distributed applications that harness the power of the cloud without servers. Now you can develop applications with fairness in decision making, speed, trust and reliability, at a fraction of the cost of traditional server-based platforms.

There is a newer version: 0.56.6
Show newest version
/*
 * Copyright (C) 2023-2024 Hedera Hashgraph, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.swirlds.common.io.utility;

import com.swirlds.base.state.Startable;
import com.swirlds.base.state.Stoppable;
import com.swirlds.base.time.Time;
import com.swirlds.common.io.config.FileSystemManagerConfig;
import com.swirlds.common.io.filesystem.FileSystemManager;
import com.swirlds.common.platform.NodeId;
import com.swirlds.common.threading.manager.ThreadManager;
import com.swirlds.config.api.Configuration;
import com.swirlds.metrics.api.Metrics;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.nio.file.Path;

/**
 * This class provides the abstraction of deleting a file, but actually moves the file to a temporary location in case
 * the file becomes useful later for debugging.
 * 

* Data moved to the recycle bin persist in the temporary location for an unspecified amount of time, perhaps even no * time at all. Files in this temporary location may be deleted at any time without warning. It is never ok to write * code that depends on the existence of files in this temporary location. Files in this temporary location should be * treated as deleted by java code, and only used for debugging purposes. */ public interface RecycleBin extends Startable, Stoppable { /** * Remove a file or directory tree from its current location and move it to a temporary location. *

* Recycled data will persist in the temporary location for an unspecified amount of time, perhaps even no time at * all. Files in this temporary location may be deleted at any time without warning. It is never ok to write code * that depends on the existence of files in this temporary location. Files in this temporary location should be * treated as deleted by java code, and only used for debugging purposes. * * @param path the file or directory to recycle */ void recycle(@NonNull Path path) throws IOException; /** * Create a default recycle bin. * * @param metrics manages the creation of metrics * @param configuration configuration * @param threadManager manages the creation of threads * @param time provides wall clock time * @param fileSystemManager the manager that would be used to operate the fs. * @param nodeId this node id */ static RecycleBin create( @NonNull final Metrics metrics, @NonNull final Configuration configuration, @NonNull final ThreadManager threadManager, @NonNull final Time time, @NonNull final FileSystemManager fileSystemManager, @NonNull final NodeId nodeId) { final FileSystemManagerConfig fsmConfig = configuration.getConfigData(FileSystemManagerConfig.class); final Path recycleBinPath = fileSystemManager.resolve(Path.of(fsmConfig.recycleBinDir())).resolve(nodeId.toString()); return new RecycleBinImpl( metrics, threadManager, time, recycleBinPath, fsmConfig.recycleBinMaximumFileAge(), fsmConfig.recycleBinCollectionPeriod()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy