///////////////////////////////////////////////////////////////
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
///////////////////////////////////////////////////////////////

[[tut-services-step2,Step 2 - Hooking into the Service Activation]]
= Step 2 - Hooking into the Service Activation =

Services can be "activated" and "passivated". Applications can be notified of this occurring
by Polygene™ 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:

- Add a createInitialData method to Library.
- In the implementation, create a couple of books of each title and store each copy in a HashMap<String,ArrayList<Book>>.
- Write an Activator<ServiceReference<Library>> class extending ActivatorAdapter.
- Override the afterActivation method, use the ServiceReference to get a handle on the Library and call its createInitialData method.
- Add the @Activators annotation to the LibraryService declaring the new LibraryActivator.
