Services can be "activated" and "passivated". Applications can be notified of this occurring
by Zestâ„¢ runtime by assembling them with an Activator.
Activators methods are called around "activation" and "passivation": beforeActivation,
afterActivation, beforeActivation, afterPassivation. The
ActivatorAdapter class help you keeping your code short when you only need one or two hooks.
To showcase how this works, we refactor the code to create a number of copies of the books, to be lend out
upon call to the borrowBook method, which will return null if no copy is available. The book
copies are created in the activate method.
Steps to do.
createInitialData method to Library.
HashMap<String,ArrayList<Book>>.
Activator<ServiceReference<Library>> class extending
ActivatorAdapter.
afterActivation method, use the ServiceReference to get a
handle on the Library and call its createInitialData method.
@Activators annotation to the LibraryService declaring the new
LibraryActivator.