-
Notifications
You must be signed in to change notification settings - Fork 20
/
LogViewer.Receivers.Zmq.pas
145 lines (115 loc) · 3.63 KB
/
LogViewer.Receivers.Zmq.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
{
Copyright (C) 2013-2022 Tim Sinaeve tim.sinaeve@gmail.com
Licensed 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.
}
unit LogViewer.Receivers.Zmq;
{ ZeroMQ channel receiver. }
interface
uses
System.Classes,
Vcl.ExtCtrls,
Spring,
ZeroMQ,
LogViewer.Interfaces, LogViewer.Receivers.Base,
LogViewer.Receivers.Zmq.Settings;
{$REGION 'documentation'}
{ Receives logmessages from one or more ZMQ publisher through a subscriber
socket.
A ZeroMQChannelReceiver can receive messages from multiple channels that are
bound to one or more ZMQ publisher sockets.
In this setup the source application (sender of log messages) acts as a server
which binds to a ZeroMQ socket (publisher).
Multiple subscribers (TZeroMQChannelReceiver instances) can connect to the
same publisher.
REMARKS:
- communication with ZeroMQ sockets is asynchronious. So the source
application is never blocked as all messages are queued.
- when the receiver cannot keep up with the publisher, messages are thrown
away by the ZeroMQ subscriber.
TODO:
- list of connectionstrings to subscribe to?
}
{$ENDREGION}
type
TZmqChannelReceiver = class(TChannelReceiver, IChannelReceiver, IZmq)
private
FZmq : IZeroMQ;
protected
{$REGION 'property access methods'}
function GetSettings: TZmqSettings;
procedure SetEnabled(const Value: Boolean); override;
{$ENDREGION}
procedure SettingsChanged(Sender: TObject);
public
procedure AfterConstruction; override;
constructor Create(
AManager : ILogViewerManager;
AZmq : IZeroMQ;
const AName : string
); reintroduce;
destructor Destroy; override;
property Settings: TZmqSettings
read GetSettings;
end;
implementation
uses
System.SysUtils,
Vcl.Forms;
{$REGION 'construction and destruction'}
procedure TZmqChannelReceiver.AfterConstruction;
begin
inherited AfterConstruction;
PollTimer.OnTimer := PollTimerTimer;
PollTimer.Interval := Settings.PollingInterval;
Settings.OnChanged.Add(SettingsChanged);
end;
constructor TZmqChannelReceiver.Create(AManager: ILogViewerManager; AZmq:
IZeroMQ; const AName: string);
begin
inherited Create(AManager, AName);
FZmq := AZmq;
end;
destructor TZmqChannelReceiver.Destroy;
begin
PollTimer.Enabled := False;
Settings.OnChanged.RemoveAll(Self);
FZmq := nil;
inherited Destroy;
end;
{$ENDREGION}
{$REGION 'property access methods'}
procedure TZmqChannelReceiver.SetEnabled(const Value: Boolean);
begin
inherited SetEnabled(Value);
PollTimer.Enabled := Value;
end;
function TZmqChannelReceiver.GetSettings: TZmqSettings;
begin
Result := Manager.Settings.ZmqSettings;
end;
{$ENDREGION}
{$REGION 'event handlers'}
procedure TZmqChannelReceiver.SettingsChanged(Sender: TObject);
var
LSubscriber : ISubscriber;
begin
Enabled := Settings.Enabled;
PollTimer.Interval := Settings.PollingInterval;
for LSubscriber in SubscriberList.Values do
begin
(LSubscriber as ILogMessageSubscriptionFilter).LogMessageTypes :=
Settings.LogMessageTypes;
(LSubscriber as ILogMessageSubscriptionFilter).LogMessageLevels :=
Settings.LogMessageLevels;
end;
end;
{$ENDREGION}
end.