Fixed nullness anotations for TriggerHandlerCallback (#2589)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
pull/2591/head
Christoph Weitkamp 2021-12-04 17:48:18 +01:00 committed by GitHub
parent 3493c85e19
commit eb982f430d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 16 deletions

View File

@ -54,5 +54,5 @@ public interface TriggerHandlerCallback extends ModuleHandlerCallback {
/**
* @return the scheduler of this rule
*/
public @Nullable ScheduledExecutorService getScheduler();
public ScheduledExecutorService getScheduler();
}

View File

@ -19,7 +19,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.RuleStatus;
@ -37,15 +36,16 @@ import org.openhab.core.common.NamedThreadFactory;
* @author Kai Kreuzer - improved stability
* @author Fabian Wolter - Change executor to ScheduledExecutorService and expose it
*/
@NonNullByDefault
public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback {
private final RuleEngineImpl re;
private final String ruleUID;
private ScheduledExecutorService executor;
private Future<?> future;
private final RuleEngineImpl re;
private @Nullable Future<?> future;
protected TriggerHandlerCallbackImpl(RuleEngineImpl re, String ruleUID) {
this.re = re;
@ -54,11 +54,8 @@ public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback {
}
@Override
public void triggered(Trigger trigger, @Nullable Map<@NonNull String, ?> context) {
public void triggered(Trigger trigger, @Nullable Map<String, ?> context) {
synchronized (this) {
if (executor == null) {
return;
}
future = executor.submit(new TriggerData(trigger, context));
}
re.logger.debug("The trigger '{}' of rule '{}' is triggered.", trigger.getId(), ruleUID);
@ -69,7 +66,6 @@ public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback {
return future == null || !future.isDone();
}
@NonNullByDefault
class TriggerData implements Runnable {
private final Trigger trigger;
@ -96,16 +92,15 @@ public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback {
public void dispose() {
synchronized (this) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
AccessController.doPrivileged((PrivilegedAction<@Nullable Void>) () -> {
executor.shutdownNow();
return null;
});
executor = null;
}
}
@Override
public Boolean isEnabled(String ruleUID) {
public @Nullable Boolean isEnabled(String ruleUID) {
return re.isEnabled(ruleUID);
}
@ -115,12 +110,12 @@ public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback {
}
@Override
public RuleStatusInfo getStatusInfo(String ruleUID) {
public @Nullable RuleStatusInfo getStatusInfo(String ruleUID) {
return re.getStatusInfo(ruleUID);
}
@Override
public RuleStatus getStatus(String ruleUID) {
public @Nullable RuleStatus getStatus(String ruleUID) {
return re.getStatus(ruleUID);
}
@ -130,7 +125,7 @@ public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback {
}
@Override
public void runNow(String uid, boolean considerConditions, Map<String, Object> context) {
public void runNow(String uid, boolean considerConditions, @Nullable Map<String, Object> context) {
re.runNow(uid, considerConditions, context);
}