-
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 asycnGets return future type.
- Loading branch information
Showing
5 changed files
with
70 additions
and
40 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
src/main/java/net/spy/memcached/internal/result/CASGetResultImpl.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,28 @@ | ||
package net.spy.memcached.internal.result; | ||
|
||
import net.spy.memcached.CASValue; | ||
import net.spy.memcached.CachedData; | ||
import net.spy.memcached.transcoders.Transcoder; | ||
|
||
public class CASGetResultImpl<T> implements GetResult<CASValue<T>> { | ||
|
||
private final long cas; | ||
private final CachedData cachedData; | ||
private final Transcoder<T> transcoder; | ||
private volatile CASValue<T> decodedValue = null; | ||
|
||
public CASGetResultImpl(long cas, CachedData cachedData, Transcoder<T> transcoder) { | ||
this.cas = cas; | ||
this.cachedData = cachedData; | ||
this.transcoder = transcoder; | ||
} | ||
|
||
@Override | ||
public CASValue<T> getDecodedValue() { | ||
if (decodedValue == null) { | ||
decodedValue = new CASValue<T>(cas, transcoder.decode(cachedData)); | ||
} | ||
|
||
return decodedValue; | ||
} | ||
} |
30 changes: 2 additions & 28 deletions
30
src/main/java/net/spy/memcached/internal/result/GetResult.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 |
---|---|---|
@@ -1,31 +1,5 @@ | ||
package net.spy.memcached.internal.result; | ||
|
||
import net.spy.memcached.CachedData; | ||
import net.spy.memcached.transcoders.Transcoder; | ||
|
||
public final class GetResult<T> { | ||
private final Transcoder<T> transcoder; | ||
|
||
private volatile CachedData cachedData = null; | ||
private volatile T decodedValue = null; | ||
|
||
public GetResult(Transcoder<T> transcoder) { | ||
this.transcoder = transcoder; | ||
} | ||
|
||
public void setCachedData(CachedData cachedData) { | ||
this.cachedData = cachedData; | ||
} | ||
|
||
public T getDecodedValue() { | ||
if (cachedData == null) { | ||
return null; | ||
} | ||
|
||
if (decodedValue == null) { | ||
decodedValue = transcoder.decode(cachedData); | ||
} | ||
|
||
return decodedValue; | ||
} | ||
public interface GetResult<T> { | ||
T getDecodedValue(); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/net/spy/memcached/internal/result/GetResultImpl.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,28 @@ | ||
package net.spy.memcached.internal.result; | ||
|
||
import net.spy.memcached.CachedData; | ||
import net.spy.memcached.transcoders.Transcoder; | ||
|
||
public class GetResultImpl<T> implements GetResult<T> { | ||
private final Transcoder<T> transcoder; | ||
private final CachedData cachedData; | ||
private volatile T decodedValue = null; | ||
|
||
public GetResultImpl(CachedData cachedData, Transcoder<T> transcoder) { | ||
this.cachedData = cachedData; | ||
this.transcoder = transcoder; | ||
} | ||
|
||
@Override | ||
public T getDecodedValue() { | ||
if (cachedData == null) { | ||
return null; | ||
} | ||
|
||
if (decodedValue == null) { | ||
decodedValue = transcoder.decode(cachedData); | ||
} | ||
|
||
return decodedValue; | ||
} | ||
} |