camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1409097 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/ main/java/org/apache/camel/component/language/ test/java/org/apache/camel/component/language/
Date Wed, 14 Nov 2012 06:33:37 GMT
Author: cmueller
Date: Wed Nov 14 06:33:36 2012
New Revision: 1409097

URL: http://svn.apache.org/viewvc?rev=1409097&view=rev
Log:
CAMEL-5678: It should be possible to clear the cached script in LanguageEndpoint via JMX

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/ResourceEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageProducer.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/language/LanguageLoadScriptFromFileCachedTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/ResourceEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/ResourceEndpoint.java?rev=1409097&r1=1409096&r2=1409097&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/ResourceEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/ResourceEndpoint.java
Wed Nov 14 06:33:36 2012
@@ -21,6 +21,8 @@ import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.camel.Component;
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedOperation;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.api.management.mbean.ManagedResourceEndpointMBean;
 import org.apache.camel.converter.IOConverter;
@@ -92,15 +94,21 @@ public abstract class ResourceEndpoint e
         return ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(),
uri);
     }
 
+    @ManagedAttribute(description = "Whether the resource is cached")
     public boolean isContentCache() {
         return contentCache;
     }
-    
+
+    @ManagedOperation(description = "Clears the cached resource, forcing to re-load the resource
on next request")
     public void clearContentCache() {
         log.debug("Clearing resource: {} from the content cache", resourceUri);
         buffer = null;
     }
 
+    public boolean isContentCacheCleared() {
+        return buffer == null;
+    }
+
     /**
      * Sets whether to use resource content cache or not - default is <tt>false</tt>.
      *

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageEndpoint.java?rev=1409097&r1=1409096&r2=1409097&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageEndpoint.java
Wed Nov 14 06:33:36 2012
@@ -44,6 +44,7 @@ public class LanguageEndpoint extends Re
     private String languageName;
     private String script;
     private boolean transform = true;
+    private boolean contentResolvedFromResource = false;
 
     public LanguageEndpoint() {
         // enable cache by default
@@ -118,6 +119,9 @@ public class LanguageEndpoint extends Re
     }
 
     public Expression getExpression() {
+        if (isContentResolvedFromResource() && isContentCacheCleared()) {
+            return null;
+        }
         return expression;
     }
 
@@ -158,4 +162,11 @@ public class LanguageEndpoint extends Re
         this.script = script;
     }
 
+    public boolean isContentResolvedFromResource() {
+        return contentResolvedFromResource;
+    }
+
+    public void setContentResolvedFromResource(boolean contentResolvedFromResource) {
+        this.contentResolvedFromResource = contentResolvedFromResource;
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageProducer.java?rev=1409097&r1=1409096&r2=1409097&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageProducer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/language/LanguageProducer.java
Wed Nov 14 06:33:36 2012
@@ -65,6 +65,8 @@ public class LanguageProducer extends De
                 }
                 // create the expression from the script
                 exp = getEndpoint().getLanguage().createExpression(script);
+                // expression was resolved from resource
+                getEndpoint().setContentResolvedFromResource(true);
                 // if we cache then set this as expression on endpoint so we don't re-create
it again
                 if (getEndpoint().isContentCache()) {
                     getEndpoint().setExpression(exp);

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/language/LanguageLoadScriptFromFileCachedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/language/LanguageLoadScriptFromFileCachedTest.java?rev=1409097&r1=1409096&r2=1409097&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/language/LanguageLoadScriptFromFileCachedTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/language/LanguageLoadScriptFromFileCachedTest.java
Wed Nov 14 06:33:36 2012
@@ -16,6 +16,12 @@
  */
 package org.apache.camel.component.language;
 
+import java.util.ArrayList;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
@@ -30,6 +36,11 @@ public class LanguageLoadScriptFromFileC
         deleteDirectory("target/script");
         super.setUp();
     }
+    
+    @Override
+    public boolean useJmx() {
+        return true;
+    }
 
     public void testLanguage() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Hello World");
@@ -42,6 +53,27 @@ public class LanguageLoadScriptFromFileC
 
         assertMockEndpointsSatisfied();
     }
+    
+    public void testClearCachedScriptViaJmx() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Hello World",
"Bye World");
+
+        template.sendBody("direct:start", "World");
+
+        // even if we update the file the content is cached
+        template.sendBodyAndHeader("file:target/script", "Bye ${body}", Exchange.FILE_NAME,
"myscript.txt");
+        template.sendBody("direct:start", "World");
+
+        // now clear the cache via the mbean server
+        MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
+        Set<ObjectName> objNameSet = mbeanServer.queryNames(
+            new ObjectName("org.apache.camel:type=endpoints,name=\"language://simple:*contentCache=true*\",*"),
null);
+        ObjectName managedObjName = new ArrayList<ObjectName>(objNameSet).get(0);
+        mbeanServer.invoke(managedObjName, "clearContentCache", null, null);
+
+        template.sendBody("direct:start", "World");
+
+        assertMockEndpointsSatisfied();
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {



Mime
View raw message