diff --git a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoBrainConfig.java b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoBrainConfig.java index 52fc4173b28..843e63d3b2b 100644 --- a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoBrainConfig.java +++ b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoBrainConfig.java @@ -14,10 +14,9 @@ package org.openhab.binding.neeo.internal; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.neeo.internal.handler.NeeoBrainHandler; /** - * The configuration class a neeo brain and used by {@link NeeoBrainHandler} + * Configuration used by {@link org.openhab.binding.neeo.internal.handler.NeeoBrainHandler} * * @author Tim Roberts - initial contribution */ diff --git a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoDeviceConfig.java b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoDeviceConfig.java index 2be34c3afe7..5f1244f6cf7 100644 --- a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoDeviceConfig.java +++ b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoDeviceConfig.java @@ -14,12 +14,11 @@ package org.openhab.binding.neeo.internal; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.neeo.internal.handler.NeeoDeviceHandler; /** - * THe configuration class for the device used by {@link NeeoDeviceHandler} + * Configuration used by {@link org.openhab.binding.neeo.internal.handler.NeeoDeviceHandler} * - * @author Tim Roberts - initial contribution + * @author Tim Roberts - Initial contribution */ @NonNullByDefault public class NeeoDeviceConfig { diff --git a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoHandlerCallback.java b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoHandlerCallback.java index bd5307dc2a3..5794fffa971 100644 --- a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoHandlerCallback.java +++ b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoHandlerCallback.java @@ -16,17 +16,16 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; -import org.openhab.core.thing.binding.ThingHandler; import org.openhab.core.types.State; /** * - * This interface is used to provide a callback mechanism between a @link {@link ThingHandler} and the assoicated - * protocol. + * This interface is used to provide a callback mechanism between a {@link org.openhab.core.thing.binding.ThingHandler} + * and the associated protocol. * This is necessary since the status and state of a bridge/thing is private and the protocol handler cannot access it * directly. * - * @author Tim Roberts - initial contribution + * @author Tim Roberts - Initial contribution * */ @NonNullByDefault diff --git a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoRoomConfig.java b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoRoomConfig.java index 720e62779c5..dfeec4c86fb 100644 --- a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoRoomConfig.java +++ b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/NeeoRoomConfig.java @@ -14,10 +14,9 @@ package org.openhab.binding.neeo.internal; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.neeo.internal.handler.NeeoRoomHandler; /** - * THe configuration class for the room used by {@link NeeoRoomHandler} + * Configuration used by {@link org.openhab.binding.neeo.internal.handler.NeeoRoomHandler} * * @author Tim Roberts - initial contribution */ diff --git a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoBrainHandler.java b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoBrainHandler.java index b907cc15ed0..9892ca882ed 100644 --- a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoBrainHandler.java +++ b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoBrainHandler.java @@ -46,7 +46,6 @@ import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.binding.BaseBridgeHandler; -import org.openhab.core.thing.binding.ThingHandler; import org.openhab.core.types.Command; import org.osgi.service.http.HttpService; import org.osgi.service.http.NamespaceException; @@ -187,22 +186,16 @@ public class NeeoBrainHandler extends BaseBridgeHandler { addProperty(properties, "Last Change", String.valueOf(brain.getLastChange())); updateProperties(properties); - String forwardChain = config.getForwardChain(); - if (config.isEnableForwardActions() && forwardChain != null && !forwardChain.isEmpty()) { + if (config.isEnableForwardActions()) { NeeoUtil.checkInterrupt(); forwardActionServlet = new NeeoForwardActionsServlet(scheduler, json -> { triggerChannel(NeeoConstants.CHANNEL_BRAIN_FOWARDACTIONS, json); final NeeoAction action = Objects.requireNonNull(gson.fromJson(json, NeeoAction.class)); - - for (final Thing child : getThing().getThings()) { - final ThingHandler th = child.getHandler(); - if (th instanceof NeeoRoomHandler) { - ((NeeoRoomHandler) th).processAction(action); - } - } - }, forwardChain, clientBuilder); + getThing().getThings().stream().map(Thing::getHandler).filter(NeeoRoomHandler.class::isInstance) + .forEach(h -> ((NeeoRoomHandler) h).processAction(action)); + }, config.getForwardChain(), clientBuilder); NeeoUtil.checkInterrupt(); try { diff --git a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoForwardActionsServlet.java b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoForwardActionsServlet.java index dc1815d17ea..1fe60c5167b 100644 --- a/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoForwardActionsServlet.java +++ b/bundles/org.openhab.binding.neeo/src/main/java/org/openhab/binding/neeo/internal/handler/NeeoForwardActionsServlet.java @@ -14,6 +14,7 @@ package org.openhab.binding.neeo.internal.handler; import java.io.IOException; import java.util.concurrent.ScheduledExecutorService; +import java.util.function.Consumer; import java.util.stream.Collectors; import javax.servlet.http.HttpServlet; @@ -44,10 +45,10 @@ public class NeeoForwardActionsServlet extends HttpServlet { private final Logger logger = LoggerFactory.getLogger(NeeoForwardActionsServlet.class); /** The event publisher */ - private final Callback callback; + private final Consumer callback; /** The forwarding chain */ - private final String forwardChain; + private final @Nullable String forwardChain; /** The {@link ClientBuilder} to use */ private final ClientBuilder clientBuilder; @@ -56,14 +57,14 @@ public class NeeoForwardActionsServlet extends HttpServlet { private final ScheduledExecutorService scheduler; /** - * Creates the servlet the will process foward action events from the NEEO brain. + * Creates the servlet the will process forward action events from the NEEO brain. * * @param scheduler a non-null {@link ScheduledExecutorService} to schedule forward actions - * @param callback a non-null {@link Callback} + * @param callback a non-null String consumer * @param forwardChain a possibly null, possibly empty forwarding chain */ - NeeoForwardActionsServlet(ScheduledExecutorService scheduler, Callback callback, String forwardChain, - ClientBuilder clientBuilder) { + NeeoForwardActionsServlet(ScheduledExecutorService scheduler, Consumer callback, + @Nullable String forwardChain, ClientBuilder clientBuilder) { super(); this.scheduler = scheduler; @@ -89,24 +90,22 @@ public class NeeoForwardActionsServlet extends HttpServlet { final String json = req.getReader().lines().collect(Collectors.joining("\n")); logger.debug("handleForwardActions {}", json); - callback.post(json); + callback.accept(json); - scheduler.execute(() -> { - try (final HttpRequest request = new HttpRequest(clientBuilder)) { - for (final String forwardUrl : forwardChain.split(",")) { - if (forwardUrl != null && !forwardUrl.isEmpty()) { - final HttpResponse httpResponse = request.sendPostJsonCommand(forwardUrl, json); - if (httpResponse.getHttpCode() != HttpStatus.OK_200) { - logger.debug("Cannot forward event {} to {}: {}", json, forwardUrl, - httpResponse.getHttpCode()); + if (forwardChain != null && !forwardChain.isEmpty()) { + scheduler.execute(() -> { + try (final HttpRequest request = new HttpRequest(clientBuilder)) { + for (final String forwardUrl : forwardChain.split(",")) { + if (!forwardUrl.isEmpty()) { + final HttpResponse httpResponse = request.sendPostJsonCommand(forwardUrl, json); + if (httpResponse.getHttpCode() != HttpStatus.OK_200) { + logger.debug("Cannot forward event {} to {}: {}", json, forwardUrl, + httpResponse.getHttpCode()); + } } } } - } - }); - } - - interface Callback { - void post(String json); + }); + } } }