X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=statesystem%2Forg.eclipse.tracecompass.segmentstore.core%2Fsrc%2Forg%2Feclipse%2Ftracecompass%2Fsegmentstore%2Fcore%2Ftreemap%2FTreeMapStore.java;h=e9a5b0d26a0ac411ba9d46498e19aaa4dc718998;hb=def1d9d0cd83d812a3d19ef72860c188e1a830ba;hp=1632d91c041f5a373b4b7a98ce6ad7fe687f2323;hpb=1a9cb076d18071a3f6aba14d07806df070066ccd;p=deliverable%2Ftracecompass.git diff --git a/statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java b/statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java index 1632d91c04..e9a5b0d26a 100644 --- a/statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java +++ b/statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java @@ -12,24 +12,15 @@ package org.eclipse.tracecompass.segmentstore.core.treemap; -import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; - import java.util.Collection; import java.util.Iterator; import java.util.TreeMap; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.segmentstore.core.ISegment; import org.eclipse.tracecompass.segmentstore.core.ISegmentStore; -import org.eclipse.tracecompass.segmentstore.core.SegmentComparators; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Ordering; -import com.google.common.collect.Sets; -import com.google.common.collect.TreeMultimap; +import org.eclipse.tracecompass.segmentstore.core.SegmentStoreFactory; /** * Implementation of a {@link ISegmentStore} using in-memory {@link TreeMap}'s. @@ -51,43 +42,16 @@ import com.google.common.collect.TreeMultimap; * The type of segment held in this store * * @author Alexandre Montplaisir + * @deprecated Use the {@link SegmentStoreFactory} to create a new segment store */ -public class TreeMapStore implements ISegmentStore { - - private final ReadWriteLock fLock = new ReentrantReadWriteLock(false); - - private final TreeMultimap fStartTimesIndex; - private final TreeMultimap fEndTimesIndex; - - private volatile long fSize; - - private @Nullable transient Iterable fLastSnapshot = null; +@Deprecated +public class TreeMapStore<@NonNull E extends ISegment> extends org.eclipse.tracecompass.internal.segmentstore.core.treemap.TreeMapStore { /** * Constructor */ public TreeMapStore() { - /* - * For the start times index, the "key comparator" will compare the - * start times as longs directly. This is the primary comparator for its - * tree map. - * - * The secondary "value" comparator will check the end times first, and - * in the event of a tie, defer to the ISegment's Comparable - * implementation, a.k.a. its natural ordering. - * - * The same is done for the end times index, but swapping the first two - * comparators instead. - */ - fStartTimesIndex = checkNotNull(TreeMultimap. create( - SegmentComparators.LONG_COMPARATOR, - Ordering.from(SegmentComparators.INTERVAL_END_COMPARATOR).compound(Ordering.natural()))); - - fEndTimesIndex = checkNotNull(TreeMultimap. create( - SegmentComparators.LONG_COMPARATOR, - Ordering.from(SegmentComparators.INTERVAL_START_COMPARATOR).compound(Ordering.natural()))); - - fSize = 0; + super(); } // ------------------------------------------------------------------------ @@ -96,132 +60,67 @@ public class TreeMapStore implements ISegmentStore { @Override public Iterator iterator() { - fLock.readLock().lock(); - try { - Iterable lastSnapshot = fLastSnapshot; - if (lastSnapshot == null) { - lastSnapshot = checkNotNull(ImmutableList.copyOf(fStartTimesIndex.values())); - fLastSnapshot = lastSnapshot; - } - return checkNotNull(lastSnapshot.iterator()); - } finally { - fLock.readLock().unlock(); - } + return super.iterator(); } @Override public boolean add(@Nullable E val) { - if (val == null) { - throw new IllegalArgumentException(); - } - - fLock.writeLock().lock(); - try { - /* We can take a read lock while holding the write lock. */ - if (contains(val)) { - return false; - } - - if (fStartTimesIndex.put(Long.valueOf(val.getStart()), val)) { - fEndTimesIndex.put(Long.valueOf(val.getEnd()), val); - fSize++; - fLastSnapshot = null; - } - } finally { - fLock.writeLock().unlock(); - } - return true; + return super.add(val); } @Override public int size() { - return Long.valueOf(fSize).intValue(); + return super.size(); // me } @Override public boolean isEmpty() { - return (fSize == 0); + return super.isEmpty(); } @Override public boolean contains(@Nullable Object o) { - fLock.readLock().lock(); - try { - return fStartTimesIndex.containsValue(o); - } finally { - fLock.readLock().unlock(); - } + return super.contains(o); } - @Override public boolean containsAll(@Nullable Collection c) { - fLock.readLock().lock(); - try { - return fStartTimesIndex.values().containsAll(c); - } finally { - fLock.readLock().unlock(); - } + return super.containsAll(c); } @Override public Object[] toArray() { - fLock.readLock().lock(); - try { - return checkNotNull(fStartTimesIndex.values().toArray()); - } finally { - fLock.readLock().unlock(); - } + return super.toArray(); } @Override - public T[] toArray(@Nullable T[] a) { - fLock.readLock().lock(); - try { - return checkNotNull(fStartTimesIndex.values().toArray(a)); - } finally { - fLock.readLock().unlock(); - } + public T[] toArray(T[] a) { + return super.toArray(a); } @Override public boolean remove(@Nullable Object o) { - throw new UnsupportedOperationException(); + return super.remove(o); } @Override public boolean addAll(@Nullable Collection c) { - if (c == null) { - throw new IllegalArgumentException(); - } - - fLock.writeLock().lock(); - try { - boolean changed = false; - for (E elem : c) { - if (this.add(elem)) { - changed = true; - } - } - return changed; - } finally { - fLock.writeLock().unlock(); - } + return super.addAll(c); } @Override public boolean removeAll(@Nullable Collection c) { - throw new UnsupportedOperationException(); + return super.removeAll(c); } @Override public boolean retainAll(@Nullable Collection c) { - throw new UnsupportedOperationException(); + return super.retainAll(c); } @Override public void clear() { - throw new UnsupportedOperationException(); + super.clear(); } // ------------------------------------------------------------------------ @@ -230,41 +129,17 @@ public class TreeMapStore implements ISegmentStore { @Override public Iterable getIntersectingElements(long position) { - /* - * The intervals intersecting 't' are those whose 1) start time is - * *lower* than 't' AND 2) end time is *higher* than 't'. - */ - fLock.readLock().lock(); - try { - Iterable matchStarts = Iterables.concat(fStartTimesIndex.asMap().headMap(position, true).values()); - Iterable matchEnds = Iterables.concat(fEndTimesIndex.asMap().tailMap(position, true).values()); - return checkNotNull(Sets.intersection(Sets.newHashSet(matchStarts), Sets.newHashSet(matchEnds))); - } finally { - fLock.readLock().unlock(); - } + return super.getIntersectingElements(position); } @Override public Iterable getIntersectingElements(long start, long end) { - fLock.readLock().lock(); - try { - Iterable matchStarts = Iterables.concat(fStartTimesIndex.asMap().headMap(end, true).values()); - Iterable matchEnds = Iterables.concat(fEndTimesIndex.asMap().tailMap(start, true).values()); - return checkNotNull(Sets.intersection(Sets.newHashSet(matchStarts), Sets.newHashSet(matchEnds))); - } finally { - fLock.readLock().unlock(); - } + return super.getIntersectingElements(start, end); } @Override public void dispose() { - fLock.writeLock().lock(); - try { - fStartTimesIndex.clear(); - fEndTimesIndex.clear(); - fSize = 0; - } finally { - fLock.writeLock().unlock(); - } + super.dispose(); } + }