-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyCat.BackEnd.Generics.HeartBeatConnection.pas
88 lines (68 loc) · 2.28 KB
/
MyCat.BackEnd.Generics.HeartBeatConnection.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
unit MyCat.BackEnd.Generics.HeartBeatConnection;
interface
uses
System.SysUtils, MyCat.BackEnd.Interfaces;
// 结构的容器的声明模版
{$I DGLCfg.inc_h}
type
THeartBeatConnection = record
private
FTimeOutTimestamp: Int64;
FConnection: IBackEndConnection;
public
constructor Create(const Connection: IBackEndConnection);
property TimeOutTimestamp: Int64 read FTimeOutTimestamp;
property Connection: IBackEndConnection read FConnection;
end;
_KeyType = Int64;
_ValueType = THeartBeatConnection;
const
_NULL_Value: _ValueType = (FTimeOutTimestamp: (0); FConnection: (nil));
{$DEFINE _DGL_NotHashFunction}
{$DEFINE _DGL_Compare} // 是否需要比较函数,可选
function _IsEqual(const A, B: _ValueType): boolean;
{$IFDEF _DGL_Inline} inline;
{$ENDIF} // result:=(a=b);
function _IsLess(const A, B: _ValueType): boolean;
{$IFDEF _DGL_Inline} inline;
{$ENDIF} // result:=(a<b); 默认排序准则
{$I Map.inc_h} // "类"模版的声明文件
{$I HashMap.inc_h} // "类"模版的声明文件
type
IHeartBeatConnectionIterator = _IIterator;
IHeartBeatConnectionContainer = _IContainer;
IHeartBeatConnectionSerialContainer = _ISerialContainer;
IHeartBeatConnectionVector = _IVector;
IHeartBeatConnectionList = _IList;
IHeartBeatConnectionDeque = _IDeque;
IHeartBeatConnectionStack = _IStack;
IHeartBeatConnectionQueue = _IQueue;
IHeartBeatConnectionPriorityQueue = _IPriorityQueue;
IHeartBeatConnectionSet = _ISet;
IHeartBeatConnectionMultiSet = _IMultiSet;
IHeartBeatConnectionMapIterator = _IMapIterator;
IHeartBeatConnectionMap = _IMap;
IHeartBeatConnectionMultiMap = _IMultiMap;
THeartBeatConnectionHashMap = _THashMap;
THeartBeatConnectionHashMultiMap = _THashMultiMap;
implementation
uses
MyCat.Util;
{$I Map.inc_pas} // "类"模版的实现文件
{$I HashMap.inc_pas} // "类"模版的实现文件
function _IsEqual(const A, B: _ValueType): boolean;
begin
Result := (A.FTimeOutTimestamp = B.FTimeOutTimestamp) and
(A.FConnection = B.FConnection);
end;
function _IsLess(const A, B: _ValueType): boolean;
begin
Result := A.FTimeOutTimestamp < B.FTimeOutTimestamp;
end;
{ THeartBeatConnection }
constructor THeartBeatConnection.Create(const Connection: IBackEndConnection);
begin
FTimeOutTimestamp := TTimeUtil.CurrentTimeMillis + 20 * 1000;
FConnection := Connection;
end;
end.