camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/6] camel git commit: Allow to use CamelCatalog in cache mode
Date Mon, 28 Dec 2015 13:05:11 GMT
Allow to use CamelCatalog in cache mode


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

Branch: refs/heads/master
Commit: 1741937b754e1750e12033b55f4e5f21db916f96
Parents: 3a4d17e
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Dec 28 13:52:03 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Dec 28 13:57:22 2015 +0100

----------------------------------------------------------------------
 .../camel/catalog/DefaultCamelCatalog.java      | 47 ++++++++++++--------
 1 file changed, 29 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1741937b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index bff2ca9..e1a1622 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -1192,27 +1192,38 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
     @Override
     public String listComponentsAsJson() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("[");
-        List<String> names = findComponentNames();
-        for (int i = 0; i < names.size(); i++) {
-            String scheme = names.get(i);
-            String json = componentJSonSchema(scheme);
-            // skip first line
-            json = CatalogHelper.between(json, "\"component\": {", "\"componentProperties\":
{");
-            json = json != null ? json.trim() : "";
-            // skip last comma if not the last
-            if (i == names.size() - 1) {
-                json = json.substring(0, json.length() - 1);
+        String answer = null;
+        if (caching) {
+            answer = (String) cache.get("listComponentsAsJson");
+        }
+
+        if (answer == null) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("[");
+            List<String> names = findComponentNames();
+            for (int i = 0; i < names.size(); i++) {
+                String scheme = names.get(i);
+                String json = componentJSonSchema(scheme);
+                // skip first line
+                json = CatalogHelper.between(json, "\"component\": {", "\"componentProperties\":
{");
+                json = json != null ? json.trim() : "";
+                // skip last comma if not the last
+                if (i == names.size() - 1) {
+                    json = json.substring(0, json.length() - 1);
+                }
+                sb.append("\n");
+                sb.append("  {\n");
+                sb.append("    ");
+                sb.append(json);
+            }
+            sb.append("\n]");
+            answer = sb.toString();
+            if (caching) {
+                cache.put("listComponentsAsJson", answer);
             }
-            sb.append("\n");
-            sb.append("  {\n");
-            sb.append("    ");
-            sb.append(json);
         }
 
-        sb.append("\n]");
-        return sb.toString();
+        return answer;
     }
 
     @Override


Mime
View raw message