修改targetVersion为26时发送广播可能接受不到的问题

This commit is contained in:
远方夕阳 2019-04-01 14:49:24 +08:00
parent ec2dec5a0a
commit 3f3d7e95e9
52 changed files with 145 additions and 97 deletions

View File

@ -5,6 +5,6 @@
<classpathentry kind="lib" path="libs/log4j-1.2.17.jar"/>
<classpathentry kind="lib" path="libs/mina-core-2.0.16.jar"/>
<classpathentry kind="lib" path="libs/protobuf-java-3.2.0.jar"/>
<classpathentry kind="lib" path="D:/dev/Android-SDK-Windows/platforms/android-25/android.jar"/>
<classpathentry kind="lib" path="C:/Program Files/Android/android-sdk-windows/platforms/android-24/android.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -71,16 +71,18 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
private final String KEY_LAST_HEART_TIME = "KEY_LAST_HEART_TIME";
private NioSocketConnector connector;
private Context context;
private static CIMConnectorManager manager;
private ExecutorService executor = Executors.newFixedThreadPool(1);
private Semaphore semaphore = new Semaphore(1,true);
private Context context;
private static CIMConnectorManager manager;
private CIMConnectorManager(Context ctx) {
context = ctx;
makeNioConnector();
}
private void makeNioConnector() {
connector = new NioSocketConnector();
connector.setConnectTimeoutMillis(CONNECT_TIMEOUT);
connector.getSessionConfig().setTcpNoDelay(true);
@ -95,37 +97,30 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ClientMessageCodecFactory()));
connector.getFilterChain().addLast("heartbeat", keepAliveaHandler);
connector.getFilterChain().addLast("logger",CIMLoggingFilter.getLogger());
connector.setHandler(this);
}
public synchronized static CIMConnectorManager getManager(Context context) {
if (manager == null) {
manager = new CIMConnectorManager(context);
}
return manager;
}
private void handleConnectFailure(Throwable error,InetSocketAddress remoteAddress) {
long interval = CIMConstant.RECONN_INTERVAL_TIME - (5 * 1000 - new Random().nextInt(15 * 1000));
CIMLoggingFilter.getLogger().connectFailure(remoteAddress, interval);
Intent intent = new Intent();
intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_FAILED);
intent.putExtra(Exception.class.getName(), error.getClass().getSimpleName());
intent.putExtra("interval", interval);
context.sendBroadcast(intent);
}
public void connect(final String host, final int port) {
if (!isNetworkConnected(context)) {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_FAILED);
intent.putExtra(Exception.class.getName(), NetworkDisabledException.class.getSimpleName());
context.sendBroadcast(intent);
@ -136,16 +131,21 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
if (isConnected() || !semaphore.tryAcquire()) {
return;
}
if(connector == null || connector.isDisposed()) {
makeNioConnector();
}
executor.execute(new Runnable() {
@Override
public void run() {
CIMCacheManager.putBoolean(context, CIMCacheManager.KEY_CIM_CONNECTION_STATE, false);
final InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
CIMLoggingFilter.getLogger().startConnect(remoteAddress);
CIMCacheManager.putBoolean(context, CIMCacheManager.KEY_CIM_CONNECTION_STATE, false);
connector.connect(remoteAddress).addListener(new IoFutureListener<ConnectFuture>() {
@Override
public void operationComplete(ConnectFuture future) {
@ -160,7 +160,25 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
});
}
private void handleConnectFailure(Throwable error,InetSocketAddress remoteAddress) {
long interval = CIMConstant.RECONN_INTERVAL_TIME - (5 * 1000 - new Random().nextInt(15 * 1000));
CIMLoggingFilter.getLogger().connectFailure(remoteAddress, interval);
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_FAILED);
intent.putExtra(Exception.class.getName(), error.getClass().getSimpleName());
intent.putExtra("interval", interval);
context.sendBroadcast(intent);
}
public void send(SentBody body) {
boolean isSuccessed = false;
@ -180,6 +198,7 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
if (!isSuccessed) {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
intent.setAction(CIMConstant.IntentAction.ACTION_SENT_FAILED);
intent.putExtra(Exception.class.getName(), exceptionName);
intent.putExtra(SentBody.class.getName(), body);
@ -196,9 +215,9 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
if (connector != null && !connector.isDisposed()) {
connector.dispose();
connector = null;
}
manager = null;
}
public boolean isConnected() {
@ -214,6 +233,11 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
}
public IoSession getCurrentSession() {
if(connector == null || connector.isDisposed()) {
return null;
}
Map<Long, IoSession> sessions = connector.getManagedSessions();
for (Long key : sessions.keySet()) {
IoSession session = sessions.get(key);
@ -230,6 +254,7 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
setLastHeartbeatTime(session);
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_SUCCESSED);
context.sendBroadcast(intent);
@ -239,6 +264,7 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
public void sessionClosed(IoSession session) {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_CLOSED);
context.sendBroadcast(intent);
@ -246,22 +272,25 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
@Override
public void sessionIdle(IoSession session, IdleStatus status) {
/**
* 用于解决wifi情况下偶而路由器与服务器断开连接时客户端并没及时收到关闭事件 导致这样的情况下当前连接无效也不会重连的问题
*
*/
long lastHeartbeatTime = getLastHeartbeatTime(session);
if (System.currentTimeMillis() - lastHeartbeatTime >= HEARBEAT_TIME_OUT) {
session.closeNow();
session.closeOnFlush();
}
}
@Override
public void messageReceived(IoSession session, Object obj) {
if (obj instanceof Message) {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
intent.setAction(CIMConstant.IntentAction.ACTION_MESSAGE_RECEIVED);
intent.putExtra(Message.class.getName(), (Message) obj);
context.sendBroadcast(intent);
@ -270,6 +299,7 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
if (obj instanceof ReplyBody) {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
intent.setAction(CIMConstant.IntentAction.ACTION_REPLY_RECEIVED);
intent.putExtra(ReplyBody.class.getName(), (ReplyBody) obj);
context.sendBroadcast(intent);
@ -280,6 +310,7 @@ class CIMConnectorManager extends IoHandlerAdapter implements KeepAliveMessageFa
public void messageSent(IoSession session, Object message) {
if (message instanceof SentBody) {
Intent intent = new Intent();
intent.setPackage(context.getPackageName());
intent.setAction(CIMConstant.IntentAction.ACTION_SENT_SUCCESSED);
intent.putExtra(SentBody.class.getName(), (SentBody) message);
context.sendBroadcast(intent);

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2033 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -210,7 +210,6 @@ public class WebMessageDecoder extends MessageDecoderAdapter {
}
private void handleClose(IoSession iosession, IoBuffer in) {
in.get(new byte[in.remaining()]);
iosession.closeOnFlush();
}

View File

@ -9,6 +9,6 @@
<classpathentry kind="lib" path="libs/netty-transport-4.1.9.Final.jar"/>
<classpathentry kind="lib" path="libs/netty-common-4.1.9.Final.jar"/>
<classpathentry kind="lib" path="libs/netty-handler-4.1.9.Final.jar"/>
<classpathentry kind="lib" path="D:/dev/Android-SDK-Windows/platforms/android-25/android.jar"/>
<classpathentry kind="lib" path="C:/Program Files/Android/android-sdk-windows/platforms/android-24/android.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -83,7 +83,11 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
private CIMConnectorManager(Context ctx) {
context = ctx;
makeNioBootstrap();
}
private void makeNioBootstrap() {
bootstrap = new Bootstrap();
loopGroup = new NioEventLoopGroup(1);
bootstrap.group(loopGroup);
@ -101,7 +105,6 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
ch.pipeline().addLast(CIMConnectorManager.this);
}
});
}
public synchronized static CIMConnectorManager getManager(Context context) {
@ -118,8 +121,8 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
CIMLoggingHandler.getLogger().connectFailure(remoteAddress, interval);
Intent intent = new Intent();
intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_FAILED);
Intent intent = new Intent(CIMConstant.IntentAction.ACTION_CONNECTION_FAILED);
intent.setPackage(context.getPackageName());
intent.putExtra(Exception.class.getName(), error.getClass().getSimpleName());
intent.putExtra("interval", interval);
context.sendBroadcast(intent);
@ -133,8 +136,8 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
if (!isNetworkConnected(context)) {
Intent intent = new Intent();
intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_FAILED);
Intent intent = new Intent(CIMConstant.IntentAction.ACTION_CONNECTION_FAILED);
intent.setPackage(context.getPackageName());
intent.putExtra(Exception.class.getName(), NetworkDisabledException.class.getSimpleName());
context.sendBroadcast(intent);
@ -144,6 +147,10 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
if (isConnected() || !semaphore.tryAcquire()) {
return;
}
if (bootstrap == null || loopGroup.isShutdown()) {
makeNioBootstrap();
}
executor.execute(new Runnable() {
@Override
@ -187,14 +194,14 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
}
if (!isSuccessed) {
Intent intent = new Intent();
intent.setAction(CIMConstant.IntentAction.ACTION_SENT_FAILED);
Intent intent = new Intent(CIMConstant.IntentAction.ACTION_SENT_FAILED);
intent.setPackage(context.getPackageName());
intent.putExtra(Exception.class.getName(), exceptionName);
intent.putExtra(SentBody.class.getName(), body);
context.sendBroadcast(intent);
} else {
Intent intent = new Intent();
intent.setAction(CIMConstant.IntentAction.ACTION_SENT_SUCCESSED);
Intent intent = new Intent(CIMConstant.IntentAction.ACTION_SENT_SUCCESSED);
intent.setPackage(context.getPackageName());
intent.putExtra(SentBody.class.getName(), (SentBody) body);
context.sendBroadcast(intent);
}
@ -210,7 +217,6 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
loopGroup.shutdownGracefully();
}
manager = null;
}
public boolean isConnected() {
@ -229,8 +235,8 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
setLastHeartbeatTime(ctx.channel());
Intent intent = new Intent();
intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_SUCCESSED);
Intent intent = new Intent(CIMConstant.IntentAction.ACTION_CONNECTION_SUCCESSED);
intent.setPackage(context.getPackageName());
context.sendBroadcast(intent);
}
@ -238,8 +244,8 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
@Override
public void channelInactive(ChannelHandlerContext ctx) {
Intent intent = new Intent();
intent.setAction(CIMConstant.IntentAction.ACTION_CONNECTION_CLOSED);
Intent intent = new Intent(CIMConstant.IntentAction.ACTION_CONNECTION_CLOSED);
intent.setPackage(context.getPackageName());
context.sendBroadcast(intent);
}
@ -264,16 +270,16 @@ class CIMConnectorManager extends SimpleChannelInboundHandler<Object> {
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof Message) {
Intent intent = new Intent();
intent.setAction(CIMConstant.IntentAction.ACTION_MESSAGE_RECEIVED);
Intent intent = new Intent(CIMConstant.IntentAction.ACTION_MESSAGE_RECEIVED);
intent.setPackage(context.getPackageName());
intent.putExtra(Message.class.getName(), (Message) msg);
context.sendBroadcast(intent);
}
if (msg instanceof ReplyBody) {
Intent intent = new Intent();
intent.setAction(CIMConstant.IntentAction.ACTION_REPLY_RECEIVED);
Intent intent = new Intent(CIMConstant.IntentAction.ACTION_REPLY_RECEIVED);
intent.setPackage(context.getPackageName());
intent.putExtra(ReplyBody.class.getName(), (ReplyBody) msg);
context.sendBroadcast(intent);
}

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="libs/protobuf-java-3.2.0.jar"/>
<classpathentry kind="lib" path="libs/slf4j-api-1.7.25.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>

View File

@ -1,7 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,10 +34,12 @@ import com.farsunset.cim.sdk.server.session.CIMSession;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
@ -82,7 +84,9 @@ public class CIMNioSocketAcceptor extends SimpleChannelInboundHandler<SentBody>
innerHandlerMap.put(WEBSOCKET_HANDLER_KEY, new WebsocketHandler());
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup());
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
bootstrap.group(bossGroup, workerGroup);
bootstrap.childOption(ChannelOption.TCP_NODELAY, true);
bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
bootstrap.channel(NioServerSocketChannel.class);
@ -99,6 +103,14 @@ public class CIMNioSocketAcceptor extends SimpleChannelInboundHandler<SentBody>
});
bootstrap.bind(port);
ChannelFuture channelFuture = bootstrap.bind(port).syncUninterruptibly();
channelFuture.channel().closeFuture().addListener(future -> {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
});
}
/**

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013-2023 Xia Jun(3979434@qq.com).
* Copyright 2013-2019 Xia Jun(3979434@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.