Skip to content

Commit

Permalink
Added nullness annotations (openhab#850)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <[email protected]>
  • Loading branch information
cweitkamp authored and maggu2810 committed Jun 3, 2019
1 parent 7f0d61d commit 64a466f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
*/
package org.eclipse.smarthome.model.rule.runtime;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* This is a marker interface for Rule Engines.
*
* @author Kai Kreuzer - Initial contribution and API
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public interface RuleEngine {

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.concurrent.TimeUnit;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.common.ThreadPoolManager;
import org.eclipse.smarthome.core.events.Event;
import org.eclipse.smarthome.core.events.EventFilter;
Expand Down Expand Up @@ -70,6 +72,7 @@
*/
@SuppressWarnings("restriction")
@Component(immediate = true, service = { EventSubscriber.class, RuleEngine.class })
@NonNullByDefault
public class RuleEngineImpl implements ItemRegistryChangeListener, StateChangeListener, ModelRepositoryChangeListener,
RuleEngine, EventSubscriber {

Expand All @@ -83,11 +86,10 @@ public class RuleEngineImpl implements ItemRegistryChangeListener, StateChangeLi
private final ModelRepository modelRepository;
private final ScriptEngine scriptEngine;

private RuleTriggerManager triggerManager;
private @NonNullByDefault({}) Injector injector;
private @NonNullByDefault({}) RuleTriggerManager triggerManager;

private Injector injector;

private ScheduledFuture<?> startupJob;
private @Nullable ScheduledFuture<?> startupJob;

// This flag is used to signal that items are still being added and that we hence do not consider the rule engine
// ready to be operational.
Expand Down Expand Up @@ -191,7 +193,7 @@ public void stateUpdated(Item item, State state) {
}

private void receiveCommand(ItemCommandEvent commandEvent) {
if (!starting && triggerManager != null && itemRegistry != null) {
if (!starting && triggerManager != null) {
String itemName = commandEvent.getItemName();
Command command = commandEvent.getItemCommand();
try {
Expand Down Expand Up @@ -265,8 +267,9 @@ public void modelChanged(String modelName, org.eclipse.smarthome.model.core.Even
}

private void scheduleStartupRules() {
if (startupJob != null && !startupJob.isCancelled() && !startupJob.isDone()) {
startupJob.cancel(true);
ScheduledFuture<?> job = startupJob;
if (job != null && !job.isCancelled() && !job.isDone()) {
job.cancel(true);
}
startupJob = scheduler.schedule(() -> {
runStartupRules();
Expand Down Expand Up @@ -393,7 +396,7 @@ public Set<String> getSubscribedEventTypes() {
}

@Override
public EventFilter getEventFilter() {
public @Nullable EventFilter getEventFilter() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.text.DateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -51,13 +52,15 @@
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.quartz.Job;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This class implements a persistence manager to manage all persistence services etc.
*
* @author Kai Kreuzer - Initial contribution and API
* @author Kai Kreuzer - Initial contribution
* @author Markus Rathgeb - Separation of persistence core and model, drop Quartz usage.
*/
@Component(service = PersistenceManager.class, immediate = true)
Expand All @@ -80,7 +83,7 @@ public PersistenceManagerImpl() {
}

protected void activate() {
allItemsChanged(null);
allItemsChanged(Collections.emptySet());
started = true;
itemRegistry.addRegistryChangeListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@

import java.util.Collection;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.common.registry.RegistryChangeListener;

/**
* This is a listener interface which should be implemented where ever the item registry is
* used in order to be notified of any dynamic changes in the provided items.
*
* @author Kai Kreuzer - Initial contribution and API
*
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
public interface ItemRegistryChangeListener extends RegistryChangeListener<Item> {

/**
* Notifies the listener that all items in the registry have changed and thus should be reloaded.
*
*
* @param oldItemNames a collection of all previous item names, so that references can be removed
*/
public void allItemsChanged(Collection<String> oldItemNames);
Expand Down

0 comments on commit 64a466f

Please sign in to comment.