I have the following sftp
bean Id configured in my spring application-context
file. It defines two sftp targets which my application is to send different types of files to:
<bean id="targetA"
class="com.sftp.Sender">
<constructor-arg value="${A.host}"/>
<constructor-arg value="${A.username}"/>
<constructor-arg value="${A.remoteDir}"/>
<constructor-arg value="${A.notificationDir}"/>
</bean>
<bean id="targetB" class="com.sftp.Sender">
<constructor-arg value="${B.host}"/>
<constructor-arg value="${B.username}"/>
<constructor-arg value="${B.remoteDir}"/>
</bean>
My main
class looks something like this:
public class Main {
Occ occ= ctx.getBean("occ", Occ.class);
public static void main(String[] args) {
if (args != null && args.length >= 1) {
String target = args[0];
occ.rePublish(target);
} else {
String target = "Both";
orc.processReports(target);
}
}
My Occ
class something like this:
public class Occ {
public void rePublish(String target) {
processReports(target);
}
public void processReports(String target) {
// determines who the target is and prepare the appropriate
// file to send to that target
if (target.equal("Both")) {
// prepare both target A and B files
}
}
}
Generally, when the program is executed, it should prepare both sets of files for both target A and target B. In certain scenarios, one transfer may fail and I want to be able to prepare and distribute files for just that target. I can only think of passing in the resend target as arguments
in main
method. But is this the best way to do this? What are your thoughts and how would you do it? Can I restructure the above code in other better ways?
Aucun commentaire:
Enregistrer un commentaire