svn commit: r932265 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/strategy/ main/java/org/apache/camel/component/mock/ main/java/org/apache/camel/impl/ main/java/org/apac

2010-04-08 Thread davsclaus
Author: davsclaus
Date: Fri Apr  9 06:11:51 2010
New Revision: 932265

URL: http://svn.apache.org/viewvc?rev=932265&view=rev
Log:
CAMEL-2627: Added StopWatch and time startup/shutdown times of Camel. Also time 
@Converter loader.

Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/StopWatch.java   
(with props)

camel/trunk/camel-core/src/test/java/org/apache/camel/util/StopWatchTest.java   
(with props)
Modified:

camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java

camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java

camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java

camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java

camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java

camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java

camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java

camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java

camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/DefaultTypeConverter.java

camel/trunk/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
camel/trunk/camel-core/src/main/java/org/apache/camel/util/Time.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java?rev=932265&r1=932264&r2=932265&view=diff
==
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
 Fri Apr  9 06:11:51 2010
@@ -23,6 +23,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.component.file.GenericFileEndpoint;
 import org.apache.camel.component.file.GenericFileOperations;
+import org.apache.camel.util.StopWatch;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -50,13 +51,12 @@ public class FileChangedExclusiveReadLoc
 try {
 long lastModified = Long.MIN_VALUE;
 long length = Long.MIN_VALUE;
-
-long start = System.currentTimeMillis();
+StopWatch watch = new StopWatch();
 
 while (!exclusive) {
 // timeout check
 if (timeout > 0) {
-long delta = System.currentTimeMillis() - start;
+long delta = watch.taken();
 if (delta > timeout) {
 LOG.warn("Cannot acquire read lock within " + timeout 
+ " millis. Will skip the file: " + file);
 // we could not get the lock within the timeout 
period, so return false

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java?rev=932265&r1=932264&r2=932265&view=diff
==
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
 Fri Apr  9 06:11:51 2010
@@ -30,6 +30,7 @@ import org.apache.camel.component.file.G
 import org.apache.camel.component.file.GenericFileOperations;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StopWatch;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -57,13 +58,13 @@ public class FileLockExclusiveReadLockSt
 // try to acquire rw lock on the file before we can consume it
 FileChannel channel = new RandomAccessFile(target, 
"rw").getChannel();
 
-long start = System.currentTimeMillis();
 boolean exclusive = false;
+StopWatch watch = new StopWatch();
 
 while (!exclusive) {
 // timeout check
 if (timeout > 0) {
-long delta = System.currentTimeMillis() - start;
+long delta = watch.taken();

svn commit: r932258 - /camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/appengine-web.xml

2010-04-08 Thread krasserm
Author: krasserm
Date: Fri Apr  9 05:44:15 2010
New Revision: 932258

URL: http://svn.apache.org/viewvc?rev=932258&view=rev
Log:
use placeholder for GAE application name

Modified:

camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/appengine-web.xml

Modified: 
camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/appengine-web.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/appengine-web.xml?rev=932258&r1=932257&r2=932258&view=diff
==
--- 
camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/appengine-web.xml
 (original)
+++ 
camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/appengine-web.xml
 Fri Apr  9 05:44:15 2010
@@ -18,7 +18,7 @@
 -->
 
 http://appengine.google.com/ns/1.0";>
-   ipfcloud
+   replaceme
1






svn commit: r932255 - in /camel/trunk/examples: ./ camel-example-gauth/ camel-example-gauth/src/ camel-example-gauth/src/main/ camel-example-gauth/src/main/java/ camel-example-gauth/src/main/java/org/

2010-04-08 Thread krasserm
Author: krasserm
Date: Fri Apr  9 05:33:15 2010
New Revision: 932255

URL: http://svn.apache.org/viewvc?rev=932255&view=rev
Log:
CAMEL-2626: OAuth demo webapp.

Added:
camel/trunk/examples/camel-example-gauth/   (with props)
camel/trunk/examples/camel-example-gauth/README.txt   (with props)
camel/trunk/examples/camel-example-gauth/pom.xml   (with props)
camel/trunk/examples/camel-example-gauth/src/
camel/trunk/examples/camel-example-gauth/src/main/
camel/trunk/examples/camel-example-gauth/src/main/java/
camel/trunk/examples/camel-example-gauth/src/main/java/org/
camel/trunk/examples/camel-example-gauth/src/main/java/org/apache/
camel/trunk/examples/camel-example-gauth/src/main/java/org/apache/camel/

camel/trunk/examples/camel-example-gauth/src/main/java/org/apache/camel/example/

camel/trunk/examples/camel-example-gauth/src/main/java/org/apache/camel/example/gauth/

camel/trunk/examples/camel-example-gauth/src/main/java/org/apache/camel/example/gauth/TutorialController.java
   (with props)

camel/trunk/examples/camel-example-gauth/src/main/java/org/apache/camel/example/gauth/TutorialRouteBuilder.java
   (with props)

camel/trunk/examples/camel-example-gauth/src/main/java/org/apache/camel/example/gauth/TutorialService.java
   (with props)

camel/trunk/examples/camel-example-gauth/src/main/java/org/apache/camel/example/gauth/TutorialTokenProcessor.java
   (with props)
camel/trunk/examples/camel-example-gauth/src/main/resources/
camel/trunk/examples/camel-example-gauth/src/main/resources/META-INF/

camel/trunk/examples/camel-example-gauth/src/main/resources/META-INF/LICENSE.txt
   (with props)

camel/trunk/examples/camel-example-gauth/src/main/resources/META-INF/NOTICE.txt 
  (with props)

camel/trunk/examples/camel-example-gauth/src/main/resources/context-camel.xml   
(with props)
camel/trunk/examples/camel-example-gauth/src/main/resources/context-web.xml 
  (with props)

camel/trunk/examples/camel-example-gauth/src/main/resources/context.properties  
 (with props)

camel/trunk/examples/camel-example-gauth/src/main/resources/log4j.properties   
(with props)
camel/trunk/examples/camel-example-gauth/src/main/webapp/
camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/

camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/appengine-web.xml
   (with props)
camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/jsp/

camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/jsp/authorize.jsp
   (with props)

camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/jsp/bottom.jsp 
  (with props)

camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/jsp/calendar.jsp
   (with props)

camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/jsp/top.jsp   
(with props)

camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/logging.properties
   (with props)
camel/trunk/examples/camel-example-gauth/src/main/webapp/WEB-INF/web.xml   
(with props)
camel/trunk/examples/camel-example-gauth/src/main/webapp/images/
camel/trunk/examples/camel-example-gauth/src/main/webapp/images/camel.png   
(with props)
camel/trunk/examples/camel-example-gauth/src/main/webapp/index.html   (with 
props)
Modified:
camel/trunk/examples/pom.xml

Propchange: camel/trunk/examples/camel-example-gauth/
--
--- svn:ignore (added)
+++ svn:ignore Fri Apr  9 05:33:15 2010
@@ -0,0 +1,8 @@
+.checkstyle
+.pmd
+eclipse-classes
+target
+.classpath
+.project
+.settings
+*.i??

Added: camel/trunk/examples/camel-example-gauth/README.txt
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-gauth/README.txt?rev=932255&view=auto
==
--- camel/trunk/examples/camel-example-gauth/README.txt (added)
+++ camel/trunk/examples/camel-example-gauth/README.txt Fri Apr  9 05:33:15 2010
@@ -0,0 +1,14 @@
+GAuth Example
+=
+
+TODO: fill in description and link to tutorial
+
+Please help us make Apache Camel better - we appreciate any feedback you
+may have.
+
+Enjoy!
+
+
+The Camel riders!
+
+

Propchange: camel/trunk/examples/camel-example-gauth/README.txt
--
svn:eol-style = native

Added: camel/trunk/examples/camel-example-gauth/pom.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-gauth/pom.xml?rev=932255&view=auto
==
--- camel/trunk/examples/camel-example-gauth/pom.xml (added)
+++ camel/trunk/examples/camel-example-gauth/pom.xml Fri Apr  9 05:33:15 2010
@@ -0,0 +1,70 @@
+
+http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:sche

[CONF] Apache Camel > Tutorial-OAuth

2010-04-08 Thread confluence







Tutorial-OAuth
Page  added by Martin Krasser

 

 work in progress ...


   
Change Notification Preferences
   
   View Online
  |
   Add Comment
   








[CONF] Apache Camel > Tutorial for Camel on Google App Engine

2010-04-08 Thread confluence







 Tutorial for Camel on Google App Engine
 Page edited by Martin Krasser

 
  
 
 Camel on Google App Engine Tutorial

Overview

Goal of this tutorial is to get a non-trivial Camel application running on Google App Engine (GAE). For developing that application the Camel Components for Google App Engine are used. The example web application generates a weather report for a city that is entered by the user into a form and sends the weather report via email to either the currently logged-in user or a user-defined receiver. The following figure gives an overview. Users of this application need to login with their Google account.



POSTed form data are dispatched to the Camel application via the ghttp component. The application transforms the report request and enqueues it with the gtask component for further background processing. It then generates an immediate HTML response containing information about the city and the receiver of the report. The response also contains a link logging out from the application. In the background, the application retrieves weather data from the Google Weather Service, transforms the data to generate a simple weather report and sends the report by email via the gmail component. 

Java clientsClients other than web browsers may also interact with this application by POSTing the form data and an authentication cookie. At the moment the example application doesn't include a standalone Java client that demonstrates how to do that. This is work in progress. In the meantime, refer to this blog post for instructions how to access security-enabled GAE services using the Google ClientLogin API. 

Tutorial onlineThe next two sections describe how to checkout, build and deploy the example application. If you want to skip these steps, go directly to the Usage section and use the pre-deployed example application at http://camelcloud.appspot.com.

Prerequisites


	Sign up  for a Google App Engine accountif you don't have one.
	Create a new application via the admin console or reuse an existing one for uploading the example.
	Install the Google App Engine SDK for Java. This tutorial has been tested with version 1.3.2.



Deployment

First, checkout the sources from the Camel code repository.


svn co http://svn.apache.org/repos/asf/camel/trunk/examples/camel-example-gae camel-example-gae



Open the camel-example-gae/src/main/webapp/WEB-INF/application-web.xml file and replace the template application name replaceme with the name of the application that you created in the previous section. Optionally, adjust the version number if needed.

appengine-web.xml

"1.0" encoding="utf-8"?>
"http://appengine.google.com/ns/1.0">

replaceme
1
	

"/index.html" />



"java.util.logging.config.file" value="WEB-INF/logging.properties"/>

	




Then go to the camel-example-gae directory and enter


mvn install



This will create the application war file in the target directory. Finally use the appcfg command-line tool of the App Engine SDK to deploy the application.


appcfg update target/camel-example-gae-



where version needs to be replaced with the version of Camel you're using. You will be prompted for the email address and password of your Google App Engine account. After deployment the example application is ready to use. 

Usage

In the following, the application name camelcloud will be used as an example. If you deployed the example application somewhere else, use your application name instead. Go to http://camelcloud.appspot.com. The application will redirect you to a login page (see also Security for Camel GAE Applications). 



After login, the application displays the tutorial's main page where you can enter the name of a city and optionally enter an email address where to send the waether report. If you check Send report to me the report will be send to the email address that you used for login.



After pressing Submit the response is 



The home link brings you back to the main page, the logout link is to logout from the application (which brings you back to the login page). In the background, the current weather conditions for the user-entered city will be retrieved from the Google weather service and a formatted weather report will be send by email. Submitting the form the first time initializes the application on Google App Engine which can take several seconds. Subsequent submissions (within a certain time frame) are served much faster. Check your emails and you should now see a new email with subject Wheather report and content similar to this one:


Weather report for:  London, England
Current condition:   Klar
Current temperature: 12 (Celsius) 



The report is partly internationalized, depending on the language settings of your browser.

Code walkthrough

The TutorialRouteBuilder implements the message processing routes shown in the Overview section. Input form data are received via the

svn commit: r932250 - in /camel/trunk/examples/camel-example-gae: pom.xml src/main/webapp/WEB-INF/lib/

2010-04-08 Thread krasserm
Author: krasserm
Date: Fri Apr  9 05:07:17 2010
New Revision: 932250

URL: http://svn.apache.org/viewvc?rev=932250&view=rev
Log:
get rid of checked-in jars (required GAE SDK dependencies now in central Maven 
repository).

Removed:
camel/trunk/examples/camel-example-gae/src/main/webapp/WEB-INF/lib/
Modified:
camel/trunk/examples/camel-example-gae/pom.xml

Modified: camel/trunk/examples/camel-example-gae/pom.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-gae/pom.xml?rev=932250&r1=932249&r2=932250&view=diff
==
--- camel/trunk/examples/camel-example-gae/pom.xml (original)
+++ camel/trunk/examples/camel-example-gae/pom.xml Fri Apr  9 05:07:17 2010
@@ -20,6 +20,11 @@
 camel-gae
 
 
+com.google.appengine.orm
+datanucleus-appengine
+1.0.5
+
+
 com.sun.xml.bind
 jaxb-impl
 runtime




svn commit: r932246 - in /camel/trunk/components/camel-gae/src: main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java test/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding

2010-04-08 Thread krasserm
Author: krasserm
Date: Fri Apr  9 05:01:26 2010
New Revision: 932246

URL: http://svn.apache.org/viewvc?rev=932246&view=rev
Log:
proper handling of non-existing access tokens

Modified:

camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java

camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthUpgradeBindingTest.java

Modified: 
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java?rev=932246&r1=932245&r2=932246&view=diff
==
--- 
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java
 (original)
+++ 
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java
 Fri Apr  9 05:01:26 2010
@@ -40,6 +40,11 @@ public class GAuthUpgradeBinding impleme
 public static final String GAUTH_ACCESS_TOKEN_SECRET = 
"CamelGauthAccessTokenSecret";
 
 /**
+ * Default value for access token and access token secret in 
GoogleOAuthParameters
+ */
+private static final String EMPTY_TOKEN = "";
+
+/**
  * Creates a {...@link GoogleOAuthParameters} object from endpoint and
  * exchange.getIn() data. The created parameter object is used
  * to upgrade an authorized request token to an access token. If the
@@ -90,9 +95,19 @@ public class GAuthUpgradeBinding impleme
  */
 public Exchange readResponse(GAuthEndpoint endpoint, Exchange exchange, 
GoogleOAuthParameters response) throws IOException {
 exchange.getOut().setHeaders(exchange.getIn().getHeaders());
-exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN, 
response.getOAuthToken());
-exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN_SECRET, 
response.getOAuthTokenSecret());
+exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN, 
canonicalizeToken(response.getOAuthToken()));
+exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN_SECRET, 
canonicalizeToken(response.getOAuthTokenSecret()));
 return exchange;
 }
 
+private static String canonicalizeToken(String token) {
+if (token == null) {
+return null;
+} else if (EMPTY_TOKEN.equals(token)) {
+return null;
+} else {
+return token;
+}
+}
+
 }

Modified: 
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthUpgradeBindingTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthUpgradeBindingTest.java?rev=932246&r1=932245&r2=932246&view=diff
==
--- 
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthUpgradeBindingTest.java
 (original)
+++ 
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthUpgradeBindingTest.java
 Fri Apr  9 05:01:26 2010
@@ -28,6 +28,7 @@ import static org.apache.camel.component
 import static 
org.apache.camel.component.gae.auth.GAuthUpgradeBinding.GAUTH_ACCESS_TOKEN;
 import static 
org.apache.camel.component.gae.auth.GAuthUpgradeBinding.GAUTH_ACCESS_TOKEN_SECRET;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 public class GAuthUpgradeBindingTest {
 
@@ -81,4 +82,12 @@ public class GAuthUpgradeBindingTest {
 assertEquals("tokenSecret2", 
exchange.getOut().getHeader(GAUTH_ACCESS_TOKEN_SECRET));
 }
 
+@Test
+public void testReadResponseNoToken() throws Exception {
+GoogleOAuthParameters params = new GoogleOAuthParameters();
+binding.readResponse(endpoint, exchange, params);
+assertNull(exchange.getOut().getHeader(GAUTH_ACCESS_TOKEN));
+assertNull(exchange.getOut().getHeader(GAUTH_ACCESS_TOKEN_SECRET));
+}
+
 }




svn commit: r931845 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/processor/aggregate/ camel-core/src/test/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/pro

2010-04-08 Thread davsclaus
Author: davsclaus
Date: Thu Apr  8 09:20:19 2010
New Revision: 931845

URL: http://svn.apache.org/viewvc?rev=931845&view=rev
Log:
CAMEL-2568: Polished aggregator and fixed a timeout in some rare cases could 
send the last and not aggregated exchange.

Added:

camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateGroupedExchangeSizePredicateTest.java
   (with props)

camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateGroupedExchangeSizeTest.java
  - copied, changed from r931784, 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateGroupedExchangeTest.java

camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregatorTest.java
   (contents, props changed)
  - copied, changed from r931784, 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorTest.java
Removed:

camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorTest.java
Modified:

camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java

camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BodyInAggregatingStrategy.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java?rev=931845&r1=931844&r2=931845&view=diff
==
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
 Thu Apr  8 09:20:19 2010
@@ -81,7 +81,8 @@ public class AggregateProcessor extends 
 private final Expression correlationExpression;
 private final ExecutorService executorService;
 private ScheduledExecutorService recoverService;
-private TimeoutMap timeoutMap;
+// store correlation key -> exchange id in timeout map
+private TimeoutMap timeoutMap;
 private ExceptionHandler exceptionHandler = new 
LoggingExceptionHandler(getClass());
 private AggregationRepository aggregationRepository = new 
MemoryAggregationRepository();
 private Map closedCorrelationKeys;
@@ -203,7 +204,7 @@ public class AggregateProcessor extends 
 }
 
 // check if we are complete
-boolean complete = false;
+String complete = null;
 if (isEagerCheckCompletion()) {
 // put the current aggregated size on the exchange so its avail 
during completion check
 newExchange.setProperty(Exchange.AGGREGATED_SIZE, size);
@@ -224,14 +225,13 @@ public class AggregateProcessor extends 
 }
 
 // only need to update aggregation repository if we are not complete
-if (!complete) {
+if (complete == null) {
 if (LOG.isTraceEnabled()) {
 LOG.trace("In progress aggregated exchange: " + answer + " 
with correlation key:" + key);
 }
 aggregationRepository.add(exchange.getContext(), key, answer);
-}
-
-if (complete) {
+} else {
+answer.setProperty(Exchange.AGGREGATED_COMPLETED_BY, complete);
 onCompletion(key, answer, false);
 }
 
@@ -242,12 +242,18 @@ public class AggregateProcessor extends 
 return answer;
 }
 
-protected boolean isCompleted(Object key, Exchange exchange) {
+/**
+ * Tests whether the given exchange is complete or not
+ *
+ * @param key   the correlation key
+ * @param exchange  the incoming exchange
+ * @return null if not completed, otherwise a String with the 
type that triggered the completion
+ */
+protected String isCompleted(Object key, Exchange exchange) {
 if (getCompletionPredicate() != null) {
 boolean answer = getCompletionPredicate().matches(exchange);
 if (answer) {
-exchange.setProperty(Exchange.AGGREGATED_COMPLETED_BY, 
"predicate");
-return true;
+return "predicate";
 }
 }
 
@@ -256,16 +262,14 @@ public class AggregateProcessor extends 
 if (value != null && value > 0) {
 int size = exchange.getProperty(Exchange.AGGREGATED_SIZE, 1, 
Integer.class);
 if (size >= value) {
-exchange.setProperty(Exchange.AGGREGATED_COMPLETED_BY, 
"size");
-return true;
+return "size";
 }
 }
 }
 if (getCompletionSize() > 0) {
 int size = exchange.getProperty(Exchange.AGGREGATED_SIZE, 1, 
Integer.class);
 if (size >= getCompletionSize()) {
- 

svn commit: r931804 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/processor/aggregate/ camel-core/src/test/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/pro

2010-04-08 Thread davsclaus
Author: davsclaus
Date: Thu Apr  8 07:22:39 2010
New Revision: 931804

URL: http://svn.apache.org/viewvc?rev=931804&view=rev
Log:
CAMEL-2568: Reworked lock on Aggregator a bit.

Added:

camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateShouldSkipFilteredExchangesTest.java
   (contents, props changed)
  - copied, changed from r931784, 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregateShouldSkipFilteredExchanges.java

camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorTest.java
   (contents, props changed)
  - copied, changed from r931784, 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java
Removed:

camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregateShouldSkipFilteredExchanges.java

camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AggregatorTest.java
Modified:

camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java

camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateCompletionPredicateTest.java

camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateConcurrentDifferentGroupsTest.java

camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateConcurrentSameGroupTest.java

camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadAndRecoverTest.java

camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadConcurrentTest.java

camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadTest.java

camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/util/SpringAntPathMatcherFileFilter.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java?rev=931804&r1=931803&r2=931804&view=diff
==
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
 Thu Apr  8 07:22:39 2010
@@ -27,6 +27,8 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelExchangeException;
@@ -37,7 +39,6 @@ import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.LoggingExceptionHandler;
 import org.apache.camel.impl.ServiceSupport;
-import org.apache.camel.processor.RedeliveryPolicy;
 import org.apache.camel.processor.Traceable;
 import org.apache.camel.spi.AggregationRepository;
 import org.apache.camel.spi.ExceptionHandler;
@@ -73,6 +74,7 @@ public class AggregateProcessor extends 
 
 private static final Log LOG = LogFactory.getLog(AggregateProcessor.class);
 
+private final Lock lock = new ReentrantLock();
 private final CamelContext camelContext;
 private final Processor processor;
 private final AggregationStrategy aggregationStrategy;
@@ -164,7 +166,15 @@ public class AggregateProcessor extends 
 throw new ClosedCorrelationKeyException(key, exchange);
 }
 
-doAggregation(key, exchange);
+// when memory based then its fast using synchronized, but if the 
aggregation repository is IO
+// bound such as JPA etc then concurrent aggregation per correlation 
key could
+// improve performance as we can run aggregation repository get/add in 
parallel
+try {
+lock.lock();
+doAggregation(key, exchange);
+} finally {
+lock.unlock();
+}
 }
 
 /**
@@ -177,11 +187,7 @@ public class AggregateProcessor extends 
  * @param exchange the exchange
  * @return the aggregated exchange
  */
-private synchronized Exchange doAggregation(Object key, Exchange exchange) 
{
-// when memory based then its fast using synchronized, but if the 
aggregation repository is IO
-// bound such as JPA etc then concurrent aggregation per correlation 
key could
-// improve performance as we can run aggregation repository get/add in 
parallel
-
+private Exchange doAggregation(Object key, Exchange exchange) {
 if (LOG.isTraceEnabled()) {
 LOG.trace("onAggregation +++ start +++ with correlation key: " + 
key