[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [collector/release] Replace anonymous types with lambdas.
commit 20742f46907e0085592aebe917acabe8f77ed0c7
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon Aug 20 15:11:13 2018 +0200
Replace anonymous types with lambdas.
---
.../metrics/collector/conf/Configuration.java | 30 ++++++++++------------
.../metrics/collector/conf/ConfigurationTest.java | 14 ++--------
2 files changed, 16 insertions(+), 28 deletions(-)
diff --git a/src/main/java/org/torproject/metrics/collector/conf/Configuration.java b/src/main/java/org/torproject/metrics/collector/conf/Configuration.java
index 6f38c45..f797947 100644
--- a/src/main/java/org/torproject/metrics/collector/conf/Configuration.java
+++ b/src/main/java/org/torproject/metrics/collector/conf/Configuration.java
@@ -60,23 +60,21 @@ public class Configuration extends Observable implements Cloneable {
if (this.getBool(Key.RunOnce)) { // no need to watch
return;
}
- this.scheduler.scheduleAtFixedRate(new Runnable() {
- public void run() {
- logger.trace("Check configuration file.");
- try {
- FileTime ftNow = Files.getLastModifiedTime(confPath);
- if (ft.compareTo(ftNow) < 0) {
- logger.info("Configuration file was changed.");
- reload();
- setChanged();
- notifyObservers(null);
- }
- ft = ftNow;
- } catch (Throwable th) { // Catch all and keep running.
- logger.error("Cannot reload configuration file.", th);
- }
+ this.scheduler.scheduleAtFixedRate(() -> {
+ logger.trace("Check configuration file.");
+ try {
+ FileTime ftNow = Files.getLastModifiedTime(confPath);
+ if (ft.compareTo(ftNow) < 0) {
+ logger.info("Configuration file was changed.");
+ reload();
+ setChanged();
+ notifyObservers(null);
}
- }, 5, 5, TimeUnit.SECONDS);
+ ft = ftNow;
+ } catch (Throwable th) { // Catch all and keep running.
+ logger.error("Cannot reload configuration file.", th);
+ }
+ }, 5, 5, TimeUnit.SECONDS);
}
private final void reload() throws IOException {
diff --git a/src/test/java/org/torproject/metrics/collector/conf/ConfigurationTest.java b/src/test/java/org/torproject/metrics/collector/conf/ConfigurationTest.java
index f6172bf..4ac623e 100644
--- a/src/test/java/org/torproject/metrics/collector/conf/ConfigurationTest.java
+++ b/src/test/java/org/torproject/metrics/collector/conf/ConfigurationTest.java
@@ -23,8 +23,6 @@ import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
-import java.util.Observable;
-import java.util.Observer;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -186,11 +184,7 @@ public class ConfigurationTest {
public void testConfigChange() throws Exception {
Configuration conf = new Configuration();
final AtomicBoolean called = new AtomicBoolean(false);
- conf.addObserver(new Observer() {
- public void update(Observable obs, Object obj) {
- called.set(true);
- }
- });
+ conf.addObserver((obs, obj) -> called.set(true));
File confFile = tmpf.newFile("empty");
Files.write(confFile.toPath(), (Key.RelaydescsActivated.name() + "=true")
.getBytes());
@@ -208,11 +202,7 @@ public class ConfigurationTest {
public void testConfigUnreadable() throws Exception {
Configuration conf = new Configuration();
final AtomicBoolean called = new AtomicBoolean(false);
- conf.addObserver(new Observer() {
- public void update(Observable obs, Object obj) {
- called.set(true);
- }
- });
+ conf.addObserver((obs, obj) -> called.set(true));
File confFile = tmpf.newFile("empty");
Files.write(confFile.toPath(), (Key.RelaydescsActivated.name() + "=true")
.getBytes());
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits