Added config SI for io.netty.util.Timer and config module wrapper for HashedWheelTime...
[controller.git] / opendaylight / config / netty-timer-config / src / main / java / org / opendaylight / controller / config / yang / netty / timer / HashedWheelTimerModule.java
1 /**
2  * Generated file
3
4  * Generated from: yang module name: netty-event-executor  yang module local name: netty-hashed-wheel-timer
5  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6  * Generated at: Tue Nov 19 12:49:59 CET 2013
7  *
8  * Do not modify this file unless it is present under src/main directory
9  */
10 package org.opendaylight.controller.config.yang.netty.timer;
11
12 import io.netty.util.HashedWheelTimer;
13 import io.netty.util.Timeout;
14 import io.netty.util.Timer;
15 import io.netty.util.TimerTask;
16
17 import java.util.Set;
18 import java.util.concurrent.TimeUnit;
19
20 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
21
22 /**
23 *
24 */
25 public final class HashedWheelTimerModule extends
26         org.opendaylight.controller.config.yang.netty.timer.AbstractHashedWheelTimerModule {
27
28     public HashedWheelTimerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
29             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
30         super(identifier, dependencyResolver);
31     }
32
33     public HashedWheelTimerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
34             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
35             HashedWheelTimerModule oldModule, java.lang.AutoCloseable oldInstance) {
36         super(identifier, dependencyResolver, oldModule, oldInstance);
37     }
38
39     @Override
40     public void validate() {
41         super.validate();
42         if (getTickDuration() != null) {
43             JmxAttributeValidationException.checkCondition(getTickDuration() > 0, "value must be greater than 0",
44                     tickDurationJmxAttribute);
45         }
46         if (getTicksPerWheel() != null) {
47             JmxAttributeValidationException.checkCondition(getTicksPerWheel() > 0, "value must be greater than 0",
48                     ticksPerWheelJmxAttribute);
49         }
50     }
51
52     @Override
53     public java.lang.AutoCloseable createInstance() {
54         TimeUnit unit = TimeUnit.MILLISECONDS;
55         if (getTickDuration() != null && getThreadFactoryDependency() == null && getTicksPerWheel() == null) {
56             return new HashedWheelTimerCloseable(new HashedWheelTimer(getTickDuration(), unit));
57         }
58         if (getTickDuration() != null && getThreadFactoryDependency() == null && getTicksPerWheel() != null) {
59             return new HashedWheelTimerCloseable(new HashedWheelTimer(getTickDuration(), unit, getTicksPerWheel()));
60         }
61         if (getTickDuration() == null && getThreadFactoryDependency() != null && getTicksPerWheel() == null) {
62             return new HashedWheelTimerCloseable(new HashedWheelTimer(getThreadFactoryDependency()));
63         }
64         if (getTickDuration() != null && getThreadFactoryDependency() != null && getTicksPerWheel() == null) {
65             return new HashedWheelTimerCloseable(new HashedWheelTimer(getThreadFactoryDependency(), getTickDuration(),
66                     unit));
67         }
68         if (getTickDuration() != null && getThreadFactoryDependency() != null && getTicksPerWheel() != null) {
69             return new HashedWheelTimerCloseable(new HashedWheelTimer(getThreadFactoryDependency(), getTickDuration(),
70                     unit, getTicksPerWheel()));
71         }
72         return new HashedWheelTimerCloseable(new HashedWheelTimer());
73     }
74
75     static final private class HashedWheelTimerCloseable implements AutoCloseable, Timer {
76
77         private final Timer timer;
78
79         public HashedWheelTimerCloseable(Timer timer) {
80             this.timer = timer;
81         }
82
83         @Override
84         public void close() throws Exception {
85             stop();
86         }
87
88         @Override
89         public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit) {
90             return this.timer.newTimeout(task, delay, unit);
91         }
92
93         @Override
94         public Set<Timeout> stop() {
95             return this.timer.stop();
96         }
97
98     }
99 }