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.ThreadFactory;
14 import javassist.ClassPool;
16 import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator;
17 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory;
19 import com.google.common.util.concurrent.ListeningExecutorService;
20 import com.google.common.util.concurrent.MoreExecutors;
21 import com.google.common.util.concurrent.ThreadFactoryBuilder;
23 public class SingletonHolder {
25 public static final ClassPool CLASS_POOL = new ClassPool();
26 public static final org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator RPC_GENERATOR_IMPL = new org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator(
28 public static final RuntimeCodeGenerator RPC_GENERATOR = RPC_GENERATOR_IMPL;
29 public static final NotificationInvokerFactory INVOKER_FACTORY = RPC_GENERATOR_IMPL.getInvokerFactory();
30 private static ListeningExecutorService NOTIFICATION_EXECUTOR = null;
31 private static ListeningExecutorService COMMIT_EXECUTOR = null;
33 public static synchronized final ListeningExecutorService getDefaultNotificationExecutor() {
34 if (NOTIFICATION_EXECUTOR == null) {
35 NOTIFICATION_EXECUTOR = createNamedExecutor("md-sal-binding-notification-%d");
37 return NOTIFICATION_EXECUTOR;
41 * @deprecated This method is only used from configuration modules and thus callers of it
42 * should use service injection to make the executor configurable.
45 public static synchronized final ListeningExecutorService getDefaultCommitExecutor() {
46 if (COMMIT_EXECUTOR == null) {
47 ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("md-sal-binding-commit-%d").build();
49 * FIXME: this used to be newCacheThreadPool(), but MD-SAL does not have transaction
50 * ordering guarantees, which means that using a concurrent threadpool results
51 * in application data being committed in random order, potentially resulting
52 * in inconsistent data being present. Once proper primitives are introduced,
53 * concurrency can be reintroduced.
55 ExecutorService executor = Executors.newSingleThreadExecutor(factory);
56 COMMIT_EXECUTOR = MoreExecutors.listeningDecorator(executor);
59 return COMMIT_EXECUTOR;
62 private static ListeningExecutorService createNamedExecutor(String format) {
63 ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat(format).build();
64 ExecutorService executor = Executors.newCachedThreadPool(factory);
65 return MoreExecutors.listeningDecorator(executor);