camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [camel] 01/02: CAMEL-13870: Fast property configuration of Camel endpoints. Work in progress.
Date Thu, 22 Aug 2019 11:45:25 GMT
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-13870
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 3b87d7806810ba4d3291cef452af6acd4ebc1b44
Author: Claus Ibsen <claus.ibsen@gmail.com>
AuthorDate: Thu Aug 22 13:05:30 2019 +0200

    CAMEL-13870: Fast property configuration of Camel endpoints. Work in progress.
---
 .../org/apache/camel/spi/BeanIntrospection.java    | 27 ++++++---
 .../impl/engine/DefaultBeanIntrospection.java      | 25 +++-----
 .../mbean/ManagedBeanIntrospectionMBean.java       |  6 ++
 .../management/mbean/ManagedBeanIntrospection.java | 10 ++++
 .../DefaultComponentVerifierExtension.java         |  4 +-
 .../org/apache/camel/support/DefaultComponent.java |  3 +-
 .../org/apache/camel/support/DefaultEndpoint.java  |  3 +-
 .../apache/camel/support/IntrospectionSupport.java | 11 ++++
 .../camel/support/ScheduledPollEndpoint.java       |  3 +-
 .../org/apache/camel/util/PropertiesHelper.java    | 69 ++++++++++++++++++++++
 10 files changed, 133 insertions(+), 28 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
index 176bff4..fd63878 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/BeanIntrospection.java
@@ -24,6 +24,7 @@ import java.util.Set;
 import org.apache.camel.CamelContext;
 import org.apache.camel.StaticService;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.meta.Experimental;
 
 // TODO: Keep only public used methods so we can remove the tech debt
 
@@ -32,7 +33,10 @@ import org.apache.camel.TypeConverter;
  * or updating one or more properties etc.
  *
  * End users should favour using org.apache.camel.support.PropertyBindingSupport instead.
+ * <p/>
+ * Notice this API is not final yet
  */
+@Experimental
 public interface BeanIntrospection extends StaticService {
 
     /**
@@ -54,6 +58,9 @@ public interface BeanIntrospection extends StaticService {
         public Boolean hasGetterAndSetter;
     }
 
+    // Statistics
+    // ----------------------------------------------------
+
     /**
      * Number of times bean introspection has been invoked
      */
@@ -64,6 +71,19 @@ public interface BeanIntrospection extends StaticService {
      */
     void resetCounters();
 
+    /**
+     * Whether to gather extended statistics for introspection usage.
+     */
+    boolean isExtendedStatistics();
+
+    /**
+     * Whether to gather extended statistics for introspection usage.
+     */
+    void setExtendedStatistics(boolean extendedStatistics);
+
+    // Introspection
+    // ----------------------------------------------------
+
     boolean isGetter(Method method);
 
     String getGetterShorthandName(Method method);
@@ -147,13 +167,6 @@ public interface BeanIntrospection extends StaticService {
     @Deprecated
     boolean setProperties(Object target, Map<String, Object> properties, String optionPrefix)
throws Exception;
 
-    Map<String, Object> extractProperties(Map<String, Object> properties, String
optionPrefix);
-
-    Map<String, Object> extractProperties(Map<String, Object> properties, String
optionPrefix, boolean remove);
-
-    @Deprecated
-    Map<String, String> extractStringProperties(Map<String, Object> properties);
-
     /**
      * @deprecated use org.apache.camel.support.PropertyBindingSupport
      */
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
index 4963104..0e08eaa 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultBeanIntrospection.java
@@ -36,6 +36,7 @@ public class DefaultBeanIntrospection extends ServiceSupport implements
BeanIntr
     private static final Logger LOG = LoggerFactory.getLogger(DefaultBeanIntrospection.class);
 
     private final AtomicLong invoked = new AtomicLong();
+    private volatile boolean extendedStatistics;
 
     @Override
     public long getInvokedCounter() {
@@ -47,6 +48,14 @@ public class DefaultBeanIntrospection extends ServiceSupport implements
BeanIntr
         invoked.set(0);
     }
 
+    public boolean isExtendedStatistics() {
+        return extendedStatistics;
+    }
+
+    public void setExtendedStatistics(boolean extendedStatistics) {
+        this.extendedStatistics = extendedStatistics;
+    }
+
     @Override
     public ClassInfo cacheClass(Class<?> clazz) {
         invoked.incrementAndGet();
@@ -157,22 +166,6 @@ public class DefaultBeanIntrospection extends ServiceSupport implements
BeanIntr
     }
 
     @Override
-    public Map<String, Object> extractProperties(Map<String, Object> properties,
String optionPrefix) {
-        return IntrospectionSupport.extractProperties(properties, optionPrefix);
-    }
-
-    @Override
-    public Map<String, Object> extractProperties(Map<String, Object> properties,
String optionPrefix, boolean remove) {
-        return IntrospectionSupport.extractProperties(properties, optionPrefix, remove);
-    }
-
-    @Override
-    @Deprecated
-    public Map<String, String> extractStringProperties(Map<String, Object> properties)
{
-        return IntrospectionSupport.extractStringProperties(properties);
-    }
-
-    @Override
     @Deprecated
     public boolean setProperties(CamelContext context, TypeConverter typeConverter, Object
target, Map<String, Object> properties) throws Exception {
         invoked.incrementAndGet();
diff --git a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBeanIntrospectionMBean.java
b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBeanIntrospectionMBean.java
index 0654d19..b9beb31 100644
--- a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBeanIntrospectionMBean.java
+++ b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedBeanIntrospectionMBean.java
@@ -24,6 +24,12 @@ public interface ManagedBeanIntrospectionMBean extends ManagedServiceMBean
{
     @ManagedAttribute(description = "Number of times bean introspection has been invoked")
     Long getInvokedCounter();
 
+    @ManagedAttribute(description = "Whether to gather extended statistics for introspection
usage")
+    Boolean isExtendedStatistics();
+
+    @ManagedAttribute(description = "Whether to gather extended statistics for introspection
usage")
+    void setExtendedStatistics(boolean extendedStatistics);
+
     @ManagedOperation(description = "Rests the statistic counters")
     void resetCounters();
 
diff --git a/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedBeanIntrospection.java
b/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedBeanIntrospection.java
index d8205f9..f1e5f5f 100644
--- a/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedBeanIntrospection.java
+++ b/core/camel-management-impl/src/main/java/org/apache/camel/management/mbean/ManagedBeanIntrospection.java
@@ -44,6 +44,16 @@ public class ManagedBeanIntrospection extends ManagedService implements
ManagedB
     }
 
     @Override
+    public Boolean isExtendedStatistics() {
+        return beanIntrospection.isExtendedStatistics();
+    }
+
+    @Override
+    public void setExtendedStatistics(boolean extendedStatistics) {
+        beanIntrospection.setExtendedStatistics(extendedStatistics);
+    }
+
+    @Override
     public void resetCounters() {
         beanIntrospection.resetCounters();
     }
diff --git a/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
b/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
index 66e19f3..ba9b790 100644
--- a/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
+++ b/core/camel-support/src/main/java/org/apache/camel/component/extension/verifier/DefaultComponentVerifierExtension.java
@@ -25,12 +25,12 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.Component;
 import org.apache.camel.ComponentAware;
-import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.component.extension.ComponentVerifierExtension;
 import org.apache.camel.runtimecatalog.EndpointValidationResult;
 import org.apache.camel.runtimecatalog.RuntimeCamelCatalog;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.PropertyBindingSupport;
+import org.apache.camel.util.PropertiesHelper;
 
 import static org.apache.camel.util.StreamUtils.stream;
 
@@ -194,7 +194,7 @@ public class DefaultComponentVerifierExtension implements ComponentVerifierExten
     }
 
     protected <T> T setProperties(T instance, String prefix, Map<String, Object>
properties) throws Exception {
-        return setProperties(instance, getCamelContext().getExtension(ExtendedCamelContext.class).getBeanIntrospection().extractProperties(properties,
prefix, false));
+        return setProperties(instance, PropertiesHelper.extractProperties(properties, prefix,
false));
     }
 
     protected <T> Optional<T> getOption(Map<String, Object> parameters,
String key, Class<T> type) {
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
index e461970..fbcd4ea 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
@@ -43,6 +43,7 @@ import org.apache.camel.spi.PropertyConfigurer;
 import org.apache.camel.spi.PropertyConfigurerAware;
 import org.apache.camel.support.service.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.PropertiesHelper;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.URISupport;
 import org.apache.camel.util.UnsafeUriCharactersEncoder;
@@ -285,7 +286,7 @@ public abstract class DefaultComponent extends ServiceSupport implements
Compone
 
         Map<String, Object> param = parameters;
         if (optionPrefix != null) {
-            param = getCamelContext().getExtension(ExtendedCamelContext.class).getBeanIntrospection().extractProperties(parameters,
optionPrefix);
+            param = PropertiesHelper.extractProperties(parameters, optionPrefix);
         }
 
         if (param.size() > 0) {
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
b/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
index 72174b6..4248230 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultEndpoint.java
@@ -37,6 +37,7 @@ import org.apache.camel.spi.PropertyConfigurerAware;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.support.service.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.PropertiesHelper;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.URISupport;
 
@@ -396,7 +397,7 @@ public abstract class DefaultEndpoint extends ServiceSupport implements
Endpoint
 
     @Override
     public void configureProperties(Map<String, Object> options) {
-        Map<String, Object> consumerProperties = getCamelContext().getExtension(ExtendedCamelContext.class).getBeanIntrospection().extractProperties(options,
"consumer.");
+        Map<String, Object> consumerProperties = PropertiesHelper.extractProperties(options,
"consumer.");
         if (consumerProperties != null && !consumerProperties.isEmpty()) {
             setConsumerProperties(consumerProperties);
         }
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
index ba988d5..f214af2 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/IntrospectionSupport.java
@@ -469,10 +469,18 @@ public final class IntrospectionSupport {
         return setProperties(target, properties, optionPrefix, false);
     }
 
+    /**
+     * @deprecated use {@link org.apache.camel.util.PropertiesHelper}
+     */
+    @Deprecated
     public static Map<String, Object> extractProperties(Map<String, Object> properties,
String optionPrefix) {
         return extractProperties(properties, optionPrefix, true);
     }
 
+    /**
+     * @deprecated use {@link org.apache.camel.util.PropertiesHelper}
+     */
+    @Deprecated
     public static Map<String, Object> extractProperties(Map<String, Object> properties,
String optionPrefix, boolean remove) {
         ObjectHelper.notNull(properties, "properties");
 
@@ -495,6 +503,9 @@ public final class IntrospectionSupport {
         return rc;
     }
 
+    /**
+     * @deprecated use {@link org.apache.camel.util.PropertiesHelper}
+     */
     @Deprecated
     public static Map<String, String> extractStringProperties(Map<String, Object>
properties) {
         ObjectHelper.notNull(properties, "properties");
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
index a5d6c98..52c0e05 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java
@@ -29,6 +29,7 @@ import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.spi.PollingConsumerPollStrategy;
 import org.apache.camel.spi.ScheduledPollConsumerScheduler;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.PropertiesHelper;
 
 /**
  * A base class for {@link org.apache.camel.Endpoint} which creates a {@link ScheduledPollConsumer}
@@ -108,7 +109,7 @@ public abstract class ScheduledPollEndpoint extends DefaultEndpoint {
     protected void configureScheduledPollConsumerProperties(Map<String, Object> options,
Map<String, Object> consumerProperties) {
         // special for scheduled poll consumers as we want to allow end users to configure
its options
         // from the URI parameters without the consumer. prefix
-        Map<String, Object> schedulerProperties = getCamelContext().getExtension(ExtendedCamelContext.class).getBeanIntrospection().extractProperties(options,
"scheduler.");
+        Map<String, Object> schedulerProperties = PropertiesHelper.extractProperties(options,
"scheduler.");
         if (schedulerProperties != null && !schedulerProperties.isEmpty()) {
             setSchedulerProperties(schedulerProperties);
         }
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/PropertiesHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/PropertiesHelper.java
new file mode 100644
index 0000000..baa25ee
--- /dev/null
+++ b/core/camel-util/src/main/java/org/apache/camel/util/PropertiesHelper.java
@@ -0,0 +1,69 @@
+/*
+ * 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.util;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public final class PropertiesHelper {
+
+    private PropertiesHelper() {
+    }
+
+    public static Map<String, Object> extractProperties(Map<String, Object> properties,
String optionPrefix) {
+        return extractProperties(properties, optionPrefix, true);
+    }
+
+    public static Map<String, Object> extractProperties(Map<String, Object> properties,
String optionPrefix, boolean remove) {
+        ObjectHelper.notNull(properties, "properties");
+
+        Map<String, Object> rc = new LinkedHashMap<>(properties.size());
+
+        for (Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator();
it.hasNext();) {
+            Map.Entry<String, Object> entry = it.next();
+            String name = entry.getKey();
+            if (name.startsWith(optionPrefix)) {
+                Object value = properties.get(name);
+                name = name.substring(optionPrefix.length());
+                rc.put(name, value);
+
+                if (remove) {
+                    it.remove();
+                }
+            }
+        }
+
+        return rc;
+    }
+
+    @Deprecated
+    public static Map<String, String> extractStringProperties(Map<String, Object>
properties) {
+        ObjectHelper.notNull(properties, "properties");
+
+        Map<String, String> rc = new LinkedHashMap<>(properties.size());
+
+        for (Map.Entry<String, Object> entry : properties.entrySet()) {
+            String name = entry.getKey();
+            String value = entry.getValue().toString();
+            rc.put(name, value);
+        }
+
+        return rc;
+    }
+
+}


Mime
View raw message