You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2017/03/14 11:19:58 UTC

[1/2] camel git commit: CAMEL-10978: Fixed CS

Repository: camel
Updated Branches:
  refs/heads/master 854b7ea5e -> 4e1cfa87c


CAMEL-10978: Fixed CS


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4e1cfa87
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4e1cfa87
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4e1cfa87

Branch: refs/heads/master
Commit: 4e1cfa87c4e33b999da30cdb78905b0f9992d9dd
Parents: ac12e52
Author: Andrea Cosentino <an...@gmail.com>
Authored: Tue Mar 14 11:24:58 2017 +0100
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue Mar 14 12:18:58 2017 +0100

----------------------------------------------------------------------
 .../component/hazelcast/HazelcastComponent.java | 30 ++++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4e1cfa87/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 c9ac8a0..dfa2b0f 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
@@ -49,10 +49,10 @@ import org.apache.camel.util.ResourceHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CONFIGU_PARAM;
-import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CONFIGU_URI_PARAM;
 import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CLIENT_CONFIGU_PARAM;
 import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CLIENT_CONFIGU_URI_PARAM;
+import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CONFIGU_PARAM;
+import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CONFIGU_URI_PARAM;
 import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_INSTANCE_NAME_PARAM;
 import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_INSTANCE_PARAM;
 import static org.apache.camel.util.ObjectHelper.removeStartingCharacters;
@@ -80,12 +80,12 @@ public class HazelcastComponent extends UriEndpointComponent {
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
 
         // use the given hazelcast Instance or create one if not given
-    	HazelcastInstance hzInstance;
-    	if (ObjectHelper.equal(hazelcastMode, HazelcastConstants.HAZELCAST_NODE_MODE)) {
+        HazelcastInstance hzInstance;
+        if (ObjectHelper.equal(hazelcastMode, HazelcastConstants.HAZELCAST_NODE_MODE)) {
             hzInstance = getOrCreateHzInstance(getCamelContext(), parameters);
-    	} else {
-    		hzInstance = getOrCreateHzClientInstance(getCamelContext(), parameters);
-    	}
+        } else {
+            hzInstance = getOrCreateHzClientInstance(getCamelContext(), parameters);
+        }
 
         String defaultOperation = getAndRemoveOrResolveReferenceParameter(parameters, HazelcastConstants.OPERATION_PARAM, String.class);
         if (defaultOperation == null) {
@@ -218,18 +218,18 @@ public class HazelcastComponent extends UriEndpointComponent {
     }
 
     public String getHazelcastMode() {
-		return hazelcastMode;
-	}
+        return hazelcastMode;
+    }
 
     /**
      * The hazelcast mode reference which kind of instance should be used.
      * If you don't specify the mode, then the node mode will be the default. 
      */
-	public void setHazelcastMode(String hazelcastMode) {
-		this.hazelcastMode = hazelcastMode;
-	}
+    public void setHazelcastMode(String hazelcastMode) {
+        this.hazelcastMode = hazelcastMode;
+    }
 
-	private HazelcastInstance getOrCreateHzInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
+    private HazelcastInstance getOrCreateHzInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
         HazelcastInstance hzInstance = null;
         Config config = null;
 
@@ -280,8 +280,8 @@ public class HazelcastComponent extends UriEndpointComponent {
 
         return hzInstance == null ? hazelcastInstance : hzInstance;
     }
-	
-	private HazelcastInstance getOrCreateHzClientInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
+
+    private HazelcastInstance getOrCreateHzClientInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
         HazelcastInstance hzInstance = null;
         ClientConfig config = null;
 


[2/2] camel git commit: CAMEL-10978: Camel-Hazelcast: support client mode

Posted by ac...@apache.org.
CAMEL-10978: Camel-Hazelcast: support client mode


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ac12e522
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ac12e522
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ac12e522

Branch: refs/heads/master
Commit: ac12e5227a4e36509ca2323a75a6998ab43c69d2
Parents: 854b7ea
Author: Andrea Cosentino <an...@gmail.com>
Authored: Tue Mar 14 11:17:21 2017 +0100
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue Mar 14 12:18:58 2017 +0100

----------------------------------------------------------------------
 .../src/main/docs/hazelcast-component.adoc      |  3 +-
 .../component/hazelcast/HazelcastComponent.java | 76 +++++++++++++++++++-
 .../component/hazelcast/HazelcastConstants.java |  6 ++
 .../HazelcastComponentConfiguration.java        | 13 ++++
 4 files changed, 95 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ac12e522/components/camel-hazelcast/src/main/docs/hazelcast-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/docs/hazelcast-component.adoc b/components/camel-hazelcast/src/main/docs/hazelcast-component.adoc
index de90cf2..492d8d9 100644
--- a/components/camel-hazelcast/src/main/docs/hazelcast-component.adoc
+++ b/components/camel-hazelcast/src/main/docs/hazelcast-component.adoc
@@ -46,7 +46,7 @@ hazelcast:[ map | multimap | queue | topic | seda | set | atomicvalue | instance
 
 
 // component options: START
-The Hazelcast component supports 2 options which are listed below.
+The Hazelcast component supports 3 options which are listed below.
 
 
 
@@ -54,6 +54,7 @@ The Hazelcast component supports 2 options which are listed below.
 |=======================================================================
 | Name | Group | Default | Java Type | Description
 | hazelcastInstance | advanced |  | HazelcastInstance | The hazelcast instance reference which can be used for hazelcast endpoint. If you don't specify the instance reference camel use the default hazelcast instance from the camel-hazelcast instance.
+| hazelcastMode | advanced | node | String | The hazelcast mode reference which kind of instance should be used. If you don't specify the mode then the node mode will be the default.
 | resolvePropertyPlaceholders | advanced | true | boolean | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.
 |=======================================================================
 // component options: END

http://git-wip-us.apache.org/repos/asf/camel/blob/ac12e522/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 5d2ff04..c9ac8a0 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
@@ -21,6 +21,9 @@ import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
+import com.hazelcast.client.HazelcastClient;
+import com.hazelcast.client.config.ClientConfig;
+import com.hazelcast.client.config.XmlClientConfigBuilder;
 import com.hazelcast.config.Config;
 import com.hazelcast.config.XmlConfigBuilder;
 import com.hazelcast.core.Hazelcast;
@@ -48,6 +51,8 @@ import org.slf4j.LoggerFactory;
 
 import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CONFIGU_PARAM;
 import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CONFIGU_URI_PARAM;
+import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CLIENT_CONFIGU_PARAM;
+import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_CLIENT_CONFIGU_URI_PARAM;
 import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_INSTANCE_NAME_PARAM;
 import static org.apache.camel.component.hazelcast.HazelcastConstants.HAZELCAST_INSTANCE_PARAM;
 import static org.apache.camel.util.ObjectHelper.removeStartingCharacters;
@@ -58,6 +63,8 @@ public class HazelcastComponent extends UriEndpointComponent {
     private final Set<HazelcastInstance> customHazelcastInstances;
     @Metadata(label = "advanced")
     private HazelcastInstance hazelcastInstance;
+    @Metadata(label = "advanced", defaultValue = "" + HazelcastConstants.HAZELCAST_NODE_MODE)
+    private String hazelcastMode = HazelcastConstants.HAZELCAST_NODE_MODE;
 
     public HazelcastComponent() {
         super(HazelcastDefaultEndpoint.class);
@@ -73,7 +80,12 @@ public class HazelcastComponent extends UriEndpointComponent {
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
 
         // use the given hazelcast Instance or create one if not given
-        HazelcastInstance hzInstance = getOrCreateHzInstance(getCamelContext(), parameters);
+    	HazelcastInstance hzInstance;
+    	if (ObjectHelper.equal(hazelcastMode, HazelcastConstants.HAZELCAST_NODE_MODE)) {
+            hzInstance = getOrCreateHzInstance(getCamelContext(), parameters);
+    	} else {
+    		hzInstance = getOrCreateHzClientInstance(getCamelContext(), parameters);
+    	}
 
         String defaultOperation = getAndRemoveOrResolveReferenceParameter(parameters, HazelcastConstants.OPERATION_PARAM, String.class);
         if (defaultOperation == null) {
@@ -205,7 +217,19 @@ public class HazelcastComponent extends UriEndpointComponent {
         this.hazelcastInstance = hazelcastInstance;
     }
 
-    private HazelcastInstance getOrCreateHzInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
+    public String getHazelcastMode() {
+		return hazelcastMode;
+	}
+
+    /**
+     * The hazelcast mode reference which kind of instance should be used.
+     * If you don't specify the mode, then the node mode will be the default. 
+     */
+	public void setHazelcastMode(String hazelcastMode) {
+		this.hazelcastMode = hazelcastMode;
+	}
+
+	private HazelcastInstance getOrCreateHzInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
         HazelcastInstance hzInstance = null;
         Config config = null;
 
@@ -256,4 +280,52 @@ public class HazelcastComponent extends UriEndpointComponent {
 
         return hzInstance == null ? hazelcastInstance : hzInstance;
     }
+	
+	private HazelcastInstance getOrCreateHzClientInstance(CamelContext context, Map<String, Object> parameters) throws Exception {
+        HazelcastInstance hzInstance = null;
+        ClientConfig config = null;
+
+        // Query param named 'hazelcastInstance' (if exists) overrides the instance that was set
+        hzInstance = resolveAndRemoveReferenceParameter(parameters, HAZELCAST_INSTANCE_PARAM, HazelcastInstance.class);
+
+        // Check if an already created instance is given then just get instance by its name.
+        if (hzInstance == null && parameters.get(HAZELCAST_INSTANCE_NAME_PARAM) != null) {
+            hzInstance = Hazelcast.getHazelcastInstanceByName((String) parameters.get(HAZELCAST_INSTANCE_NAME_PARAM));
+        }
+
+        // If instance neither supplied nor found by name, try to lookup its config
+        // as reference or as xml configuration file.
+        if (hzInstance == null) {
+            config = resolveAndRemoveReferenceParameter(parameters, HAZELCAST_CLIENT_CONFIGU_PARAM, ClientConfig.class);
+            if (config == null) {
+                String configUri = getAndRemoveParameter(parameters, HAZELCAST_CLIENT_CONFIGU_URI_PARAM, String.class);
+                if (configUri != null) {
+                    configUri = getCamelContext().resolvePropertyPlaceholders(configUri);
+                }
+                if (configUri != null) {
+                    InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, configUri);
+                    config = new XmlClientConfigBuilder(is).build();
+                }
+            }
+
+            if (hazelcastInstance == null && config == null) {
+                config = new XmlClientConfigBuilder().build();
+                // Disable the version check
+                config.getProperties().setProperty("hazelcast.version.check.enabled", "false");
+                config.getProperties().setProperty("hazelcast.phone.home.enabled", "false");
+
+                hzInstance = HazelcastClient.newHazelcastClient(config);
+            } else if (config != null) {
+                hzInstance = HazelcastClient.newHazelcastClient(config);
+            }
+
+            if (hzInstance != null) {
+                if (this.customHazelcastInstances.add(hzInstance)) {
+                    LOGGER.debug("Add managed HZ instance {}", hzInstance.getName());
+                }
+            }
+        }
+
+        return hzInstance == null ? hazelcastInstance : hzInstance;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/ac12e522/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
index dffe7eb..67ffb6e 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
@@ -132,7 +132,13 @@ public final class HazelcastConstants {
     public static final String HAZELCAST_INSTANCE_NAME_PARAM = "hazelcastInstanceName";
     public static final String HAZELCAST_INSTANCE_PARAM = "hazelcastInstance";
     public static final String HAZELCAST_CONFIGU_PARAM = "hazelcastConfig";
+    public static final String HAZELCAST_CLIENT_CONFIGU_PARAM = "hazelcastClientConfig";
     public static final String HAZELCAST_CONFIGU_URI_PARAM = "hazelcastConfigUri";
+    public static final String HAZELCAST_CLIENT_CONFIGU_URI_PARAM = "hazelcastClientConfigUri";
+    
+    // Hazelcast mode
+    public static final String HAZELCAST_NODE_MODE = "node";
+    public static final String HAZELCAST_CLIENT_MODE = "client";
 
 
     private HazelcastConstants() {

http://git-wip-us.apache.org/repos/asf/camel/blob/ac12e522/platforms/spring-boot/components-starter/camel-hazelcast-starter/src/main/java/org/apache/camel/component/hazelcast/springboot/HazelcastComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-hazelcast-starter/src/main/java/org/apache/camel/component/hazelcast/springboot/HazelcastComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-hazelcast-starter/src/main/java/org/apache/camel/component/hazelcast/springboot/HazelcastComponentConfiguration.java
index 304ea3b..a6a8fec 100644
--- a/platforms/spring-boot/components-starter/camel-hazelcast-starter/src/main/java/org/apache/camel/component/hazelcast/springboot/HazelcastComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-hazelcast-starter/src/main/java/org/apache/camel/component/hazelcast/springboot/HazelcastComponentConfiguration.java
@@ -37,6 +37,11 @@ public class HazelcastComponentConfiguration {
     @NestedConfigurationProperty
     private HazelcastInstance hazelcastInstance;
     /**
+     * The hazelcast mode reference which kind of instance should be used. If
+     * you don't specify the mode then the node mode will be the default.
+     */
+    private String hazelcastMode = "node";
+    /**
      * Whether the component should resolve property placeholders on itself when
      * starting. Only properties which are of String type can use property
      * placeholders.
@@ -51,6 +56,14 @@ public class HazelcastComponentConfiguration {
         this.hazelcastInstance = hazelcastInstance;
     }
 
+    public String getHazelcastMode() {
+        return hazelcastMode;
+    }
+
+    public void setHazelcastMode(String hazelcastMode) {
+        this.hazelcastMode = hazelcastMode;
+    }
+
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }