Convert netty-timer-config to OSGi DS 78/91778/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jul 2020 17:07:38 +0000 (19:07 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jul 2020 17:14:10 +0000 (19:14 +0200)
This is an extremely simple forwarder, convert it to OSGi DS.

JIRA: CONTROLLER-1882
Change-Id: I8fbb71fba704e273b8e1c8fa79b4e4dd90aeff31
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/config/netty-timer-config/pom.xml
opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/OSGiGlobalTimer.java [new file with mode: 0644]
opendaylight/config/netty-timer-config/src/main/resources/OSGI-INF/blueprint/netty-timer.xml [deleted file]

index 77cc3edbaaea900a8851e77ff6921f6b7b56fdd7..b1b777f3d9db18e8df41e495cd60e868b119c245 100644 (file)
@@ -21,5 +21,9 @@
       <groupId>io.netty</groupId>
       <artifactId>netty-common</artifactId>
     </dependency>
       <groupId>io.netty</groupId>
       <artifactId>netty-common</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+    </dependency>
   </dependencies>
 </project>
   </dependencies>
 </project>
diff --git a/opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/OSGiGlobalTimer.java b/opendaylight/config/netty-timer-config/src/main/java/org/opendaylight/controller/config/yang/netty/timer/OSGiGlobalTimer.java
new file mode 100644 (file)
index 0000000..9613000
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2020 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.timer;
+
+import io.netty.util.Timeout;
+import io.netty.util.Timer;
+import io.netty.util.TimerTask;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+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.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(immediate = true, configurationPid = "org.opendaylight.netty.timer", property = "type=global-timer")
+@Designate(ocd = OSGiGlobalTimer.Config.class)
+public final class OSGiGlobalTimer implements Timer {
+    @ObjectClassDefinition
+    public @interface Config {
+        @AttributeDefinition(name = "tick-duration")
+        long tickDuration() default 0;
+        @AttributeDefinition(name = "ticks-per-wheel")
+        int ticksPerWheel() default 0;
+    }
+
+    private static final Logger LOG = LoggerFactory.getLogger(OSGiGlobalTimer.class);
+
+    private Timer delegate;
+
+    @Override
+    public Timeout newTimeout(final TimerTask task, final long delay, final TimeUnit unit) {
+        return delegate.newTimeout(task, delay, unit);
+    }
+
+    @Override
+    public Set<Timeout> stop() {
+        return delegate.stop();
+    }
+
+    @Activate
+    void activate(final Config config) {
+        delegate = HashedWheelTimerCloseable.newInstance(config.tickDuration(), config.ticksPerWheel());
+        LOG.info("Global Netty timer started");
+    }
+
+    @Deactivate
+    void deactivate() {
+        delegate.stop();
+        LOG.info("Global Netty timer stopped");
+    }
+}
diff --git a/opendaylight/config/netty-timer-config/src/main/resources/OSGI-INF/blueprint/netty-timer.xml b/opendaylight/config/netty-timer-config/src/main/resources/OSGI-INF/blueprint/netty-timer.xml
deleted file mode 100644 (file)
index b198449..0000000
+++ /dev/null
@@ -1,22 +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.timer" update-strategy="none">
-    <cm:default-properties>
-      <cm:property name="tick-duration" value="0"/>
-      <cm:property name="ticks-per-wheel" value="0"/>
-    </cm:default-properties>
-  </cm:property-placeholder>
-
-  <bean id="timer" class="org.opendaylight.controller.config.yang.netty.timer.HashedWheelTimerCloseable"
-          factory-method="newInstance">
-    <argument value="${tick-duration}"/>
-    <argument value="${ticks-per-wheel}"/>
-  </bean>
-
-  <service ref="timer" interface="io.netty.util.Timer" odl:type="global-timer"/>
-
-</blueprint>