Kernel Extension reacting to instance role change

Hello. I'm developing a Neo4j java plugin using the ExtensionFactory. The plugin starts a background thread that listens for external events and manipulates the graph db. The plugin needs to be aware of the status of the instance it's running on, as only the leader can perform write operations against the database. When running on a multi-node cluster there is only one leader, and I understand that the leader can change. The question I have is how can my code detect when the instance's role changes from leader to follower and vice versa?

Thanks in advance!

I may have found the answer myself. There is a procedure:

CALL dbms.cluster.role()

That returns the current instance's role for a given database name.