Author: hadrian
Date: Fri Aug 19 14:18:17 2011
New Revision: 1159643
URL: http://svn.apache.org/viewvc?rev=1159643&view=rev
Log:
CAMEL-4345. Backport to 2.8.x
Modified:
camel/branches/camel-2.8.x/ (props changed)
camel/branches/camel-2.8.x/camel-core/pom.xml
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.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/impl/DefaultCamelContextTest.java
camel/branches/camel-2.8.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wsdl/Order.java
camel/branches/camel-2.8.x/parent/pom.xml
Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 19 14:18:17 2011
@@ -1 +1 @@
-/camel/trunk:1155230,1156108,1156260,1156524,1157348,1157798,1157831,1157878,1158153,1159171,1159174
+/camel/trunk:1155230,1156108,1156260,1156524,1157348,1157798,1157831,1157878,1158153,1159171,1159174,1159457,1159460,1159606
Modified: camel/branches/camel-2.8.x/camel-core/pom.xml
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/pom.xml?rev=1159643&r1=1159642&r2=1159643&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/pom.xml (original)
+++ camel/branches/camel-2.8.x/camel-core/pom.xml Fri Aug 19 14:18:17 2011
@@ -37,6 +37,7 @@
</camel.osgi.export.pkg>
<camel.osgi.import>
!org.apache.camel.*,
+ !com.googlecode.concurrentlinkedhashmap,
org.apache.xalan.xsltc.trax;resolution:=optional,
javax.activation;resolution:=optional,
javax.xml.bind;resolution:=optional,
@@ -60,6 +61,11 @@
<!-- required dependencies by camel-core -->
<dependency>
+ <groupId>com.googlecode.concurrentlinkedhashmap</groupId>
+ <artifactId>concurrentlinkedhashmap-lru</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
@@ -134,6 +140,26 @@
<build>
<plugins>
+ <!-- Shade the googlecode stuff for OSGi -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <artifactSet>
+ <includes>
+
<include>com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru</include>
+ </includes>
+ </artifactSet>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<!-- generate the attached tests jar -->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Modified:
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1159643&r1=1159642&r2=1159643&view=diff
==============================================================================
---
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Fri Aug 19 14:18:17 2011
@@ -331,40 +331,34 @@ public class DefaultCamelContext extends
// -----------------------------------------------------------------------
public Collection<Endpoint> getEndpoints() {
- synchronized (endpoints) {
- return new ArrayList<Endpoint>(endpoints.values());
- }
+ return new ArrayList<Endpoint>(endpoints.values());
}
public Map<String, Endpoint> getEndpointMap() {
- synchronized (endpoints) {
- TreeMap<String, Endpoint> answer = new TreeMap<String, Endpoint>();
- for (Map.Entry<EndpointKey, Endpoint> entry :
endpoints.entrySet()) {
- answer.put(entry.getKey().get(), entry.getValue());
- }
- return answer;
+ TreeMap<String, Endpoint> answer = new TreeMap<String, Endpoint>();
+ for (Map.Entry<EndpointKey, Endpoint> entry : endpoints.entrySet()) {
+ answer.put(entry.getKey().get(), entry.getValue());
}
+ return answer;
}
public Endpoint hasEndpoint(String uri) {
- synchronized (endpoints) {
- return endpoints.get(getEndpointKey(uri));
- }
+ return endpoints.get(getEndpointKey(uri));
}
public Endpoint addEndpoint(String uri, Endpoint endpoint) throws
Exception {
Endpoint oldEndpoint;
- synchronized (endpoints) {
- startServices(endpoint);
- oldEndpoint = endpoints.remove(getEndpointKey(uri));
- for (LifecycleStrategy strategy : lifecycleStrategies) {
- strategy.onEndpointAdd(endpoint);
- }
- addEndpointToRegistry(uri, endpoint);
- if (oldEndpoint != null) {
- stopServices(oldEndpoint);
- }
+
+ startServices(endpoint);
+ oldEndpoint = endpoints.remove(getEndpointKey(uri));
+ for (LifecycleStrategy strategy : lifecycleStrategies) {
+ strategy.onEndpointAdd(endpoint);
+ }
+ addEndpointToRegistry(uri, endpoint);
+ if (oldEndpoint != null) {
+ stopServices(oldEndpoint);
}
+
return oldEndpoint;
}
@@ -416,39 +410,37 @@ public class DefaultCamelContext extends
Endpoint answer;
String scheme = null;
- synchronized (endpoints) {
- answer = endpoints.get(getEndpointKey(uri));
- if (answer == null) {
- try {
- // Use the URI prefix to find the component.
- String splitURI[] = ObjectHelper.splitOnCharacter(uri,
":", 2);
- if (splitURI[1] != null) {
- scheme = splitURI[0];
- Component component = getComponent(scheme);
-
- // Ask the component to resolve the endpoint.
- if (component != null) {
- // Have the component create the endpoint if it
can.
- answer = component.createEndpoint(uri);
-
- if (answer != null && log.isDebugEnabled()) {
- log.debug("{} converted to endpoint: {} by
component: {}", new Object[]{uri, answer, component});
- }
+ answer = endpoints.get(getEndpointKey(uri));
+ if (answer == null) {
+ try {
+ // Use the URI prefix to find the component.
+ String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 2);
+ if (splitURI[1] != null) {
+ scheme = splitURI[0];
+ Component component = getComponent(scheme);
+
+ // Ask the component to resolve the endpoint.
+ if (component != null) {
+ // Have the component create the endpoint if it can.
+ answer = component.createEndpoint(uri);
+
+ if (answer != null && log.isDebugEnabled()) {
+ log.debug("{} converted to endpoint: {} by
component: {}", new Object[]{uri, answer, component});
}
}
+ }
- if (answer == null) {
- // no component then try in registry and elsewhere
- answer = createEndpoint(uri);
- }
+ if (answer == null) {
+ // no component then try in registry and elsewhere
+ answer = createEndpoint(uri);
+ }
- if (answer != null) {
- addService(answer);
- answer = addEndpointToRegistry(uri, answer);
- }
- } catch (Exception e) {
- throw new ResolveEndpointFailedException(uri, e);
+ if (answer != null) {
+ addService(answer);
+ answer = addEndpointToRegistry(uri, answer);
}
+ } catch (Exception e) {
+ throw new ResolveEndpointFailedException(uri, e);
}
}
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=1159643&r1=1159642&r2=1159643&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
Fri Aug 19 14:18:17 2011
@@ -16,10 +16,13 @@
*/
package org.apache.camel.util;
-import java.util.LinkedHashMap;
+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;
/**
@@ -27,14 +30,15 @@ import org.apache.camel.Service;
*
* @version
*/
-public class LRUCache<K, V> extends LinkedHashMap<K, V> implements Service {
+public class LRUCache<K, V> implements Service, Map<K, V> {
private static final long serialVersionUID = -342098639681884414L;
private int maxCacheSize = 10000;
private final AtomicLong hits = new AtomicLong();
private final AtomicLong misses = new AtomicLong();
+ private ConcurrentLinkedHashMap<K, V> map;
public LRUCache(int maximumCacheSize) {
- this(maximumCacheSize, maximumCacheSize, 0.75f, true);
+ this(maximumCacheSize, maximumCacheSize);
}
/**
@@ -43,20 +47,21 @@ public class LRUCache<K, V> extends Link
*
* @param initialCapacity the initial capacity.
* @param maximumCacheSize the max capacity.
- * @param loadFactor the load factor.
- * @param accessOrder the ordering mode - <tt>true</tt> for
- * access-order, <tt>false</tt> for
insertion-order.
* @throws IllegalArgumentException if the initial capacity is negative
* or the load factor is non positive.
*/
- public LRUCache(int initialCapacity, int maximumCacheSize, float
loadFactor, boolean accessOrder) {
- super(initialCapacity, loadFactor, accessOrder);
+ public LRUCache(int initialCapacity, int maximumCacheSize) {
+ map = new ConcurrentLinkedHashMap
+ .Builder<K, V>()
+ .initialCapacity(initialCapacity)
+ .maximumWeightedCapacity(maximumCacheSize).build();
+// super(initialCapacity, loadFactor, accessOrder);
this.maxCacheSize = maximumCacheSize;
}
@Override
public V get(Object o) {
- V answer = super.get(o);
+ V answer = map.get(o);
if (answer != null) {
hits.incrementAndGet();
} else {
@@ -65,6 +70,61 @@ public class LRUCache<K, V> extends Link
return answer;
}
+ @Override
+ public int size() {
+ return map.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return map.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(Object o) {
+ return map.containsKey(o);
+ }
+
+ @Override
+ public boolean containsValue(Object o) {
+ return map.containsValue(0);
+ }
+
+ @Override
+ public V put(K k, V v) {
+ return map.put(k, v);
+ }
+
+ @Override
+ public V remove(Object o) {
+ return map.remove(o);
+ }
+
+ @Override
+ public void putAll(Map<? extends K, ? extends V> map) {
+ ((AbstractMap)map).putAll(map);
+ }
+
+ @Override
+ public void clear() {
+ map.clear();
+ }
+
+ @Override
+ public Set<K> keySet() {
+ return map.ascendingKeySet();
+ }
+
+ @Override
+ public Collection<V> values() {
+ return map.ascendingMap().values();
+ }
+
+ @Override
+ public Set<Entry<K, V>> entrySet() {
+ return map.ascendingMap().entrySet();
+ }
+
/**
* Gets the number of cache hits
*/
@@ -95,7 +155,7 @@ public class LRUCache<K, V> extends Link
}
protected boolean removeEldestEntry(Map.Entry<K, V> entry) {
- return size() > maxCacheSize;
+ return map.size() > maxCacheSize;
}
public void start() throws Exception {
@@ -106,7 +166,7 @@ public class LRUCache<K, V> extends Link
// stop the value and clear the cache
if (!isEmpty()) {
ServiceHelper.stopServices(values());
- clear();
+ map.clear();
hits.set(0);
misses.set(0);
}
@@ -116,4 +176,4 @@ public class LRUCache<K, V> extends Link
public String toString() {
return "LRUCache@" + ObjectHelper.getIdentityHashCode(this);
}
-}
\ No newline at end of file
+}
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=1159643&r1=1159642&r2=1159643&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
Fri Aug 19 14:18:17 2011
@@ -55,8 +55,8 @@ public class LRUSoftCache<K, V> extends
super(maximumCacheSize);
}
- public LRUSoftCache(int initialCapacity, int maximumCacheSize, float
loadFactor, boolean accessOrder) {
- super(initialCapacity, maximumCacheSize, loadFactor, accessOrder);
+ public LRUSoftCache(int initialCapacity, int maximumCacheSize) {
+ super(initialCapacity, maximumCacheSize);
}
@Override
@@ -130,21 +130,6 @@ public class LRUSoftCache<K, V> extends
}
@Override
- public Set<K> keySet() {
- // must use a copy of the keys to avoid concurrent modifications
- Set<K> keys = new LinkedHashSet<K>(super.keySet());
-
- // filter out un referenced values
- Set<K> answer = new LinkedHashSet<K>();
- for (K key : keys) {
- if (containsKey(key)) {
- answer.add(key);
- }
- }
- return answer;
- }
-
- @Override
public Set<Map.Entry<K, V>> entrySet() {
Set<Map.Entry<K, V>> original = super.entrySet();
Modified:
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java?rev=1159643&r1=1159642&r2=1159643&view=diff
==============================================================================
---
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
(original)
+++
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
Fri Aug 19 14:18:17 2011
@@ -116,6 +116,7 @@ public class DefaultCamelContextTest ext
list = ctx.removeEndpoints("log:*");
assertEquals(2, list.size());
+
Iterator<Endpoint> it = list.iterator();
assertEquals("log://bar", it.next().getEndpointUri());
assertEquals("log://baz", it.next().getEndpointUri());
Modified:
camel/branches/camel-2.8.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wsdl/Order.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wsdl/Order.java?rev=1159643&r1=1159642&r2=1159643&view=diff
==============================================================================
---
camel/branches/camel-2.8.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wsdl/Order.java
(original)
+++
camel/branches/camel-2.8.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wsdl/Order.java
Fri Aug 19 14:18:17 2011
@@ -1,47 +1,47 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.cxf.wsdl;
-
-import javax.xml.bind.annotation.XmlRootElement;
-
-public class Order {
-
- String customerName;
- String productName;
-
- public String getCustomerName() {
- return customerName;
- }
-
- public void setCustomerName(String customerName) {
- this.customerName = customerName;
- }
-
- public String getProductName() {
- return productName;
- }
-
- public void setProductName(String productName) {
- this.productName = productName;
- }
-
- @Override
- public String toString() {
- return "order[" + customerName + "," + productName + "]";
- }
-
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.wsdl;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+public class Order {
+
+ String customerName;
+ String productName;
+
+ public String getCustomerName() {
+ return customerName;
+ }
+
+ public void setCustomerName(String customerName) {
+ this.customerName = customerName;
+ }
+
+ public String getProductName() {
+ return productName;
+ }
+
+ public void setProductName(String productName) {
+ this.productName = productName;
+ }
+
+ @Override
+ public String toString() {
+ return "order[" + customerName + "," + productName + "]";
+ }
+
+}
Modified: camel/branches/camel-2.8.x/parent/pom.xml
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/parent/pom.xml?rev=1159643&r1=1159642&r2=1159643&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/parent/pom.xml (original)
+++ camel/branches/camel-2.8.x/parent/pom.xml Fri Aug 19 14:18:17 2011
@@ -55,6 +55,7 @@
<commons-logging-version>1.1.1</commons-logging-version>
<commons-net-version>2.2</commons-net-version>
<commons-pool-version>1.5.4</commons-pool-version>
+ <concurrentlinkedhashmap.version>1.2</concurrentlinkedhashmap.version>
<!-- When updating cxf-version, may need to change CXF version range in
platforms/karaf/features/src/main/resources/features.xml -->
<cxf-version>2.4.2</cxf-version>
@@ -898,6 +899,11 @@
<artifactId>commons-management</artifactId>
<version>${fuse-commons-management-version}</version>
</dependency>
+ <dependency>
+ <groupId>com.googlecode.concurrentlinkedhashmap</groupId>
+ <artifactId>concurrentlinkedhashmap-lru</artifactId>
+ <version>${concurrentlinkedhashmap.version}</version>
+ </dependency>
<!-- optional dependencies -->
<dependency>
@@ -1617,6 +1623,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>1.4</version>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.0</version>
</plugin>