Convert netty-event-executor-config to OSGi DS 77/91777/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 Jul 2020 16:10:41 +0000 (18:10 +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: Iff74bad52a78adcb6398b09300f6bfa7457dea7d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/config/netty-event-executor-config/pom.xml
opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/OSGiGlobalEventExecutor.java [new file with mode: 0644]
opendaylight/config/netty-event-executor-config/src/main/resources/OSGI-INF/blueprint/netty-event-executor.xml [deleted file]

index b7f8c66a631684f381a176c88e7286d234336326..68e45931815a34da4f60ac0f77f60a6caf091939 100644 (file)
@@ -25,5 +25,9 @@
       <groupId>io.netty</groupId>
       <artifactId>netty-common</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+    </dependency>
   </dependencies>
 </project>
diff --git a/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/OSGiGlobalEventExecutor.java b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/OSGiGlobalEventExecutor.java
new file mode 100644 (file)
index 0000000..f5081ee
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * 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.eventexecutor;
+
+import static io.netty.util.concurrent.GlobalEventExecutor.INSTANCE;
+
+import com.google.common.annotations.Beta;
+import io.netty.util.concurrent.EventExecutor;
+import io.netty.util.concurrent.EventExecutorGroup;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.ProgressivePromise;
+import io.netty.util.concurrent.Promise;
+import io.netty.util.concurrent.ScheduledFuture;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Beta
+@Component(immediate = true, property = "type=global-event-executor")
+public final class OSGiGlobalEventExecutor implements EventExecutor {
+    private static final Logger LOG = LoggerFactory.getLogger(OSGiGlobalEventExecutor.class);
+
+    @Override
+    public boolean isShuttingDown() {
+        return INSTANCE.isShuttingDown();
+    }
+
+    @Override
+    public Future<?> shutdownGracefully() {
+        return INSTANCE.shutdownGracefully();
+    }
+
+    @Override
+    public Future<?> shutdownGracefully(final long quietPeriod, final long timeout, final TimeUnit unit) {
+        return INSTANCE.shutdownGracefully(quietPeriod, timeout, unit);
+    }
+
+    @Override
+    public Future<?> terminationFuture() {
+        return INSTANCE.terminationFuture();
+    }
+
+    @Override
+    @Deprecated
+    public void shutdown() {
+        INSTANCE.shutdown();
+    }
+
+    @Override
+    public List<Runnable> shutdownNow() {
+        return INSTANCE.shutdownNow();
+    }
+
+    @Override
+    public Iterator<EventExecutor> iterator() {
+        return INSTANCE.iterator();
+    }
+
+    @Override
+    public Future<?> submit(final Runnable task) {
+        return INSTANCE.submit(task);
+    }
+
+    @Override
+    public <T> Future<T> submit(final Runnable task, final T result) {
+        return INSTANCE.submit(task, result);
+    }
+
+    @Override
+    public <T> Future<T> submit(final Callable<T> task) {
+        return INSTANCE.submit(task);
+    }
+
+    @Override
+    public ScheduledFuture<?> schedule(final Runnable command, final long delay, final TimeUnit unit) {
+        return INSTANCE.schedule(command, delay, unit);
+    }
+
+    @Override
+    public <V> ScheduledFuture<V> schedule(final Callable<V> callable, final long delay, final TimeUnit unit) {
+        return INSTANCE.schedule(callable, delay, unit);
+    }
+
+    @Override
+    public ScheduledFuture<?> scheduleAtFixedRate(final Runnable command, final long initialDelay, final long period,
+            final TimeUnit unit) {
+        return INSTANCE.scheduleAtFixedRate(command, initialDelay, period, unit);
+    }
+
+    @Override
+    public ScheduledFuture<?> scheduleWithFixedDelay(final Runnable command, final long initialDelay, final long delay,
+            final TimeUnit unit) {
+        return INSTANCE.scheduleWithFixedDelay(command, initialDelay, delay, unit);
+    }
+
+    @Override
+    public boolean isShutdown() {
+        return INSTANCE.isShutdown();
+    }
+
+    @Override
+    public boolean isTerminated() {
+        return INSTANCE.isTerminated();
+    }
+
+    @Override
+    public boolean awaitTermination(final long timeout, final TimeUnit unit) throws InterruptedException {
+        return INSTANCE.awaitTermination(timeout, unit);
+    }
+
+    @Override
+    public <T> List<java.util.concurrent.Future<T>> invokeAll(final Collection<? extends Callable<T>> tasks)
+            throws InterruptedException {
+        return INSTANCE.invokeAll(tasks);
+    }
+
+    @Override
+    public <T> List<java.util.concurrent.Future<T>> invokeAll(final Collection<? extends Callable<T>> tasks,
+            final long timeout, final TimeUnit unit) throws InterruptedException {
+        return INSTANCE.invokeAll(tasks, timeout, unit);
+    }
+
+    @Override
+    public <T> T invokeAny(final Collection<? extends Callable<T>> tasks)
+            throws InterruptedException, ExecutionException {
+        return INSTANCE.invokeAny(tasks);
+    }
+
+    @Override
+    public <T> T invokeAny(final Collection<? extends Callable<T>> tasks, final long timeout, final TimeUnit unit)
+            throws InterruptedException, ExecutionException, TimeoutException {
+        return INSTANCE.invokeAny(tasks, timeout, unit);
+    }
+
+    @Override
+    public void execute(final Runnable command) {
+        INSTANCE.execute(command);
+    }
+
+    @Override
+    public EventExecutor next() {
+        return INSTANCE.next();
+    }
+
+    @Override
+    public EventExecutorGroup parent() {
+        return INSTANCE.parent();
+    }
+
+    @Override
+    public boolean inEventLoop() {
+        return INSTANCE.inEventLoop();
+    }
+
+    @Override
+    public boolean inEventLoop(final Thread thread) {
+        return INSTANCE.inEventLoop(thread);
+    }
+
+    @Override
+    public <V> Promise<V> newPromise() {
+        return INSTANCE.newPromise();
+    }
+
+    @Override
+    public <V> ProgressivePromise<V> newProgressivePromise() {
+        return INSTANCE.newProgressivePromise();
+    }
+
+    @Override
+    public <V> Future<V> newSucceededFuture(final V result) {
+        return INSTANCE.newSucceededFuture(result);
+    }
+
+    @Override
+    public <V> Future<V> newFailedFuture(final Throwable cause) {
+        return INSTANCE.newFailedFuture(cause);
+    }
+
+    @Activate
+    void activate() {
+        LOG.info("Global Event executor enabled");
+    }
+
+    @Deactivate
+    void deactivate() {
+        LOG.info("Global Event executor disabled");
+    }
+
+}
diff --git a/opendaylight/config/netty-event-executor-config/src/main/resources/OSGI-INF/blueprint/netty-event-executor.xml b/opendaylight/config/netty-event-executor-config/src/main/resources/OSGI-INF/blueprint/netty-event-executor.xml
deleted file mode 100644 (file)
index 0e845df..0000000
+++ /dev/null
@@ -1,12 +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">
-
-  <bean id="executor" class="org.opendaylight.controller.config.yang.netty.eventexecutor.AutoCloseableEventExecutor"
-          factory-method="globalEventExecutor" destroy-method="close"/>
-
-  <service ref="executor" interface="io.netty.util.concurrent.EventExecutor"
-        odl:type="global-event-executor"/>
-
-</blueprint>