Skip to content

Commit

Permalink
Pick from apache#7282 51d5a88
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed May 27, 2021
1 parent 216587e commit 7b0a664
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.dubbo.qos.server.handler;

import org.apache.dubbo.common.utils.ExecutorUtil;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
Expand All @@ -30,7 +32,6 @@
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.ScheduledFuture;
import org.apache.dubbo.common.utils.ExecutorUtil;

import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -90,6 +91,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
p.addLast(new StringDecoder(CharsetUtil.UTF_8));
p.addLast(new StringEncoder(CharsetUtil.UTF_8));
p.addLast(new IdleStateHandler(0, 0, 5 * 60));
p.addLast(new TelnetIdleEventHandler());
p.addLast(new TelnetProcessHandler());
p.remove(this);
}
Expand Down
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.qos.server.handler;

import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;

import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;

public class TelnetIdleEventHandler extends ChannelDuplexHandler {
private static final Logger log = LoggerFactory.getLogger(TelnetIdleEventHandler.class);

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
// server will close channel when server don't receive any request from client util timeout.
if (evt instanceof IdleStateEvent) {
Channel channel = ctx.channel();
log.info("IdleStateEvent triggered, close channel " + channel);
channel.close();
} else {
super.userEventTriggered(ctx, evt);
}
}

}

0 comments on commit 7b0a664

Please sign in to comment.