5f92f943e38253b2dad493b14343749393d5a162
[controller.git] / opendaylight / config / netty-threadgroup-config / src / main / java / org / opendaylight / controller / config / yang / netty / threadgroup / NioEventLoopGroupCloseable.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 package org.opendaylight.controller.config.yang.netty.threadgroup;
9
10 import io.netty.channel.nio.NioEventLoopGroup;
11 import java.util.concurrent.TimeUnit;
12
13 public class NioEventLoopGroupCloseable extends NioEventLoopGroup implements AutoCloseable {
14     private NioEventLoopGroupCloseable(final int threadCount) {
15         super(threadCount);
16     }
17
18     private NioEventLoopGroupCloseable() {
19     }
20
21     @Override
22     public void close() throws Exception {
23         shutdownGracefully(0, 1, TimeUnit.SECONDS);
24     }
25
26     public static NioEventLoopGroupCloseable newInstance(final Integer threadCount) {
27         if(threadCount == null || threadCount <= 0) {
28             return new NioEventLoopGroupCloseable();
29         }
30
31         return new NioEventLoopGroupCloseable(threadCount);
32     }
33 }