From cd49938de68773bd9c97c62c84e5400caf6aaf49 Mon Sep 17 00:00:00 2001
From: SmallChi <564952747@qq.com>
Date: Wed, 13 Mar 2019 22:03:06 +0800
Subject: [PATCH] =?UTF-8?q?1.=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E9=A1=B9?=
=?UTF-8?q?=E7=9B=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Handlers/JT809MsgIdDefaultTcpHandler.cs | 23 --
.../Handlers/JT809TcpConnectionHandler.cs | 98 --------
.../Handlers/JT809TcpServerHandler.cs | 84 -------
.../JT809.DotNetty.Tcp.csproj | 11 -
.../JT809TcpDotnettyExtensions.cs | 31 ---
src/JT809.DotNetty.Tcp/JT809TcpServerHost.cs | 95 --------
src/JT809Netty.Core/AtomicCounter.cs | 39 ----
.../Configs/JT809NettyOptions.cs | 14 --
.../Handlers/JT809DecodeHandler.cs | 65 ------
.../JT809DownMasterLinkConnectionHandler.cs | 94 --------
.../JT809DownMasterLinkServiceHandler.cs | 61 -----
.../JT809DownSlaveLinkConnectionHandler.cs | 82 -------
src/JT809Netty.Core/IAppSession.cs | 19 --
.../JT809DownMasterLinkNettyService.cs | 121 ----------
.../JT809DownSlaveLinkNettyService.cs | 104 ---------
src/JT809Netty.Core/JT809Netty.Core.csproj | 28 ---
src/JT809Netty.Core/JT809Session.cs | 39 ----
.../JT809DownMasterLinkBusinessTypeHandler.cs | 139 -----------
src/JT809Netty.Core/SessionManager.cs | 220 ------------------
.../JT809Netty.DownMasterLink.csproj | 26 ---
src/JT809Netty.DownMasterLink/Program.cs | 57 -----
.../appsettings.Development.json | 25 --
.../appsettings.json | 25 --
23 files changed, 1500 deletions(-)
delete mode 100644 src/JT809.DotNetty.Tcp/Handlers/JT809MsgIdDefaultTcpHandler.cs
delete mode 100644 src/JT809.DotNetty.Tcp/Handlers/JT809TcpConnectionHandler.cs
delete mode 100644 src/JT809.DotNetty.Tcp/Handlers/JT809TcpServerHandler.cs
delete mode 100644 src/JT809.DotNetty.Tcp/JT809.DotNetty.Tcp.csproj
delete mode 100644 src/JT809.DotNetty.Tcp/JT809TcpDotnettyExtensions.cs
delete mode 100644 src/JT809.DotNetty.Tcp/JT809TcpServerHost.cs
delete mode 100644 src/JT809Netty.Core/AtomicCounter.cs
delete mode 100644 src/JT809Netty.Core/Configs/JT809NettyOptions.cs
delete mode 100644 src/JT809Netty.Core/Handlers/JT809DecodeHandler.cs
delete mode 100644 src/JT809Netty.Core/Handlers/JT809DownMasterLinkConnectionHandler.cs
delete mode 100644 src/JT809Netty.Core/Handlers/JT809DownMasterLinkServiceHandler.cs
delete mode 100644 src/JT809Netty.Core/Handlers/JT809DownSlaveLinkConnectionHandler.cs
delete mode 100644 src/JT809Netty.Core/IAppSession.cs
delete mode 100644 src/JT809Netty.Core/JT809DownMasterLinkNettyService.cs
delete mode 100644 src/JT809Netty.Core/JT809DownSlaveLinkNettyService.cs
delete mode 100644 src/JT809Netty.Core/JT809Netty.Core.csproj
delete mode 100644 src/JT809Netty.Core/JT809Session.cs
delete mode 100644 src/JT809Netty.Core/ServiceHandlers/JT809DownMasterLinkBusinessTypeHandler.cs
delete mode 100644 src/JT809Netty.Core/SessionManager.cs
delete mode 100644 src/JT809Netty.DownMasterLink/JT809Netty.DownMasterLink.csproj
delete mode 100644 src/JT809Netty.DownMasterLink/Program.cs
delete mode 100644 src/JT809Netty.DownMasterLink/appsettings.Development.json
delete mode 100644 src/JT809Netty.DownMasterLink/appsettings.json
diff --git a/src/JT809.DotNetty.Tcp/Handlers/JT809MsgIdDefaultTcpHandler.cs b/src/JT809.DotNetty.Tcp/Handlers/JT809MsgIdDefaultTcpHandler.cs
deleted file mode 100644
index c7ae997..0000000
--- a/src/JT809.DotNetty.Tcp/Handlers/JT809MsgIdDefaultTcpHandler.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using JT809.DotNetty.Core;
-using JT809.DotNetty.Core.Handlers;
-using JT809.DotNetty.Core.Interfaces;
-using JT809.DotNetty.Core.Links;
-using JT809.DotNetty.Core.Session;
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace JT809.DotNetty.Tcp.Handlers
-{
- ///
- /// 默认消息处理业务实现
- ///
- internal class JT809MsgIdDefaultTcpHandler : JT809MainMsgIdHandlerBase
- {
- public JT809MsgIdDefaultTcpHandler(IJT809VerifyCodeGenerator verifyCodeGenerator,
- JT809SubordinateClient subordinateLinkClient, JT809MainSessionManager sessionManager)
- : base(verifyCodeGenerator, subordinateLinkClient, sessionManager)
- {
- }
- }
-}
diff --git a/src/JT809.DotNetty.Tcp/Handlers/JT809TcpConnectionHandler.cs b/src/JT809.DotNetty.Tcp/Handlers/JT809TcpConnectionHandler.cs
deleted file mode 100644
index 1bce81c..0000000
--- a/src/JT809.DotNetty.Tcp/Handlers/JT809TcpConnectionHandler.cs
+++ /dev/null
@@ -1,98 +0,0 @@
-using DotNetty.Handlers.Timeout;
-using DotNetty.Transport.Channels;
-using JT809.DotNetty.Core;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Threading.Tasks;
-
-namespace JT809.DotNetty.Tcp.Handlers
-{
- ///
- /// JT809服务通道处理程序
- ///
- internal class JT809TcpConnectionHandler : ChannelHandlerAdapter
- {
- private readonly ILogger logger;
-
- private readonly JT809MainSessionManager jT809SessionManager;
-
- public JT809TcpConnectionHandler(
- JT809MainSessionManager jT809SessionManager,
- ILoggerFactory loggerFactory)
- {
- this.jT809SessionManager = jT809SessionManager;
- logger = loggerFactory.CreateLogger();
- }
-
- ///
- /// 通道激活
- ///
- ///
- public override void ChannelActive(IChannelHandlerContext context)
- {
- string channelId = context.Channel.Id.AsShortText();
- if (logger.IsEnabled(LogLevel.Debug))
- logger.LogDebug($"<<<{ channelId } Successful client connection to server.");
- base.ChannelActive(context);
- }
-
- ///
- /// 设备主动断开
- ///
- ///
- public override void ChannelInactive(IChannelHandlerContext context)
- {
- string channelId = context.Channel.Id.AsShortText();
- if (logger.IsEnabled(LogLevel.Debug))
- logger.LogDebug($">>>{ channelId } The client disconnects from the server.");
- jT809SessionManager.RemoveSessionByChannel(context.Channel);
- base.ChannelInactive(context);
- }
-
- ///
- /// 服务器主动断开
- ///
- ///
- ///
- public override Task CloseAsync(IChannelHandlerContext context)
- {
- string channelId = context.Channel.Id.AsShortText();
- if (logger.IsEnabled(LogLevel.Debug))
- logger.LogDebug($"<<<{ channelId } The server disconnects from the client.");
- jT809SessionManager.RemoveSessionByChannel(context.Channel);
- return base.CloseAsync(context);
- }
-
- public override void ChannelReadComplete(IChannelHandlerContext context)=> context.Flush();
-
- ///
- /// 超时策略
- ///
- ///
- ///
- public override void UserEventTriggered(IChannelHandlerContext context, object evt)
- {
- IdleStateEvent idleStateEvent = evt as IdleStateEvent;
- if (idleStateEvent != null)
- {
- if(idleStateEvent.State== IdleState.ReaderIdle)
- {
- string channelId = context.Channel.Id.AsShortText();
- logger.LogInformation($"{idleStateEvent.State.ToString()}>>>{channelId}");
- jT809SessionManager.RemoveSessionByChannel(context.Channel);
- context.CloseAsync();
- }
- }
- base.UserEventTriggered(context, evt);
- }
-
- public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
- {
- string channelId = context.Channel.Id.AsShortText();
- logger.LogError(exception,$"{channelId} {exception.Message}" );
- jT809SessionManager.RemoveSessionByChannel(context.Channel);
- context.CloseAsync();
- }
- }
-}
-
diff --git a/src/JT809.DotNetty.Tcp/Handlers/JT809TcpServerHandler.cs b/src/JT809.DotNetty.Tcp/Handlers/JT809TcpServerHandler.cs
deleted file mode 100644
index 6a91746..0000000
--- a/src/JT809.DotNetty.Tcp/Handlers/JT809TcpServerHandler.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-using DotNetty.Buffers;
-using DotNetty.Transport.Channels;
-using JT809.Protocol;
-using System;
-using Microsoft.Extensions.Logging;
-using JT809.Protocol.Exceptions;
-using JT809.DotNetty.Core.Services;
-using JT809.DotNetty.Core;
-using JT809.DotNetty.Core.Handlers;
-using JT809.DotNetty.Core.Metadata;
-using JT809.DotNetty.Core.Enums;
-
-namespace JT809.DotNetty.Tcp.Handlers
-{
- ///
- /// JT809服务端处理程序
- ///
- internal class JT809TcpServerHandler : SimpleChannelInboundHandler
- {
- private readonly JT809MainMsgIdHandlerBase handler;
-
- private readonly JT809MainSessionManager jT809SessionManager;
-
- private readonly JT809AtomicCounterService jT809AtomicCounterService;
-
- private readonly ILogger logger;
-
- public JT809TcpServerHandler(
- ILoggerFactory loggerFactory,
- JT809MainMsgIdHandlerBase handler,
- JT809AtomicCounterServiceFactory jT809AtomicCounterServiceFactorty,
- JT809MainSessionManager jT809SessionManager
- )
- {
- this.handler = handler;
- this.jT809SessionManager = jT809SessionManager;
- this.jT809AtomicCounterService = jT809AtomicCounterServiceFactorty.Create(JT809AtomicCounterType.ServerMain.ToString()); ;
- logger = loggerFactory.CreateLogger();
- }
-
-
- protected override void ChannelRead0(IChannelHandlerContext ctx, byte[] msg)
- {
- try
- {
- JT809Package jT809Package = JT809Serializer.Deserialize(msg);
- jT809AtomicCounterService.MsgSuccessIncrement();
- if (logger.IsEnabled(LogLevel.Debug))
- {
- logger.LogDebug("accept package success count<<<" + jT809AtomicCounterService.MsgSuccessCount.ToString());
- }
- jT809SessionManager.TryAdd(ctx.Channel, jT809Package.Header.MsgGNSSCENTERID);
- Func handlerFunc;
- if (handler.HandlerDict.TryGetValue(jT809Package.Header.BusinessType, out handlerFunc))
- {
- JT809Response jT808Response = handlerFunc(new JT809Request(jT809Package, msg));
- if (jT808Response != null)
- {
- var sendData = JT809Serializer.Serialize(jT808Response.Package, jT808Response.MinBufferSize);
- ctx.WriteAndFlushAsync(Unpooled.WrappedBuffer(sendData));
- }
- }
- }
- catch (JT809Exception ex)
- {
- jT809AtomicCounterService.MsgFailIncrement();
- if (logger.IsEnabled(LogLevel.Error))
- {
- logger.LogError("accept package fail count<<<" + jT809AtomicCounterService.MsgFailCount.ToString());
- logger.LogError(ex, "accept msg<<<" + ByteBufferUtil.HexDump(msg));
- }
- }
- catch (Exception ex)
- {
- jT809AtomicCounterService.MsgFailIncrement();
- if (logger.IsEnabled(LogLevel.Error))
- {
- logger.LogError("accept package fail count<<<" + jT809AtomicCounterService.MsgFailCount.ToString());
- logger.LogError(ex, "accept msg<<<" + ByteBufferUtil.HexDump(msg));
- }
- }
- }
- }
-}
diff --git a/src/JT809.DotNetty.Tcp/JT809.DotNetty.Tcp.csproj b/src/JT809.DotNetty.Tcp/JT809.DotNetty.Tcp.csproj
deleted file mode 100644
index 16a978d..0000000
--- a/src/JT809.DotNetty.Tcp/JT809.DotNetty.Tcp.csproj
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- netstandard2.0
-
-
-
-
-
-
-
diff --git a/src/JT809.DotNetty.Tcp/JT809TcpDotnettyExtensions.cs b/src/JT809.DotNetty.Tcp/JT809TcpDotnettyExtensions.cs
deleted file mode 100644
index 9fc3da3..0000000
--- a/src/JT809.DotNetty.Tcp/JT809TcpDotnettyExtensions.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using JT809.DotNetty.Core;
-using JT809.DotNetty.Core.Codecs;
-using JT809.DotNetty.Core.Handlers;
-using JT809.DotNetty.Core.Services;
-using JT809.DotNetty.Tcp.Handlers;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.DependencyInjection.Extensions;
-using Microsoft.Extensions.Hosting;
-using Newtonsoft.Json;
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-
-[assembly: InternalsVisibleTo("JT809.DotNetty.Tcp.Test")]
-
-namespace JT809.DotNetty.Tcp
-{
- public static class JT809TcpDotnettyExtensions
- {
- public static IServiceCollection AddJT809TcpHost(this IServiceCollection serviceDescriptors)
- {
- serviceDescriptors.TryAddSingleton();
- serviceDescriptors.TryAddSingleton();
- serviceDescriptors.TryAddScoped();
- serviceDescriptors.TryAddScoped();
- serviceDescriptors.TryAddScoped();
- serviceDescriptors.AddHostedService();
- return serviceDescriptors;
- }
- }
-}
\ No newline at end of file
diff --git a/src/JT809.DotNetty.Tcp/JT809TcpServerHost.cs b/src/JT809.DotNetty.Tcp/JT809TcpServerHost.cs
deleted file mode 100644
index 1cc42d7..0000000
--- a/src/JT809.DotNetty.Tcp/JT809TcpServerHost.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-using DotNetty.Buffers;
-using DotNetty.Codecs;
-using DotNetty.Handlers.Timeout;
-using DotNetty.Transport.Bootstrapping;
-using DotNetty.Transport.Channels;
-using DotNetty.Transport.Libuv;
-using JT809.DotNetty.Core.Configurations;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Options;
-using System;
-using System.Net;
-using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-using JT809.Protocol;
-using JT809.DotNetty.Core.Codecs;
-using JT809.DotNetty.Tcp.Handlers;
-
-namespace JT809.DotNetty.Tcp
-{
- ///
- /// JT809 Tcp网关服务
- ///
- internal class JT809TcpServerHost : IHostedService
- {
- private readonly IServiceProvider serviceProvider;
- private readonly JT809Configuration configuration;
- private readonly ILogger logger;
- private DispatcherEventLoopGroup bossGroup;
- private WorkerEventLoopGroup workerGroup;
- private IChannel bootstrapChannel;
- private IByteBufferAllocator serverBufferAllocator;
-
- public JT809TcpServerHost(
- IServiceProvider provider,
- ILoggerFactory loggerFactory,
- IOptions jT809ConfigurationAccessor)
- {
- serviceProvider = provider;
- configuration = jT809ConfigurationAccessor.Value;
- logger=loggerFactory.CreateLogger();
- }
-
- public Task StartAsync(CancellationToken cancellationToken)
- {
- bossGroup = new DispatcherEventLoopGroup();
- workerGroup = new WorkerEventLoopGroup(bossGroup, configuration.EventLoopCount);
- serverBufferAllocator = new PooledByteBufferAllocator();
- ServerBootstrap bootstrap = new ServerBootstrap();
- bootstrap.Group(bossGroup, workerGroup);
- bootstrap.Channel();
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
- || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
- {
- bootstrap
- .Option(ChannelOption.SoReuseport, true)
- .ChildOption(ChannelOption.SoReuseaddr, true);
- }
- bootstrap
- .Option(ChannelOption.SoBacklog, configuration.SoBacklog)
- .ChildOption(ChannelOption.Allocator, serverBufferAllocator)
- .ChildHandler(new ActionChannelInitializer(channel =>
- {
- IChannelPipeline pipeline = channel.Pipeline;
- using (var scope = serviceProvider.CreateScope())
- {
- channel.Pipeline.AddLast("jt809SystemIdleState", new IdleStateHandler(
- configuration.ReaderIdleTimeSeconds,
- configuration.WriterIdleTimeSeconds,
- configuration.AllIdleTimeSeconds));
- channel.Pipeline.AddLast("jt809TcpConnection", scope.ServiceProvider.GetRequiredService());
- channel.Pipeline.AddLast("jt809TcpBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
- Unpooled.CopiedBuffer(new byte[] { JT809Package.BEGINFLAG }),
- Unpooled.CopiedBuffer(new byte[] { JT809Package.ENDFLAG })));
- channel.Pipeline.AddLast("jt809TcpDecode", scope.ServiceProvider.GetRequiredService());
- channel.Pipeline.AddLast("jt809TcpService", scope.ServiceProvider.GetRequiredService());
- }
- }));
- logger.LogInformation($"JT809 TCP Server start at {IPAddress.Any}:{configuration.TcpPort}.");
- return bootstrap.BindAsync(configuration.TcpPort)
- .ContinueWith(i => bootstrapChannel = i.Result);
- }
-
- public async Task StopAsync(CancellationToken cancellationToken)
- {
- await bootstrapChannel.CloseAsync();
- var quietPeriod = configuration.QuietPeriodTimeSpan;
- var shutdownTimeout = configuration.ShutdownTimeoutTimeSpan;
- await workerGroup.ShutdownGracefullyAsync(quietPeriod, shutdownTimeout);
- await bossGroup.ShutdownGracefullyAsync(quietPeriod, shutdownTimeout);
- }
- }
-}
diff --git a/src/JT809Netty.Core/AtomicCounter.cs b/src/JT809Netty.Core/AtomicCounter.cs
deleted file mode 100644
index 9b4fcaa..0000000
--- a/src/JT809Netty.Core/AtomicCounter.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading;
-
-namespace JT809Netty.Core
-{
- ///
- ///
- /// ref:Grpc.Core.Internal
- ///
- public class AtomicCounter
- {
- long counter = 0;
-
- public AtomicCounter(long initialCount = 0)
- {
- this.counter = initialCount;
- }
-
- public long Increment()
- {
- return Interlocked.Increment(ref counter);
- }
-
- public long Decrement()
- {
- return Interlocked.Decrement(ref counter);
- }
-
- public long Count
- {
- get
- {
- return Interlocked.Read(ref counter);
- }
- }
- }
-}
diff --git a/src/JT809Netty.Core/Configs/JT809NettyOptions.cs b/src/JT809Netty.Core/Configs/JT809NettyOptions.cs
deleted file mode 100644
index e802b77..0000000
--- a/src/JT809Netty.Core/Configs/JT809NettyOptions.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace JT809Netty.Core.Configs
-{
- public class JT809NettyOptions
- {
- public string Host { get; set; }
- public int Port { get; set; }
- public List IpWhiteList { get; set; } = new List();
- public bool IpWhiteListDisabled { get; set; }
- }
-}
diff --git a/src/JT809Netty.Core/Handlers/JT809DecodeHandler.cs b/src/JT809Netty.Core/Handlers/JT809DecodeHandler.cs
deleted file mode 100644
index 735d97d..0000000
--- a/src/JT809Netty.Core/Handlers/JT809DecodeHandler.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-using DotNetty.Buffers;
-using DotNetty.Codecs;
-using DotNetty.Transport.Channels;
-using JT809.Protocol;
-using JT809.Protocol.JT809Exceptions;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading;
-
-namespace JT809Netty.Core.Handlers
-{
- ///
- /// JT809解码
- ///
- public class JT809DecodeHandler : ByteToMessageDecoder
- {
- private readonly ILogger logger;
-
- public JT809DecodeHandler(ILoggerFactory loggerFactory)
- {
- logger = loggerFactory.CreateLogger();
- }
-
- private static readonly AtomicCounter MsgSuccessCounter = new AtomicCounter();
-
- private static readonly AtomicCounter MsgFailCounter = new AtomicCounter();
-
- protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List