--- /dev/null
+/*
+ * 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");
+ }
+}
+++ /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.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>