Added FileTargetAdapter.

This commit is contained in:
Mark Fisher
2008-01-03 03:24:01 +00:00
parent 4d7a0bae5a
commit 4404d5a260
2 changed files with 57 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed 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.springframework.integration.adapter.file;
import java.io.File;
import org.springframework.integration.adapter.DefaultTargetAdapter;
import org.springframework.integration.adapter.Target;
/**
* A convenience adapter for writing files. The actual file writing occurs in
* the message mapper ({@link TextFileMapper} or {@link ByteArrayFileMapper}).
*
* @author Mark Fisher
*/
public class FileTargetAdapter extends DefaultTargetAdapter {
public FileTargetAdapter(File directory) {
this(directory, true);
}
public FileTargetAdapter(File directory, boolean isTextBased) {
super(new FileTarget());
if (isTextBased) {
this.setMessageMapper(new TextFileMapper(directory));
}
else {
this.setMessageMapper(new ByteArrayFileMapper(directory));
}
}
private static class FileTarget implements Target<File> {
public boolean send(File file) {
return file.exists();
}
}
}

View File

@@ -199,6 +199,9 @@ public class MessageBus implements ChannelRegistry, ApplicationContextAware, Lif
UnicastMessageDispatcher dispatcher = new UnicastMessageDispatcher(retriever, policy);
dispatcher.addExecutor(new MessageReceivingExecutor(adapter, policy.getConcurrency(), policy.getMaxConcurrency()));
this.addDispatcherTask(new DispatcherTask(dispatcher, policy));
if (logger.isInfoEnabled()) {
logger.info("registered target adapter '" + name + "'");
}
}
}