28
28
import io .netty .buffer .ByteBufAllocatorMetricProvider ;
29
29
import io .netty .buffer .UnpooledByteBufAllocator ;
30
30
import io .netty .channel .ChannelInitializer ;
31
- import io .netty .channel .DefaultEventLoopGroup ;
32
31
import io .netty .channel .EventLoop ;
33
- import io .netty .channel .nio .NioEventLoopGroup ;
32
+ import io .netty .channel .local .LocalIoHandler ;
33
+ import io .netty .channel .MultithreadEventLoopGroup ;
34
+ import io .netty .channel .MultiThreadIoEventLoopGroup ;
35
+ import io .netty .channel .nio .NioIoHandler ;
36
+ import io .netty .channel .SingleThreadIoEventLoop ;
34
37
import io .netty .channel .socket .SocketChannel ;
35
38
import io .netty .channel .socket .nio .NioSocketChannel ;
36
39
import io .netty .util .concurrent .SingleThreadEventExecutor ;
@@ -54,7 +57,7 @@ void directInstrumentationExample() throws Exception {
54
57
Set <String > names = new LinkedHashSet <>();
55
58
// tag::directInstrumentation[]
56
59
// Create or get an existing resources
57
- DefaultEventLoopGroup eventExecutors = new DefaultEventLoopGroup ( );
60
+ MultithreadEventLoopGroup eventExecutors = new MultiThreadIoEventLoopGroup ( LocalIoHandler . newFactory () );
58
61
UnpooledByteBufAllocator unpooledByteBufAllocator = new UnpooledByteBufAllocator (false );
59
62
// Use binders to instrument them
60
63
new NettyEventExecutorMetrics (eventExecutors ).bindTo (this .registry );
@@ -84,18 +87,18 @@ void directInstrumentationExample() throws Exception {
84
87
85
88
@ Test
86
89
void shouldInstrumentEventLoopDuringChannelInit () throws Exception {
87
- NioEventLoopGroup eventExecutors = new NioEventLoopGroup ( );
90
+ MultiThreadIoEventLoopGroup eventExecutors = new MultiThreadIoEventLoopGroup ( NioIoHandler . newFactory () );
88
91
CustomChannelInitializer channelInitializer = new CustomChannelInitializer (this .registry );
89
92
NioSocketChannel channel = new NioSocketChannel ();
90
93
eventExecutors .register (channel ).await ();
91
94
channelInitializer .initChannel (channel );
92
95
assertThat (this .registry .get (NettyMeters .EVENT_EXECUTOR_TASKS_PENDING .getName ())
93
- .tags (Tags .of ("name" , channel .eventLoop ().threadProperties ().name ()))
96
+ .tags (Tags .of ("name" , (( SingleThreadIoEventLoop ) channel .eventLoop () ).threadProperties ().name ()))
94
97
.gauge ()
95
98
.value ()).isZero ();
96
99
ByteBuf buffer = channel .alloc ().buffer ();
97
100
Tags tags = Tags .of ("id" , String .valueOf (channel .alloc ().hashCode ()), "allocator.type" ,
98
- "PooledByteBufAllocator " , "memory.type" , "direct" );
101
+ "AdaptiveByteBufAllocator " , "memory.type" , "direct" );
99
102
assertThat (this .registry .get (NettyMeters .ALLOCATOR_MEMORY_USED .getName ()).tags (tags ).gauge ().value ())
100
103
.isPositive ();
101
104
buffer .release ();
0 commit comments