d1d55405a96a825ff23c44a00f4b9b10e80eec17
[controller.git] / opendaylight / config / netty-timer-config / src / main / java / org / opendaylight / controller / config / yang / netty / timer / HashedWheelTimerModule.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 /**
10  * Generated file
11
12  * Generated from: yang module name: netty-event-executor  yang module local name: netty-hashed-wheel-timer
13  * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
14  * Generated at: Tue Nov 19 12:49:59 CET 2013
15  *
16  * Do not modify this file unless it is present under src/main directory
17  */
18 package org.opendaylight.controller.config.yang.netty.timer;
19
20 import com.google.common.reflect.AbstractInvocationHandler;
21 import com.google.common.reflect.Reflection;
22 import io.netty.util.Timer;
23 import java.lang.reflect.Method;
24 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
25 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
26 import org.osgi.framework.BundleContext;
27
28 /**
29  * @deprecated Replaced by blueprint wiring
30  */
31 @Deprecated
32 public final class HashedWheelTimerModule extends
33         org.opendaylight.controller.config.yang.netty.timer.AbstractHashedWheelTimerModule {
34     private BundleContext bundleContext;
35
36     public HashedWheelTimerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
37             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
38         super(identifier, dependencyResolver);
39     }
40
41     public HashedWheelTimerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
42             org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
43             HashedWheelTimerModule oldModule, java.lang.AutoCloseable oldInstance) {
44         super(identifier, dependencyResolver, oldModule, oldInstance);
45     }
46
47     @Override
48     public void validate() {
49         super.validate();
50         if (getTickDuration() != null) {
51             JmxAttributeValidationException.checkCondition(getTickDuration() > 0, "value must be greater than 0",
52                     tickDurationJmxAttribute);
53         }
54         if (getTicksPerWheel() != null) {
55             JmxAttributeValidationException.checkCondition(getTicksPerWheel() > 0, "value must be greater than 0",
56                     ticksPerWheelJmxAttribute);
57         }
58     }
59
60     @Override
61     public AutoCloseable createInstance() {
62         // The service is provided via blueprint so wait for and return it here for backwards compatibility.
63         final WaitingServiceTracker<Timer> tracker = WaitingServiceTracker.create(
64                 Timer.class, bundleContext, "(type=global-timer)");
65         final Timer timer = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
66
67         return Reflection.newProxy(AutoCloseableTimerInterface.class, new AbstractInvocationHandler() {
68             @Override
69             protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
70                 if (method.getName().equals("close")) {
71                     tracker.close();
72                     return null;
73                 } else {
74                     return method.invoke(timer, args);
75                 }
76             }
77         });
78     }
79
80     public void setBundleContext(BundleContext bundleContext) {
81         this.bundleContext = bundleContext;
82     }
83
84     private static interface AutoCloseableTimerInterface extends Timer, AutoCloseable {
85     }
86 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.