From bb4dffd69d1192e65bf5c17ed6cd35701c2ab466 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 30 Jul 2020 18:10:41 +0200 Subject: [PATCH] Convert netty-event-executor-config to OSGi DS This is an extremely simple forwarder, convert it to OSGi DS. JIRA: CONTROLLER-1882 Change-Id: Iff74bad52a78adcb6398b09300f6bfa7457dea7d Signed-off-by: Robert Varga --- .../netty-event-executor-config/pom.xml | 4 + .../OSGiGlobalEventExecutor.java | 204 ++++++++++++++++++ .../blueprint/netty-event-executor.xml | 12 -- 3 files changed, 208 insertions(+), 12 deletions(-) create mode 100644 opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/OSGiGlobalEventExecutor.java delete mode 100644 opendaylight/config/netty-event-executor-config/src/main/resources/OSGI-INF/blueprint/netty-event-executor.xml diff --git a/opendaylight/config/netty-event-executor-config/pom.xml b/opendaylight/config/netty-event-executor-config/pom.xml index b7f8c66a63..68e4593181 100644 --- a/opendaylight/config/netty-event-executor-config/pom.xml +++ b/opendaylight/config/netty-event-executor-config/pom.xml @@ -25,5 +25,9 @@ io.netty netty-common + + org.osgi + osgi.cmpn + 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 index 0000000000..f5081eea7b --- /dev/null +++ b/opendaylight/config/netty-event-executor-config/src/main/java/org/opendaylight/controller/config/yang/netty/eventexecutor/OSGiGlobalEventExecutor.java @@ -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 shutdownNow() { + return INSTANCE.shutdownNow(); + } + + @Override + public Iterator iterator() { + return INSTANCE.iterator(); + } + + @Override + public Future submit(final Runnable task) { + return INSTANCE.submit(task); + } + + @Override + public Future submit(final Runnable task, final T result) { + return INSTANCE.submit(task, result); + } + + @Override + public Future submit(final Callable 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 ScheduledFuture schedule(final Callable 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 List> invokeAll(final Collection> tasks) + throws InterruptedException { + return INSTANCE.invokeAll(tasks); + } + + @Override + public List> invokeAll(final Collection> tasks, + final long timeout, final TimeUnit unit) throws InterruptedException { + return INSTANCE.invokeAll(tasks, timeout, unit); + } + + @Override + public T invokeAny(final Collection> tasks) + throws InterruptedException, ExecutionException { + return INSTANCE.invokeAny(tasks); + } + + @Override + public T invokeAny(final Collection> 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 Promise newPromise() { + return INSTANCE.newPromise(); + } + + @Override + public ProgressivePromise newProgressivePromise() { + return INSTANCE.newProgressivePromise(); + } + + @Override + public Future newSucceededFuture(final V result) { + return INSTANCE.newSucceededFuture(result); + } + + @Override + public Future 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 index 0e845dfd8f..0000000000 --- a/opendaylight/config/netty-event-executor-config/src/main/resources/OSGI-INF/blueprint/netty-event-executor.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - -- 2.36.6