--- /dev/null
+/*
+ * 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 java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import org.opendaylight.controller.config.threadpool.ThreadPool;
+
+/**
+ * Implementation of {@link ThreadPool} using fixed number of threads wraps
+ * {@link ExecutorService}.
+ */
+public class FixedThreadPoolWrapper implements ThreadPool, Closeable {
+
+ private final ThreadPoolExecutor executor;
+
+ public FixedThreadPoolWrapper(int threadCount, ThreadFactory factory) {
+ this.executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadCount, factory);
+ executor.prestartAllCoreThreads();
+ }
+
+ @Override
+ public ExecutorService getExecutor() {
+ return Executors.unconfigurableExecutorService(executor);
+ }
+
+ @Override
+ public void close() {
+ executor.shutdown();
+ }
+
+ @Override
+ public int getMaxThreadCount() {
+ return executor.getMaximumPoolSize();
+ }
+
+ public void setMaxThreadCount(int maxThreadCount) {
+ executor.setCorePoolSize(maxThreadCount);
+ executor.setMaximumPoolSize(maxThreadCount);
+ }
+}
--- /dev/null
+/*
+ * 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 java.io.IOException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.opendaylight.controller.config.threadpool.ThreadPool;
+
+/**
+ * Implementation of {@link ThreadPool} using flexible number of threads wraps
+ * {@link ExecutorService}.
+ */
+public class FlexibleThreadPoolWrapper implements ThreadPool, Closeable {
+ private final ThreadPoolExecutor executor;
+
+ public FlexibleThreadPoolWrapper(int minThreadCount, int maxThreadCount, long keepAlive, TimeUnit timeUnit,
+ ThreadFactory threadFactory) {
+
+ executor = new ThreadPoolExecutor(minThreadCount, maxThreadCount, keepAlive, timeUnit,
+ new SynchronousQueue<Runnable>(), threadFactory);
+ executor.prestartAllCoreThreads();
+ }
+
+ @Override
+ public ExecutorService getExecutor() {
+ return Executors.unconfigurableExecutorService(executor);
+ }
+
+ public int getMinThreadCount() {
+ return executor.getCorePoolSize();
+ }
+
+ public void setMinThreadCount(int minThreadCount) {
+ executor.setCorePoolSize(minThreadCount);
+ }
+
+ @Override
+ public int getMaxThreadCount() {
+ return executor.getMaximumPoolSize();
+ }
+
+ public void setMaxThreadCount(int maxThreadCount) {
+ executor.setMaximumPoolSize(maxThreadCount);
+ }
+
+ public long getKeepAliveMillis() {
+ return executor.getKeepAliveTime(TimeUnit.MILLISECONDS);
+ }
+
+ public void setKeepAliveMillis(long keepAliveMillis) {
+ executor.setKeepAliveTime(keepAliveMillis, TimeUnit.MILLISECONDS);
+ }
+
+ public void setThreadFactory(ThreadFactory threadFactory) {
+ executor.setThreadFactory(threadFactory);
+ }
+
+ public void prestartAllCoreThreads() {
+ executor.prestartAllCoreThreads();
+ }
+
+ @Override
+ public void close() throws IOException {
+ executor.shutdown();
+ }
+
+}
--- /dev/null
+/*
+ * 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 java.io.IOException;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Implementation of {@link ThreadFactory}.
+ */
+@ThreadSafe
+public class NamingThreadPoolFactory implements ThreadFactory, Closeable {
+
+ private final ThreadGroup group;
+ private final String namePrefix;
+ private final AtomicLong threadName = new AtomicLong();
+
+ public NamingThreadPoolFactory(String namePrefix) {
+ Preconditions.checkNotNull(namePrefix);
+ this.group = new ThreadGroup(namePrefix);
+ this.namePrefix = namePrefix;
+ }
+
+ @Override
+ public Thread newThread(Runnable r) {
+ return new Thread(group, r, String.format("%s-%d", group.getName(), threadName.incrementAndGet()));
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+
+ public String getNamePrefix() {
+ return namePrefix;
+ }
+
+}
--- /dev/null
+/*
+ * 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 java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadFactory;
+
+import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
+
+/**
+ * Implementation of {@link ScheduledThreadPool} wraps
+ * {@link ScheduledExecutorService}.
+ */
+public class ScheduledThreadPoolWrapper implements ScheduledThreadPool, Closeable {
+
+ private final ScheduledThreadPoolExecutor executor;
+ private final int threadCount;
+
+ public ScheduledThreadPoolWrapper(int threadCount, ThreadFactory factory) {
+ this.threadCount = threadCount;
+ this.executor = new ScheduledThreadPoolExecutor(threadCount, factory);
+ executor.prestartAllCoreThreads();
+ }
+
+ @Override
+ public ScheduledExecutorService getExecutor() {
+ return Executors.unconfigurableScheduledExecutorService(executor);
+ }
+
+ @Override
+ public void close() {
+ executor.shutdown();
+ }
+
+ @Override
+ public int getMaxThreadCount() {
+ return threadCount;
+ }
+
+}
--- /dev/null
+/**
+ * Generated file
+
+ * Generated from: yang module name: threadpool-impl yang module local name: threadpool-fixed
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Nov 06 16:19:33 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.api.JmxAttributeValidationException;
+import org.opendaylight.controller.config.threadpool.util.FixedThreadPoolWrapper;
+
+/**
+*
+*/
+public final class FixedThreadPoolModule extends
+ org.opendaylight.controller.config.yang.threadpool.impl.AbstractFixedThreadPoolModule {
+
+ public FixedThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public FixedThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ FixedThreadPoolModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ public void validate() {
+ super.validate();
+
+ JmxAttributeValidationException.checkNotNull(getMaxThreadCount(), maxThreadCountJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getMaxThreadCount() > 0, "must be greater than zero",
+ maxThreadCountJmxAttribute);
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ return new FixedThreadPoolWrapper(getMaxThreadCount(), getThreadFactoryDependency());
+ }
+}
--- /dev/null
+/**
+ * Generated file
+
+ * Generated from: yang module name: threadpool-impl yang module local name: threadpool-fixed
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Nov 06 16:19:33 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 FixedThreadPoolModuleFactory extends
+ org.opendaylight.controller.config.yang.threadpool.impl.AbstractFixedThreadPoolModuleFactory {
+
+}
--- /dev/null
+/**
+ * Generated file
+
+ * Generated from: yang module name: threadpool-impl yang module local name: threadpool-flexible
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Nov 06 16:19:33 CET 2013
+ *
+ * Do not modify this file unless it is present under src/main directory
+ */
+package org.opendaylight.controller.config.yang.threadpool.impl;
+
+import java.util.concurrent.TimeUnit;
+
+import org.opendaylight.controller.config.api.JmxAttributeValidationException;
+import org.opendaylight.controller.config.threadpool.util.FlexibleThreadPoolWrapper;
+
+/**
+*
+*/
+public final class FlexibleThreadPoolModule extends
+ org.opendaylight.controller.config.yang.threadpool.impl.AbstractFlexibleThreadPoolModule {
+
+ public FlexibleThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public FlexibleThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ FlexibleThreadPoolModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ public void validate() {
+ super.validate();
+ JmxAttributeValidationException.checkNotNull(getKeepAliveMillis(), keepAliveMillisJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getKeepAliveMillis() > 0, "must be greater than zero",
+ keepAliveMillisJmxAttribute);
+
+ JmxAttributeValidationException.checkNotNull(getMinThreadCount(), minThreadCountJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getMinThreadCount() > 0, "must be greater than zero",
+ minThreadCountJmxAttribute);
+
+ JmxAttributeValidationException.checkNotNull(getMaxThreadCount(), maxThreadCountJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getMaxThreadCount() > 0, "must be greater than zero",
+ maxThreadCountJmxAttribute);
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ return new FlexibleThreadPoolWrapper(getMinThreadCount(), getMaxThreadCount(), getKeepAliveMillis(),
+ TimeUnit.MILLISECONDS, getThreadFactoryDependency());
+ }
+}
--- /dev/null
+/**
+ * Generated file
+
+ * Generated from: yang module name: threadpool-impl yang module local name: threadpool-flexible
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Nov 06 16:19:33 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 FlexibleThreadPoolModuleFactory extends
+ org.opendaylight.controller.config.yang.threadpool.impl.AbstractFlexibleThreadPoolModuleFactory {
+
+}
--- /dev/null
+/**
+ * Generated file
+
+ * Generated from: yang module name: threadpool-impl yang module local name: threadfactory-naming
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Nov 06 16:19:33 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.api.JmxAttributeValidationException;
+import org.opendaylight.controller.config.threadpool.util.NamingThreadPoolFactory;
+
+/**
+*
+*/
+public final class NamingThreadFactoryModule extends
+ org.opendaylight.controller.config.yang.threadpool.impl.AbstractNamingThreadFactoryModule {
+
+ public NamingThreadFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public NamingThreadFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ NamingThreadFactoryModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ public void validate() {
+ super.validate();
+ JmxAttributeValidationException.checkNotNull(getNamePrefix(), namePrefixJmxAttribute);
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ return new NamingThreadPoolFactory(getNamePrefix());
+ }
+}
--- /dev/null
+/**
+ * Generated file
+
+ * Generated from: yang module name: threadpool-impl yang module local name: threadfactory-naming
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Nov 06 16:19:33 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 NamingThreadFactoryModuleFactory extends
+ org.opendaylight.controller.config.yang.threadpool.impl.AbstractNamingThreadFactoryModuleFactory {
+
+}
--- /dev/null
+/**
+ * Generated file
+
+ * Generated from: yang module name: threadpool-impl yang module local name: threadpool-scheduled
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Nov 06 16:19:33 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.api.JmxAttributeValidationException;
+import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
+
+/**
+*
+*/
+public final class ScheduledThreadPoolModule extends
+ org.opendaylight.controller.config.yang.threadpool.impl.AbstractScheduledThreadPoolModule {
+
+ public ScheduledThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public ScheduledThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ ScheduledThreadPoolModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ public void validate() {
+ super.validate();
+ JmxAttributeValidationException.checkNotNull(getMaxThreadCount(), maxThreadCountJmxAttribute);
+ JmxAttributeValidationException.checkCondition(getMaxThreadCount() > 0, "must be greater than zero",
+ maxThreadCountJmxAttribute);
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ return new ScheduledThreadPoolWrapper(getMaxThreadCount(), getThreadFactoryDependency());
+ }
+}
--- /dev/null
+/**
+ * Generated file
+
+ * Generated from: yang module name: threadpool-impl yang module local name: threadpool-scheduled
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Nov 06 16:19:33 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 ScheduledThreadPoolModuleFactory extends
+ org.opendaylight.controller.config.yang.threadpool.impl.AbstractScheduledThreadPoolModuleFactory {
+
+}
}
}
-
-
rpc get-dead-events-count {
config:java-name-prefix countDeadEvents;
input {
}
}
}
+
+ identity threadfactory-naming {
+ base config:module-type;
+ config:provided-service th:threadfactory;
+ config:java-name-prefix NamingThreadFactory;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case threadfactory-naming {
+ when "/config:modules/config:module/config:type = 'threadfactory-naming'";
+ leaf name-prefix {
+ type string;
+ }
+ }
+ }
+
+ identity threadpool-fixed {
+ base config:module-type;
+ config:provided-service th:threadpool;
+ config:java-name-prefix FixedThreadPool;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case threadpool-fixed {
+ when "/config:modules/config:module/config:type = 'threadpool-fixed'";
+ leaf max-thread-count {
+ type uint16;
+ }
+
+ container threadFactory {
+ uses config:service-ref {
+ refine type {
+ //mandatory true;
+ config:required-identity th:threadfactory;
+ }
+ }
+ }
+ }
+ }
+
+ identity threadpool-flexible {
+ base config:module-type;
+ config:provided-service th:threadpool;
+ config:java-name-prefix FlexibleThreadPool;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case threadpool-flexible {
+ when "/config:modules/config:module/config:type = 'threadpool-flexible'";
+ leaf max-thread-count {
+ type uint16;
+ }
+ leaf minThreadCount {
+ type uint16;
+ }
+ leaf keepAliveMillis {
+ type uint32;
+ }
+
+ container threadFactory {
+ uses config:service-ref {
+ refine type {
+ // mandatory true;
+ config:required-identity th:threadfactory;
+ }
+ }
+ }
+ }
+ }
+
+ identity threadpool-scheduled {
+ base config:module-type;
+ config:provided-service th:scheduled-threadpool;
+ config:java-name-prefix ScheduledThreadPool;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case threadpool-scheduled {
+ when "/config:modules/config:module/config:type = 'threadpool-scheduled'";
+ leaf max-thread-count {
+ type uint16;
+ }
+
+ container threadFactory {
+ uses config:service-ref {
+ refine type {
+ // mandatory true;
+ config:required-identity th:threadfactory;
+ }
+ }
+ }
+ }
+ }
}