You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/05/25 10:50:10 UTC
svn commit: r778354 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/component/file/
camel-core/src/test/java/org/apache/camel/component/file/
components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/
components/camel-ftp/s...
Author: davsclaus
Date: Mon May 25 08:50:09 2009
New Revision: 778354
URL: http://svn.apache.org/viewvc?rev=778354&view=rev
Log:
CAMEL-1641: Ftp producer concurrent fixes. Requires CAMEL-1644 to be fully fixed.
Added:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerConcurrentTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveExpressionTest.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpComponent.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java Mon May 25 08:50:09 2009
@@ -39,10 +39,6 @@
config.setDirectory(file.getPath());
result.setConfiguration(config);
- FileOperations operations = new FileOperations();
- operations.setEndpoint(result);
- result.setOperations(operations);
-
return result;
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java Mon May 25 08:50:09 2009
@@ -88,14 +88,6 @@
return new GenericFileExchange(this);
}
- public FileOperations getOperations() {
- return operations;
- }
-
- public void setOperations(FileOperations operations) {
- this.operations = operations;
- }
-
public File getFile() {
return file;
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java Mon May 25 08:50:09 2009
@@ -50,7 +50,6 @@
protected final transient Log log = LogFactory.getLog(getClass());
protected GenericFileProcessStrategy<T> processStrategy;
- protected GenericFileOperations<T> operations;
protected GenericFileConfiguration configuration;
protected String localWorkDirectory;
@@ -369,14 +368,6 @@
this.autoCreate = autoCreate;
}
- public GenericFileOperations<T> getOperations() {
- return operations;
- }
-
- public void setOperations(GenericFileOperations<T> operations) {
- this.operations = operations;
- }
-
public GenericFileProcessStrategy<T> getProcessStrategy() {
return processStrategy;
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveExpressionTest.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveExpressionTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerMoveExpressionTest.java Mon May 25 08:50:09 2009
@@ -142,7 +142,6 @@
FileEndpoint endpoint = new FileEndpoint();
endpoint.setCamelContext(context);
endpoint.setFile(new File("target/filelanguage/"));
- endpoint.setOperations(new FileOperations(endpoint));
endpoint.setAutoCreate(false);
endpoint.setMove(BeanLanguage.bean("myguidgenerator"));
endpoint.setExclude(".*bak");
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpComponent.java Mon May 25 08:50:09 2009
@@ -49,11 +49,7 @@
// must pass on baseUri to the configuration (see above)
FtpConfiguration config = new FtpConfiguration(new URI(baseUri));
- FtpOperations operations = new FtpOperations();
- FtpEndpoint result = new FtpEndpoint(uri, this, operations, config);
- operations.setEndpoint(result);
-
- return result;
+ return new FtpEndpoint(uri, this, config);
}
protected void afterPropertiesSet(GenericFileEndpoint<FTPFile> endpoint) throws Exception {
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpEndpoint.java Mon May 25 08:50:09 2009
@@ -17,6 +17,7 @@
package org.apache.camel.component.file.remote;
import org.apache.camel.Processor;
+import org.apache.camel.component.file.GenericFileProducer;
import org.apache.commons.net.ftp.FTPFile;
/**
@@ -25,24 +26,29 @@
public class FtpEndpoint extends RemoteFileEndpoint<FTPFile> {
public FtpEndpoint() {
- FtpOperations operations = new FtpOperations();
- operations.setEndpoint(this);
- this.operations = operations;
}
- public FtpEndpoint(String uri, FtpComponent component, FtpOperations operations,
- RemoteFileConfiguration configuration) {
- super(uri, component, operations, configuration);
+ public FtpEndpoint(String uri, FtpComponent component, RemoteFileConfiguration configuration) {
+ super(uri, component, configuration);
}
@Override
- protected RemoteFileConsumer<FTPFile> buildConsumer(Processor processor, RemoteFileOperations<FTPFile> operations) {
- return new FtpConsumer(this, processor, operations);
+ protected RemoteFileConsumer<FTPFile> buildConsumer(Processor processor) {
+ return new FtpConsumer(this, processor, createRemoteFileOperations());
+ }
+
+ protected GenericFileProducer<FTPFile> buildProducer() {
+ return new RemoteFileProducer<FTPFile>(this, createRemoteFileOperations());
+ }
+
+ protected RemoteFileOperations<FTPFile> createRemoteFileOperations() {
+ FtpOperations operations = new FtpOperations();
+ operations.setEndpoint(this);
+ return operations;
}
@Override
public String getScheme() {
return "ftp";
}
-
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java Mon May 25 08:50:09 2009
@@ -59,6 +59,10 @@
}
public boolean connect(RemoteFileConfiguration config) throws GenericFileOperationFailedException {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Connecting using FTPClient: " + client);
+ }
+
String host = config.getHost();
int port = config.getPort();
String username = config.getUsername();
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java Mon May 25 08:50:09 2009
@@ -33,10 +33,8 @@
// no args constructor for spring bean endpoint configuration
}
- public RemoteFileEndpoint(String uri, RemoteFileComponent<T> component, RemoteFileOperations<T> operations,
- RemoteFileConfiguration configuration) {
+ public RemoteFileEndpoint(String uri, RemoteFileComponent<T> component, RemoteFileConfiguration configuration) {
super(uri, component);
- this.operations = operations;
this.configuration = configuration;
}
@@ -56,13 +54,13 @@
@Override
public GenericFileProducer<T> createProducer() throws Exception {
afterPropertiesSet();
- return new RemoteFileProducer<T>(this, (RemoteFileOperations<T>) this.operations);
+ return buildProducer();
}
@Override
public RemoteFileConsumer<T> createConsumer(Processor processor) throws Exception {
afterPropertiesSet();
- RemoteFileConsumer<T> consumer = buildConsumer(processor, (RemoteFileOperations<T>) operations);
+ RemoteFileConsumer<T> consumer = buildConsumer(processor);
// we assume its a file if the name has a dot in it (eg foo.txt)
if (configuration.getDirectory().contains(".")) {
@@ -95,7 +93,6 @@
* @throws Exception is thrown if endpoint is invalid configured for its mandatory options
*/
protected void afterPropertiesSet() throws Exception {
- ObjectHelper.notNull(operations, "operations");
RemoteFileConfiguration config = (RemoteFileConfiguration) getConfiguration();
ObjectHelper.notEmpty(config.getHost(), "host");
ObjectHelper.notEmpty(config.getProtocol(), "protocol");
@@ -108,10 +105,16 @@
* Remote File Endpoints, impl this method to create a custom consumer specific to their "protocol" etc.
*
* @param processor the processor
- * @param operations the operations
* @return the created consumer
*/
- protected abstract RemoteFileConsumer<T> buildConsumer(Processor processor, RemoteFileOperations<T> operations);
+ protected abstract RemoteFileConsumer<T> buildConsumer(Processor processor);
+
+ /**
+ * Remote File Endpoints, impl this method to create a custom producer specific to their "protocol" etc.
+ *
+ * @return the created producer
+ */
+ protected abstract GenericFileProducer<T> buildProducer();
/**
* Returns human readable server information for logging purpose
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileProducer.java Mon May 25 08:50:09 2009
@@ -20,6 +20,7 @@
import java.io.IOException;
import org.apache.camel.Exchange;
+import org.apache.camel.IsSingleton;
import org.apache.camel.component.file.GenericFileExchange;
import org.apache.camel.component.file.GenericFileOperationFailedException;
import org.apache.camel.component.file.GenericFileProducer;
@@ -29,7 +30,7 @@
* Remote file producer. Handles connecting and disconnecting if we are not.
* Generic type F is the remote system implementation of a file.
*/
-public class RemoteFileProducer<T> extends GenericFileProducer<T> {
+public class RemoteFileProducer<T> extends GenericFileProducer<T> implements IsSingleton {
private boolean loggedIn;
@@ -122,4 +123,8 @@
}
}
+ public boolean isSingleton() {
+ // this producer is stateful because the remote file operations is not thread safe
+ return false;
+ }
}
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpComponent.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpComponent.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpComponent.java Mon May 25 08:50:09 2009
@@ -49,10 +49,7 @@
// customize its own version
SftpConfiguration config = new SftpConfiguration(new URI(baseUri));
- SftpOperations operations = new SftpOperations();
- SftpEndpoint result = new SftpEndpoint(uri, this, operations, config);
- operations.setEndpoint(result);
- return result;
+ return new SftpEndpoint(uri, this, config);
}
protected void afterPropertiesSet(GenericFileEndpoint<ChannelSftp.LsEntry> endpoint) throws Exception {
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java?rev=778354&r1=778353&r2=778354&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpEndpoint.java Mon May 25 08:50:09 2009
@@ -18,7 +18,7 @@
import com.jcraft.jsch.ChannelSftp;
import org.apache.camel.Processor;
-
+import org.apache.camel.component.file.GenericFileProducer;
/**
* Secure FTP endpoint
@@ -26,20 +26,25 @@
public class SftpEndpoint extends RemoteFileEndpoint<ChannelSftp.LsEntry> {
public SftpEndpoint() {
- SftpOperations operations = new SftpOperations();
- operations.setEndpoint(this);
- this.operations = operations;
}
- public SftpEndpoint(String uri, SftpComponent component, RemoteFileOperations<ChannelSftp.LsEntry> operations,
- RemoteFileConfiguration configuration) {
- super(uri, component, operations, configuration);
+ public SftpEndpoint(String uri, SftpComponent component, RemoteFileConfiguration configuration) {
+ super(uri, component, configuration);
}
@Override
- protected RemoteFileConsumer<ChannelSftp.LsEntry> buildConsumer(Processor processor,
- RemoteFileOperations<ChannelSftp.LsEntry> operations) {
- return new SftpConsumer(this, processor, operations);
+ protected RemoteFileConsumer<ChannelSftp.LsEntry> buildConsumer(Processor processor) {
+ return new SftpConsumer(this, processor, createRemoteFileOperations());
+ }
+
+ protected GenericFileProducer<ChannelSftp.LsEntry> buildProducer() {
+ return new RemoteFileProducer<ChannelSftp.LsEntry>(this, createRemoteFileOperations());
+ }
+
+ protected RemoteFileOperations<ChannelSftp.LsEntry> createRemoteFileOperations() {
+ SftpOperations operations = new SftpOperations();
+ operations.setEndpoint(this);
+ return operations;
}
@Override
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerConcurrentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerConcurrentTest.java?rev=778354&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerConcurrentTest.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerConcurrentTest.java Mon May 25 08:50:09 2009
@@ -0,0 +1,75 @@
+/**
+ * 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.component.file.remote;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Concurrent producers test.
+ *
+ * @version $Revision$
+ */
+public class FtpProducerConcurrentTest extends FtpServerTestSupport {
+
+ private String getFtpUrl() {
+ return "ftp://admin@localhost:" + getPort() + "/concurrent?binary=false&password=admin";
+ }
+
+ public void testNoConcurrentProducers() throws Exception {
+ doSendMessages(1, 1);
+ }
+
+ public void testConcurrentProducers() throws Exception {
+ // TODO: Bug CAMEL-1641 is fixed by CAMEL-1644
+ // doSendMessages(10, 5);
+ }
+
+ private void doSendMessages(int files, int poolSize) throws Exception {
+ deleteDirectory("res/home/concurrent");
+
+ getMockEndpoint("mock:result").expectedMessageCount(files);
+
+ ExecutorService executor = Executors.newFixedThreadPool(poolSize);
+ for (int i = 0; i < files; i++) {
+ getMockEndpoint("mock:result").expectedFileExists("res/home/concurrent/" + i + ".txt");
+
+ final int index = i;
+ executor.submit(new Callable<Object>() {
+ public Object call() throws Exception {
+ sendFile("direct:start", "Hello World", index + ".txt");
+ return null;
+ }
+ });
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to(getFtpUrl(), "mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerConcurrentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerConcurrentTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date