001/*
002 * Syncany, www.syncany.org
003 * Copyright (C) 2011-2016 Philipp C. Heckel <philipp.heckel@gmail.com>
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package org.syncany.plugins.transfer.features;
019
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025import org.syncany.plugins.transfer.features.PathAwareFeatureTransferManager.PathAwareRemoteFileAttributes;
026import org.syncany.plugins.transfer.files.MultichunkRemoteFile;
027import org.syncany.plugins.transfer.files.RemoteFile;
028import org.syncany.plugins.transfer.files.TempRemoteFile;
029import org.syncany.plugins.transfer.TransferManager;
030
031/**
032 * Feature annotation to mark a transfer manager of transfer plugins
033 * that need to be sub-foldered. This feature adds sub folders to some {@link RemoteFile}
034 * storage paths in the backend for the purpose of limiting the per-folder file 
035 * count. 
036 * 
037 * <p>This is especially critical if the backend storage has a limit
038 * on how many files can be stored in a single folder, e.g. the Dropbox plugin can only
039 * store 25,000 files in one folder.  
040 * 
041 * <p>This annotation is only recognized if used on a {@link TransferManager}. If
042 * applied, it wraps the original transfer manager in a {@link PathAwareFeatureTransferManager},
043 * which defines details for the subfoldering, such as the depths of the subfolders, the path
044 * separator or other relevant settings. 
045 * 
046 * <p>The only mandatory configuration for this feature is specifying a
047 * {@link PathAwareFeatureExtension} to manage the required subfolders (creating, 
048 * deleting, listing). It must be implemented by the transfer plugin.
049 * 
050 * <p>Example: If the {@link #subfolderDepth()} is 2, the {@link #bytesPerFolder()} is 1,
051 * and the {@link #folderSeparator()} is '/', a multichunk file might be located at
052 * 'multichunks/e3/5f/multichunk-e35f0d48060...' instead of 
053 * 'multichunks/multichunk-e35f0d4806...'.
054 * 
055 * @see PathAwareFeatureTransferManager
056 * @see PathAwareFeatureExtension
057 * @see PathAwareRemoteFileAttributes 
058 * @author Christian Roth (christian.roth@port17.de)
059 */
060@Feature(required = false)
061@Target(ElementType.TYPE)
062@Retention(RetentionPolicy.RUNTIME)
063public @interface PathAware {
064        /**
065         * The path aware extension must be specified to manage the required
066         * subfolders (creating, deleting, listing). 
067         */
068        Class<? extends PathAwareFeatureExtension> extension();
069
070        /**
071         * Defines the depth of the subfolders to be created. The higher the depth, the 
072         * bigger the overhead required for managing the subfolders. 
073         */
074        int subfolderDepth() default 2;
075
076        /**
077         * Defines the bytes of the subfolder identifier used for the 
078         * subfolders. If the bytes per folder is 2 (and the subfolder depth is 2), 
079         * a multichunk might be located at 'multichunks/e35f/0d48/multichunk-e35f0d4...'.
080         */
081        int bytesPerFolder() default 1;
082
083        /** 
084         * Defines the separator used to complete the folder paths.
085         */
086        char folderSeparator() default '/';
087
088        /**
089         * Defines the remote file classes to be affected by the subfoldering. Do not
090         * change the default unless you know what you are doing.
091         */
092        Class<? extends RemoteFile>[] affected() default { MultichunkRemoteFile.class, TempRemoteFile.class };
093}