@@ -110,35 +110,7 @@ | |||
} | |||
``` | |||
#### 2.通过通道Id移除对应会话 | |||
请求地址:Session/RemoveByChannelId | |||
请求方式:POST | |||
请求参数: | |||
|属性|数据类型|参数说明| | |||
|:------:|:------:|:------| | |||
| channelId| string| 通道Id| | |||
返回数据: | |||
|属性|数据类型|参数说明| | |||
|:------:|:------:|:------| | |||
| Data| bool | 是否成功 | | |||
返回结果: | |||
``` session2 | |||
{ | |||
"Message":"", | |||
"Code":200, | |||
"Data":true | |||
} | |||
``` | |||
#### 3.通过设备终端号移除对应会话 | |||
#### 2.通过设备终端号移除对应会话 | |||
请求地址:Session/RemoveByTerminalPhoneNo | |||
@@ -48,10 +48,6 @@ namespace JT808.DotNetty.Test.Internal | |||
Thread.Sleep(1000); | |||
var result = jT808SessionServiceDefaultImpl.GetAll(); | |||
var info5 = result.Data.FirstOrDefault(f => f.TerminalPhoneNo == "123456789005"); | |||
var remove5 = jT808SessionServiceDefaultImpl.RemoveByChannelId(info5.ChannelId); | |||
var result1 = jT808SessionServiceDefaultImpl.GetAll(); | |||
Thread.Sleep(10000); | |||
@@ -15,17 +15,17 @@ namespace JT808.DotNetty.Test | |||
public void Test3() | |||
{ | |||
var channel = new EmbeddedChannel(); | |||
jT808SessionManager.TryAddOrUpdateSession(new Metadata.JT808Session(channel, TerminalPhoneNo)); | |||
var sessionInfo=jT808SessionManager.GetSessionByTerminalPhoneNo(TerminalPhoneNo); | |||
jT808SessionManager.TryAdd(new Metadata.JT808Session(channel, TerminalPhoneNo)); | |||
var sessionInfo=jT808SessionManager.GetSession(TerminalPhoneNo); | |||
Assert.Equal(TerminalPhoneNo, sessionInfo.TerminalPhoneNo); | |||
Assert.Equal("embedded", sessionInfo.SessionID); | |||
Assert.Equal("123456789123", sessionInfo.TerminalPhoneNo); | |||
} | |||
[Fact] | |||
public void Test4() | |||
{ | |||
var channel = new EmbeddedChannel(); | |||
jT808SessionManager.TryAddOrUpdateSession(new Metadata.JT808Session(channel, TerminalPhoneNo)); | |||
jT808SessionManager.TryAdd(new Metadata.JT808Session(channel, TerminalPhoneNo)); | |||
jT808SessionManager.Heartbeat(TerminalPhoneNo); | |||
} | |||
@@ -33,10 +33,9 @@ namespace JT808.DotNetty.Test | |||
public void Test5() | |||
{ | |||
var channel = new EmbeddedChannel(); | |||
jT808SessionManager.TryAddOrUpdateSession(new Metadata.JT808Session(channel, TerminalPhoneNo)); | |||
var sessionInfo = jT808SessionManager.GetSessionByID("embedded"); | |||
jT808SessionManager.TryAdd(new Metadata.JT808Session(channel, TerminalPhoneNo)); | |||
var sessionInfo = jT808SessionManager.GetSession(TerminalPhoneNo); | |||
Assert.Equal(TerminalPhoneNo, sessionInfo.TerminalPhoneNo); | |||
Assert.Equal("embedded", sessionInfo.SessionID); | |||
} | |||
@@ -44,10 +43,9 @@ namespace JT808.DotNetty.Test | |||
public void Test6() | |||
{ | |||
var channel = new EmbeddedChannel(); | |||
jT808SessionManager.TryAddOrUpdateSession(new Metadata.JT808Session(channel, TerminalPhoneNo)); | |||
var sessionInfo = jT808SessionManager.RemoveSessionByID("embedded"); | |||
jT808SessionManager.TryAdd(new Metadata.JT808Session(channel, TerminalPhoneNo)); | |||
var sessionInfo = jT808SessionManager.RemoveSession(TerminalPhoneNo); | |||
Assert.Equal(TerminalPhoneNo, sessionInfo.TerminalPhoneNo); | |||
Assert.Equal("embedded", sessionInfo.SessionID); | |||
} | |||
@@ -69,8 +67,7 @@ namespace JT808.DotNetty.Test | |||
[Fact] | |||
public void Test9() | |||
{ | |||
var realSessionCount = jT808SessionManager.RealSessionCount; | |||
var relevanceSessionCount = jT808SessionManager.RelevanceSessionCount; | |||
var realSessionCount = jT808SessionManager.SessionCount; | |||
} | |||
} | |||
} |
@@ -18,7 +18,7 @@ namespace JT808.DotNetty.Test | |||
for (var i = 0; i < 10; i++) | |||
{ | |||
var channel = new EmbeddedChannel(new JT808DefaultChannelId()); | |||
jT808SessionManager.TryAddOrUpdateSession(new Metadata.JT808Session(channel, i.ToString())); | |||
jT808SessionManager.TryAdd(new Metadata.JT808Session(channel, i.ToString())); | |||
} | |||
} | |||
@@ -28,7 +28,7 @@ namespace JT808.DotNetty.Test | |||
for (var i = 0; i < 10; i++) | |||
{ | |||
var channel = new EmbeddedChannel(new JT808DefaultChannelId()); | |||
jT808SessionManager.TryAddOrUpdateSession(new Metadata.JT808Session(channel, i.ToString())); | |||
jT808SessionManager.TryAdd(new Metadata.JT808Session(channel, i.ToString())); | |||
} | |||
} | |||
} | |||
@@ -48,7 +48,7 @@ namespace JT808.DotNetty.Handlers | |||
string channelId = context.Channel.Id.AsShortText(); | |||
if (logger.IsEnabled(LogLevel.Debug)) | |||
logger.LogDebug($">>>{ channelId } The client disconnects from the server."); | |||
jT808SessionManager.RemoveSessionByID(channelId); | |||
jT808SessionManager.RemoveSessionByChannel(context.Channel); | |||
base.ChannelInactive(context); | |||
} | |||
@@ -62,7 +62,7 @@ namespace JT808.DotNetty.Handlers | |||
string channelId = context.Channel.Id.AsShortText(); | |||
if (logger.IsEnabled(LogLevel.Debug)) | |||
logger.LogDebug($"<<<{ channelId } The server disconnects from the client."); | |||
jT808SessionManager.RemoveSessionByID(channelId); | |||
jT808SessionManager.RemoveSessionByChannel(context.Channel); | |||
return base.CloseAsync(context); | |||
} | |||
@@ -83,7 +83,7 @@ namespace JT808.DotNetty.Handlers | |||
string channelId = context.Channel.Id.AsShortText(); | |||
logger.LogInformation($"{idleStateEvent.State.ToString()}>>>{channelId}"); | |||
// 由于808是设备发心跳,如果很久没有上报数据,那么就由服务器主动关闭连接。 | |||
jT808SessionManager.RemoveSessionByID(channelId); | |||
jT808SessionManager.RemoveSessionByChannel(context.Channel); | |||
context.CloseAsync(); | |||
} | |||
// 按照808的消息,有些请求必须要应答,但是转发可以不需要有应答可以节省部分资源包括: | |||
@@ -99,7 +99,7 @@ namespace JT808.DotNetty.Handlers | |||
{ | |||
string channelId = context.Channel.Id.AsShortText(); | |||
logger.LogError(exception,$"{channelId} {exception.Message}" ); | |||
jT808SessionManager.RemoveSessionByID(channelId); | |||
jT808SessionManager.RemoveSessionByChannel(context.Channel); | |||
context.CloseAsync(); | |||
} | |||
} | |||
@@ -59,7 +59,7 @@ namespace JT808.DotNetty.Handlers | |||
{ | |||
logger.LogDebug("accept package success count<<<" + jT808AtomicCounterService.MsgSuccessCount.ToString()); | |||
} | |||
jT808SessionManager.TryAddOrUpdateSession(new JT808Session(ctx.Channel, jT808Package.Header.TerminalPhoneNo)); | |||
jT808SessionManager.TryAdd(new JT808Session(ctx.Channel, jT808Package.Header.TerminalPhoneNo)); | |||
Func<JT808Request, JT808Response> handlerFunc; | |||
if (handler.HandlerDict.TryGetValue(jT808Package.Header.MsgId, out handlerFunc)) | |||
{ | |||
@@ -58,7 +58,7 @@ namespace JT808.DotNetty.Handlers | |||
public override void ChannelRead(IChannelHandlerContext context, object message) | |||
{ | |||
if(logger.IsEnabled(LogLevel.Debug)) | |||
logger.LogError($"The server returns a message {message.ToString()}"); | |||
logger.LogDebug($"The server returns a message {message.ToString()}"); | |||
} | |||
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception) | |||
@@ -16,12 +16,6 @@ namespace JT808.DotNetty.Interfaces | |||
/// <returns></returns> | |||
JT808ResultDto<List<JT808SessionInfoDto>> GetAll(); | |||
/// <summary> | |||
/// 通过通道Id移除对应会话 | |||
/// </summary> | |||
/// <param name="channelId"></param> | |||
/// <returns></returns> | |||
JT808ResultDto<bool> RemoveByChannelId(string channelId); | |||
/// <summary> | |||
/// 通过设备终端号移除对应会话 | |||
/// </summary> | |||
/// <param name="terminalPhoneNo"></param> | |||
@@ -27,7 +27,6 @@ namespace JT808.DotNetty.Internal | |||
{ | |||
resultDto.Data = jT808SessionManager.GetAll().Select(s => new JT808SessionInfoDto | |||
{ | |||
ChannelId = s.SessionID, | |||
LastActiveTime = s.LastActiveTime, | |||
StartTime = s.StartTime, | |||
TerminalPhoneNo = s.TerminalPhoneNo, | |||
@@ -44,43 +43,18 @@ namespace JT808.DotNetty.Internal | |||
return resultDto; | |||
} | |||
public JT808ResultDto<bool> RemoveByChannelId(string channelId) | |||
{ | |||
JT808ResultDto<bool> resultDto = new JT808ResultDto<bool>(); | |||
try | |||
{ | |||
var session = jT808SessionManager.RemoveSessionByID(channelId); | |||
if (session != null) | |||
{ | |||
session.Channel.CloseAsync(); | |||
} | |||
resultDto.Code = JT808ResultCode.Ok; | |||
resultDto.Data = true; | |||
} | |||
catch (AggregateException ex) | |||
{ | |||
resultDto.Data = false; | |||
resultDto.Code = JT808ResultCode.Error; | |||
resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex); | |||
} | |||
catch (Exception ex) | |||
{ | |||
resultDto.Data = false; | |||
resultDto.Code = JT808ResultCode.Error; | |||
resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex); | |||
} | |||
return resultDto; | |||
} | |||
public JT808ResultDto<bool> RemoveByTerminalPhoneNo(string terminalPhoneNo) | |||
{ | |||
JT808ResultDto<bool> resultDto = new JT808ResultDto<bool>(); | |||
try | |||
{ | |||
var session = jT808SessionManager.RemoveSessionByTerminalPhoneNo(terminalPhoneNo); | |||
var session = jT808SessionManager.RemoveSession(terminalPhoneNo); | |||
if (session != null) | |||
{ | |||
session.Channel.CloseAsync(); | |||
if(session.Channel.Open) | |||
{ | |||
session.Channel.CloseAsync(); | |||
} | |||
} | |||
resultDto.Code = JT808ResultCode.Ok; | |||
resultDto.Data = true; | |||
@@ -21,7 +21,7 @@ namespace JT808.DotNetty.Internal | |||
JT808ResultDto<bool> resultDto = new JT808ResultDto<bool>(); | |||
try | |||
{ | |||
var session = jT808SessionManager.GetSessionByTerminalPhoneNo(terminalPhoneNo); | |||
var session = jT808SessionManager.GetSession(terminalPhoneNo); | |||
if (session != null) | |||
{ | |||
if (session.Channel.Open) | |||
@@ -52,7 +52,6 @@ namespace JT808.DotNetty.Internal | |||
{ | |||
{$"{RouteTablePrefix}/UnificationSend", UnificationSend}, | |||
{$"{RouteTablePrefix}/{sessionRoutePrefix}/GetAll", GetSessionAll}, | |||
{$"{RouteTablePrefix}/{sessionRoutePrefix}/RemoveByChannelId", RemoveByChannelId}, | |||
{$"{RouteTablePrefix}/{sessionRoutePrefix}/RemoveByTerminalPhoneNo", RemoveByTerminalPhoneNo}, | |||
{$"{RouteTablePrefix}/GetAtomicCounter", GetAtomicCounter}, | |||
{$"{RouteTablePrefix}/{sourcePackagePrefix}/Add", AddSourcePackageAddress}, | |||
@@ -91,21 +90,6 @@ namespace JT808.DotNetty.Internal | |||
return CreateJT808HttpResponse(result); | |||
} | |||
/// <summary> | |||
/// 会话服务-通过通道Id移除对应会话 | |||
/// </summary> | |||
/// <param name="request"></param> | |||
/// <returns></returns> | |||
public JT808HttpResponse RemoveByChannelId(JT808HttpRequest request) | |||
{ | |||
if (string.IsNullOrEmpty(request.Json)) | |||
{ | |||
return EmptyHttpResponse(); | |||
} | |||
var result = jT808SessionService.RemoveByChannelId(request.Json); | |||
return CreateJT808HttpResponse(result); | |||
} | |||
/// <summary> | |||
/// 会话服务-通过设备终端号移除对应会话 | |||
/// </summary> | |||
@@ -42,18 +42,15 @@ namespace JT808.DotNetty | |||
public Dictionary<ushort, Func<JT808Request, JT808Response>> HandlerDict { get; protected set; } | |||
/// <summary> | |||
/// 终端通用应答 | |||
/// 平台无需回复 | |||
/// 实现自己的业务 | |||
/// </summary> | |||
/// <param name="reqJT808Package"></param> | |||
/// <param name="ctx"></param> | |||
/// <returns></returns> | |||
public virtual JT808Response Msg0x0001(JT808Request request) | |||
{ | |||
return new JT808Response(JT808MsgId.平台通用应答.Create(request.Package.Header.TerminalPhoneNo, new JT808_0x8001() | |||
{ | |||
MsgId = request.Package.Header.MsgId, | |||
JT808PlatformResult = JT808PlatformResult.成功, | |||
MsgNum = request.Package.Header.MsgNum | |||
})); | |||
return null; | |||
} | |||
/// <summary> | |||
/// 终端心跳 | |||
@@ -4,6 +4,7 @@ using System.Collections.Concurrent; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using JT808.DotNetty.Metadata; | |||
using DotNetty.Transport.Channels; | |||
namespace JT808.DotNetty | |||
{ | |||
@@ -20,23 +21,9 @@ namespace JT808.DotNetty | |||
logger = loggerFactory.CreateLogger<JT808SessionManager>(); | |||
} | |||
/// <summary> | |||
/// Netty生成的sessionID和Session的对应关系 | |||
/// key = seession id | |||
/// value = Session | |||
/// </summary> | |||
private ConcurrentDictionary<string, JT808Session> SessionIdDict = new ConcurrentDictionary<string, JT808Session>(StringComparer.OrdinalIgnoreCase); | |||
/// <summary> | |||
/// 终端手机号和netty生成的sessionID的对应关系 | |||
/// key = 终端手机号 | |||
/// value = seession id | |||
/// </summary> | |||
private ConcurrentDictionary<string, string> TerminalPhoneNo_SessionId_Dict = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |||
/// <summary> | |||
/// 获取实际连接数 | |||
/// </summary> | |||
public int RealSessionCount | |||
public int SessionCount | |||
{ | |||
get | |||
{ | |||
@@ -44,166 +31,106 @@ namespace JT808.DotNetty | |||
} | |||
} | |||
/// <summary> | |||
/// 获取设备相关连的连接数 | |||
/// </summary> | |||
public int RelevanceSessionCount | |||
public JT808Session GetSession(string terminalPhoneNo) | |||
{ | |||
get | |||
{ | |||
return TerminalPhoneNo_SessionId_Dict.Count; | |||
} | |||
} | |||
public JT808Session GetSessionByID(string sessionID) | |||
{ | |||
if (string.IsNullOrEmpty(sessionID)) | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) | |||
return default; | |||
JT808Session targetSession; | |||
SessionIdDict.TryGetValue(sessionID, out targetSession); | |||
return targetSession; | |||
} | |||
public JT808Session GetSessionByTerminalPhoneNo(string terminalPhoneNo) | |||
{ | |||
try | |||
if (SessionIdDict.TryGetValue(terminalPhoneNo, out JT808Session targetSession)) | |||
{ | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) | |||
return default; | |||
if (TerminalPhoneNo_SessionId_Dict.TryGetValue(terminalPhoneNo, out string sessionId)) | |||
{ | |||
if (SessionIdDict.TryGetValue(sessionId, out JT808Session targetSession)) | |||
{ | |||
return targetSession; | |||
} | |||
else | |||
{ | |||
return default; | |||
} | |||
} | |||
else | |||
{ | |||
return default; | |||
} | |||
return targetSession; | |||
} | |||
catch (Exception ex) | |||
else | |||
{ | |||
logger.LogError(ex, terminalPhoneNo); | |||
return default; | |||
} | |||
} | |||
public void Heartbeat(string terminalPhoneNo) | |||
{ | |||
try | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) return; | |||
if (SessionIdDict.TryGetValue(terminalPhoneNo, out JT808Session oldjT808Session)) | |||
{ | |||
if (TerminalPhoneNo_SessionId_Dict.TryGetValue(terminalPhoneNo, out string sessionId)) | |||
{ | |||
if (SessionIdDict.TryGetValue(sessionId, out JT808Session oldjT808Session)) | |||
{ | |||
if (oldjT808Session.Channel.Active) | |||
{ | |||
oldjT808Session.LastActiveTime = DateTime.Now; | |||
if (SessionIdDict.TryUpdate(sessionId, oldjT808Session, oldjT808Session)) | |||
{ | |||
} | |||
} | |||
} | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
logger.LogError(ex, terminalPhoneNo); | |||
oldjT808Session.LastActiveTime = DateTime.Now; | |||
SessionIdDict.TryUpdate(terminalPhoneNo, oldjT808Session, oldjT808Session); | |||
} | |||
} | |||
public void TryAddOrUpdateSession(JT808Session appSession) | |||
public void TryAdd(JT808Session appSession) | |||
{ | |||
SessionIdDict.TryAdd(appSession.SessionID, appSession); | |||
if(TerminalPhoneNo_SessionId_Dict.TryAdd(appSession.TerminalPhoneNo, appSession.SessionID)) | |||
// 解决了设备号跟通道绑定到一起,不需要用到通道本身的SessionId | |||
// 不管设备下发更改了设备终端号,只要是没有在内存中就当是新的 | |||
// todo: | |||
// 存在的问题: | |||
// 1.原先老的如何销毁 | |||
// 2.这时候用的通道是相同的,设备终端是不同的 | |||
if (SessionIdDict.TryAdd(appSession.TerminalPhoneNo, appSession)) | |||
{ | |||
//使用场景: | |||
//部标的超长待机设备,不会像正常的设备一样一直连着,可能10几分钟连上了,然后发完就关闭连接, | |||
//这时候想下发数据需要知道设备什么时候上线,在这边做通知最好不过了。 | |||
//todo: 有设备关联上来可以进行通知 | |||
//todo: 使用Redis发布订阅 | |||
//todo: 平台更改设备号的时候,这时候通道和设备号是绑定在一起的,那么要是同样的通道上来,是关联不到新的设备,需要考虑 | |||
//todo: 平台下发更改设备号的时候,这时候通道和设备号是绑定在一起的,那么要是同样的通道上来,是关联不到新的设备,需要考虑 | |||
} | |||
} | |||
public JT808Session RemoveSessionByID(string sessionID) | |||
public JT808Session RemoveSession(string terminalPhoneNo) | |||
{ | |||
if (sessionID == null) return null; | |||
try | |||
//todo: 设备离线可以进行通知 | |||
//todo: 使用Redis 发布订阅 | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) return default; | |||
if (!SessionIdDict.TryGetValue(terminalPhoneNo, out JT808Session jT808Session)) | |||
{ | |||
if (SessionIdDict.TryRemove(sessionID, out JT808Session session)) | |||
return default; | |||
} | |||
// 处理转发过来的是数据 这时候通道对设备是1对多关系,需要清理垃圾数据 | |||
//1.用当前会话的通道Id找出通过转发过来的其他设备的终端号 | |||
var terminalPhoneNos = SessionIdDict.Where(w => w.Value.Channel.Id == jT808Session.Channel.Id).Select(s => s.Key).ToList(); | |||
//2.存在则一个个移除 | |||
if (terminalPhoneNos.Count > 1) | |||
{ | |||
//3.移除包括当前的设备号 | |||
foreach (var key in terminalPhoneNos) | |||
{ | |||
// 处理转发过来的是数据 这时候通道对设备是1对多关系 | |||
var removeKeys = TerminalPhoneNo_SessionId_Dict.Where(s => s.Value == sessionID).Select(s => s.Key).ToList(); | |||
foreach(var key in removeKeys) | |||
{ | |||
TerminalPhoneNo_SessionId_Dict.TryRemove(key, out string sessionid); | |||
} | |||
//todo: 设备离线可以进行通知 | |||
//todo: 使用Redis 发布订阅 | |||
logger.LogInformation($">>>{sessionID}-{string.Join(",",removeKeys)} Session Remove."); | |||
return session; | |||
SessionIdDict.TryRemove(key, out JT808Session jT808SessionRemove); | |||
} | |||
return null; | |||
logger.LogInformation($">>>{terminalPhoneNo}-{string.Join(",", terminalPhoneNos)} 1-n Session Remove."); | |||
return jT808Session; | |||
} | |||
catch (Exception ex) | |||
else | |||
{ | |||
logger.LogError(ex, $">>>{sessionID} Session Remove Exception"); | |||
if (SessionIdDict.TryRemove(terminalPhoneNo, out JT808Session jT808SessionRemove)) | |||
{ | |||
logger.LogInformation($">>>{terminalPhoneNo} Session Remove."); | |||
return jT808SessionRemove; | |||
} | |||
else | |||
{ | |||
return default; | |||
} | |||
} | |||
return null; | |||
} | |||
public JT808Session RemoveSessionByTerminalPhoneNo(string terminalPhoneNo) | |||
internal void RemoveSessionByChannel(IChannel channel) | |||
{ | |||
if (terminalPhoneNo == null) return null; | |||
try | |||
{ | |||
if (TerminalPhoneNo_SessionId_Dict.TryRemove(terminalPhoneNo, out string sessionid)) | |||
{ | |||
// 处理转发过来的是数据 这时候通道对设备是1对多关系 | |||
var removeKeys = TerminalPhoneNo_SessionId_Dict.Where(w => w.Value == sessionid).Select(s=>s.Key).ToList(); | |||
if (removeKeys.Count > 0) | |||
{ | |||
foreach (var key in removeKeys) | |||
{ | |||
TerminalPhoneNo_SessionId_Dict.TryRemove(key, out string sessionid1); | |||
} | |||
logger.LogInformation($">>>{sessionid}-{string.Join(",", removeKeys)} 1-n Session Remove."); | |||
} | |||
if (SessionIdDict.TryRemove(sessionid, out JT808Session session)) | |||
{ | |||
logger.LogInformation($">>>{sessionid}-{session.TerminalPhoneNo} 1-1 Session Remove."); | |||
return session; | |||
} | |||
else | |||
{ | |||
return null; | |||
} | |||
} | |||
} | |||
catch (Exception ex) | |||
//todo: 设备离线可以进行通知 | |||
//todo: 使用Redis 发布订阅 | |||
var terminalPhoneNos = SessionIdDict.Where(w => w.Value.Channel.Id == channel.Id).Select(s => s.Key).ToList(); | |||
foreach (var key in terminalPhoneNos) | |||
{ | |||
logger.LogError(ex, $">>>{terminalPhoneNo} Session Remove Exception"); | |||
SessionIdDict.TryRemove(key, out JT808Session jT808SessionRemove); | |||
} | |||
return null; | |||
logger.LogInformation($">>>{string.Join(",", terminalPhoneNos)} Channel Remove."); | |||
} | |||
public IEnumerable<JT808Session> GetAll() | |||
{ | |||
return TerminalPhoneNo_SessionId_Dict.Join(SessionIdDict, m => m.Value, s => s.Key, (m, s) => new JT808Session | |||
return SessionIdDict.Select(s => new JT808Session | |||
{ | |||
Channel= s.Value.Channel, | |||
LastActiveTime= s.Value.LastActiveTime, | |||
SessionID= s.Value.SessionID, | |||
StartTime= s.Value.StartTime, | |||
TerminalPhoneNo= m.Key | |||
TerminalPhoneNo= s.Key | |||
}).ToList(); | |||
} | |||
} | |||
@@ -20,19 +20,11 @@ namespace JT808.DotNetty.Metadata | |||
public long Increment() | |||
{ | |||
if (counter < 0) | |||
{ | |||
Interlocked.Exchange(ref counter,0); | |||
} | |||
return Interlocked.Increment(ref counter); | |||
} | |||
public long Add(long len) | |||
{ | |||
if (counter < 0) | |||
{ | |||
Interlocked.Exchange(ref counter, 0); | |||
} | |||
return Interlocked.Add(ref counter,len); | |||
} | |||
@@ -13,15 +13,6 @@ namespace JT808.DotNetty.Metadata | |||
TerminalPhoneNo = terminalPhoneNo; | |||
StartTime = DateTime.Now; | |||
LastActiveTime = DateTime.Now; | |||
SessionID = Channel.Id.AsShortText(); | |||
} | |||
public JT808Session(IChannel channel) | |||
{ | |||
Channel = channel; | |||
StartTime = DateTime.Now; | |||
LastActiveTime = DateTime.Now; | |||
SessionID = Channel.Id.AsShortText(); | |||
} | |||
public JT808Session() { } | |||
@@ -31,8 +22,6 @@ namespace JT808.DotNetty.Metadata | |||
/// </summary> | |||
public string TerminalPhoneNo { get; set; } | |||
public string SessionID { get; set; } | |||
public IChannel Channel { get; set; } | |||
public DateTime LastActiveTime { get; set; } | |||