netty-threadgroup-config: final parameters
[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         super();
20     }
21
22     @Override
23     public void close() throws Exception {
24         shutdownGracefully(0, 1, TimeUnit.SECONDS);
25     }
26
27     public static NioEventLoopGroupCloseable newInstance(final Integer threadCount) {
28         if(threadCount == null || threadCount <= 0) {
29             return new NioEventLoopGroupCloseable();
30         }
31
32         return new NioEventLoopGroupCloseable(threadCount);
33     }
34 }