001package co.codewizards.cloudstore.core.repo.transport;
002
003import co.codewizards.cloudstore.core.config.Config;
004
005/**
006 * Strategy controlling how and when a destination file is written.
007 * <p>
008 * This is merely a setting in the {@link Config}. The actual implementation is in the
009 * {@link co.codewizards.cloudstore.local.transport.file.FileRepoTransport FileRepoTransport}.
010 *
011 * @author Marco หงุ่ยตระกูล-Schulze - marco at codewizards dot co
012 */
013public enum FileWriteStrategy {
014        /**
015         * Write directly into the destination file after all blocks have been transferred.
016         * During transfer, the destination file is not touched.
017         * <p>
018         * This strategy requires as much temporary space in the destination file system as
019         * blocks are transferred: The maximum total space requirement is thus twice
020         * the file size (old file + all blocks).
021         */
022        directAfterTransfer,
023
024        /**
025         * Write each block directly into the destination file immediately when it was transferred.
026         * Don't wait for all other blocks.
027         * <p>
028         * In contrast to {@link #directAfterTransfer} this may leave the destination file in an
029         * inconsistent state for hours or even days - as long as the transfer takes.
030         * <p>
031         * However, this strategy requires the least space in the file system: Only once the file size.
032         * There are no temporary files involved and thus no additional temporary space required.
033         */
034        directDuringTransfer,
035
036        /**
037         * Similar to {@link #directAfterTransfer}, but write a new file and then switch
038         * the files (delete the old file and rename the new file).
039         * <p>
040         * This strategy is the safest concerning consistency, but requires the most temporary space in
041         * the destination file system: The maximum total space requirement is a bit more than twice
042         * the file size (old file + blocks not yet written to new file + partial new file).
043         * Because the blocks are immediately deleted when written to the (partial) new file
044         * and the new file is growing while blocks are deleted (it doesn't have the final size immediately),
045         * the required space is <i>not</i> 3 times the size, but - as said - only a bit more than twice
046         * the size.
047         */
048        replaceAfterTransfer
049        ;
050
051        /**
052         * The {@code key} used with {@link Config#getPropertyAsEnum(String, Enum)}.
053         */
054        public static final String CONFIG_KEY = "fileWriteStrategy"; //$NON-NLS-1$
055        /**
056         * The {@code defaultValue} used with {@link Config#getPropertyAsEnum(String, Enum)}.
057         */
058        public static final FileWriteStrategy CONFIG_DEFAULT_VALUE = directAfterTransfer;
059
060}