So guys, in the previous lecture video we discussed and we implemented the subscription.
Now we will going to implement the notification.
So whenever a publisher updates any entries of its routing table, a notification is supposed to be
sent to the all the threads which are subscribed to that entry, which is being updated.
Right.
So in order to send the notification, we will use an API and invoke notification chain which we have
already implemented.
Right.
This is one API which can be used to send all type of notifications, whether it is an update or it
is an ad or it is a deletion of an entry from the routing table by the publisher.
Right.
So I expect that you have implemented this API in the file notifs already.
And now let us see that how we can make our routing table or data source intelligent so that whenever
any entry in the data source is updated by the publisher, our data source would be intelligent enough
to send notification to all the subscribers which are subscribed for that entry, which is being updated.
Right.
So this will be the final part of implementation of publisher subscriber model using notification chains.
So guys, you can see that I'm in the function to add or update routing table entry.
And we already know that publisher uses this API in order to update routing table entries in the routing
table.
Right?
So coming to the problem statement that whenever any entry in the routing table is updated by the publisher,
we need to send notification to all the registered subscribers for that entry, Right?
So you can see that here.
We need to hook up some code inside this function in order to accomplish our goal.
So what are we going to do is that I will going to add some code at the end of this function to achieve
our goal.
Right.
So what I will going to do is that I will simply check whether this entry has a relevant data.
The data means the gateway IP address and the outgoing interface.
Right.
The data part of the routing table entry will be not null if this routing table entry is being updated
by the publisher.
Right.
So in that case, simply you need to notify all the subscribers which are associated to this routing
table entry.
As simple as that.
So it simply means that whenever publisher updates the routing table entry in the routing table, a
notification will be sent to all the subscribers associated with this routing table entry.
Right.
So remember, this function is used by the subscribers also to create a routing table entry.
And this function is also used by the publisher to create a routing table entry.
The only difference is that that when this function is invoked by the publisher, the data part associated
with this routing table entry would have some valid values, right?
Whereas if this API is invoked by the subscriber, then gateway and outgoing interface of the routing
table entry would be null.
Right?
So you can use this logic in order to differentiate whether this entry is being updated by the publisher
or it is being created by the subscriber.
Right.
Similarly, if the subscriber chooses to delete an entry from the routing table.
So this is currently our implementation is right.
The data source doesn't convey anything to the subscribers at all in this function.
Now we will going to add an additional code in this function so that whenever the publisher deletes
an entry from the routing table before the entry is finally deleted from the routing table, a notification
should be sent to all the subscribers and telling them that, Hey, subscribers, this entry is going
to be deleted.
Do whatever you want, right?
So you can see that in this API after I have found the entry of interest to be deleted, I remove this
entry from the routing table and before actually freeing the entry, you need to notify this entry to
all the subscribers.
So before actually freeing the entry, let us invoke an API and invoke notification chain.
Right.
And simply do the same stuff since we are deleting the entry.
Therefore you need to pass NFC delete as an operation code.
Right.
And when this function returns, it means that all the subscribers have been notified about this entry.
And then simply because the entry is going to be deleted, it is your job to free the notification chain
associated with this routing table entry, right?
Otherwise you will end up doing some memory leak.
And finally, free up the notification chain itself, which is associated with the routing table entry.
And then finally, you can free the routing table entry, right?
So by adding only this piece of code, your routing table has become intelligent that whenever the entry
is deleted from the routing table entry.
Before freeing the routing table entry, a notification will be sent to all the subscribers about this
delete.
Right.
So it simply means that your data source has now become intelligent and now it has an intelligence to
tell the subscribers about all the operations that is being done on this data source by the publisher.
Right.