?????????????????????????????????????HTTP??FTP??SOCKET?????????????????
???????????BackupServiceExecuter????????????????????????????????BackupFileSenderExecuter??send???????????????????£?
boolean result = backupService.backup();
//????????????????????????????
if(result){
backupFileSenderExecuter.send(getNewestBackupFile());
}
????BackupFileSenderExecuter??????BackupServiceExecuter???????????????????????????ж??Sender?????????????е?Sender??????ж????????????BackupFileSenderExecuter??????????log.backup.file.sender??????????????ЩSender???????ε??????Sender??send???????????????????????????
????log.backup.file.sender=localBackupFileSender;
???????? localBackupFileSender??LocalBackupFileSender??Spring Bean?????
/**
*??б????????????????????????????ж??????Щ??????????????????????????ε???
* @author ???д?
*/
@Service
public class BackupFileSenderExecuter  implements  BackupFileSender?? ApplicationListener{
protected final APDPlatLogger LOG = new APDPlatLogger(getClass());
private static final List<BackupFileSender> backupFileSenders = new LinkedList<>();
@Override
public void send(File file) {
for(BackupFileSender sender : backupFileSenders){
sender.send(file);
}
}
@Override
public void onApplicationEvent(ApplicationEvent event){
if(event instanceof ContextRefreshedEvent){
LOG.info("spring????????????????????BackupFileSender");
String senderstr = PropertyHolder.getProperty("log.backup.file.sender");
if(StringUtils.isBlank(senderstr)){
LOG.info("δ????log.backup.file.sender");
return;
}
LOG.info("log.backup.file.sender??"+senderstr);
String[] senders = senderstr.trim().split(";");
for(String sender : senders){
BackupFileSender backupFileSender = SpringContextUtils.getBean(sender.trim());
if(backupFileSender != null){
backupFileSenders.add(backupFileSender);
LOG.info("???BackupFileSender??"+sender);
}else{
LOG.info("δ???BackupFileSender??"+sender);
}
}
}
}
}
?????????????????????????LocalBackupFileSender??
/**
* ???????????????????????????????
* @author ???д?
*/
@Service
public class LocalBackupFileSender implements BackupFileSender{
protected final APDPlatLogger LOG = new APDPlatLogger(getClass());
@Override
public void send(File file) {
try {
String dist = PropertyHolder.getProperty("log.backup.file.local.dir");
LOG.info("?????????"+file.getAbsolutePath());
LOG.info("???????"+dist);
FileUtils.copyFile(file?? new File(dist??file.getName()));
} catch (IOException ex) {
LOG.info("LocalBackupFileSender???"?? ex);
}
}
}