2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.util
;
20 import org
.apache
.hbase
.thirdparty
.io
.netty
.channel
.Channel
;
21 import org
.apache
.hbase
.thirdparty
.io
.netty
.channel
.EventLoopGroup
;
22 import org
.apache
.hbase
.thirdparty
.io
.netty
.channel
.ServerChannel
;
23 import org
.apache
.hbase
.thirdparty
.io
.netty
.channel
.epoll
.EpollEventLoopGroup
;
24 import org
.apache
.hbase
.thirdparty
.io
.netty
.channel
.epoll
.EpollServerSocketChannel
;
25 import org
.apache
.hbase
.thirdparty
.io
.netty
.channel
.epoll
.EpollSocketChannel
;
26 import org
.apache
.hbase
.thirdparty
.io
.netty
.channel
.nio
.NioEventLoopGroup
;
27 import org
.apache
.hbase
.thirdparty
.io
.netty
.channel
.socket
.nio
.NioServerSocketChannel
;
28 import org
.apache
.hbase
.thirdparty
.io
.netty
.channel
.socket
.nio
.NioSocketChannel
;
29 import org
.apache
.hbase
.thirdparty
.io
.netty
.util
.concurrent
.DefaultThreadFactory
;
31 import java
.util
.concurrent
.ThreadFactory
;
33 import org
.apache
.hadoop
.conf
.Configuration
;
34 import org
.apache
.yetus
.audience
.InterfaceAudience
;
37 * Event loop group related config.
39 @InterfaceAudience.Private
40 public class NettyEventLoopGroupConfig
{
42 private final EventLoopGroup group
;
44 private final Class
<?
extends ServerChannel
> serverChannelClass
;
46 private final Class
<?
extends Channel
> clientChannelClass
;
48 private static boolean useEpoll(Configuration conf
) {
49 // Config to enable native transport.
50 boolean epollEnabled
= conf
.getBoolean("hbase.netty.nativetransport", true);
51 // Use the faster native epoll transport mechanism on linux if enabled
52 return epollEnabled
&& JVM
.isLinux() && JVM
.isAmd64();
55 public NettyEventLoopGroupConfig(Configuration conf
, String threadPoolName
) {
56 boolean useEpoll
= useEpoll(conf
);
57 int workerCount
= conf
.getInt("hbase.netty.worker.count", 0);
58 ThreadFactory eventLoopThreadFactory
=
59 new DefaultThreadFactory(threadPoolName
, true, Thread
.MAX_PRIORITY
);
61 group
= new EpollEventLoopGroup(workerCount
, eventLoopThreadFactory
);
62 serverChannelClass
= EpollServerSocketChannel
.class;
63 clientChannelClass
= EpollSocketChannel
.class;
65 group
= new NioEventLoopGroup(workerCount
, eventLoopThreadFactory
);
66 serverChannelClass
= NioServerSocketChannel
.class;
67 clientChannelClass
= NioSocketChannel
.class;
71 public EventLoopGroup
group() {
75 public Class
<?
extends ServerChannel
> serverChannelClass() {
76 return serverChannelClass
;
79 public Class
<?
extends Channel
> clientChannelClass() {
80 return clientChannelClass
;