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.ScheduledExecutorService;
13 import java.util.concurrent.ThreadFactory;
15 import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator;
16 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory;
18 import com.google.common.util.concurrent.ListeningExecutorService;
19 import com.google.common.util.concurrent.MoreExecutors;
20 import com.google.common.util.concurrent.ThreadFactoryBuilder;
22 import javassist.ClassPool;
24 public class SingletonHolder {
26 public static final ClassPool CLASS_POOL = new ClassPool();
27 public static final org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator RPC_GENERATOR_IMPL = new org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator(
29 public static final RuntimeCodeGenerator RPC_GENERATOR = RPC_GENERATOR_IMPL;
30 public static final NotificationInvokerFactory INVOKER_FACTORY = RPC_GENERATOR_IMPL.getInvokerFactory();
31 private static ListeningExecutorService NOTIFICATION_EXECUTOR = null;
32 private static ListeningExecutorService COMMIT_EXECUTOR = null;
34 public static synchronized final ListeningExecutorService getDefaultNotificationExecutor() {
35 if (NOTIFICATION_EXECUTOR == null) {
36 NOTIFICATION_EXECUTOR = createNamedExecutor("md-sal-binding-notification-%d");
38 return NOTIFICATION_EXECUTOR;
41 public static synchronized final ListeningExecutorService getDefaultCommitExecutor() {
42 if (COMMIT_EXECUTOR == null) {
43 COMMIT_EXECUTOR = createNamedExecutor("md-sal-binding-commit-%d");
46 return COMMIT_EXECUTOR;
49 private static ListeningExecutorService createNamedExecutor(String format) {
50 ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat(format).build();
51 ExecutorService executor = Executors.newCachedThreadPool(factory);
52 return MoreExecutors.listeningDecorator(executor);