initial registry files

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

Branch: refs/heads/master
Commit: cc1e8a09575a968f16309a263cd41b49eec8b142
Parents: 36f25f4
Author: Bernd Prager <be...@prager.ws>
Authored: Wed May 25 10:53:42 2016 -0400
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sat May 28 09:18:07 2016 +0200

----------------------------------------------------------------------
 components/camel-consul/pom.xml                 | 221 ++++++++++---------
 .../camel/component/consul/ConsulRegistry.java  |  17 +-
 2 files changed, 114 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cc1e8a09/components/camel-consul/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-consul/pom.xml b/components/camel-consul/pom.xml
index 9b9dca9..256899f 100644
--- a/components/camel-consul/pom.xml
+++ b/components/camel-consul/pom.xml
@@ -1,120 +1,125 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
 
-  http://www.apache.org/licenses/LICENSE-2.0
+       <modelVersion>4.0.0</modelVersion>
 
-  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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+       <parent>
+               <groupId>org.apache.camel</groupId>
+               <artifactId>components</artifactId>
+               <version>2.18-SNAPSHOT</version>
+       </parent>
 
-  <modelVersion>4.0.0</modelVersion>
+       <artifactId>camel-consul</artifactId>
+       <packaging>jar</packaging>
+       <name>Camel :: Consul</name>
+       <description>Camel Consul support</description>
 
-  <parent>
-    <groupId>org.apache.camel</groupId>
-    <artifactId>components</artifactId>
-    <version>2.18-SNAPSHOT</version>
-  </parent>
+       <properties>
+               <camel.osgi.export.pkg>
+                       org.apache.camel.component.consul.*,
+               </camel.osgi.export.pkg>
+               <camel.osgi.export.service>
+                       org.apache.camel.spi.ComponentResolver;component=consul
+               </camel.osgi.export.service>
+       </properties>
 
-  <artifactId>camel-consul</artifactId>
-  <packaging>jar</packaging>
-  <name>Camel :: Consul</name>
-  <description>Camel Consul support</description>
+       <dependencies>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-core</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>com.orbitz.consul</groupId>
+                       <artifactId>consul-client</artifactId>
+                       <version>${consul-client-version}</version>
+               </dependency>
 
-  <properties>
-    <camel.osgi.export.pkg>
-      org.apache.camel.component.consul.*,
-    </camel.osgi.export.pkg>
-    <camel.osgi.export.service>
-      org.apache.camel.spi.ComponentResolver;component=consul
-    </camel.osgi.export.service>
-  </properties>
+               <!-- testing -->
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-test</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-log4j12</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>log4j</groupId>
+                       <artifactId>log4j</artifactId>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.mockito</groupId>
+                       <artifactId>mockito-all</artifactId>
+                       <version>${mockito-version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.hamcrest</groupId>
+                       <artifactId>java-hamcrest</artifactId>
+                       <version>${hamcrest-version}</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.directory.studio</groupId>
+                       <artifactId>org.apache.commons.lang</artifactId>
+                       <version>2.6</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.directory.studio</groupId>
+                       <artifactId>org.apache.commons.codec</artifactId>
+                       <version>1.8</version>
+               </dependency>
+       </dependencies>
 
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-core</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>com.orbitz.consul</groupId>
-      <artifactId>consul-client</artifactId>
-      <version>${consul-client-version}</version>
-    </dependency>
 
-    <!-- testing -->
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-test</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-log4j12</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <version>${mockito-version}</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>java-hamcrest</artifactId>
-      <version>${hamcrest-version}</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
+       <profiles>
+               <profile>
+                       <id>consul-skip-tests</id>
+                       <activation>
+                               <activeByDefault>true</activeByDefault>
+                       </activation>
+                       <build>
+                               <plugins>
+                                       <plugin>
+                                               
<artifactId>maven-surefire-plugin</artifactId>
+                                               <configuration>
+                                                       
<skipTests>true</skipTests>
+                                               </configuration>
+                                       </plugin>
+                               </plugins>
+                       </build>
+               </profile>
+               <profile>
+                       <id>consul-tests</id>
+                       <activation>
+                               <activeByDefault>false</activeByDefault>
+                       </activation>
+                       <build>
+                               <plugins>
+                                       <plugin>
+                                               
<artifactId>maven-surefire-plugin</artifactId>
+                                               <configuration>
+                                                       
<skipTests>false</skipTests>
+                                               </configuration>
+                                       </plugin>
+                               </plugins>
+                       </build>
+               </profile>
 
-
-  <profiles>
-    <profile>
-      <id>consul-skip-tests</id>
-      <activation>
-        <activeByDefault>true</activeByDefault>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-surefire-plugin</artifactId>
-            <configuration>
-              <skipTests>true</skipTests>
-            </configuration>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>consul-tests</id>
-      <activation>
-        <activeByDefault>false</activeByDefault>
-      </activation>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-surefire-plugin</artifactId>
-            <configuration>
-              <skipTests>false</skipTests>
-            </configuration>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-
-  </profiles>
+       </profiles>
 
 </project>

http://git-wip-us.apache.org/repos/asf/camel/blob/cc1e8a09/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java
----------------------------------------------------------------------
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java
index 472a537..7f959b4 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java
@@ -26,9 +26,8 @@ import java.util.UUID;
 
 import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.spi.Registry;
-import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang.SerializationUtils;
-import org.apache.log4j.Logger;
+import org.apache.commons.codec.binary.Base64;
 
 import com.google.common.base.Optional;
 import com.google.common.net.HostAndPort;
@@ -49,8 +48,6 @@ import com.orbitz.consul.model.session.SessionCreatedResponse;
  */
 public class ConsulRegistry implements Registry {
 
-       private static final Logger logger = 
Logger.getLogger(ConsulRegistry.class);
-
        private String hostname = "localhost";
        private int port = 8500;
        private Consul consul;
@@ -66,7 +63,6 @@ public class ConsulRegistry implements Registry {
                super();
                this.hostname = hostname;
                this.port = port;
-               logger.debug("get consul client for: " + hostname + ":" + port);
                HostAndPort hostAndPort = HostAndPort.fromParts(hostname, port);
                this.consul = 
Consul.builder().withHostAndPort(hostAndPort).build();
        }
@@ -75,7 +71,6 @@ public class ConsulRegistry implements Registry {
        private ConsulRegistry(Builder builder) {
                this.hostname = builder.hostname;
                this.port = builder.port;
-               logger.debug("get consul client for: " + hostname + ":" + port);
                HostAndPort hostAndPort = HostAndPort.fromParts(hostname, port);
                this.consul = 
Consul.builder().withHostAndPort(hostAndPort).build();
        }
@@ -84,12 +79,10 @@ public class ConsulRegistry implements Registry {
        public Object lookupByName(String key) {
                // Substitute $ character in key
                key = key.replaceAll("\\$", "/");
-               logger.debug("lookup by name: " + key);
                kvClient = consul.keyValueClient();
                Optional<String> result = kvClient.getValueAsString(key);
                if (result.isPresent()) {
                        byte[] postDecodedValue = 
Base64.decodeBase64(result.get());
-                       logger.debug("got result: " + postDecodedValue);
                        return SerializationUtils.deserialize(postDecodedValue);
                }
                return null;
@@ -97,7 +90,6 @@ public class ConsulRegistry implements Registry {
 
        @Override
        public <T> T lookupByNameAndType(String name, Class<T> type) {
-               logger.debug("lookup by name: " + name + " and type: " + type);
                Object object = lookupByName(name);
                if (object == null)
                        return null;
@@ -112,12 +104,10 @@ public class ConsulRegistry implements Registry {
 
        @Override
        public <T> Map<String, T> findByTypeWithName(Class<T> type) {
-               logger.debug("find by type with name: " + type);
                Object obj = null;
                Map<String, T> result = new HashMap<String, T>();
                // encode $ signs as they occur in subclass types
                String keyPrefix = type.getName().replaceAll("\\$", "/");
-               logger.debug("keyPrefix: " + keyPrefix);
                kvClient = consul.keyValueClient();
                List<String> keys = null;
                try {
@@ -141,21 +131,18 @@ public class ConsulRegistry implements Registry {
        @Override
        public <T> Set<T> findByType(Class<T> type) {
                String keyPrefix = type.getName().replaceAll("\\$", "/");
-               logger.debug("find by type using keyPrefix: " + keyPrefix);
                Object object = null;
                Set<T> result = new HashSet<T>();
                List<String> keys = null;
                try {
                        keys = kvClient.getKeys(keyPrefix);
                } catch (ConsulException e) {
-                       logger.debug("no keys found");
                        return result;
                }
                if (keys != null) {
                        for (String key : keys) {
                                // change bookmark back into actual key
                                key = key.substring((key.lastIndexOf('/') + 1));
-                               logger.debug("now going for key :" + key);
                                object = lookupByName(key.replaceAll("\\$", 
"/"));
                                if (type.isInstance(object)) {
                                        result.add(type.cast(object));
@@ -210,10 +197,8 @@ public class ConsulRegistry implements Registry {
                byte[] preEncodedValue = Base64.encodeBase64(serializedObject);
                String value = new String(preEncodedValue);
                // store the actual class
-               logger.debug("store value: " + value + " ,under key: " + key);
                kvClient.putValue(key, value);
                // store just as a bookmark
-               logger.debug("store bookmark: " + 1 + " ,under key: " + 
object.getClass().getName().replaceAll("\\$", "/") + "/" + key);
                kvClient.putValue(object.getClass().getName().replaceAll("\\$", 
"/") + "/" + key, "1");
                kvClient.releaseLock(lockKey, sessionId);
        }

Reply via email to