Repository: camel Updated Branches: refs/heads/master 9c2ea186a -> 970707f4e
CAMEL-7563 Fixed the CS error and avoid hazelcast component share the hazelcast reference across the component Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/970707f4 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/970707f4 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/970707f4 Branch: refs/heads/master Commit: 970707f4e3dff3a242c95e1bb9c516c262e658d4 Parents: b505dd8 Author: Willem Jiang <[email protected]> Authored: Fri Jul 4 22:07:06 2014 +0800 Committer: Willem Jiang <[email protected]> Committed: Fri Jul 4 22:08:24 2014 +0800 ---------------------------------------------------------------------- .../component/hazelcast/HazelcastComponent.java | 38 ++++++++++---------- ...astComponentInstanceReferenceSpringTest.java | 16 +++++++++ 2 files changed, 34 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/970707f4/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java index c77d4a6..a95ccda 100644 --- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java +++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java @@ -50,53 +50,47 @@ public class HazelcastComponent extends DefaultComponent { @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - + // Query param named 'hazelcastInstance' (if exists) overrides the instance that was set // programmatically and cancels local instance creation as well. HazelcastInstance hzInstance = resolveAndRemoveReferenceParameter(parameters, "hazelcastInstance", HazelcastInstance.class); - if (hzInstance != null) { - hazelcastInstance = hzInstance; - createOwnInstance = false; - } - - // Instance was neither set programmtically nor provided as a bean reference. - if (hazelcastInstance == null) { - createOwnInstance = true; - createOwnInstance(); + // Now we use the hazelcastInstance from compomnent + if (hzInstance == null) { + hzInstance = hazelcastInstance; } - + HazelcastDefaultEndpoint endpoint = null; // check type of endpoint if (remaining.startsWith(HazelcastConstants.MAP_PREFIX)) { // remaining is the cache name remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.MAP_PREFIX.length()), '/'); - endpoint = new HazelcastMapEndpoint(hazelcastInstance, uri, remaining, this); + endpoint = new HazelcastMapEndpoint(hzInstance, uri, remaining, this); } if (remaining.startsWith(HazelcastConstants.MULTIMAP_PREFIX)) { // remaining is the cache name remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.MULTIMAP_PREFIX.length()), '/'); - endpoint = new HazelcastMultimapEndpoint(hazelcastInstance, uri, remaining, this); + endpoint = new HazelcastMultimapEndpoint(hzInstance, uri, remaining, this); } if (remaining.startsWith(HazelcastConstants.ATOMICNUMBER_PREFIX)) { // remaining is the name of the atomic value remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.ATOMICNUMBER_PREFIX.length()), '/'); - endpoint = new HazelcastAtomicnumberEndpoint(hazelcastInstance, uri, this, remaining); + endpoint = new HazelcastAtomicnumberEndpoint(hzInstance, uri, this, remaining); } if (remaining.startsWith(HazelcastConstants.INSTANCE_PREFIX)) { // remaining is anything (name it foo ;) remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.INSTANCE_PREFIX.length()), '/'); - endpoint = new HazelcastInstanceEndpoint(hazelcastInstance, uri, this); + endpoint = new HazelcastInstanceEndpoint(hzInstance, uri, this); } if (remaining.startsWith(HazelcastConstants.QUEUE_PREFIX)) { // remaining is anything (name it foo ;) remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.QUEUE_PREFIX.length()), '/'); - endpoint = new HazelcastQueueEndpoint(hazelcastInstance, uri, this, remaining); + endpoint = new HazelcastQueueEndpoint(hzInstance, uri, this, remaining); } if (remaining.startsWith(HazelcastConstants.SEDA_PREFIX)) { @@ -104,13 +98,13 @@ public class HazelcastComponent extends DefaultComponent { setProperties(config, parameters); config.setQueueName(remaining.substring(remaining.indexOf(":") + 1, remaining.length())); - endpoint = new HazelcastSedaEndpoint(hazelcastInstance, uri, this, config); + endpoint = new HazelcastSedaEndpoint(hzInstance, uri, this, config); } if (remaining.startsWith(HazelcastConstants.LIST_PREFIX)) { // remaining is anything (name it foo ;) remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.LIST_PREFIX.length()), '/'); - endpoint = new HazelcastListEndpoint(hazelcastInstance, uri, this, remaining); + endpoint = new HazelcastListEndpoint(hzInstance, uri, this, remaining); } if (endpoint == null) { @@ -125,6 +119,10 @@ public class HazelcastComponent extends DefaultComponent { @Override public void doStart() throws Exception { super.doStart(); + if (hazelcastInstance == null) { + createOwnInstance = true; + hazelcastInstance = createOwnInstance(); + } } @Override @@ -143,10 +141,10 @@ public class HazelcastComponent extends DefaultComponent { this.hazelcastInstance = hazelcastInstance; } - private void createOwnInstance() { + private HazelcastInstance createOwnInstance() { Config config = new XmlConfigBuilder().build(); // Disable the version check config.getProperties().setProperty("hazelcast.version.check.enabled", "false"); - hazelcastInstance = Hazelcast.newHazelcastInstance(config); + return Hazelcast.newHazelcastInstance(config); } } http://git-wip-us.apache.org/repos/asf/camel/blob/970707f4/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastComponentInstanceReferenceSpringTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastComponentInstanceReferenceSpringTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastComponentInstanceReferenceSpringTest.java index 9e84047..46f1ee2 100644 --- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastComponentInstanceReferenceSpringTest.java +++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastComponentInstanceReferenceSpringTest.java @@ -1,3 +1,19 @@ +/** + * 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.hazelcast; import org.junit.Test;
