elanmanager dead code removal
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / ha / listeners / HAJobScheduler.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  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.netvirt.elan.l2gw.ha.listeners;
9
10 import com.google.common.util.concurrent.ThreadFactoryBuilder;
11 import java.util.concurrent.ExecutorService;
12 import java.util.concurrent.Executors;
13 import java.util.concurrent.ThreadFactory;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17
18 public final class HAJobScheduler implements Thread.UncaughtExceptionHandler {
19
20     private static final Logger LOG = LoggerFactory.getLogger(HAJobScheduler.class);
21     ExecutorService executorService;
22
23     static HAJobScheduler instance = new HAJobScheduler();
24
25     private HAJobScheduler() {
26         ThreadFactory threadFact = new ThreadFactoryBuilder()
27                 .setNameFormat("hwvtep-ha-task-%d").setUncaughtExceptionHandler(this).build();
28         executorService = Executors.newSingleThreadScheduledExecutor(threadFact);
29     }
30
31     public static HAJobScheduler getInstance() {
32         return instance;
33     }
34
35     public void submitJob(Runnable runnable) {
36         executorService.execute(runnable);
37     }
38
39     @Override
40     public void uncaughtException(Thread thread, Throwable throwable) {
41         LOG.error("Failed to execute task", throwable);
42     }
43 }