From e628f75d7bb3bf4587284d47e6756a6e07108ee8 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Sun, 18 Feb 2024 21:27:44 +0100 Subject: [PATCH] Upgrade jUPnP to 3.0.0 (#4098) * Upgrades jUPnP from 2.7.1 to 3.0.0. * Uses a custom OSGiUpnpServiceConfiguration for JDK-8301341 workaround For release notes, see: https://github.com/jupnp/jupnp/releases/tag/3.0.0 Signed-off-by: Wouter Born --- bom/compile/pom.xml | 3 +- bom/openhab-core/pom.xml | 6 +++ bom/runtime/pom.xml | 3 +- .../org.openhab.core.config.jupnp/.classpath | 29 +++++++++++ .../org.openhab.core.config.jupnp/.project | 23 ++++++++ bundles/org.openhab.core.config.jupnp/NOTICE | 14 +++++ bundles/org.openhab.core.config.jupnp/pom.xml | 25 +++++++++ .../internal/OHUpnpServiceConfiguration.java | 52 +++++++++++++++++++ bundles/pom.xml | 1 + .../openhab-tp/src/main/feature/feature.xml | 6 ++- 10 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 bundles/org.openhab.core.config.jupnp/.classpath create mode 100644 bundles/org.openhab.core.config.jupnp/.project create mode 100644 bundles/org.openhab.core.config.jupnp/NOTICE create mode 100644 bundles/org.openhab.core.config.jupnp/pom.xml create mode 100644 bundles/org.openhab.core.config.jupnp/src/main/java/org/openhab/core/config/jupnp/internal/OHUpnpServiceConfiguration.java diff --git a/bom/compile/pom.xml b/bom/compile/pom.xml index b7894a7d1..0636f9064 100644 --- a/bom/compile/pom.xml +++ b/bom/compile/pom.xml @@ -203,8 +203,7 @@ org.jupnp org.jupnp - - 2.7.1.OH1 + 3.0.0 compile diff --git a/bom/openhab-core/pom.xml b/bom/openhab-core/pom.xml index 786fc9df5..905bfb7e0 100644 --- a/bom/openhab-core/pom.xml +++ b/bom/openhab-core/pom.xml @@ -376,6 +376,12 @@ ${project.version} compile + + org.openhab.core.bundles + org.openhab.core.config.jupnp + ${project.version} + compile + org.openhab.core.bundles org.openhab.core.config.serial diff --git a/bom/runtime/pom.xml b/bom/runtime/pom.xml index a2341cb8d..30d434af8 100644 --- a/bom/runtime/pom.xml +++ b/bom/runtime/pom.xml @@ -475,8 +475,7 @@ org.jupnp org.jupnp - - 2.7.1.OH1 + 3.0.0 compile diff --git a/bundles/org.openhab.core.config.jupnp/.classpath b/bundles/org.openhab.core.config.jupnp/.classpath new file mode 100644 index 000000000..58cd399d6 --- /dev/null +++ b/bundles/org.openhab.core.config.jupnp/.classpath @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.openhab.core.config.jupnp/.project b/bundles/org.openhab.core.config.jupnp/.project new file mode 100644 index 000000000..2ce193699 --- /dev/null +++ b/bundles/org.openhab.core.config.jupnp/.project @@ -0,0 +1,23 @@ + + + org.openhab.core.config.jupnp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/bundles/org.openhab.core.config.jupnp/NOTICE b/bundles/org.openhab.core.config.jupnp/NOTICE new file mode 100644 index 000000000..6c17d0d8a --- /dev/null +++ b/bundles/org.openhab.core.config.jupnp/NOTICE @@ -0,0 +1,14 @@ +This content is produced and maintained by the openHAB project. + +* Project home: https://www.openhab.org + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/openhab/openhab-core + diff --git a/bundles/org.openhab.core.config.jupnp/pom.xml b/bundles/org.openhab.core.config.jupnp/pom.xml new file mode 100644 index 000000000..4ad3d61e6 --- /dev/null +++ b/bundles/org.openhab.core.config.jupnp/pom.xml @@ -0,0 +1,25 @@ + + + + 4.0.0 + + + org.openhab.core.bundles + org.openhab.core.reactor.bundles + 4.2.0-SNAPSHOT + + + org.openhab.core.config.jupnp + + openHAB Core :: Bundles :: Configuration jUPnP + + + + org.jupnp + org.jupnp + 3.0.0 + + + + diff --git a/bundles/org.openhab.core.config.jupnp/src/main/java/org/openhab/core/config/jupnp/internal/OHUpnpServiceConfiguration.java b/bundles/org.openhab.core.config.jupnp/src/main/java/org/openhab/core/config/jupnp/internal/OHUpnpServiceConfiguration.java new file mode 100644 index 000000000..e5707de5a --- /dev/null +++ b/bundles/org.openhab.core.config.jupnp/src/main/java/org/openhab/core/config/jupnp/internal/OHUpnpServiceConfiguration.java @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.core.config.jupnp.internal; + +import java.util.concurrent.ExecutorService; + +import org.jupnp.OSGiUpnpServiceConfiguration; +import org.jupnp.QueueingThreadPoolExecutor; +import org.jupnp.UpnpServiceConfiguration; +import org.openhab.basefixes.util.concurrent.LinkedTransferQueue; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ConfigurationPolicy; + +/** + * Uses the Java 11 {@link LinkedTransferQueue} with jUPnP as workaround for the buggy OpenJDK 17 implementation. + * + * @see JDK-8301341: LinkedTransferQueue does not respect timeout + * for poll() + * @see openhab-core#3755: LinkedTransferQueue in OpenJDK + * 17 sometimes causes high CPU usage + * + * @author Wouter Born - Initial contribution + */ +@Component(configurationPid = "org.jupnp", configurationPolicy = ConfigurationPolicy.REQUIRE, service = UpnpServiceConfiguration.class) +public class OHUpnpServiceConfiguration extends OSGiUpnpServiceConfiguration { + @Override + protected ExecutorService createMainExecutorService() { + return QueueingThreadPoolExecutor.createInstance("upnp-main", threadPoolSize, new LinkedTransferQueue<>()); + } + + @Override + protected ExecutorService createAsyncProtocolExecutorService() { + return QueueingThreadPoolExecutor.createInstance("upnp-async", asyncThreadPoolSize, + new LinkedTransferQueue<>()); + } + + @Override + protected ExecutorService createRemoteProtocolExecutorService() { + return QueueingThreadPoolExecutor.createInstance("upnp-remote", remoteThreadPoolSize, + new LinkedTransferQueue<>()); + } +} diff --git a/bundles/pom.xml b/bundles/pom.xml index 8f6fd77f7..de659616c 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -43,6 +43,7 @@ org.openhab.core.config.discovery.usbserial.windowsregistry org.openhab.core.config.discovery.upnp org.openhab.core.config.dispatch + org.openhab.core.config.jupnp org.openhab.core.config.serial org.openhab.core org.openhab.core.audio diff --git a/features/karaf/openhab-tp/src/main/feature/feature.xml b/features/karaf/openhab-tp/src/main/feature/feature.xml index 293a545e1..5f193d301 100644 --- a/features/karaf/openhab-tp/src/main/feature/feature.xml +++ b/features/karaf/openhab-tp/src/main/feature/feature.xml @@ -194,12 +194,14 @@ - openhab.tp;feature=jupnp;version=2.7.1 + openhab.tp;feature=jupnp;version=3.0.0 http scr openhab.tp-httpclient + mvn:org.openhab/base-fixes/1.0.0 - mvn:org.jupnp/org.jupnp/2.7.1.OH1 + mvn:org.openhab.core.bundles/org.openhab.core.config.jupnp/${project.version} + mvn:org.jupnp/org.jupnp/3.0.0