fixed code smells

This commit is contained in:
Sebastian Stenzel
2021-12-03 12:17:07 +01:00
parent f277d4d21b
commit 0fd6e5bbb0
4 changed files with 23 additions and 14 deletions

View File

@@ -79,8 +79,9 @@ public class LoggerModule {
@Singleton
@Named("fileAppender")
static Appender<ILoggingEvent> provideFileAppender(LoggerContext context, PatternLayoutEncoder encoder, Environment environment) {
if (environment.getLogDir().isPresent()) {
Path logDir = environment.getLogDir().get();
var optionalLogDir = environment.getLogDir();
if (optionalLogDir.isPresent()) {
Path logDir = optionalLogDir.get();
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
appender.setContext(context);
appender.setFile(logDir.resolve(LOGFILE_NAME).toString());
@@ -110,9 +111,10 @@ public class LoggerModule {
@Singleton
@Named("upgradeAppender")
static Appender<ILoggingEvent> provideUpgradeAppender(LoggerContext context, PatternLayoutEncoder encoder, Environment environment) {
if (environment.getLogDir().isPresent()) {
var optionalLogDir = environment.getLogDir();
if (optionalLogDir.isPresent()) {
FileAppender<ILoggingEvent> appender = new FileAppender<>();
appender.setFile(environment.getLogDir().get().resolve(UPGRADE_FILENAME).toString());
appender.setFile(optionalLogDir.get().resolve(UPGRADE_FILENAME).toString());
appender.setContext(context);
appender.setEncoder(encoder);
appender.start();

View File

@@ -4,30 +4,35 @@ import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class UserInteractionLock<E extends Enum> {
public class UserInteractionLock<E extends Enum<E>> {
private final Lock lock = new ReentrantLock();
private final Condition condition = lock.newCondition();
private final BooleanProperty awaitingInteraction = new SimpleBooleanProperty();
private volatile E state;
private final AtomicBoolean interacted = new AtomicBoolean();
private final AtomicReference<E> state;
public UserInteractionLock(E initialValue) {
this.state = initialValue;
this.state = new AtomicReference<>(initialValue);
}
public synchronized void reset(E value) {
this.state = value;
state.set(value);
interacted.set(false);
}
public void interacted(E result) {
assert Platform.isFxApplicationThread();
lock.lock();
try {
state = result;
state.set(result);
interacted.set(true);
awaitingInteraction.set(false);
condition.signal();
} finally {
@@ -40,8 +45,10 @@ public class UserInteractionLock<E extends Enum> {
lock.lock();
try {
Platform.runLater(() -> awaitingInteraction.set(true));
condition.await();
return state;
while (!interacted.get()) {
condition.await();
}
return state.get();
} finally {
lock.unlock();
}

View File

@@ -23,7 +23,7 @@ public class UpdateCheckerTask extends Task<String> {
private static final Logger LOG = LoggerFactory.getLogger(UpdateCheckerTask.class);
private static final long MAX_RESPONSE_SIZE = 10 * 1024; // 10kb should be sufficient. protect against flooding
private static final long MAX_RESPONSE_SIZE = 10L * 1024; // 10kb should be sufficient. protect against flooding
private static final Gson GSON = new GsonBuilder().setLenient().create();
private final HttpClient httpClient;

View File

@@ -127,10 +127,10 @@ public class VaultStatisticsController implements FxController {
encryptedBytesWrite.getData().add(new Data<>(currentStep, encBytes));
// adjust ranges:
readChartXAxis.setLowerBound(currentStep - IO_SAMPLING_STEPS);
readChartXAxis.setLowerBound(currentStep - IO_SAMPLING_STEPS * 1.0);
readChartXAxis.setUpperBound(currentStep);
readChartYAxis.setUpperBound(allTimeMax);
writeChartXAxis.setLowerBound(currentStep - IO_SAMPLING_STEPS);
writeChartXAxis.setLowerBound(currentStep - IO_SAMPLING_STEPS * 1.0);
writeChartXAxis.setUpperBound(currentStep);
writeChartYAxis.setUpperBound(allTimeMax);
}