mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
removed getLater(0 putLater() and removeLater() because the stateless client is now mulithreaded
This commit is contained in:
@@ -211,68 +211,6 @@ public interface ChronicleMap<K, V> extends ConcurrentMap<K, V>, ChronicleHash {
|
||||
*/
|
||||
<R> R updateForKey(K key, @NotNull Mutator<? super V, R> mutator);
|
||||
|
||||
/**
|
||||
* Returns a {@link java.util.concurrent.Future} containing the value to which the specified key
|
||||
* is mapped, or {@code null} if this map contains no mapping for the key. This method behaves
|
||||
* the same as {@link java.util.Map#get(java.lang.Object)} yet wraps result in a future a {@link
|
||||
* java.util.concurrent.Future}.
|
||||
*
|
||||
* Calling this method may or may not block until the operating is complete depending on the
|
||||
* implementation.
|
||||
*
|
||||
* @param key the key whose associated value is to be returned in the future
|
||||
* @return a future containing the value to which the specified key is mapped after this method
|
||||
* call, or {@code null} if no value is mapped
|
||||
* @see java.util.Map#get(java.lang.Object)
|
||||
* @see java.util.concurrent.Future
|
||||
*/
|
||||
Future<V> getLater(@NotNull K key);
|
||||
|
||||
/**
|
||||
* Associates the specified value with the specified key in this map (optional operation). If
|
||||
* the map previously contained a mapping for the key, the old value is replaced by the
|
||||
* specified value. (A map <tt>m</tt> is said to contain a mapping for a key <tt>k</tt> if and
|
||||
* only if {@link #containsKey(Object) m.containsKey(k)} would return <tt>true</tt>.)
|
||||
*
|
||||
* Calling this method may or may not block until the operating is complete depending on the
|
||||
* implementation.
|
||||
*
|
||||
* @param key key with which the specified value is to be associated
|
||||
* @param value value to be associated with the specified key * @return a future containing the
|
||||
* previous value associated with <tt>key</tt>, or <tt>null</tt> if there was no
|
||||
* mapping for <tt>key</tt>. (A <tt>null</tt> return can also indicate that the map
|
||||
* previously associated <tt>null</tt> with <tt>key</tt>, if the implementation
|
||||
* supports <tt>null</tt> values.)
|
||||
* @return a future containing either, the previous value associated with <tt>key</tt>, or
|
||||
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
|
||||
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
|
||||
* @see java.util.concurrent.Future
|
||||
*/
|
||||
Future<V> putLater(@NotNull K key, @NotNull V value);
|
||||
|
||||
/**
|
||||
* Removes the mapping for a key from this map if it is present (optional operation). More
|
||||
* formally, if this map contains a mapping from key <tt>k</tt> to value <tt>v</tt> such that
|
||||
* <code>(key==null ? k==null : key.equals(k))</code>, that mapping is removed. (The map can
|
||||
* contain at most one such mapping.)
|
||||
*
|
||||
* <p>Returns a future containing, either the value to which this map previously associated the
|
||||
* key, or <tt>null</tt> if the map contained no mapping for the key.
|
||||
*
|
||||
* This method behaves the same as {@link java.util.Map#remove(java.lang.Object)} yet wraps
|
||||
* result in a future a {@link java.util.concurrent.Future}.
|
||||
*
|
||||
* Calling this method may or may not block until the operating is complete depending on the
|
||||
* implementation.
|
||||
*
|
||||
* @param key key whose mapping is to be removed from the map
|
||||
* @return a future containing either, the previous value associated with <tt>key</tt>, or
|
||||
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
|
||||
* @see java.util.Map#remove(java.lang.Object)
|
||||
* @see java.util.concurrent.Future
|
||||
*/
|
||||
Future<V> removeLater(@NotNull K key);
|
||||
|
||||
/**
|
||||
* exports all the entries to a {@link java.io.File} storing them in JSON format, an attempt is
|
||||
* made where possible to use standard java serialisation and keep the data human readable, data
|
||||
|
||||
@@ -157,40 +157,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Future<V> getLater(@NotNull final K key) {
|
||||
return lazyExecutorService().submit(new Callable<V>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
return StatelessChronicleMap.this.get(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Future<V> putLater(@NotNull final K key, @NotNull final V value) {
|
||||
return lazyExecutorService().submit(new Callable<V>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
return StatelessChronicleMap.this.put(key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> removeLater(@NotNull final K key) {
|
||||
return lazyExecutorService().submit(new Callable<V>() {
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
return StatelessChronicleMap.this.remove(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAll(File toFile) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
@@ -50,10 +50,7 @@ import java.lang.reflect.Array;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static java.lang.Class.forName;
|
||||
import static java.lang.Long.numberOfTrailingZeros;
|
||||
@@ -569,102 +566,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> getLater(@NotNull K key) {
|
||||
final V v = get(key);
|
||||
return new Future<V>() {
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() throws InterruptedException, ExecutionException {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(long timeout, @NotNull TimeUnit unit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return v;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> putLater(@NotNull K key, @NotNull V value) {
|
||||
final V v = put(key, value);
|
||||
return new Future<V>() {
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() throws InterruptedException, ExecutionException {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(long timeout, TimeUnit unit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return v;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> removeLater(@NotNull K key) {
|
||||
final V v = remove(key);
|
||||
return new Future<V>() {
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() throws InterruptedException, ExecutionException {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(long timeout, TimeUnit unit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return v;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void getAll(File toFile) throws IOException {
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class CHMUseCasesTest {
|
||||
*/
|
||||
try (ChronicleMap<String, String> map = ChronicleMapBuilder
|
||||
.of(String.class, String.class)
|
||||
.checkSerializedValues() // for testng purposes only
|
||||
.checkSerializedValues() // for testing purposes only
|
||||
.create()) {
|
||||
map.put("Hello", "World");
|
||||
assertEquals("World", map.get("Hello"));
|
||||
@@ -65,10 +65,6 @@ public class CHMUseCasesTest {
|
||||
// TODO replace with the specific exception.
|
||||
}
|
||||
|
||||
assertEquals(null, map.putLater("Bye", "For now").get());
|
||||
assertEquals("For now", map.getLater("Bye").get());
|
||||
assertEquals("For now", map.removeLater("Bye").get());
|
||||
assertEquals(null, map.removeLater("Bye").get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +77,7 @@ public class CHMUseCasesTest {
|
||||
public void testCharSequenceCharSequenceMap() throws ExecutionException, InterruptedException {
|
||||
try (ChronicleMap<CharSequence, CharSequence> map = ChronicleMapBuilder
|
||||
.of(CharSequence.class, CharSequence.class)
|
||||
.checkSerializedValues() // for testng purposes only
|
||||
.checkSerializedValues() // for testing purposes only
|
||||
.create()) {
|
||||
map.put("Hello", "World");
|
||||
StringBuilder key = new StringBuilder();
|
||||
@@ -129,10 +125,6 @@ public class CHMUseCasesTest {
|
||||
}
|
||||
}));
|
||||
|
||||
assertEquals(null, map.putLater("Bye", "For now").get());
|
||||
assertEquals("For now", map.getLater("Bye").get().toString());
|
||||
assertEquals("For now", map.removeLater("Bye").get().toString());
|
||||
assertEquals(null, map.removeLater("Bye").get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +136,7 @@ public class CHMUseCasesTest {
|
||||
public void testStringValueStringValueMap() {
|
||||
try (ChronicleMap<StringValue, StringValue> map = ChronicleMapBuilder
|
||||
.of(StringValue.class, StringValue.class)
|
||||
.checkSerializedValues() // for testng purposes only
|
||||
.checkSerializedValues() // for testing purposes only
|
||||
.create()) {
|
||||
StringValue key1 = DataValueClasses.newDirectInstance(StringValue.class);
|
||||
StringValue key2 = DataValueClasses.newInstance(StringValue.class);
|
||||
@@ -283,10 +275,7 @@ public class CHMUseCasesTest {
|
||||
} catch (Exception todoMoreSpecificException) {
|
||||
}
|
||||
|
||||
assertEquals(null, map.putLater(3, 4).get());
|
||||
assertEquals((Integer) 4, map.getLater(3).get());
|
||||
assertEquals((Integer) 4, map.removeLater(3).get());
|
||||
assertEquals(null, map.removeLater(3).get());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,10 +320,7 @@ public class CHMUseCasesTest {
|
||||
} catch (Exception todoMoreSpecificException) {
|
||||
}
|
||||
|
||||
assertEquals(null, map.putLater(3L, 4L).get());
|
||||
assertEquals((Long) 4L, map.getLater(3L).get());
|
||||
assertEquals((Long) 4L, map.removeLater(3L).get());
|
||||
assertEquals(null, map.removeLater(3L).get());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,10 +365,7 @@ public class CHMUseCasesTest {
|
||||
} catch (Exception todoMoreSpecificException) {
|
||||
}
|
||||
|
||||
assertEquals(null, map.putLater(3.0, 4.0).get());
|
||||
assertEquals((Double) 4.0, map.getLater(3.0).get());
|
||||
assertEquals((Double) 4.0, map.removeLater(3.0).get());
|
||||
assertEquals(null, map.removeLater(3.0).get());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,10 +413,6 @@ public class CHMUseCasesTest {
|
||||
byte[] key3 = {3, 3, 3, 3};
|
||||
byte[] value3 = {4, 4, 4, 4};
|
||||
|
||||
assertEquals(null, map.putLater(key3, value3).get());
|
||||
assertTrue(Arrays.equals(value3, map.getLater(key3).get()));
|
||||
assertTrue(Arrays.equals(value3, map.removeLater(key3).get()));
|
||||
assertEquals(null, map.removeLater(key3).get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,13 +500,7 @@ public class CHMUseCasesTest {
|
||||
assertBBEquals(bb1, valueA);
|
||||
}
|
||||
|
||||
ByteBuffer key3 = ByteBuffer.wrap(new byte[]{3, 3, 3, 3});
|
||||
ByteBuffer value3 = ByteBuffer.wrap(new byte[]{4, 4, 4, 4});
|
||||
|
||||
assertEquals(null, map.putLater(key3, value3).get());
|
||||
assertBBEquals(value3, map.getLater(key3).get());
|
||||
assertBBEquals(value3, map.removeLater(key3).get());
|
||||
assertEquals(null, map.removeLater(key3).get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -579,15 +552,6 @@ public class CHMUseCasesTest {
|
||||
|
||||
assertBBEquals(ByteBuffer.wrap(new byte[]{12, 10, 11, 11}), map.get(key1));
|
||||
|
||||
ByteBuffer key3 = ByteBuffer.wrap(new byte[]{3, 3, 3, 3});
|
||||
ByteBuffer value3 = ByteBuffer.allocateDirect(4);
|
||||
value3.put(new byte[]{4, 4, 4, 4});
|
||||
value3.flip();
|
||||
|
||||
assertEquals(null, map.putLater(key3, value3).get());
|
||||
assertBBEquals(value3, map.getLater(key3).get());
|
||||
assertBBEquals(value3, map.removeLater(key3).get());
|
||||
assertEquals(null, map.removeLater(key3).get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
@@ -228,21 +227,6 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
return map1.updateForKey(key, mutator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> getLater(@NotNull K key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> putLater(@NotNull K key, @NotNull V value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> removeLater(@NotNull K key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAll(File toFile) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
@@ -453,60 +453,7 @@ public class StatelessClientTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
public void testGetLater() throws IOException,
|
||||
InterruptedException, ExecutionException {
|
||||
|
||||
try (ChronicleMap<Integer, CharSequence> serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(8056)).create()) {
|
||||
try (ChronicleMap<Integer, CharSequence> statelessMap = ChronicleMapBuilder.of(Integer
|
||||
.class, CharSequence.class)
|
||||
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
|
||||
statelessMap.put(1, "some value");
|
||||
|
||||
assertEquals("some value", statelessMap.getLater(1).get());
|
||||
assertEquals(1, statelessMap.size());
|
||||
|
||||
statelessMap.remove(1);
|
||||
|
||||
assertEquals(null, statelessMap.getLater(1).get());
|
||||
assertEquals(0, statelessMap.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutLater() throws IOException,
|
||||
InterruptedException, ExecutionException {
|
||||
|
||||
try (ChronicleMap<Integer, CharSequence> serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(8056)).create()) {
|
||||
try (ChronicleMap<Integer, CharSequence> statelessMap = ChronicleMapBuilder.of(Integer
|
||||
.class, CharSequence.class)
|
||||
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
|
||||
CharSequence oldValue = statelessMap.putLater(1, "some value").get();
|
||||
assertEquals("some value", statelessMap.get(1));
|
||||
assertEquals(1, statelessMap.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
public void testRemoveLater() throws IOException,
|
||||
InterruptedException, ExecutionException {
|
||||
|
||||
try (ChronicleMap<Integer, CharSequence> serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(8056)).create()) {
|
||||
try (ChronicleMap<Integer, CharSequence> statelessMap = ChronicleMapBuilder.of(Integer
|
||||
.class, CharSequence.class)
|
||||
.statelessClient(new InetSocketAddress("localhost", 8056)).create()) {
|
||||
statelessMap.put(1, "some value");
|
||||
statelessMap.removeLater(1).get();
|
||||
assertEquals(null, statelessMap.get(1));
|
||||
assertEquals(0, statelessMap.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
public void testGetAndEntryWeDontHave() throws IOException,
|
||||
|
||||
@@ -33,7 +33,6 @@ import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -180,21 +179,6 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
return d.updateForKey(key, mutator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> getLater(@NotNull K key) {
|
||||
return d.getLater(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> putLater(@NotNull K key, @NotNull V value) {
|
||||
return d.putLater(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<V> removeLater(@NotNull K key) {
|
||||
return d.removeLater(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAll(File toFile) throws IOException {
|
||||
d.getAll(toFile);
|
||||
|
||||
Reference in New Issue
Block a user