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

com.instaclustr.cassandra.backup.impl.StorageInteractor Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha8
Show newest version
package com.instaclustr.cassandra.backup.impl;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public abstract class StorageInteractor implements AutoCloseable {

    private final StorageLocation storageLocation;

    public abstract RemoteObjectReference objectKeyToRemoteReference(final Path objectKey) throws Exception;

    public StorageInteractor(final StorageLocation storageLocation) {
        this.storageLocation = storageLocation;
    }

    public String resolveRemotePath(final Path objectKey) {
        return Paths.get(storageLocation.clusterId).resolve(storageLocation.datacenterId).resolve(storageLocation.nodeId).resolve(objectKey).toString();
    }

    protected abstract void cleanup() throws Exception;

    private boolean isClosed = false;

    public void close() throws IOException {
        if (isClosed) {
            return;
        }

        try {
            cleanup();

            isClosed = true;
        } catch (Exception ex) {
            throw new IOException(ex);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy