Permalink
Browse files

Clean up get stats methods in (Queued)KeyedResourcePool. Fix error in…

… test case.
  • Loading branch information...
1 parent 0626f60 commit e0707033c5a5c63fd044a59e7ee4055453334a01 @jayjwylie jayjwylie committed Oct 9, 2012
@@ -297,17 +297,15 @@ public synchronized void reset(K key) {
* given key.
*/
public int getTotalResourceCount(K key) {
- int rc = 0;
- if(!resourcePoolMap.containsKey(key)) {
- return rc;
- }
- try {
- Pool<V> resourcePool = getResourcePoolForExistingKey(key);
- rc = resourcePool.size.get();
- } catch(IllegalArgumentException iae) {
- logger.debug("getTotalResourceCount called on invalid key: ", iae);
+ if(resourcePoolMap.containsKey(key)) {
+ try {
+ Pool<V> resourcePool = getResourcePoolForExistingKey(key);
+ return resourcePool.size.get();
+ } catch(IllegalArgumentException iae) {
+ logger.debug("getTotalResourceCount called on invalid key: ", iae);
+ }
}
- return rc;
+ return 0;
}
/**
@@ -332,17 +330,15 @@ public int getTotalResourceCount() {
* for given key.
*/
public int getCheckedInResourcesCount(K key) {
- int rc = 0;
- if(!resourcePoolMap.containsKey(key)) {
- return rc;
- }
- try {
- Pool<V> resourcePool = getResourcePoolForExistingKey(key);
- rc = resourcePool.queue.size();
- } catch(IllegalArgumentException iae) {
- logger.debug("getCheckedInResourceCount called on invalid key: ", iae);
+ if(resourcePoolMap.containsKey(key)) {
+ try {
+ Pool<V> resourcePool = getResourcePoolForExistingKey(key);
+ return resourcePool.queue.size();
+ } catch(IllegalArgumentException iae) {
+ logger.debug("getCheckedInResourceCount called on invalid key: ", iae);
+ }
}
- return rc;
+ return 0;
}
/**
@@ -367,17 +363,15 @@ public int getCheckedInResourceCount() {
* key.
*/
public int getBlockingGetsCount(K key) {
- int rc = 0;
- if(!resourcePoolMap.containsKey(key)) {
- return rc;
- }
- try {
- Pool<V> resourcePool = getResourcePoolForExistingKey(key);
- rc = resourcePool.blockingGets.get();
- } catch(IllegalArgumentException iae) {
- logger.debug("getBlockingGetsCount called on invalid key: ", iae);
+ if(resourcePoolMap.containsKey(key)) {
+ try {
+ Pool<V> resourcePool = getResourcePoolForExistingKey(key);
+ return resourcePool.blockingGets.get();
+ } catch(IllegalArgumentException iae) {
+ logger.debug("getBlockingGetsCount called on invalid key: ", iae);
+ }
}
- return rc;
+ return 0;
}
/**
@@ -329,18 +329,16 @@ public void reset(K key) {
* exists for given key.
*/
public int getRegisteredResourceRequestCount(K key) {
- int rc = 0;
- if(!requestQueueMap.containsKey(key)) {
- return rc;
- }
- try {
- Queue<AsyncResourceRequest<V>> requestQueue = getRequestQueueForExistingKey(key);
- // FYI: .size() is not constant time in the next call. ;)
- rc = requestQueue.size();
- } catch(IllegalArgumentException iae) {
- logger.debug("getRegisteredResourceRequestCount called on invalid key: ", iae);
+ if(requestQueueMap.containsKey(key)) {
+ try {
+ Queue<AsyncResourceRequest<V>> requestQueue = getRequestQueueForExistingKey(key);
+ // FYI: .size() is not constant time in the next call. ;)
+ return requestQueue.size();
+ } catch(IllegalArgumentException iae) {
+ logger.debug("getRegisteredResourceRequestCount called on invalid key: ", iae);
+ }
}
- return rc;
+ return 0;
}
/**
@@ -66,7 +66,9 @@ public void setUp() throws Exception {
// unit tests assert on specific delays occurring.
OpTimeMap queued = new OpTimeMap(10, 20, 30, 40, 50);
OpTimeMap concurrent = new OpTimeMap(50, 40, 30, 20, 10);
- this.store = new SlowStorageEngine<ByteArray, byte[], byte[]>("test", queued, concurrent);
+ this.store = new SlowStorageEngine<ByteArray, byte[], byte[]>(new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test"),
+ queued,
+ concurrent);
}
@Override

0 comments on commit e070703

Please sign in to comment.