001package co.codewizards.cloudstore.core.repo.local;
002
003import java.beans.PropertyChangeListener;
004import java.net.URL;
005import java.util.Collection;
006import java.util.UUID;
007
008import co.codewizards.cloudstore.core.bean.PropertyBase;
009import co.codewizards.cloudstore.core.oio.File;
010
011public interface LocalRepoRegistry {
012        String LOCAL_REPO_REGISTRY_FILE = "repoRegistry.properties"; // new name since 0.9.1
013        String CONFIG_KEY_EVICT_DEAD_ENTRIES_PERIOD = "repoRegistry.evictDeadEntriesPeriod";
014        long DEFAULT_EVICT_DEAD_ENTRIES_PERIOD = 24 * 60 * 60 * 1000L;
015
016        public static interface Property extends PropertyBase {
017        }
018
019        public static enum PropertyEnum implements Property {
020                repositoryIds,
021                repositoryAliases
022        }
023
024        Collection<UUID> getRepositoryIds();
025
026        UUID getRepositoryId(String repositoryName);
027
028        UUID getRepositoryIdOrFail(String repositoryName);
029
030        URL getLocalRootURLForRepositoryNameOrFail(String repositoryName);
031
032        URL getLocalRootURLForRepositoryName(String repositoryName);
033
034        File getLocalRootForRepositoryNameOrFail(String repositoryName);
035
036        /**
037         * Get the local root for the given {@code repositoryName}.
038         * @param repositoryName the String-representation of the repositoryId or
039         * a repositoryAlias. Must not be <code>null</code>.
040         * @return the repository's local root or <code>null</code>, if the given {@code repositoryName} is neither
041         * a repositoryId nor a repositoryAlias known to this registry.
042         */
043        File getLocalRootForRepositoryName(String repositoryName);
044
045        File getLocalRoot(UUID repositoryId);
046
047        File getLocalRootOrFail(UUID repositoryId);
048
049        /**
050         * Puts an alias into the registry.
051         * <p>
052         * <b>Important:</b> Do <b>not</b> call this method directly. Most likely, you should use
053         * {@link LocalRepoManager#putRepositoryAlias(String)} instead!
054         * @param repositoryAlias
055         * @param repositoryId
056         */
057        void putRepositoryAlias(String repositoryAlias, UUID repositoryId);
058
059        void removeRepositoryAlias(String repositoryAlias);
060
061        void putRepository(UUID repositoryId, File localRoot);
062
063        /**
064         * Gets all aliases known for the specified repository.
065         * @param repositoryName the repository-ID or -alias. Must not be <code>null</code>.
066         * @return the known aliases. Never <code>null</code>, but maybe empty (if there are no aliases for this repository).
067         * @throws IllegalArgumentException if the repository with the given {@code repositoryName} does not exist,
068         * i.e. it's neither a repository-ID nor a repository-alias of a known repository.
069         */
070        Collection<String> getRepositoryAliasesOrFail(String repositoryName)
071                        throws IllegalArgumentException;
072
073        /**
074         * Gets all aliases known for the specified repository.
075         * @param repositoryName the repository-ID or -alias. Must not be <code>null</code>.
076         * @return the known aliases. <code>null</code>, if there is no repository with
077         * the given {@code repositoryName}. Empty, if the repository is known, but there
078         * are no aliases for it.
079         */
080        Collection<String> getRepositoryAliases(String repositoryName);
081
082        void addPropertyChangeListener(PropertyChangeListener listener);
083
084        void addPropertyChangeListener(Property property, PropertyChangeListener listener);
085
086        void removePropertyChangeListener(PropertyChangeListener listener);
087
088        void removePropertyChangeListener(Property property, PropertyChangeListener listener);
089
090        Collection<String> getRepositoryAliases();
091}