This is a rather simple wiring, use OSGi DS instead of blueprint.
Change-Id: I49686821b3d7f70ae058d3362b16d9c6acae8d03
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.cmpn</artifactId>
+ </dependency>
</dependencies>
</project>
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
- public void close() {
+ public final void close() {
shutdownGracefully(0, 1, TimeUnit.SECONDS);
}
-
- public static NioEventLoopGroupCloseable newInstance(final Integer threadCount) {
- if (threadCount == null || threadCount <= 0) {
- return new NioEventLoopGroupCloseable();
- }
-
- return new NioEventLoopGroupCloseable(threadCount);
- }
}
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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
+++ /dev/null
-<?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>