
org.openas2.support.FileMonitorAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openas2-server Show documentation
Show all versions of openas2-server Show documentation
Open source implementation of the AS2 standard for signed encrypted and compressed document transfer
package org.openas2.support;
import java.io.File;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.openas2.OpenAS2Exception;
public abstract class FileMonitorAdapter implements FileMonitorListener {
public static final int MINIMAL_SCHEDULE_INTERVAL = 1;
/**
* Schedule a watch for file changes.
* If schedule interval less then {@link #MINIMAL_SCHEDULE_INTERVAL} no tasks will be scheduled
*
* @param executor a executor
* @param file an existing file
* @param refreshInterval refresh interval
* @param unit a time unit
*/
public void scheduleIfNeed(ScheduledExecutorService executor, File file, int refreshInterval, TimeUnit unit)
{
if (refreshInterval >= MINIMAL_SCHEDULE_INTERVAL)
{
executor.scheduleAtFixedRate(new FileMonitor(file, this), refreshInterval, refreshInterval, unit);
}
}
@Override
public void onFileEvent(File file, int eventID)
{
switch (eventID)
{
case FileMonitorListener.EVENT_MODIFIED:
try
{
onConfigFileChanged();
} catch (OpenAS2Exception oae)
{
oae.terminate();
}
break;
}
}
/**
* A template method which is triggered once observing file is changed.
*
* @throws OpenAS2Exception - an internally handled error has occurred
*/
public abstract void onConfigFileChanged() throws OpenAS2Exception;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy