This commit is contained in:
Clebert Suconic 2017-07-07 13:58:54 -04:00
commit 74349fd178
1 changed files with 42 additions and 33 deletions

View File

@ -44,6 +44,7 @@ public class FileStoreMonitor extends ActiveMQScheduledComponent {
private final Set<Callback> callbackList = new HashSet<>();
private final Set<FileStore> stores = new HashSet<>();
private double maxUsage;
private final Object monitorLock = new Object();
public FileStoreMonitor(ScheduledExecutorService scheduledExecutorService,
Executor executor,
@ -54,30 +55,37 @@ public class FileStoreMonitor extends ActiveMQScheduledComponent {
this.maxUsage = maxUsage;
}
public synchronized FileStoreMonitor addCallback(Callback callback) {
public FileStoreMonitor addCallback(Callback callback) {
synchronized (monitorLock) {
callbackList.add(callback);
return this;
}
}
public synchronized FileStoreMonitor addStore(File file) throws IOException {
public FileStoreMonitor addStore(File file) throws IOException {
synchronized (monitorLock) {
// JDBC storage may return this as null, and we may need to ignore it
if (file != null && file.exists()) {
addStore(Files.getFileStore(file.toPath()));
}
return this;
}
}
public synchronized FileStoreMonitor addStore(FileStore store) {
public FileStoreMonitor addStore(FileStore store) {
synchronized (monitorLock) {
stores.add(store);
return this;
}
}
@Override
public void run() {
tick();
}
public synchronized void tick() {
public void tick() {
synchronized (monitorLock) {
boolean over = false;
FileStore lastStore = null;
@ -106,6 +114,7 @@ public class FileStoreMonitor extends ActiveMQScheduledComponent {
}
}
}
}
public double getMaxUsage() {
return maxUsage;