Convert netty-threadgroup-config to OSGi DS 03/96703/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 28 Jun 2021 17:53:47 +0000 (19:53 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 28 Jun 2021 19:07:03 +0000 (21:07 +0200)
This is a rather simple wiring, use OSGi DS instead of blueprint.

Change-Id: I49686821b3d7f70ae058d3362b16d9c6acae8d03
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/config/netty-threadgroup-config/pom.xml
opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/AbstractGlobalGroup.java [moved from opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/NioEventLoopGroupCloseable.java with 50% similarity]
opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/Configuration.java [new file with mode: 0644]
opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/GlobalBossGroup.java [new file with mode: 0644]
opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/GlobalWorkerGroup.java [new file with mode: 0644]
opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/package-info.java [new file with mode: 0644]
opendaylight/config/netty-threadgroup-config/src/main/resources/OSGI-INF/blueprint/netty-threadgroup.xml [deleted file]

index 690c490687039497ac8306e228aa6ce3c3123277..be77bad7afd4cb2e2f9fa3dbeebe8e0d86b6567e 100644 (file)
@@ -21,5 +21,9 @@
       <groupId>io.netty</groupId>
       <artifactId>netty-transport</artifactId>
     </dependency>
       <groupId>io.netty</groupId>
       <artifactId>netty-transport</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+    </dependency>
   </dependencies>
 </project>
   </dependencies>
 </project>
@@ -10,24 +10,13 @@ package org.opendaylight.controller.config.yang.netty.threadgroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import java.util.concurrent.TimeUnit;
 
 import io.netty.channel.nio.NioEventLoopGroup;
 import java.util.concurrent.TimeUnit;
 
-public final class NioEventLoopGroupCloseable extends NioEventLoopGroup implements AutoCloseable {
-    private NioEventLoopGroupCloseable(final int threadCount) {
-        super(threadCount);
-    }
-
-    private NioEventLoopGroupCloseable() {
+abstract class AbstractGlobalGroup extends NioEventLoopGroup implements AutoCloseable {
+    AbstractGlobalGroup(final int threadCount) {
+        super(threadCount < 0 ? 0 : threadCount);
     }
 
     @Override
     }
 
     @Override
-    public void close() {
+    public final void close() {
         shutdownGracefully(0, 1, TimeUnit.SECONDS);
     }
         shutdownGracefully(0, 1, TimeUnit.SECONDS);
     }
-
-    public static NioEventLoopGroupCloseable newInstance(final Integer threadCount) {
-        if (threadCount == null || threadCount <= 0) {
-            return new NioEventLoopGroupCloseable();
-        }
-
-        return new NioEventLoopGroupCloseable(threadCount);
-    }
 }
 }
diff --git a/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/Configuration.java b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/Configuration.java
new file mode 100644 (file)
index 0000000..174b44f
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.yang.netty.threadgroup;
+
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@ObjectClassDefinition(pid = "org.opendaylight.netty.threadgroup")
+public @interface Configuration {
+    @AttributeDefinition(name = "global-boss-group-thread-count")
+    int bossThreadCount() default 0;
+
+    @AttributeDefinition(name = "global-worker-group-thread-count")
+    int workerThreadCount() default 0;
+}
diff --git a/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/GlobalBossGroup.java b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/GlobalBossGroup.java
new file mode 100644 (file)
index 0000000..5b46184
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.yang.netty.threadgroup;
+
+import io.netty.channel.EventLoopGroup;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.Designate;
+
+@Component(immediate = true, service = EventLoopGroup.class, property = "type=global-boss-group")
+@Designate(ocd = Configuration.class)
+public final class GlobalBossGroup extends AbstractGlobalGroup {
+    @Activate
+    public GlobalBossGroup(final Configuration configuration) {
+        super(configuration.bossThreadCount());
+    }
+
+    @Deactivate
+    void deactivate() {
+        close();
+    }
+}
diff --git a/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/GlobalWorkerGroup.java b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/GlobalWorkerGroup.java
new file mode 100644 (file)
index 0000000..4a9f46e
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.yang.netty.threadgroup;
+
+import io.netty.channel.EventLoopGroup;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.Designate;
+
+@Component(immediate = true, service = EventLoopGroup.class, property = "type=global-worker-group")
+@Designate(ocd = Configuration.class)
+public final class GlobalWorkerGroup extends AbstractGlobalGroup {
+    @Activate
+    public GlobalWorkerGroup(final Configuration configuration) {
+        super(configuration.workerThreadCount());
+    }
+
+    @Deactivate
+    void deactivate() {
+        close();
+    }
+}
diff --git a/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/package-info.java b/opendaylight/config/netty-threadgroup-config/src/main/java/org/opendaylight/controller/config/yang/netty/threadgroup/package-info.java
new file mode 100644 (file)
index 0000000..f5b65ee
--- /dev/null
@@ -0,0 +1,9 @@
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+@org.osgi.service.component.annotations.RequireServiceComponentRuntime
+package org.opendaylight.controller.config.yang.netty.threadgroup;
\ No newline at end of file
diff --git a/opendaylight/config/netty-threadgroup-config/src/main/resources/OSGI-INF/blueprint/netty-threadgroup.xml b/opendaylight/config/netty-threadgroup-config/src/main/resources/OSGI-INF/blueprint/netty-threadgroup.xml
deleted file mode 100644 (file)
index 77e2556..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
-    odl:restart-dependents-on-updates="false">
-
-  <cm:property-placeholder persistent-id="org.opendaylight.netty.threadgroup" update-strategy="none">
-    <cm:default-properties>
-      <!-- 0 means use the default number of threads which is 2 * number of CPUs -->
-      <cm:property name="global-boss-group-thread-count" value="0"/>
-      <cm:property name="global-worker-group-thread-count" value="0"/>
-    </cm:default-properties>
-  </cm:property-placeholder>
-
-  <bean id="globalBossGroup" class="org.opendaylight.controller.config.yang.netty.threadgroup.NioEventLoopGroupCloseable"
-          factory-method="newInstance">
-    <argument value="${global-boss-group-thread-count}"/>
-  </bean>
-
-  <service ref="globalBossGroup" interface="io.netty.channel.EventLoopGroup" odl:type="global-boss-group">
-  <service-properties>
-      <entry key="config-module-namespace" value="urn:opendaylight:params:xml:ns:yang:controller:netty:threadgroup"/>
-      <entry key="config-module-name" value="netty-threadgroup-fixed"/>
-      <entry key="config-instance-name" value="global-boss-group"/>
-    </service-properties>
-  </service>
-
-  <bean id="globalWorkerGroup" class="org.opendaylight.controller.config.yang.netty.threadgroup.NioEventLoopGroupCloseable"
-          factory-method="newInstance">
-    <argument value="${global-worker-group-thread-count}"/>
-  </bean>
-
-  <service ref="globalWorkerGroup" interface="io.netty.channel.EventLoopGroup" odl:type="global-worker-group">
-  <service-properties>
-      <entry key="config-module-namespace" value="urn:opendaylight:params:xml:ns:yang:controller:netty:threadgroup"/>
-      <entry key="config-module-name" value="netty-threadgroup-fixed"/>
-      <entry key="config-instance-name" value="global-worker-group"/>
-    </service-properties>
-  </service>
-
-</blueprint>