2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.binding.codegen.impl;
10 import java.util.concurrent.ExecutorService;
11 import java.util.concurrent.Executors;
12 import java.util.concurrent.LinkedBlockingQueue;
13 import java.util.concurrent.ThreadFactory;
14 import java.util.concurrent.ThreadPoolExecutor;
15 import java.util.concurrent.TimeUnit;
17 import javassist.ClassPool;
19 import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator;
20 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory;
22 import com.google.common.util.concurrent.ListeningExecutorService;
23 import com.google.common.util.concurrent.MoreExecutors;
24 import com.google.common.util.concurrent.ThreadFactoryBuilder;
26 public class SingletonHolder {
28 public static final ClassPool CLASS_POOL = new ClassPool();
29 public static final org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator RPC_GENERATOR_IMPL = new org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator(
31 public static final RuntimeCodeGenerator RPC_GENERATOR = RPC_GENERATOR_IMPL;
32 public static final NotificationInvokerFactory INVOKER_FACTORY = RPC_GENERATOR_IMPL.getInvokerFactory();
34 public static final int CORE_NOTIFICATION_THREADS = 4;
35 public static final int MAX_NOTIFICATION_THREADS = 32;
36 public static final int NOTIFICATION_THREAD_LIFE = 15;
38 private static ListeningExecutorService NOTIFICATION_EXECUTOR = null;
39 private static ListeningExecutorService COMMIT_EXECUTOR = null;
40 private static ListeningExecutorService CHANGE_EVENT_EXECUTOR = null;
43 * @deprecated This method is only used from configuration modules and thus callers of it
44 * should use service injection to make the executor configurable.
47 public static synchronized final ListeningExecutorService getDefaultNotificationExecutor() {
48 if (NOTIFICATION_EXECUTOR == null) {
49 ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("md-sal-binding-notification-%d").build();
50 ExecutorService executor = new ThreadPoolExecutor(CORE_NOTIFICATION_THREADS, MAX_NOTIFICATION_THREADS,
51 NOTIFICATION_THREAD_LIFE, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), factory);
52 NOTIFICATION_EXECUTOR = MoreExecutors.listeningDecorator(executor);
54 return NOTIFICATION_EXECUTOR;
58 * @deprecated This method is only used from configuration modules and thus callers of it
59 * should use service injection to make the executor configurable.
62 public static synchronized final ListeningExecutorService getDefaultCommitExecutor() {
63 if (COMMIT_EXECUTOR == null) {
64 ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("md-sal-binding-commit-%d").build();
66 * FIXME: this used to be newCacheThreadPool(), but MD-SAL does not have transaction
67 * ordering guarantees, which means that using a concurrent threadpool results
68 * in application data being committed in random order, potentially resulting
69 * in inconsistent data being present. Once proper primitives are introduced,
70 * concurrency can be reintroduced.
72 ExecutorService executor = Executors.newSingleThreadExecutor(factory);
73 COMMIT_EXECUTOR = MoreExecutors.listeningDecorator(executor);
76 return COMMIT_EXECUTOR;
79 public static ExecutorService getDefaultChangeEventExecutor() {
80 if (CHANGE_EVENT_EXECUTOR == null) {
81 ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("md-sal-binding-change-%d").build();
83 * FIXME: this used to be newCacheThreadPool(), but MD-SAL does not have transaction
84 * ordering guarantees, which means that using a concurrent threadpool results
85 * in application data being committed in random order, potentially resulting
86 * in inconsistent data being present. Once proper primitives are introduced,
87 * concurrency can be reintroduced.
89 ExecutorService executor = Executors.newSingleThreadExecutor(factory);
90 CHANGE_EVENT_EXECUTOR = MoreExecutors.listeningDecorator(executor);
93 return CHANGE_EVENT_EXECUTOR;