Bug-731: Fixed few major Sonar warnings
[bgpcep.git] / programming / impl / src / main / java / org / opendaylight / controller / config / yang / programming / impl / InstructionSchedulerImplModule.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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 /**
9  * Generated file
10
11  * Generated from: yang module name: config-programming-impl  yang module local name: instruction-scheduler-impl
12  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13  * Generated at: Mon Nov 18 16:50:17 CET 2013
14  *
15  * Do not modify this file unless it is present under src/main directory
16  */
17 package org.opendaylight.controller.config.yang.programming.impl;
18
19 import com.google.common.util.concurrent.ListenableFuture;
20 import com.google.common.util.concurrent.ListeningExecutorService;
21 import com.google.common.util.concurrent.MoreExecutors;
22 import java.util.concurrent.Executors;
23 import org.opendaylight.bgpcep.programming.impl.ProgrammingServiceImpl;
24 import org.opendaylight.bgpcep.programming.spi.Instruction;
25 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
26 import org.opendaylight.bgpcep.programming.spi.SchedulerException;
27 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.ProgrammingService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.SubmitInstructionInput;
30
31 /**
32  *
33  */
34 public final class InstructionSchedulerImplModule extends
35         org.opendaylight.controller.config.yang.programming.impl.AbstractInstructionSchedulerImplModule {
36
37     public InstructionSchedulerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
38             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
39         super(identifier, dependencyResolver);
40     }
41
42     public InstructionSchedulerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
43             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
44             final InstructionSchedulerImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
45         super(identifier, dependencyResolver, oldModule, oldInstance);
46     }
47
48     @Override
49     protected void customValidation() {
50         // Add custom validation for module attributes here.
51     }
52
53     @Override
54     public java.lang.AutoCloseable createInstance() {
55         final ListeningExecutorService exec = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
56
57         final ProgrammingServiceImpl inst = new ProgrammingServiceImpl(getDataProviderDependency(), getNotificationServiceDependency(), exec, getTimerDependency());
58
59         final RpcRegistration<ProgrammingService> reg = getRpcRegistryDependency().addRpcImplementation(ProgrammingService.class, inst);
60
61         final class ProgrammingServiceImplCloseable implements InstructionScheduler, AutoCloseable {
62             @Override
63             public void close() {
64                 try {
65                     reg.close();
66                 } finally {
67                     try {
68                         inst.close();
69                     } finally {
70                         exec.shutdown();
71                     }
72                 }
73             }
74
75             @Override
76             public ListenableFuture<Instruction> scheduleInstruction(final SubmitInstructionInput input) throws SchedulerException {
77                 return inst.scheduleInstruction(input);
78             }
79         }
80
81         return new ProgrammingServiceImplCloseable();
82     }
83 }