You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2011/09/20 01:59:48 UTC
svn commit: r1172907 - in /camel/branches/camel-2.8.x: ./
camel-core/src/main/java/org/apache/camel/impl/
camel-core/src/main/java/org/apache/camel/util/
camel-core/src/test/java/org/apache/camel/util/
components/camel-cxf/src/main/java/org/apache/came...
Author: dkulp
Date: Mon Sep 19 23:59:47 2011
New Revision: 1172907
URL: http://svn.apache.org/viewvc?rev=1172907&view=rev
Log:
Merged revisions 1163431 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1163431 | hadrian | 2011-08-30 18:07:14 -0400 (Tue, 30 Aug 2011) | 1 line
CAMEL-4392. LRUCache is no longer a Service. Other minor fixes.
........
Modified:
camel/branches/camel-2.8.x/ (props changed)
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ConsumerCache.java
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/EndpointRegistry.java
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUCacheTest.java
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUSoftCacheTest.java
camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ConsumerCache.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ConsumerCache.java?rev=1172907&r1=1172906&r2=1172907&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ConsumerCache.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ConsumerCache.java Mon Sep 19 23:59:47 2011
@@ -150,7 +150,7 @@ public class ConsumerCache extends Servi
public int getCapacity() {
int capacity = -1;
if (consumers instanceof LRUCache) {
- LRUCache cache = (LRUCache) consumers;
+ LRUCache<String, PollingConsumer> cache = (LRUCache<String, PollingConsumer>)consumers;
capacity = cache.getMaxCacheSize();
}
return capacity;
@@ -166,7 +166,7 @@ public class ConsumerCache extends Servi
public long getHits() {
long hits = -1;
if (consumers instanceof LRUCache) {
- LRUCache cache = (LRUCache) consumers;
+ LRUCache<String, PollingConsumer> cache = (LRUCache<String, PollingConsumer>)consumers;
hits = cache.getHits();
}
return hits;
@@ -182,7 +182,7 @@ public class ConsumerCache extends Servi
public long getMisses() {
long misses = -1;
if (consumers instanceof LRUCache) {
- LRUCache cache = (LRUCache) consumers;
+ LRUCache<String, PollingConsumer> cache = (LRUCache<String, PollingConsumer>)consumers;
misses = cache.getMisses();
}
return misses;
@@ -193,7 +193,7 @@ public class ConsumerCache extends Servi
*/
public void resetCacheStatistics() {
if (consumers instanceof LRUCache) {
- LRUCache cache = (LRUCache) consumers;
+ LRUCache<String, PollingConsumer> cache = (LRUCache<String, PollingConsumer>)consumers;
cache.resetStatistics();
}
}
@@ -211,11 +211,11 @@ public class ConsumerCache extends Servi
}
protected void doStart() throws Exception {
- ServiceHelper.startServices(consumers);
+ ServiceHelper.startServices(consumers.values());
}
protected void doStop() throws Exception {
- ServiceHelper.stopServices(consumers);
+ ServiceHelper.stopServices(consumers.values());
consumers.clear();
}
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/EndpointRegistry.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/EndpointRegistry.java?rev=1172907&r1=1172906&r2=1172907&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/EndpointRegistry.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/EndpointRegistry.java Mon Sep 19 23:59:47 2011
@@ -20,8 +20,10 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
+import org.apache.camel.Service;
import org.apache.camel.util.CamelContextHelper;
import org.apache.camel.util.LRUSoftCache;
+import org.apache.camel.util.ServiceHelper;
/**
* Endpoint registry which is a based on a {@link org.apache.camel.util.LRUSoftCache}.
@@ -30,7 +32,7 @@ import org.apache.camel.util.LRUSoftCach
*
* @version
*/
-public class EndpointRegistry extends LRUSoftCache<EndpointKey, Endpoint> {
+public class EndpointRegistry extends LRUSoftCache<EndpointKey, Endpoint> implements Service {
private final CamelContext context;
@@ -44,7 +46,20 @@ public class EndpointRegistry extends LR
putAll(endpoints);
}
- /**
+ @Override
+ public void start() throws Exception {
+ resetStatistics();
+ }
+
+ @Override
+ public void stop() throws Exception {
+ if (!isEmpty()) {
+ ServiceHelper.stopServices(values());
+ }
+ purge();
+ }
+
+ /**
* Purges the cache
*/
public void purge() {
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java?rev=1172907&r1=1172906&r2=1172907&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java Mon Sep 19 23:59:47 2011
@@ -394,12 +394,14 @@ public class ProducerCache extends Servi
}
protected void doStop() throws Exception {
- ServiceHelper.stopServices(producers, pool);
+ ServiceHelper.stopServices(pool);
+ ServiceHelper.stopServices(producers.values());
producers.clear();
}
protected void doStart() throws Exception {
- ServiceHelper.startServices(pool, producers);
+ ServiceHelper.startServices(producers.values());
+ ServiceHelper.startServices(pool);
}
/**
@@ -425,7 +427,7 @@ public class ProducerCache extends Servi
public int getCapacity() {
int capacity = -1;
if (producers instanceof LRUCache) {
- LRUCache cache = (LRUCache) producers;
+ LRUCache<String, Producer> cache = (LRUCache<String, Producer>)producers;
capacity = cache.getMaxCacheSize();
}
return capacity;
@@ -441,7 +443,7 @@ public class ProducerCache extends Servi
public long getHits() {
long hits = -1;
if (producers instanceof LRUCache) {
- LRUCache cache = (LRUCache) producers;
+ LRUCache<String, Producer> cache = (LRUCache<String, Producer>)producers;
hits = cache.getHits();
}
return hits;
@@ -457,7 +459,7 @@ public class ProducerCache extends Servi
public long getMisses() {
long misses = -1;
if (producers instanceof LRUCache) {
- LRUCache cache = (LRUCache) producers;
+ LRUCache<String, Producer> cache = (LRUCache<String, Producer>)producers;
misses = cache.getMisses();
}
return misses;
@@ -468,7 +470,7 @@ public class ProducerCache extends Servi
*/
public void resetCacheStatistics() {
if (producers instanceof LRUCache) {
- LRUCache cache = (LRUCache) producers;
+ LRUCache<String, Producer> cache = (LRUCache<String, Producer>)producers;
cache.resetStatistics();
}
}
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUCache.java?rev=1172907&r1=1172906&r2=1172907&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUCache.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUCache.java Mon Sep 19 23:59:47 2011
@@ -17,21 +17,19 @@
package org.apache.camel.util;
import java.io.Serializable;
-import java.util.AbstractMap;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
-import org.apache.camel.Service;
/**
* A Least Recently Used Cache
*
* @version
*/
-public class LRUCache<K, V> implements Service, Map<K, V>, Serializable {
+public class LRUCache<K, V> implements Map<K, V>, Serializable {
private static final long serialVersionUID = -342098639681884414L;
private int maxCacheSize = 10000;
private final AtomicLong hits = new AtomicLong();
@@ -52,10 +50,9 @@ public class LRUCache<K, V> implements S
* or the load factor is non positive.
*/
public LRUCache(int initialCapacity, int maximumCacheSize) {
- map = new ConcurrentLinkedHashMap
- .Builder<K, V>()
- .initialCapacity(initialCapacity)
- .maximumWeightedCapacity(maximumCacheSize).build();
+ map = new ConcurrentLinkedHashMap.Builder<K, V>()
+ .initialCapacity(initialCapacity)
+ .maximumWeightedCapacity(maximumCacheSize).build();
// super(initialCapacity, loadFactor, accessOrder);
this.maxCacheSize = maximumCacheSize;
}
@@ -109,6 +106,7 @@ public class LRUCache<K, V> implements S
@Override
public void clear() {
map.clear();
+ resetStatistics();
}
@Override
@@ -155,24 +153,6 @@ public class LRUCache<K, V> implements S
misses.set(0);
}
- protected boolean removeEldestEntry(Map.Entry<K, V> entry) {
- return map.size() > maxCacheSize;
- }
-
- public void start() throws Exception {
- // noop
- }
-
- public void stop() throws Exception {
- // stop the value and clear the cache
- if (!isEmpty()) {
- ServiceHelper.stopServices(values());
- map.clear();
- hits.set(0);
- misses.set(0);
- }
- }
-
@Override
public String toString() {
return "LRUCache@" + ObjectHelper.getIdentityHashCode(this);
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java?rev=1172907&r1=1172906&r2=1172907&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java Mon Sep 19 23:59:47 2011
@@ -104,13 +104,12 @@ public class LRUSoftCache<K, V> extends
}
@Override
- @SuppressWarnings("unchecked")
public int size() {
// only count as a size if there is a value
int size = 0;
- Collection<SoftReference<V>> col = (Collection<SoftReference<V>>) super.values();
- for (SoftReference<V> ref : col) {
- if (ref.get() != null) {
+ for (V value : super.values()) {
+ SoftReference<?> ref = (SoftReference<?>)value;
+ if (ref != null && ref.get() != null) {
size++;
}
}
Modified: camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUCacheTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUCacheTest.java?rev=1172907&r1=1172906&r2=1172907&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUCacheTest.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUCacheTest.java Mon Sep 19 23:59:47 2011
@@ -81,35 +81,8 @@ public class LRUCacheTest extends TestCa
cache.get("B");
assertEquals(1, cache.getHits());
assertEquals(0, cache.getMisses());
- }
-
- public void testLRUCacheHitsAndMissesStop() throws Exception {
- MyService service1 = new MyService();
- MyService service2 = new MyService();
-
- cache.put("A", service1);
- cache.put("B", service2);
-
- assertEquals(0, cache.getHits());
- assertEquals(0, cache.getMisses());
-
- cache.get("A");
- assertEquals(1, cache.getHits());
- assertEquals(0, cache.getMisses());
-
- cache.get("A");
- assertEquals(2, cache.getHits());
- assertEquals(0, cache.getMisses());
-
- cache.get("B");
- assertEquals(3, cache.getHits());
- assertEquals(0, cache.getMisses());
- cache.stop();
- assertEquals(0, cache.getHits());
- assertEquals(0, cache.getMisses());
-
- cache.start();
+ cache.clear();
assertEquals(0, cache.getHits());
assertEquals(0, cache.getMisses());
@@ -118,37 +91,11 @@ public class LRUCacheTest extends TestCa
assertEquals(1, cache.getMisses());
}
- public void testLRUCacheStop() throws Exception {
- MyService service1 = new MyService();
- MyService service2 = new MyService();
-
- cache.put("A", service1);
- cache.put("B", service2);
-
- assertEquals(false, service1.isStopped());
- assertEquals(false, service2.isStopped());
-
- cache.stop();
-
- assertEquals(0, cache.size());
-
- assertEquals(true, service1.isStopped());
- assertEquals(true, service2.isStopped());
- }
-
private final class MyService implements Service {
-
- private boolean stopped;
-
public void start() throws Exception {
}
public void stop() throws Exception {
- stopped = true;
- }
-
- public boolean isStopped() {
- return stopped;
}
}
}
Modified: camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUSoftCacheTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUSoftCacheTest.java?rev=1172907&r1=1172906&r2=1172907&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUSoftCacheTest.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/util/LRUSoftCacheTest.java Mon Sep 19 23:59:47 2011
@@ -31,7 +31,6 @@ public class LRUSoftCacheTest extends Te
public void testLRUSoftCacheGetAndPut() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
cache.put(1, "foo");
cache.put(2, "bar");
@@ -39,15 +38,11 @@ public class LRUSoftCacheTest extends Te
assertEquals("foo", cache.get(1));
assertEquals("bar", cache.get(2));
assertEquals(null, cache.get(3));
-
assertEquals(2, cache.size());
-
- cache.stop();
}
public void testLRUSoftCacheHitsAndMisses() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
cache.put(1, "foo");
cache.put(2, "bar");
@@ -66,13 +61,10 @@ public class LRUSoftCacheTest extends Te
cache.get(2);
assertEquals(2, cache.getHits());
assertEquals(1, cache.getMisses());
-
- cache.stop();
}
public void testLRUSoftCachePutOverride() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
Object old = cache.put(1, "foo");
assertNull(old);
@@ -85,15 +77,11 @@ public class LRUSoftCacheTest extends Te
old = cache.put(1, "changed");
assertEquals("foo", old);
assertEquals("changed", cache.get(1));
-
assertEquals(2, cache.size());
-
- cache.stop();
}
public void testLRUSoftCachePutAll() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
Map<Integer, Object> map = new HashMap<Integer, Object>();
map.put(1, "foo");
@@ -105,16 +93,12 @@ public class LRUSoftCacheTest extends Te
assertEquals("bar", cache.get(2));
assertEquals(null, cache.get(3));
assertEquals(2, cache.size());
-
- cache.stop();
}
public void testLRUSoftCachePutAllAnotherLRUSoftCache() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
LRUSoftCache<Integer, Object> cache2 = new LRUSoftCache<Integer, Object>(1000);
- cache2.start();
cache2.put(1, "foo");
cache2.put(2, "bar");
@@ -124,14 +108,10 @@ public class LRUSoftCacheTest extends Te
assertEquals("bar", cache.get(2));
assertEquals(null, cache.get(3));
assertEquals(2, cache.size());
-
- cache.stop();
- cache2.stop();
}
public void testLRUSoftCacheRemove() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
cache.put(1, "foo");
cache.put(2, "bar");
@@ -139,13 +119,10 @@ public class LRUSoftCacheTest extends Te
assertEquals("bar", cache.get(2));
cache.remove(2);
assertEquals(null, cache.get(2));
-
- cache.stop();
}
public void testLRUSoftCacheValues() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
cache.put(1, "foo");
cache.put(2, "bar");
@@ -156,13 +133,10 @@ public class LRUSoftCacheTest extends Te
Iterator<Object> it = col.iterator();
assertEquals("foo", it.next());
assertEquals("bar", it.next());
-
- cache.stop();
}
public void testLRUSoftCacheEmpty() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
assertTrue(cache.isEmpty());
@@ -177,28 +151,10 @@ public class LRUSoftCacheTest extends Te
cache.clear();
assertTrue(cache.isEmpty());
-
- cache.stop();
- assertTrue(cache.isEmpty());
- }
-
- public void testLRUSoftCacheStopEmpty() throws Exception {
- LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
-
- assertTrue(cache.isEmpty());
-
- cache.put(1, "foo");
- cache.put(2, "bar");
- assertFalse(cache.isEmpty());
-
- cache.stop();
- assertTrue(cache.isEmpty());
}
public void testLRUSoftCacheContainsKey() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
assertFalse(cache.containsKey(1));
cache.put(1, "foo");
@@ -208,14 +164,13 @@ public class LRUSoftCacheTest extends Te
cache.put(2, "foo");
assertTrue(cache.containsKey(2));
- cache.stop();
+ cache.clear();
assertFalse(cache.containsKey(1));
assertFalse(cache.containsKey(2));
}
public void testLRUSoftCacheKeySet() throws Exception {
LRUSoftCache<Integer, Object> cache = new LRUSoftCache<Integer, Object>(1000);
- cache.start();
cache.put(1, "foo");
cache.put(2, "foo");
@@ -226,8 +181,5 @@ public class LRUSoftCacheTest extends Te
Iterator<Integer> it = keys.iterator();
assertEquals(1, it.next().intValue());
assertEquals(2, it.next().intValue());
-
- cache.stop();
}
-
}
Modified: camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java?rev=1172907&r1=1172906&r2=1172907&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java (original)
+++ camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java Mon Sep 19 23:59:47 2011
@@ -343,11 +343,11 @@ public class CxfRsProducer extends Defau
}
public void start() throws Exception {
- this.cache.start();
+ // noop
}
public void stop() throws Exception {
- this.cache.stop();
+ cache.clear();
}
public JAXRSClientFactoryBean get(String address) throws Exception {