diff options
Diffstat (limited to 'src/core/src')
-rw-r--r-- | src/core/src/data/MVDataEntry.java | 238 | ||||
-rw-r--r-- | src/core/src/data/filters/MVDataCombiner.java | 164 | ||||
-rw-r--r-- | src/core/src/data/io/AbstractMVDataReader.java | 49 | ||||
-rw-r--r-- | src/core/src/data/io/AbstractMVDataWriter.java | 70 | ||||
-rw-r--r-- | src/core/src/data/io/MVDataReader.java | 39 | ||||
-rw-r--r-- | src/core/src/data/io/MVDataWriter.java | 45 | ||||
-rw-r--r-- | src/core/src/data/io/stub/StubDataReader.java | 63 | ||||
-rw-r--r-- | src/core/src/data/io/stub/StubDataWriter.java | 104 | ||||
-rw-r--r-- | src/core/src/sync/AbstractSyncTask.java | 71 |
9 files changed, 843 insertions, 0 deletions
diff --git a/src/core/src/data/MVDataEntry.java b/src/core/src/data/MVDataEntry.java new file mode 100644 index 0000000..f92a141 --- /dev/null +++ b/src/core/src/data/MVDataEntry.java @@ -0,0 +1,238 @@ +/* + * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes + * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr> + * + * This file is part of SSSync. + * + * SSSync is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SSSync is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SSSync. If not, see <http://www.gnu.org/licenses/> + */ + +package data; + +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.Set; + +import com.google.common.collect.HashMultimap; + +/** + * Generic Multi-Valued data type. Each object store a particular entry. + * Semantics are like in LDAP directories : an entry = a key + a set of multi-valued attributes. + * Relational data like in RDMS are more constrained : columns are fixed for an entire table. + * Null and empty string attribute value are silently discarded. + * + * @author lpouzenc + */ +public class MVDataEntry implements Comparable<MVDataEntry> { + + /** + * The key part that identify this particular entry. + */ + private final String key; + /** + * The data part of this particular entry. + */ + private HashMultimap<String,String> attrValPairs; + + // XXX : add an HashMap for meta or constraints ? + + // Constructors + + /** + * Build a fresh empty MVDataEntry. + * @param key Unique key identifying this entry + */ + public MVDataEntry(String key) { + if ( key == null ) { + throw new IllegalArgumentException("key must be non-null"); + } + this.key = key; + this.attrValPairs = HashMultimap.create(); + } + + /** + * Build a fresh empty MVDataEntry with hints about expected attr/values count. + * @param key Unique key identifying this entry + */ + public MVDataEntry(String key, int expectedAttribs, int expectedValuesPerAttrib) { + if ( key == null ) { + throw new IllegalArgumentException("key must be non-null"); + } + this.key = key; + this.attrValPairs = HashMultimap.create(expectedAttribs, expectedValuesPerAttrib); + } + + /** + * Deep copy of an existing MVDataEntry. + * @param key Unique key identifying this entry + */ + public MVDataEntry(final MVDataEntry copyFrom) { + this.key=copyFrom.key; // String is immutable, so ref copy is okay + this.attrValPairs = HashMultimap.create(copyFrom.attrValPairs); + } + + /** + * Proxy function to return all attribute/value pairs. + * One can use read a MVDataEntry without depending on non-standard HashMultimap. + * @return + */ + public Set<Entry<String, String>> getAllEntries() { + return this.attrValPairs.entries(); + } + + /** + * Proxy function to add an attribute/value pair in attrValPairs. + * One can use MVDataEntry without depending on non-standard HashMultimap. + * + * @param attr + * @param value + */ + public void put(String attr, String... values) { + for (String value: values) { + if ( value != null && !value.isEmpty() ) { + this.attrValPairs.put(attr, value); + } + } + } + + /** + * Proxy function to get all values from a particular attribute. + * One can use MVDataEntry without depending on non-standard HashMultimap. + * @param attr + * @return + */ + public Set<String> getValues(String attr) { + return this.attrValPairs.get(attr); + } + + /** + * Helper function to insert multiple values from a single string. + * + * @param attr + * @param value + * @param splitRegex + */ + public void splitAndPut(String attr, String value, String splitRegex) { + if ( value != null ) { + for (String v : value.split(splitRegex)) { + put(attr, v); + } + } + } + + /** + * Helper function to return list of changed attributes. + * Note : this don't keep track of deleted attributes. + * @param original + * @return + */ + public Set<String> getChangedAttributes(MVDataEntry original) { + HashSet<String> result = new HashSet<String>(); + + for (String attr: this.attrValPairs.keySet()) { + Set<String> thisValue = this.attrValPairs.get(attr); + Set<String> originalValue = original.attrValPairs.get(attr); + if ( ! thisValue.equals(originalValue) ) { + result.add(attr); + } + } + + return result; + } + + /** + * Augment this entry with attr/values from other entries. + * @param appendMode Select behavior on an existing attribute : append values or replace them + * @param entries Entries to merge with current entry + */ + public void mergeValues(boolean appendMode, MVDataEntry... entries) { + for(MVDataEntry entry : entries) { + if ( ! appendMode ) { + for (String attr : entry.attrValPairs.keySet()) { + this.attrValPairs.removeAll(attr); + } + } + this.attrValPairs.putAll(entry.attrValPairs); + } + } + + /** + * Check if this entry seems contains useful data. + * @return true if this entry seems contains useful data + */ + public boolean isValid() { + boolean validKey=(this.key != null && this.key.length() > 0 ); + boolean validVal=(this.attrValPairs != null && ! this.attrValPairs.isEmpty()); + + return (validKey && validVal); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + // Check for self-comparison (compare object references) + if ( this == obj ) { return true; } + // Check non-nullity and type + if ( !( obj instanceof MVDataEntry) ) { return false; } + // Cast safely + MVDataEntry other = (MVDataEntry) obj; + // Check all fields (known to be always non null) + return ( this.key.equals(other.key) && this.attrValPairs.equals(other.attrValPairs) ); + } + + /** + * Compares entries. Ordering of entries is the ordering of their keys. + * (java.lang.String default ordering : lexicographical ascending order) + */ + @Override + public int compareTo(MVDataEntry other) { + return this.key.compareTo(other.key); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "{key=" + key + ", attrValPairs=" + attrValPairs.toString() + "}"; + } + + + // Boring accessors + /** + * @return the attrValPairs + */ + public HashMultimap<String, String> getAttrValPairs() { + return attrValPairs; + } + + /** + * @param attrValPairs the attrValPairs to set + */ + public void setAttrValPairs(HashMultimap<String, String> attrValPairs) { + this.attrValPairs = attrValPairs; + } + + /** + * @return the key (guaranteed to be non-null) + */ + public String getKey() { + return key; + } + + + +} diff --git a/src/core/src/data/filters/MVDataCombiner.java b/src/core/src/data/filters/MVDataCombiner.java new file mode 100644 index 0000000..1b2eb3f --- /dev/null +++ b/src/core/src/data/filters/MVDataCombiner.java @@ -0,0 +1,164 @@ +/* + * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes + * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr> + * + * This file is part of SSSync. + * + * SSSync is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SSSync is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SSSync. If not, see <http://www.gnu.org/licenses/> + */ + +package data.filters; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import data.MVDataEntry; +import data.io.AbstractMVDataReader; +import data.io.MVDataReader; + +/** + * Combines arbitrary number of MVData* sources while behaving same as AbstractMVDataReader. + * This could enable a sync implementation to merge multiple sources + * before sync'ing in a transparent manner. + * To prevent memory consumption, this assumes that all sources will be read + * with lexicographical ascending order on the "key" field. + * + * @author lpouzenc + */ +public class MVDataCombiner extends AbstractMVDataReader { + + public enum MVDataCombineMode { PRIMARY_SOURCE, MERGE_APPEND, MERGE_REPLACE, OVERRIDE }; + + private final MVDataReader[] readers; + private final MVDataCombineMode[] mergeModes; + + private transient Iterator<MVDataEntry>[] readerIterators; + private transient MVDataEntry[] lookAheadData; + private transient String lastKey; + + + public MVDataCombiner(String dataSourceName, MVDataReader[] readers, MVDataCombineMode mergeModes[]) { + if ( readers == null || mergeModes == null || (mergeModes.length != readers.length) ) { + throw new IllegalArgumentException("readers and mergeModes arrays should have same size"); + } + if ( ! (mergeModes.length > 0) || mergeModes[0] != MVDataCombineMode.PRIMARY_SOURCE ) { + throw new IllegalArgumentException("MVDataCombiner first mergeModes should always be PRIMARY_SOURCE"); + } + + this.dataSourceName = dataSourceName; + this.readers = readers.clone(); + this.mergeModes = mergeModes.clone(); + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("unchecked") /* for new Iterator[...] */ + public Iterator<MVDataEntry> iterator() { + // Be cautious to reset everything + readerIterators = new Iterator[readers.length]; + for (int i=0; i<readers.length;i++) { + readerIterators[i] = readers[i].iterator(); + } + lookAheadData = new MVDataEntry[readers.length]; + lastKey = null; + + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasNext() { + for ( MVDataEntry line : lookAheadData ) { + if ( line != null ) { return true; } + } + for ( MVDataReader reader : readers ) { + if ( reader.hasNext() ) { return true; } + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public MVDataEntry next() { + + final String currentKey = lookAheadAll(); + + // Check if there was unsorted lines in source data + if ( lastKey != null && (currentKey.compareTo(lastKey) < 0) ) { + //XXX : this is checked here and in SafeDataReader (redundant), but both are optionnal... + throw new UnsupportedOperationException("At least one data source is out of order. " + + "Data sources are excepted to be read sorted by MVDataEntry key (ascending lexicogrpahical order)"); + } + + // Merge all data sources for key currentKey + MVDataEntry result = null; + for ( int i=0; i<lookAheadData.length; i++) { + if ( lookAheadData[i] != null && lookAheadData[i].getKey().equals(currentKey) ) { + if ( result == null ) { + result = lookAheadData[i]; + } else { + //XXX : some items in LDAP could have constrains like : "not multi-valued". Force MERGE_REPLACE mode ? + //FIXME : honor all Combine modes + result.mergeValues( (mergeModes[i] == MVDataCombineMode.MERGE_APPEND ),lookAheadData[i]); + } + lookAheadData[i]=null; // "Pop" the used entry + } + } + + lastKey = currentKey; + + return result; + } + + private String lookAheadAll() { + String minKey=null; + + // Feed the look-ahead buffer (look forward by 1 value for each reader) + for ( int i=0; i<lookAheadData.length; i++) { + if ( lookAheadData[i] == null && readerIterators[i].hasNext() ) { + lookAheadData[i] = readerIterators[i].next(); + } + } + + // Find the least RelData key from look-ahead buffers + for (MVDataEntry entry: lookAheadData) { + if ( entry != null ) { + final String minKeyCandidate = entry.getKey(); + if ( minKey == null || minKey.compareTo(minKeyCandidate) > 0 ) { + minKey = minKeyCandidate; + } + } + } + + // Sanity checks + if ( minKey == null ) { + // Every reader is empty and look-ahead buffer is empty (hasNext() should have said false) + throw new NoSuchElementException(); + } + + return minKey; + } + + // Boring accessors + + public String getLastKey() { + return lastKey; + } +} diff --git a/src/core/src/data/io/AbstractMVDataReader.java b/src/core/src/data/io/AbstractMVDataReader.java new file mode 100644 index 0000000..3e63de1 --- /dev/null +++ b/src/core/src/data/io/AbstractMVDataReader.java @@ -0,0 +1,49 @@ +/* + * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes + * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr> + * + * This file is part of SSSync. + * + * SSSync is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SSSync is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SSSync. If not, see <http://www.gnu.org/licenses/> + */ + +package data.io; + +/** + * Stream-oriented abstract reader from a particular data source. + * Memory footprint should not depends on readable line count nor next() call count. + * + * @author lpouzenc + */ +public abstract class AbstractMVDataReader implements MVDataReader { + + protected String dataSourceName="(unknown source)"; + + /** + * Not supported (Readers are read-only). + */ + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) + * @see data.io.MVDataReader#getDataSourceName() + */ + @Override + public String getDataSourceName() { + return dataSourceName; + } + +} diff --git a/src/core/src/data/io/AbstractMVDataWriter.java b/src/core/src/data/io/AbstractMVDataWriter.java new file mode 100644 index 0000000..454e8ce --- /dev/null +++ b/src/core/src/data/io/AbstractMVDataWriter.java @@ -0,0 +1,70 @@ +/* + * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes + * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr> + * + * This file is part of SSSync. + * + * SSSync is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SSSync is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SSSync. If not, see <http://www.gnu.org/licenses/> + */ + +package data.io; + +import java.util.Set; + +import data.MVDataEntry; + +/** + * Stream-oriented abstract writer from a particular data source. + * All derived writers should honor a dry-run mode. + * + * @author lpouzenc + */ +public abstract class AbstractMVDataWriter implements MVDataWriter { + //TODO : not so useful. Interface extraction was not a good idea ? + + /** + * Dry-run mode flag (disabled by default) + */ + protected boolean dryRun=false; + + /* (non-Javadoc) + * @see data.io.MVDataWriter#isDryRun() + */ + public boolean isDryRun() { + return dryRun; + } + + /* (non-Javadoc) + * @see data.io.MVDataWriter#setDryRun(boolean) + */ + public void setDryRun(boolean dryRun) { + this.dryRun = dryRun; + } + + /* (non-Javadoc) + * @see data.io.MVDataWriter#insert(data.MVDataEntry) + */ + @Override + public abstract void insert(MVDataEntry newEntry) throws Exception; + /* (non-Javadoc) + * @see data.io.MVDataWriter#update(data.MVDataEntry, data.MVDataEntry, java.util.Set) + */ + @Override + public abstract void update(MVDataEntry updatedEntry, MVDataEntry originalEntry, Set<String> attrToUpdate) throws Exception; + /* (non-Javadoc) + * @see data.io.MVDataWriter#delete(data.MVDataEntry) + */ + @Override + public abstract void delete(MVDataEntry existingEntry) throws Exception; +} diff --git a/src/core/src/data/io/MVDataReader.java b/src/core/src/data/io/MVDataReader.java new file mode 100644 index 0000000..8a9871a --- /dev/null +++ b/src/core/src/data/io/MVDataReader.java @@ -0,0 +1,39 @@ +/* + * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes + * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr> + * + * This file is part of SSSync. + * + * SSSync is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SSSync is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SSSync. If not, see <http://www.gnu.org/licenses/> + */ + +package data.io; + +import java.util.Iterator; + +import data.MVDataEntry; + +/** + * TODO javadoc + * + * @author lpouzenc + */ +public interface MVDataReader extends Iterator<MVDataEntry>, Iterable<MVDataEntry>{ + + /** + * @return the dataSourceName + */ + public String getDataSourceName(); + +}
\ No newline at end of file diff --git a/src/core/src/data/io/MVDataWriter.java b/src/core/src/data/io/MVDataWriter.java new file mode 100644 index 0000000..2f16fbc --- /dev/null +++ b/src/core/src/data/io/MVDataWriter.java @@ -0,0 +1,45 @@ +/* + * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes + * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr> + * + * This file is part of SSSync. + * + * SSSync is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SSSync is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SSSync. If not, see <http://www.gnu.org/licenses/> + */ + +package data.io; + +import java.util.Set; + +import data.MVDataEntry; + +/** + * TODO javadoc + * + * @author lpouzenc + */ +public interface MVDataWriter { + + public boolean isDryRun(); + public void setDryRun(boolean dryRun); + + public void insert(MVDataEntry newEntry) throws Exception; + + public void update(MVDataEntry updatedEntry, + MVDataEntry originalEntry, Set<String> attrToUpdate) + throws Exception; + + public void delete(MVDataEntry existingEntry) throws Exception; + +}
\ No newline at end of file diff --git a/src/core/src/data/io/stub/StubDataReader.java b/src/core/src/data/io/stub/StubDataReader.java new file mode 100644 index 0000000..ed91267 --- /dev/null +++ b/src/core/src/data/io/stub/StubDataReader.java @@ -0,0 +1,63 @@ +/* + * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes + * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr> + * + * This file is part of SSSync. + * + * SSSync is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SSSync is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SSSync. If not, see <http://www.gnu.org/licenses/> + */ + +package data.io.stub; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import data.MVDataEntry; +import data.io.AbstractMVDataReader; + +/** + * Stub reader implementation for automated tests. + * + * @author lpouzenc + */ +public class StubDataReader extends AbstractMVDataReader { + + private final MVDataEntry fakeEntries[]; + private int cursorRead; + + public StubDataReader(String dataSourceName, MVDataEntry[] fakeEntries) { + this.dataSourceName = dataSourceName; + this.fakeEntries = fakeEntries.clone(); + } + + @Override + public Iterator<MVDataEntry> iterator() { + this.cursorRead = 0; + return this; + } + + @Override + public boolean hasNext() { + return cursorRead < fakeEntries.length; + } + + @Override + public MVDataEntry next() { + if ( ! hasNext() ) { + throw new NoSuchElementException(); + } + return fakeEntries[cursorRead++]; + } + +} diff --git a/src/core/src/data/io/stub/StubDataWriter.java b/src/core/src/data/io/stub/StubDataWriter.java new file mode 100644 index 0000000..cd08e77 --- /dev/null +++ b/src/core/src/data/io/stub/StubDataWriter.java @@ -0,0 +1,104 @@ +/* + * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes + * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr> + * + * This file is part of SSSync. + * + * SSSync is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SSSync is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SSSync. If not, see <http://www.gnu.org/licenses/> + */ + +package data.io.stub; + +import java.util.Set; + +import data.MVDataEntry; +import data.io.AbstractMVDataWriter; + +/** + * Stub writer implementation for automated tests. + * + * @author lpouzenc + */ +public class StubDataWriter extends AbstractMVDataWriter { + + enum OpKind { INSERT, UPDATE, DELETE }; + + private final int maxLogEntries; + + private OpKind opLog[]; + private MVDataEntry opData[]; + private int cursorLog; + + public StubDataWriter(int maxLogEntries) { + this.maxLogEntries = maxLogEntries; + this.opLog = new OpKind[maxLogEntries]; + this.opData = new MVDataEntry[maxLogEntries]; + } + + @Override + public void insert(MVDataEntry newline) { + if ( cursorLog >= maxLogEntries) { + throw new IllegalStateException(); + } + opLog[cursorLog]=OpKind.INSERT; + opData[cursorLog]=newline; + cursorLog++; + } + + @Override + public void update(MVDataEntry updatedLine, MVDataEntry originalLine, Set<String> attrToUpdate) { + if ( cursorLog >= maxLogEntries) { + throw new IllegalStateException(); + } + opLog[cursorLog]=OpKind.UPDATE; + opData[cursorLog]=updatedLine; + cursorLog++; + } + + @Override + public void delete(MVDataEntry existingLine) { + if ( cursorLog >= maxLogEntries) { + throw new IllegalStateException(); + } + opLog[cursorLog]=OpKind.DELETE; + opData[cursorLog]=existingLine; + cursorLog++; + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + + for (int i = 0; i < cursorLog; i++) { + buf.append(opLog[i] + ": " + opData[i] + "\n"); + } + + return buf.toString(); + } + + /** + * @return the opLog + */ + public OpKind[] getOpLog() { + return opLog.clone(); + } + + /** + * @return the opData + */ + public MVDataEntry[] getOpData() { + return opData.clone(); + } + +} diff --git a/src/core/src/sync/AbstractSyncTask.java b/src/core/src/sync/AbstractSyncTask.java new file mode 100644 index 0000000..e2ae94d --- /dev/null +++ b/src/core/src/sync/AbstractSyncTask.java @@ -0,0 +1,71 @@ +/* + * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes + * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr> + * + * This file is part of SSSync. + * + * SSSync is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SSSync is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with SSSync. If not, see <http://www.gnu.org/licenses/> + */ + +package sync; + +import java.util.concurrent.Callable; + +/** + * Abstract class to define a common base of all kind of synchronization algorithms. + * + * @author lpouzenc + */ +public abstract class AbstractSyncTask implements Callable<Boolean> { + + /** + * Pretty task name to be inserted in log lines + */ + protected String taskName="(unknown task)"; + + /** + * Dry-run mode flag (disabled by default) + */ + protected boolean dryRun=false; + + /** + * Main method that do the actual sync + */ + public abstract Boolean call(); + + + // Boring accessors + + /** + * @return the dryRun mode status (enabled/disabled) + */ + public boolean isDryRun() { + return dryRun; + } + + /** + * @param dryRun the dryRun mode to set (enabled/disabled) + */ + public void setDryRun(boolean dryRun) { + this.dryRun = dryRun; + } + + /** + * @return the taskName + */ + public String getTaskName() { + return taskName; + } + +} |