Mechanical code cleanup (config)
[controller.git] / opendaylight / config / netty-threadgroup-config / src / main / java / org / opendaylight / controller / config / yang / netty / threadgroup / NettyThreadgroupModule.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: nsos-threadpool  yang module local name: netty-threadgroup-fixed
13 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
14 * Generated at: Fri Nov 08 08:31:45 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.threadgroup;
19
20 import com.google.common.reflect.AbstractInvocationHandler;
21 import com.google.common.reflect.Reflection;
22 import io.netty.channel.EventLoopGroup;
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 NettyThreadgroupModule extends org.opendaylight.controller.config.yang.netty.threadgroup.AbstractNettyThreadgroupModule
33 {
34     private BundleContext bundleContext;
35
36     public NettyThreadgroupModule(org.opendaylight.controller.config.api.ModuleIdentifier name, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
37         super(name, dependencyResolver);
38     }
39
40     public NettyThreadgroupModule(org.opendaylight.controller.config.api.ModuleIdentifier name, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, NettyThreadgroupModule oldModule, java.lang.AutoCloseable oldInstance) {
41         super(name, dependencyResolver, oldModule, oldInstance);
42     }
43
44     @Override
45     public void validate(){
46         if(getThreadCount()!=null) {
47             JmxAttributeValidationException.checkCondition(getThreadCount() > 0, "value must be greater than 0",
48                     threadCountJmxAttribute);
49         }
50     }
51
52     @Override
53     public AutoCloseable createInstance() {
54         // The service is provided via blueprint so wait for and return it here for backwards compatibility.
55         String typeFilter = String.format("(type=%s)", getIdentifier().getInstanceName());
56         final WaitingServiceTracker<EventLoopGroup> tracker = WaitingServiceTracker.create(
57                 EventLoopGroup.class, bundleContext, typeFilter);
58         final EventLoopGroup group = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
59
60         return Reflection.newProxy(AutoCloseableEventLoopGroupInterface.class, new AbstractInvocationHandler() {
61             @Override
62             protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
63                 if (method.getName().equals("close")) {
64                     tracker.close();
65                     return null;
66                 } else {
67                     return method.invoke(group, args);
68                 }
69             }
70         });
71     }
72
73     public void setBundleContext(BundleContext bundleContext) {
74         this.bundleContext = bundleContext;
75     }
76
77     private interface AutoCloseableEventLoopGroupInterface extends EventLoopGroup, AutoCloseable {
78     }
79 }

©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.