-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTERNAL: Change decode logic in collection Get apis.
- Loading branch information
Showing
21 changed files
with
422 additions
and
295 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/net/spy/memcached/internal/result/BopGetBulkResultImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package net.spy.memcached.internal.result; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import net.spy.memcached.CachedData; | ||
import net.spy.memcached.collection.BTreeElement; | ||
import net.spy.memcached.collection.BTreeGetResult; | ||
import net.spy.memcached.ops.CollectionOperationStatus; | ||
import net.spy.memcached.transcoders.Transcoder; | ||
|
||
public class BopGetBulkResultImpl<K, V> implements GetResult<Map<String, BTreeGetResult<K, V>>> { | ||
private final Map<String, List<BTreeElement<K, CachedData>>> cachedDataMap; | ||
private final Map<String, CollectionOperationStatus> opStatusMap; | ||
private final boolean reverse; | ||
private final Transcoder<V> transcoder; | ||
private Map<String, BTreeGetResult<K, V>> result | ||
= new HashMap<String, BTreeGetResult<K, V>>(); | ||
|
||
public BopGetBulkResultImpl(Map<String, List<BTreeElement<K, CachedData>>> cachedDataMap, | ||
Map<String, CollectionOperationStatus> opStatusMap, | ||
boolean reverse, Transcoder<V> transcoder) { | ||
this.cachedDataMap = cachedDataMap; | ||
this.opStatusMap = opStatusMap; | ||
this.reverse = reverse; | ||
this.transcoder = transcoder; | ||
} | ||
|
||
@Override | ||
public Map<String, BTreeGetResult<K, V>> getDecodedValue() { | ||
if (result.isEmpty() && !opStatusMap.isEmpty()) { | ||
Map<String, BTreeGetResult<K, V>> temp = new HashMap<String, BTreeGetResult<K, V>>(result); | ||
for (Map.Entry<String, CollectionOperationStatus> entry : opStatusMap.entrySet()) { | ||
String key = entry.getKey(); | ||
temp.put(key, new BTreeGetResult<K, V>(cachedDataMap.get(key), | ||
reverse, transcoder, entry.getValue())); | ||
} | ||
result = temp; | ||
} | ||
return result; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/net/spy/memcached/internal/result/BopGetByPositionResultImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.spy.memcached.internal.result; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
|
||
import net.spy.memcached.CachedData; | ||
import net.spy.memcached.collection.BKeyObject; | ||
import net.spy.memcached.collection.Element; | ||
import net.spy.memcached.transcoders.Transcoder; | ||
import net.spy.memcached.util.BTreeUtil; | ||
|
||
public class BopGetByPositionResultImpl<T> implements GetResult<Map<Integer, Element<T>>> { | ||
private final Map<Integer, Map.Entry<BKeyObject, CachedData>> cachedDataMap; | ||
private final Transcoder<T> transcoder; | ||
private SortedMap<Integer, Element<T>> result; | ||
|
||
public BopGetByPositionResultImpl(Map<Integer, Map.Entry<BKeyObject, CachedData>> cachedDataMap, | ||
boolean reverse, | ||
Transcoder<T> transcoder) { | ||
this.cachedDataMap = cachedDataMap; | ||
this.result = new TreeMap<Integer, Element<T>>((reverse) ? Collections.reverseOrder() : null); | ||
this.transcoder = transcoder; | ||
} | ||
|
||
@Override | ||
public Map<Integer, Element<T>> getDecodedValue() { | ||
if (result.isEmpty() && !cachedDataMap.isEmpty()) { | ||
SortedMap<Integer, Element<T>> temp = new TreeMap<Integer, Element<T>>(result); | ||
for (Map.Entry<Integer, Map.Entry<BKeyObject, CachedData>> entry : cachedDataMap.entrySet()) { | ||
Map.Entry<BKeyObject, CachedData> cachedDataEntry = entry.getValue(); | ||
temp.put(entry.getKey(), BTreeUtil.makeBTreeElement( | ||
cachedDataEntry.getKey(), cachedDataEntry.getValue(), transcoder)); | ||
} | ||
result = temp; | ||
} | ||
return result; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/net/spy/memcached/internal/result/BopGetResultImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package net.spy.memcached.internal.result; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
|
||
import net.spy.memcached.CachedData; | ||
import net.spy.memcached.collection.BKeyObject; | ||
import net.spy.memcached.collection.ByteArrayBKey; | ||
import net.spy.memcached.collection.ByteArrayTreeMap; | ||
import net.spy.memcached.collection.Element; | ||
import net.spy.memcached.transcoders.Transcoder; | ||
import net.spy.memcached.util.BTreeUtil; | ||
|
||
public class BopGetResultImpl<K, V> implements GetResult<Map<K, Element<V>>> { | ||
private final Map<K, CachedData> cachedDataMap; | ||
private final boolean reverse; | ||
private final Transcoder<V> transcoder; | ||
private SortedMap<K, Element<V>> result; | ||
|
||
public BopGetResultImpl(Map<K, CachedData> cachedDataMap, | ||
boolean reverse, Transcoder<V> transcoder) { | ||
this.cachedDataMap = cachedDataMap; | ||
this.result = new TreeMap<K, Element<V>>((reverse) ? Collections.reverseOrder() : null); | ||
this.reverse = reverse; | ||
this.transcoder = transcoder; | ||
} | ||
|
||
@Override | ||
public Map<K, Element<V>> getDecodedValue() { | ||
if (result.isEmpty() && !cachedDataMap.isEmpty()) { | ||
Set<Map.Entry<K, CachedData>> entrySet = cachedDataMap.entrySet(); | ||
K bKey = entrySet.iterator().next().getKey(); | ||
|
||
boolean isByteBKey = (bKey instanceof ByteArrayBKey); | ||
boolean isLongBKey = (bKey instanceof Long); | ||
|
||
SortedMap<K, Element<V>> temp; | ||
|
||
if (isByteBKey) { | ||
temp = new ByteArrayTreeMap<K, Element<V>>(reverse ? Collections.<K>reverseOrder() : null); | ||
} else if (isLongBKey) { | ||
temp = new TreeMap<K, Element<V>>(reverse ? Collections.<K>reverseOrder() : null); | ||
} else { | ||
return result; | ||
} | ||
|
||
for (Map.Entry<K, CachedData> entry : cachedDataMap.entrySet()) { | ||
bKey = entry.getKey(); | ||
CachedData cachedData = entry.getValue(); | ||
if (isByteBKey) { | ||
temp.put(bKey, BTreeUtil.makeBTreeElement( | ||
new BKeyObject((ByteArrayBKey) bKey), cachedData, transcoder)); | ||
} else { | ||
temp.put(bKey, BTreeUtil.makeBTreeElement( | ||
new BKeyObject((Long) bKey), cachedData, transcoder)); | ||
} | ||
} | ||
result = temp; | ||
} | ||
return result; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/net/spy/memcached/internal/result/BopStoreAndGetResultImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.spy.memcached.internal.result; | ||
|
||
import net.spy.memcached.CachedData; | ||
import net.spy.memcached.collection.BKeyObject; | ||
import net.spy.memcached.collection.Element; | ||
import net.spy.memcached.transcoders.Transcoder; | ||
import net.spy.memcached.util.BTreeUtil; | ||
|
||
public class BopStoreAndGetResultImpl<T> implements GetResult<Element<T>> { | ||
private final BKeyObject bKeyObject; | ||
private final CachedData cachedData; | ||
private final Transcoder<T> transcoder; | ||
private Element<T> result = null; | ||
|
||
public BopStoreAndGetResultImpl(BKeyObject bKeyObject, | ||
CachedData cachedData, | ||
Transcoder<T> transcoder) { | ||
this.bKeyObject = bKeyObject; | ||
this.cachedData = cachedData; | ||
this.transcoder = transcoder; | ||
} | ||
|
||
@Override | ||
public Element<T> getDecodedValue() { | ||
if (cachedData != null && result == null) { | ||
result = BTreeUtil.makeBTreeElement(bKeyObject, cachedData, transcoder); | ||
} | ||
return result; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/net/spy/memcached/internal/result/LopGetResultImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.spy.memcached.internal.result; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import net.spy.memcached.CachedData; | ||
import net.spy.memcached.transcoders.Transcoder; | ||
|
||
public class LopGetResultImpl<T> implements GetResult<List<T>> { | ||
private final List<CachedData> cachedDataList; | ||
private final Transcoder<T> transcoder; | ||
private List<T> result = new ArrayList<T>(); | ||
|
||
public LopGetResultImpl(List<CachedData> cachedDataList, Transcoder<T> transcoder) { | ||
this.cachedDataList = cachedDataList; | ||
this.transcoder = transcoder; | ||
} | ||
|
||
@Override | ||
public List<T> getDecodedValue() { | ||
if (result.isEmpty() && !cachedDataList.isEmpty()) { | ||
List<T> temp = new ArrayList<T>(); | ||
for (CachedData cachedData : cachedDataList) { | ||
temp.add(transcoder.decode(cachedData)); | ||
} | ||
result = temp; | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.