From: Milos Fabian Date: Wed, 6 Nov 2013 10:23:52 +0000 (+0100) Subject: Added AsyncEvenBus and EventBus configuration modules implementations. Added EventBus... X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~473^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=ba1dcdc6e86c2c52ba8c05192af93088ddd996c8 Added AsyncEvenBus and EventBus configuration modules implementations. Added EventBus and AsyncEventBus closeable wrappers. Change-Id: I21c4f2217fa876770c4ecdfa1c6a36778a00cbf0 Signed-off-by: Milos Fabian --- diff --git a/opendaylight/config/pom.xml b/opendaylight/config/pom.xml index b3f2fcdabc..9db5b76988 100755 --- a/opendaylight/config/pom.xml +++ b/opendaylight/config/pom.xml @@ -30,6 +30,7 @@ yang-test logback-config threadpool-config-api + threadpool-config-impl diff --git a/opendaylight/config/threadpool-config-impl/pom.xml b/opendaylight/config/threadpool-config-impl/pom.xml new file mode 100644 index 0000000000..12279781a2 --- /dev/null +++ b/opendaylight/config/threadpool-config-impl/pom.xml @@ -0,0 +1,76 @@ + + + org.opendaylight.controller + config-subsystem + 0.2.2-SNAPSHOT + + 4.0.0 + threadpool-config-impl + ${project.artifactId} + bundle + + 3.0.4 + + + + + ${project.groupId} + config-api + + + ${project.groupId} + threadpool-config-api + ${project.version} + + + com.google.guava + guava + + + org.slf4j + slf4j-api + + + + + + + org.apache.felix + maven-bundle-plugin + + + + org.opendaylight.controller.config.threadpool.util, + javax.annotation.*, + org.opendaylight.controller.config.yang.threadpool.impl, + + + org.opendaylight.controller.config.api.*, + org.opendaylight.controller.config.spi.*, + org.opendaylight.controller.config.threadpool, + org.opendaylight.controller.config.yang.threadpool, + javax.management, + org.osgi.framework, + org.slf4j, + com.google.common.* + + + org.opendaylight.controller.config.threadpool.util + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.opendaylight.yangtools + yang-maven-plugin + + + + + \ No newline at end of file diff --git a/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/CloseableAsyncEventBus.java b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/CloseableAsyncEventBus.java new file mode 100644 index 0000000000..93a08daa5d --- /dev/null +++ b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/CloseableAsyncEventBus.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. 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.threadpool.util; + +import com.google.common.eventbus.AsyncEventBus; +import com.google.common.eventbus.DeadEvent; +import com.google.common.eventbus.Subscribe; + +import java.io.Closeable; +import java.io.IOException; + +import org.opendaylight.controller.config.threadpool.ThreadPool; +import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusRuntimeMXBean; +import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusRuntimeRegistration; +import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusRuntimeRegistrator; + +/** + * Closeable version of {@link AsyncEventBus}. + */ +public class CloseableAsyncEventBus extends AsyncEventBus implements Closeable { + private final ThreadPool threadPool; + private final AsyncEventBusRuntimeRegistration rootRegistration; + + public CloseableAsyncEventBus(String identifier, ThreadPool threadPool, + AsyncEventBusRuntimeRegistrator rootRegistrator) { + super(identifier, threadPool.getExecutor()); + this.threadPool = threadPool; + rootRegistration = rootRegistrator.register(new AsyncEventBusRuntimeMXBean() { + private long deadEventsCounter = 0; + + @Subscribe + public void increaseDeadEvents(DeadEvent deadEvent) { + deadEventsCounter++; + } + + @Override + public Long countDeadEvents() { + return deadEventsCounter; + } + + }); + } + + public ThreadPool getThreadPool() { + return threadPool; + } + + @Override + public void close() throws IOException { + rootRegistration.close(); + } + +} diff --git a/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/CloseableEventBus.java b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/CloseableEventBus.java new file mode 100644 index 0000000000..b6dd77dbf3 --- /dev/null +++ b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/threadpool/util/CloseableEventBus.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. 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.threadpool.util; + +import java.io.Closeable; + +import org.opendaylight.controller.config.yang.threadpool.impl.EventBusRuntimeMXBean; +import org.opendaylight.controller.config.yang.threadpool.impl.EventBusRuntimeRegistration; +import org.opendaylight.controller.config.yang.threadpool.impl.EventBusRuntimeRegistrator; + +import com.google.common.eventbus.DeadEvent; +import com.google.common.eventbus.EventBus; +import com.google.common.eventbus.Subscribe; + +/** + * Closeable {@link EventBus}. + */ +public class CloseableEventBus extends EventBus implements Closeable { + + private final EventBusRuntimeRegistration rootRegistration; + + public CloseableEventBus(String identifier, EventBusRuntimeRegistrator rootRegistrator) { + super(identifier); + rootRegistration = rootRegistrator.register(new EventBusRuntimeMXBean() { + private long deadEventsCounter = 0; + + @Subscribe + public void increaseDeadEvents(DeadEvent deadEvent) { + deadEventsCounter++; + } + + @Override + public Long countDeadEvents() { + return deadEventsCounter; + } + }); + + } + + @Override + public void close() { + rootRegistration.close(); + + } +} diff --git a/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/AsyncEventBusModule.java b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/AsyncEventBusModule.java new file mode 100644 index 0000000000..f108303165 --- /dev/null +++ b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/AsyncEventBusModule.java @@ -0,0 +1,42 @@ +/** + * Generated file + + * Generated from: yang module name: threadpool-impl yang module local name: async-eventbus + * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + * Generated at: Tue Nov 05 15:40:46 CET 2013 + * + * Do not modify this file unless it is present under src/main directory + */ +package org.opendaylight.controller.config.yang.threadpool.impl; + +import org.opendaylight.controller.config.threadpool.util.CloseableAsyncEventBus; + +/** +* +*/ +public final class AsyncEventBusModule extends + org.opendaylight.controller.config.yang.threadpool.impl.AbstractAsyncEventBusModule { + + public AsyncEventBusModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public AsyncEventBusModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + AsyncEventBusModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void validate() { + super.validate(); + // Add custom validation for module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + return new CloseableAsyncEventBus(getIdentifier().toString(), getThreadpoolDependency(), + getRootRuntimeBeanRegistratorWrapper()); + } +} diff --git a/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/AsyncEventBusModuleFactory.java b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/AsyncEventBusModuleFactory.java new file mode 100644 index 0000000000..14fcf41758 --- /dev/null +++ b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/AsyncEventBusModuleFactory.java @@ -0,0 +1,18 @@ +/** + * Generated file + + * Generated from: yang module name: threadpool-impl yang module local name: async-eventbus + * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + * Generated at: Tue Nov 05 15:40:46 CET 2013 + * + * Do not modify this file unless it is present under src/main directory + */ +package org.opendaylight.controller.config.yang.threadpool.impl; + +/** +* +*/ +public class AsyncEventBusModuleFactory extends + org.opendaylight.controller.config.yang.threadpool.impl.AbstractAsyncEventBusModuleFactory { + +} diff --git a/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/EventBusModule.java b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/EventBusModule.java new file mode 100644 index 0000000000..92eaee5ef2 --- /dev/null +++ b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/EventBusModule.java @@ -0,0 +1,41 @@ +/** + * Generated file + + * Generated from: yang module name: threadpool-impl yang module local name: eventbus + * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + * Generated at: Tue Nov 05 15:40:46 CET 2013 + * + * Do not modify this file unless it is present under src/main directory + */ +package org.opendaylight.controller.config.yang.threadpool.impl; + +import org.opendaylight.controller.config.threadpool.util.CloseableEventBus; + +/** +* +*/ +public final class EventBusModule extends + org.opendaylight.controller.config.yang.threadpool.impl.AbstractEventBusModule { + + public EventBusModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public EventBusModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, EventBusModule oldModule, + java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void validate() { + super.validate(); + // Add custom validation for module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + return new CloseableEventBus(getIdentifier().toString(), getRootRuntimeBeanRegistratorWrapper()); + } +} diff --git a/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/EventBusModuleFactory.java b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/EventBusModuleFactory.java new file mode 100644 index 0000000000..e909998a72 --- /dev/null +++ b/opendaylight/config/threadpool-config-impl/src/main/java/org/opendaylight/controller/config/yang/threadpool/impl/EventBusModuleFactory.java @@ -0,0 +1,18 @@ +/** + * Generated file + + * Generated from: yang module name: threadpool-impl yang module local name: eventbus + * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + * Generated at: Tue Nov 05 15:40:46 CET 2013 + * + * Do not modify this file unless it is present under src/main directory + */ +package org.opendaylight.controller.config.yang.threadpool.impl; + +/** +* +*/ +public class EventBusModuleFactory extends + org.opendaylight.controller.config.yang.threadpool.impl.AbstractEventBusModuleFactory { + +} diff --git a/opendaylight/config/threadpool-config-impl/src/main/yang/threadpool-impl.yang b/opendaylight/config/threadpool-config-impl/src/main/yang/threadpool-impl.yang new file mode 100644 index 0000000000..4695564144 --- /dev/null +++ b/opendaylight/config/threadpool-config-impl/src/main/yang/threadpool-impl.yang @@ -0,0 +1,104 @@ +// vi: set smarttab et sw=4 tabstop=4: +module threadpool-impl { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl"; + prefix "th-java"; + + import threadpool { prefix th; revision-date 2013-04-09; } + import config { prefix config; revision-date 2013-04-05; } + import rpc-context { prefix rpcx; revision-date 2013-06-17; } + + organization "Cisco Systems, Inc."; + + contact "Robert Varga "; + + description + "This module contains the base YANG definitions for + thread services pure Java implementation. + + Copyright (c)2013 Cisco Systems, Inc. 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"; + + revision "2013-04-05" { + description + "Updated to work with new anchors."; + } + + revision "2013-04-03" { + description + "Initial revision by Anton Tkacik, Tomas Olvecky and + Robert Varga."; + } + + identity eventbus { + base config:module-type; + config:provided-service th:eventbus; + config:java-name-prefix EventBus; + } + + augment "/config:modules/config:module/config:configuration" { + case eventbus { + when "/config:modules/config:module/config:type = 'eventbus'"; + // No real configuration + } + } + + augment "/config:modules/config:module/config:state" { + case eventbus { + when "/config:modules/config:module/config:type = 'eventbus'"; + rpcx:rpc-context-instance "event-bus-rpc"; + } + } + + identity event-bus-rpc; + + identity async-eventbus { + base config:module-type; + config:provided-service th:eventbus; + config:java-name-prefix AsyncEventBus; + } + + augment "/config:modules/config:module/config:configuration" { + case async-eventbus { + when "/config:modules/config:module/config:type = 'async-eventbus'"; + container threadpool { + uses config:service-ref { + refine type { + //mandatory true; + config:required-identity th:threadpool; + } + } + } + } + } + + augment "/config:modules/config:module/config:state" { + case async-eventbus { + when "/config:modules/config:module/config:type = 'async-eventbus'"; + rpcx:rpc-context-instance "event-bus-rpc"; + } + } + + + + rpc get-dead-events-count { + config:java-name-prefix countDeadEvents; + input { + uses rpcx:rpc-context-ref { + refine context-instance { + rpcx:rpc-context-instance event-bus-rpc; + } + } + } + output { + leaf result { + type uint32; + } + } + } +} +