Permalink
Browse files

introduce LocalStore interface

  • Loading branch information...
1 parent 96fcfb0 commit f5470db67b9def798f16f648796e93228bc92a7b @martint martint committed Mar 28, 2012
@@ -21,7 +21,7 @@
public class DistributedStore
{
- private final InMemoryStore localStore;
+ private final LocalStore localStore;
private final RemoteStore remoteStore;
private final Provider<DateTime> timeProvider;
private final Duration tombstoneMaxAge;
@@ -30,7 +30,7 @@
private final ScheduledExecutorService garbageCollector;
@Inject
- public DistributedStore(InMemoryStore localStore, RemoteStore remoteStore, StoreConfig config, Provider<DateTime> timeProvider)
+ public DistributedStore(LocalStore localStore, RemoteStore remoteStore, StoreConfig config, Provider<DateTime> timeProvider)
{
this.localStore = localStore;
this.remoteStore = remoteStore;
@@ -12,6 +12,7 @@
import static com.proofpoint.discovery.store.Version.Occurs.SAME;
public class InMemoryStore
+ implements LocalStore
{
private final ConcurrentMap<ByteBuffer, Entry> map = new ConcurrentHashMap<ByteBuffer, Entry>();
private final ConflictResolver resolver;
@@ -22,6 +23,7 @@ public InMemoryStore(ConflictResolver resolver)
this.resolver = resolver;
}
+ @Override
public void put(Entry entry)
{
ByteBuffer key = ByteBuffer.wrap(entry.getKey());
@@ -41,13 +43,15 @@ public void put(Entry entry)
}
}
+ @Override
public Entry get(byte[] key)
{
Preconditions.checkNotNull(key, "key is null");
return map.get(ByteBuffer.wrap(key));
}
+ @Override
public void delete(byte[] key, Version version)
{
Preconditions.checkNotNull(key, "key is null");
@@ -65,6 +69,7 @@ public void delete(byte[] key, Version version)
}
}
+ @Override
public Iterable<Entry> getAll()
{
return map.values();
@@ -0,0 +1,9 @@
+package com.proofpoint.discovery.store;
+
+public interface LocalStore
+{
+ void put(Entry entry);
+ Entry get(byte[] key);
+ void delete(byte[] key, Version version);
+ Iterable<Entry> getAll();
+}
@@ -19,9 +19,9 @@ public void configure(Binder binder)
binder.bind(Replicator.class).in(Scopes.SINGLETON);
binder.bind(StoreResource.class).in(Scopes.SINGLETON);
- binder.bind(InMemoryStore.class).in(Scopes.SINGLETON);
binder.bind(DistributedStore.class).in(Scopes.SINGLETON);
binder.bind(RemoteStore.class).to(HttpRemoteStore.class).in(Scopes.SINGLETON);
+ binder.bind(LocalStore.class).to(InMemoryStore.class).in(Scopes.SINGLETON);
binder.bind(ConflictResolver.class).in(Scopes.SINGLETON);
binder.bind(DateTime.class).toProvider(RealTimeProvider.class);
@@ -38,7 +38,7 @@
private final NodeInfo node;
private final ServiceSelector selector;
private final HttpClient httpClient;
- private final InMemoryStore localStore;
+ private final LocalStore localStore;
private final Duration replicationInterval;
private ScheduledFuture<?> future;
@@ -50,7 +50,7 @@
public Replicator(NodeInfo node,
ServiceSelector selector,
@ForRemoteStoreClient HttpClient httpClient,
- InMemoryStore localStore,
+ LocalStore localStore,
StoreConfig config)
{
this.node = node;
@@ -11,17 +11,16 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import java.util.Iterator;
import java.util.List;
@Path("/v1/store")
public class StoreResource
{
- private final InMemoryStore localStore;
+ private final LocalStore localStore;
private final Duration tombstoneMaxAge;
@Inject
- public StoreResource(InMemoryStore localStore, StoreConfig config)
+ public StoreResource(LocalStore localStore, StoreConfig config)
{
this.localStore = localStore;
@@ -14,7 +14,7 @@
public class TestInMemoryStore
{
- private InMemoryStore store;
+ private LocalStore store;
@BeforeMethod
protected void setUp()

0 comments on commit f5470db

Please sign in to comment.