List of usage examples for org.apache.commons.io.monitor FileAlterationMonitor FileAlterationMonitor
public FileAlterationMonitor(long interval)
From source file:com.stefanbrenner.droplet.service.impl.XMPMetadataService.java
/** * Creates a new xmp metadata service./*from w w w. jav a 2 s. c o m*/ * * @param metadata * to be used * @param dropletContext * to be used */ public XMPMetadataService(final IMetadata metadata, final IDropletContext dropletContext) { this.metadata = metadata; this.dropletContext = dropletContext; this.monitor = new FileAlterationMonitor(INTERVAL); }
From source file:com.moneydance.modules.features.importlist.io.FileAdmin.java
public FileAdmin(final String baseDirectory, final FeatureModuleContext argContext) { this.localizable = Helper.INSTANCE.getLocalizable(); this.context = argContext; if (SystemUtils.IS_OS_MAC) { this.directoryChooser = new MacOSDirectoryChooser(baseDirectory); } else {//from www. jav a 2s.co m this.directoryChooser = new DefaultDirectoryChooser(baseDirectory); } this.directoryValidator = DirectoryValidator.INSTANCE; this.transactionFileFilter = new SuffixFileFilter( Helper.INSTANCE.getSettings().getTransactionFileExtensions(), IOCase.INSENSITIVE); this.textFileFilter = new SuffixFileFilter(Helper.INSTANCE.getSettings().getTextFileExtensions(), IOCase.INSENSITIVE); this.readableFileFilter = FileFilterUtils.and(CanReadFileFilter.CAN_READ, FileFilterUtils.or(this.transactionFileFilter, this.textFileFilter)); this.listener = new TransactionFileListener(); this.listener.addObserver(this); this.monitor = new FileAlterationMonitor(Helper.INSTANCE.getSettings().getMonitorInterval()); this.files = Collections.synchronizedList(new ArrayList<File>()); }
From source file:com.jkoolcloud.tnt4j.streams.custom.dirStream.DirWatchdog.java
private void initialize() { observer = new FileAlterationObserver(new File(dirPath), filter); monitor = new FileAlterationMonitor(interval); monitor.addObserver(observer);/* ww w .ja va2 s . co m*/ }
From source file:com.chigix.autosftp.Application.java
public static void watchDir(Path dir) throws Exception { // The monitor will perform polling on the folder every 5 seconds final long pollingInterval = 5 * 1000; File folder = dir.toFile();//www .ja v a 2 s .c om if (!folder.exists()) { // Test to see if monitored folder exists throw new FileNotFoundException("Directory not found: " + dir); } FileAlterationObserver observer = new FileAlterationObserver(folder); FileAlterationMonitor monitor = new FileAlterationMonitor(pollingInterval); FileAlterationListener listener = new FileAlterationListenerAdaptor() { // Is triggered when a file is created in the monitored folder @Override public void onFileCreate(File file) { Path relativePath = localPath.toAbsolutePath().normalize() .relativize(file.getAbsoluteFile().toPath().normalize()); System.out.println("File created: " + relativePath); final String destPath = remotePath.resolve(relativePath).normalize().toString().replace('\\', '/'); ArrayList<String> lackDirs = new ArrayList<>(); String tmpParentPath = destPath; while (!tmpParentPath.equals("/") && !tmpParentPath.equals("\\")) { tmpParentPath = new File(tmpParentPath).getParentFile().toPath().toString().replace('\\', '/'); try { sftpChannel.cd(tmpParentPath); } catch (SftpException ex) { if (ex.id == SSH_FX_NO_SUCH_FILE) { lackDirs.add(tmpParentPath); continue; } Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); return; } break; } for (int i = lackDirs.size() - 1; i > -1; i--) { try { sftpChannel.mkdir(lackDirs.get(i)); } catch (SftpException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); System.err.println(destPath + " Creating Fail."); return; } } InputStream fi = null; try { fi = new FileInputStream(file); sftpChannel.put(fi, destPath, 644); } catch (FileNotFoundException ex) { System.out.println("File: " + file.getAbsolutePath() + " not exists."); return; } catch (SftpException ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); return; } finally { if (fi != null) { try { fi.close(); } catch (IOException ex) { } } } System.out.println("File Uploaded: " + destPath); } // Is triggered when a file is deleted from the monitored folder @Override public void onFileDelete(File file) { if (file.exists()) { return; } Path relativePath = localPath.toAbsolutePath().normalize() .relativize(file.getAbsoluteFile().toPath().normalize()); System.out.println("File Deleted: " + relativePath); final String destPath = remotePath.resolve(relativePath).normalize().toString().replace('\\', '/'); try { sftpChannel.rm(destPath); } catch (SftpException ex) { if (ex.id == SSH_FX_NO_SUCH_FILE) { } else { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); } } System.out.println("Remote Deleted: " + relativePath); } @Override public void onFileChange(File file) { this.onFileCreate(file); } }; observer.addListener(listener); monitor.addObserver(observer); monitor.start(); }
From source file:com.bcmcgroup.flare.client.PublisherOutbox11.java
/** * Establishes a directory watch service that will publish STIX XML files that are placed into it. This will not account for overwrites. * * @param dir Directory to watch for STIX content to be published. * */// w ww . j ava2 s .c o m private PublisherOutbox11(final File dir) { logger.info("Outbox is awaiting files..."); // The monitor will perform polling on the folder every 2 seconds final long pollingInterval = 2000; // Create an observer, monitor, and listener to watch for directory changes FileAlterationObserver observer = new FileAlterationObserver(dir); FileAlterationMonitor monitor = new FileAlterationMonitor(pollingInterval); FileAlterationListener listener = new FileAlterationListenerAdaptor() { private String collectionName; // Is triggered when a file is created in the monitored folder. Works recursively, and ignores publishFeeds. @Override public void onFileCreate(File file) { List<ContentBlock> contentBlocks = new ArrayList<>(); // Do nothing if dropping files into the publishFeeds directory if (file.getParentFile().getName().equals("publishFeeds")) { return; } try { this.collectionName = file.getParentFile().getName(); String contentBinding = ClientUtil.getContentBinding(file); // Form a content block and ensure it passes STIX validation ContentBlock contentBlock = new ContentBlock(contentBinding, file, null, null, null); contentBlocks.add(contentBlock); int responseCode = publish(this.collectionName, null, null, contentBlocks); if (responseCode != 0) { logger.info(file.getName() + " " + responseCode); } else { logger.warn("Error publishing " + file.getName() + " to collection " + this.collectionName); } } catch (IOException e) { logger.error("IOException when trying to publish " + file.getName()); } catch (SAXException e) { logger.error("SAXException when trying to publish " + file.getName()); } } }; // Start the directory watch service observer.addListener(listener); monitor.addObserver(observer); try { monitor.start(); logger.info("Directory monitoring service has started and is awaiting files..."); logger.debug("Monitor started..."); } catch (Exception e) { logger.error("General exception thrown when trying to start the directory monitor..."); } }
From source file:com.bcmcgroup.flare.client.PublisherOutbox10.java
/** * Establishes a directory watch service that will publish STIX XML files that are placed into it. This will not account for overwrites. * * @param dir Directory to watch for STIX content to be published. * *//* ww w . ja va2 s . co m*/ private PublisherOutbox10(final File dir) { logger.info("Outbox is awaiting files..."); // The monitor will perform polling on the folder every 2 seconds final long pollingInterval = 2000; // Create an observer, monitor, and listener to watch for directory changes FileAlterationObserver observer = new FileAlterationObserver(dir); FileAlterationMonitor monitor = new FileAlterationMonitor(pollingInterval); FileAlterationListener listener = new FileAlterationListenerAdaptor() { private String feedName; // Is triggered when a file is created in the monitored folder. Works recursively, and ignores publishFeeds. @Override public void onFileCreate(File file) { List<ContentBlock> contentBlocks = new ArrayList<>(); // Do nothing if dropping files into the publishFeeds directory if (file.getParentFile().getName().equals("publishFeeds")) { return; } try { this.feedName = file.getParentFile().getName(); String contentBinding = ClientUtil.getContentBinding(file); // Form a content block and ensure it passes STIX validation ContentBlock contentBlock = new ContentBlock(contentBinding, file, null, null, null); contentBlocks.add(contentBlock); int responseCode = publish(this.feedName, null, null, contentBlocks); if (responseCode != 0) { logger.info(file.getName() + " " + responseCode); } else { logger.warn("Error publishing " + file.getName() + " to collection " + this.feedName + "."); } } catch (IOException e) { logger.error("IOException when trying to publish " + file.getName()); } catch (SAXException s) { logger.error("SAXException when trying to publish " + file.getName()); } } }; // Start the directory watch service observer.addListener(listener); monitor.addObserver(observer); try { monitor.start(); logger.info("Directory monitoring service has started and is awaiting files..."); logger.debug("Monitor started..."); } catch (Exception e) { logger.error("General exception thrown when trying to start the directory monitor..."); } }
From source file:eu.eidas.node.auth.metadata.NODEFileMetadataProcessor.java
private void initFileMonitor() { if (fileService != null && fileService.existsFile(".")) { try {/* www . jav a 2s. co m*/ monitor = new FileAlterationMonitor(MONITOR_INTERVAL); observer = new FileAlterationObserver(fileService.getRepositoryDir()); xmlObserver = new XMLObserver(); observer.addListener(xmlObserver); monitor.addObserver(observer); monitor.start(); //periodically refresh static metadata stpe = new ScheduledThreadPoolExecutor(1); refreshCommand = new RefreshStaticMetadata(xmlObserver, fileService); //TODO externalize the interval between refreshes in the property file stpe.scheduleAtFixedRate(refreshCommand, 1, 24, TimeUnit.HOURS); } catch (Exception e) { LOG.error("fail to stop file monitor {}", e); } } }
From source file:architecture.ee.jdbc.sqlquery.scanner.DirectoryScanner.java
public void start(File file) throws Exception { log.debug("starting '{0}' file alter observer ...", file.getAbsolutePath()); if (monitor == null) { monitor = new FileAlterationMonitor(pollIntervalMillis); FileAlterationObserver observer = new FileAlterationObserver(file, FileFilterUtils.suffixFileFilter(sqlQueryFactory.getConfiguration().getSuffix())); observer.addListener(new DirectoryListener(sqlQueryFactory)); monitor.addObserver(observer);/*ww w . jav a2s . c o m*/ } monitor.start(); log.debug("started '{0}' file alter observer ...", file.getAbsolutePath()); }
From source file:gobblin.runtime.local.LocalJobManager.java
public LocalJobManager(WorkUnitManager workUnitManager, Properties properties) throws Exception { this.workUnitManager = workUnitManager; this.properties = properties; this.scheduler = new StdSchedulerFactory().getScheduler(); this.jobConfigFileExtensions = Sets.newHashSet(Splitter.on(",").omitEmptyStrings() .split(this.properties.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_EXTENSIONS_KEY, ConfigurationKeys.DEFAULT_JOB_CONFIG_FILE_EXTENSIONS))); this.jobStateStore = new FsStateStore<JobState>( properties.getProperty(ConfigurationKeys.STATE_STORE_FS_URI_KEY), properties.getProperty(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY), JobState.class); this.taskStateStore = new FsStateStore<TaskState>( properties.getProperty(ConfigurationKeys.STATE_STORE_FS_URI_KEY), properties.getProperty(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY), TaskState.class); long pollingInterval = Long.parseLong( this.properties.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL_KEY, Long.toString(ConfigurationKeys.DEFAULT_JOB_CONFIG_FILE_MONITOR_POLLING_INTERVAL))); this.fileAlterationMonitor = new FileAlterationMonitor(pollingInterval); restoreLastJobIdMap();/*w ww .j av a2 s . c o m*/ }
From source file:mydropbox.MyDropboxSwing.java
private void sign_inActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_sign_inActionPerformed list = new ArrayList<>(); diffList = new ArrayList<>(); sign_in.setEnabled(false);// ww w . j a va 2s.com jScrollPane1.setEnabled(true); jTree1.setEnabled(true); sync.setEnabled(true); reload.setEnabled(true); jTextArea1.setEnabled(true); jProgressBar1.setEnabled(true); log_out.setEnabled(true); username.setEnabled(false); password.setEnabled(false); File file = new File(urls); //Kiem tra dang nhap DomRepresentation login = null; try { login = LoginForm.result(username.getText(), password.getText()); if (login == null) { JOptionPane.showMessageDialog(null, "Retry to login"); return; } } catch (Exception ex) { ex.printStackTrace(); } //Load setting tu file // userId = Integer.parseInt(login.getText("/User/UserId")); root = new DefaultMutableTreeNode("Dropbox"); DefaultTreeModel defaultTreeModel = new DefaultTreeModel(root); jTree1.setModel(defaultTreeModel); AddNodeTree tree = new AddNodeTree(); tree.addNode(file, root); //Init observer FileAlterationObserver fao = new FileAlterationObserver(file); fao.addListener(new FileWatcher()); watcher = new FileAlterationMonitor(Constants.TIME_MONITOR); //Watch Dropbox folder watcher.addObserver(fao); System.out.println("Starting monitor. Ctrc - C to stop"); try { //addAttr(urls); watcher.start(); } catch (Exception ex) { Logger.getLogger(MyDropboxSwing.class.getName()).log(Level.SEVERE, null, ex); } loadXMLDoc(); }