Permalink
Browse files

Addressed most feedback from reviews by refactoring:

- Made ResourceRequest a first class entity rather than a nested interface
- Refactored TimeoutConfig to tease apart an OpTimeMap which may be more generally useful.
- Renamed slow storage configs in Voldemort config with to make their testing nature more clear.
- Dropped OperationDelays object from SlowStorage in favor of OpTimeMap
  • Loading branch information...
1 parent 3dfd81f commit ad3d0cc5a7f711c4cd448699d78cff6a62734c49 @jayjwylie jayjwylie committed Sep 7, 2012
Showing with 75 additions and 0 deletions.
  1. +40 −0 src/java/voldemort/utils/OpTimeMap.java
  2. +35 −0 src/java/voldemort/utils/pool/ResourceRequest.java
@@ -0,0 +1,40 @@
+package voldemort.utils;
+
+import java.util.HashMap;
+
+import voldemort.common.VoldemortOpCode;
+
+/**
+ * Encapsulates time to operation mapping
+ *
+ */
+public class OpTimeMap {
+
+ private HashMap<Byte, Long> timeMap;
+
+ public OpTimeMap(long time) {
+ this(time, time, time, time, time);
+ }
+
+ public OpTimeMap(long getTime,
+ long putTime,
+ long deleteTime,
+ long getAllTime,
+ long getVersionsTime) {
+ timeMap = new HashMap<Byte, Long>();
+ timeMap.put(VoldemortOpCode.GET_OP_CODE, getTime);
+ timeMap.put(VoldemortOpCode.PUT_OP_CODE, putTime);
+ timeMap.put(VoldemortOpCode.DELETE_OP_CODE, deleteTime);
+ timeMap.put(VoldemortOpCode.GET_ALL_OP_CODE, getAllTime);
+ timeMap.put(VoldemortOpCode.GET_VERSION_OP_CODE, getVersionsTime);
+ }
+
+ public long getOpTime(Byte opCode) {
+ assert timeMap.containsKey(opCode);
+ return timeMap.get(opCode);
+ }
+
+ public void setOpTime(Byte opCode, long time) {
+ timeMap.put(opCode, time);
+ }
+}
@@ -0,0 +1,35 @@
+package voldemort.utils.pool;
+
+/**
+ * Interface for asynchronous requests for resources. Exactly one of
+ * useResource, handleTimeout, or handleException expected to be invoked within
+ * deadline specified by getDeadlineNs.
+ */
+public interface ResourceRequest<V> {
+
+ /**
+ * To be invoked with resource to use.
+ *
+ * @param resource. resource should not be null.
+ */
+ void useResource(V resource);
+
+ /**
+ * Invoked sometime after deadline.
+ */
+ void handleTimeout();
+
+ /**
+ * Invoked upon exception trying to process resource request.
+ *
+ * @param e
+ */
+ void handleException(Exception e);
+
+ /**
+ *
+ * @return Deadline (in nanoseconds), after which handleTimeout() should be
+ * invoked.
+ */
+ long getDeadlineNs();
+}

0 comments on commit ad3d0cc

Please sign in to comment.