Update MRI projects for Aluminium
[lispflowmapping.git] / mappingservice / neutron / src / main / java / org / opendaylight / lispflowmapping / neutron / intenthandler / IntentHandlerAsyncExecutorProvider.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.lispflowmapping.neutron.intenthandler;
9
10 import com.google.common.util.concurrent.ListeningExecutorService;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.concurrent.Executors;
13
14 /**
15  * Created by Shakib Ahmed on 1/24/17.
16  */
17 public final class IntentHandlerAsyncExecutorProvider {
18     private static ListeningExecutorService listeningExecutorService;
19
20     private static final int EXTRA_THREADS_TO_HANDLE_VPP_LISTENER = 1;
21
22     private static IntentHandlerAsyncExecutorProvider intentHandlerAsyncExecutorProvider;
23
24     private IntentHandlerAsyncExecutorProvider() {
25         listeningExecutorService = MoreExecutors
26                 .listeningDecorator(Executors.newFixedThreadPool(EXTRA_THREADS_TO_HANDLE_VPP_LISTENER));
27     }
28
29     public static synchronized IntentHandlerAsyncExecutorProvider getInstace() {
30         if (intentHandlerAsyncExecutorProvider == null) {
31             intentHandlerAsyncExecutorProvider = new IntentHandlerAsyncExecutorProvider();
32         }
33         return intentHandlerAsyncExecutorProvider;
34     }
35
36     public synchronized ListeningExecutorService getExecutor() {
37         return listeningExecutorService;
38     }
39
40     public void close() {
41         listeningExecutorService.shutdown();
42     }
43 }