You are not logged in.
Pages: 1
I'm trying to implement a publish-subscribe messaging system with mORMot websockets. I need something like (pusher) channels.
I want to use a unique mormot server to send messages to all clients, so, when a client subscribe to a message/event, it should be only for a determined channel/client. When a notification is sent, it is only for a specific client.
My interfaces look like this:
INotificationCallback = interface(IInvokable)
['{F5D956A4-AE70-4F47-AECC-40E2AB6AC0B4}']
procedure NotifyRefresh(const message: string);
end;
NotificationCallbackArray = array of INotificationCallback;
INotificationService = interface(IServiceWithCallbackReleased)
['{C92DCBEA-C680-40BD-8D9C-3E6F2ED9C9CF}']
procedure Subscribe(const client: string; const callback: INotificationCallback);
procedure Refresh(const client, message: string);
end;
I'm using a dictionary to store the callbacks:
fConnected: TDictionary<string, NotificationCallbackArray>;
...
procedure TNotificationService.Subscribe(const client: string; const callback: INotificationCallback);
begin
if not fConnected.ContainsKey(client) then
fConnected.Add(client, []);
InterfaceArrayAdd(fConnected[client], callback);
end;
The problem is the CallbackReleased method:
procedure CallbackReleased(const callback: IInvokable; const interfaceName: RawUTF8);
It doesn't provide any information that allow me to identify and release the correct callback.
Any ideas of how to solve this?
Last edited by Roberto Schneiders (2015-11-12 12:51:01)
Offline
Why not just check for interfaceName='INotificationCallback' then delete the callback: IInvokable from all matching entry in fConnected[]?
Or not use a dictionary, but an array of records containing the client string and the INotificationCallback entry.
Offline
Why not just check for interfaceName='INotificationCallback' then delete the callback: IInvokable from all matching entry in fConnected[]?
that will work, but, I will have more than a thousand channels with potentialy more than 5k callbacks, it would be slow, don't you think? A hashlist would be much more efficient.
Or not use a dictionary, but an array of records containing the client string and the INotificationCallback entry.
Not sure, but will end up in the same problem, I think.
Offline
If you are just looping around callback pointers, even 5,000 pointers may be fast to browse, in practice...
But why not define your own UnSubscribe(const client: string; const callback: INotificationCallback) method?
Offline
I can try that. AFAIK, the `CallbackReleased` method is used and handled internally by the framework, you are suggesting that I handle manually that behavior with this new method?
Offline
Pages: 1