BUG-731 : removed some sonar warnings
[bgpcep.git] / pcep / ietf-stateful02 / src / main / java / org / opendaylight / controller / config / yang / pcep / stateful02 / cfg / Stateful02PCEPSessionProposalFactoryModule.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.config.yang.pcep.stateful02.cfg;
9
10 import com.google.common.base.Preconditions;
11 import java.net.InetSocketAddress;
12 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
13 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
14 import org.opendaylight.protocol.pcep.ietf.stateful02.Stateful02SessionProposalFactory;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  *
21  */
22 public final class Stateful02PCEPSessionProposalFactoryModule extends org.opendaylight.controller.config.yang.pcep.stateful02.cfg.AbstractStateful02PCEPSessionProposalFactoryModule {
23     private static final Logger LOG = LoggerFactory.getLogger(Stateful02PCEPSessionProposalFactoryModule.class);
24
25     private static final String NOT_SET = "value is not set.";
26     private static final int RATIO = 4;
27
28     public Stateful02PCEPSessionProposalFactoryModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
29         final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
30         super(identifier, dependencyResolver);
31     }
32
33     public Stateful02PCEPSessionProposalFactoryModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
34         final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
35         final Stateful02PCEPSessionProposalFactoryModule oldModule, final java.lang.AutoCloseable oldInstance) {
36
37         super(identifier, dependencyResolver, oldModule, oldInstance);
38     }
39
40     @Override
41     protected void customValidation() {
42         JmxAttributeValidationException.checkNotNull(getActive(), NOT_SET, activeJmxAttribute);
43         JmxAttributeValidationException.checkNotNull(getInitiated(), NOT_SET, initiatedJmxAttribute);
44         JmxAttributeValidationException.checkNotNull(getDeadTimerValue(), NOT_SET, deadTimerValueJmxAttribute);
45         JmxAttributeValidationException.checkNotNull(getKeepAliveTimerValue(), NOT_SET, keepAliveTimerValueJmxAttribute);
46         JmxAttributeValidationException.checkNotNull(getTimeout(), NOT_SET, timeoutJmxAttribute);
47         if (getKeepAliveTimerValue() != 0) {
48             JmxAttributeValidationException.checkCondition(getKeepAliveTimerValue() >= 1, "minimum value is 1.",
49                 keepAliveTimerValueJmxAttribute);
50             if (getDeadTimerValue() != 0 && (getDeadTimerValue() / getKeepAliveTimerValue() != RATIO)) {
51                 LOG.warn("DeadTimerValue should be 4 times greater than KeepAliveTimerValue");
52             }
53         }
54         if (getActive() && !getStateful()) {
55             setStateful(true);
56         }
57         JmxAttributeValidationException.checkNotNull(getStateful(), "value is not set.", statefulJmxAttribute);
58     }
59
60     @Override
61     public java.lang.AutoCloseable createInstance() {
62         final Stateful02SessionProposalFactory inner = new Stateful02SessionProposalFactory(getDeadTimerValue(), getKeepAliveTimerValue(), getStateful(), getActive(), getInitiated(), getTimeout());
63         return new PCEPSessionProposalFactoryCloseable(inner);
64     }
65
66     private static final class PCEPSessionProposalFactoryCloseable implements PCEPSessionProposalFactory, AutoCloseable {
67         private final Stateful02SessionProposalFactory inner;
68
69         public PCEPSessionProposalFactoryCloseable(final Stateful02SessionProposalFactory inner) {
70             this.inner = Preconditions.checkNotNull(inner);
71         }
72
73         @Override
74         public void close() {
75         }
76
77         @Override
78         public Open getSessionProposal(final InetSocketAddress inetSocketAddress, final int sessionId) {
79             return this.inner.getSessionProposal(inetSocketAddress, sessionId);
80         }
81     }
82 }