001package co.codewizards.cloudstore.core.repo.sync;
002
003import java.beans.PropertyChangeListener;
004import java.util.List;
005import java.util.Set;
006import java.util.UUID;
007
008import co.codewizards.cloudstore.core.bean.Bean;
009import co.codewizards.cloudstore.core.bean.PropertyBase;
010import co.codewizards.cloudstore.core.oio.File;
011import co.codewizards.cloudstore.core.sync.SyncState;
012
013public interface RepoSyncDaemon extends Bean<RepoSyncDaemon.Property> {
014        public static interface Property extends PropertyBase {
015        }
016
017        public static enum PropertyEnum implements Property {
018                activities,
019                activities_added,
020                activities_removed,
021
022                states,
023                states_added,
024                states_removed
025        }
026
027        /**
028         * The maximum number of {@link SyncState} elements to keep for each unique combination of
029         * {@code localRepositoryId} and {@code remoteRepositoryId}.
030         * <p>
031         * The default value is {@link #DEFAULT_SYNC_STATES_MAX_SIZE}.
032         * <p>
033         * Example:
034         * If this value is set to 2 and a certain local repository is connected to 3 remote repositories,
035         * there are 3 unique combinations of local/remote-repository-id and therefore 6 sync-states are kept.
036         * These sync-states are the 2 newest ones for each pair of local+remote repo.
037         */
038        String CONFIG_KEY_SYNC_STATES_MAX_SIZE = "repoSyncDaemon.syncStates.maxSize";
039        int DEFAULT_SYNC_STATES_MAX_SIZE = 1;
040
041        UUID startSync(File file);
042
043        void shutdown();
044
045        void shutdownNow();
046
047        /**
048         * Gets the sync-states of the local repository identified by the given {@code localRepositoryId}.
049         * <p>
050         * The sync-states are sorted according to the time they are enlisted with the <b>newest entries last</b>
051         * (i.e. the oldest first).
052         * <p>
053         * Please note that these states describe only syncs that are complete (either successful or failed).
054         * To determine whether a sync is currently queued or in progress, please use {@link #getActivities(UUID)}.
055         * <p>
056         * @param localRepositoryId the identifier of the local repository. Must not be <code>null</code>.
057         * @return the sync-states. Never <code>null</code> (but maybe empty). This result is read-only and
058         * a detached copy of the internal state (not backed!).
059         */
060        List<RepoSyncState> getStates(UUID localRepositoryId);
061
062        /**
063         * Gets all {@link RepoSyncActivity}-s for the local repository identified by the given {@code localRepositoryId}.
064         * @param localRepositoryId the identifier of the local repository. Must not be <code>null</code>.
065         * @return the activities. Never <code>null</code> (but maybe empty). This result is read-only and
066         * a detached copy of the internal state (not backed!).
067         */
068        Set<RepoSyncActivity> getActivities(final UUID localRepositoryId);
069
070        @Override
071        void addPropertyChangeListener(PropertyChangeListener listener);
072
073        @Override
074        void addPropertyChangeListener(Property property, PropertyChangeListener listener);
075
076        @Override
077        void removePropertyChangeListener(PropertyChangeListener listener);
078
079        @Override
080        void removePropertyChangeListener(Property property, PropertyChangeListener listener);
081}