/**
  * This method is called when a used handler factory disappears. This method is synchronized to
  * avoid concurrent calls to method modifying the factory state.
  *
  * @param reference the leaving service reference.
  * @param service the handler factory object.
  * @see
  *     org.apache.felix.ipojo.util.TrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
  *     java.lang.Object)
  */
 public synchronized void removedService(ServiceReference reference, Object service) {
   // Look for the implied reference and invalid the handler identifier
   for (Object m_requiredHandler : m_requiredHandlers) {
     RequiredHandler req = (RequiredHandler) m_requiredHandler;
     if (reference.equals(req.getReference())) {
       req.unRef(); // This method will unget the service.
       computeFactoryState();
       return; // The factory can be used only once.
     }
   }
 }
 /**
  * This method is called when a new handler factory is detected. Test if the factory can be used
  * or not. This method need to be synchronized as it accesses to the content of required handlers.
  *
  * @param reference the new service reference.
  * @return <code>true</code> if the given factory reference matches with a required handler.
  * @see
  *     org.apache.felix.ipojo.util.TrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
  */
 public synchronized boolean addingService(ServiceReference reference) {
   for (int i = 0; i < m_requiredHandlers.size(); i++) {
     RequiredHandler req = (RequiredHandler) m_requiredHandlers.get(i);
     if (req.getReference() == null && match(req, reference)) {
       int oldP = req.getLevel();
       req.setReference(reference);
       // If the priority has changed, sort the list.
       if (oldP != req.getLevel()) {
         // Manipulate the list.
         Collections.sort(m_requiredHandlers);
       }
       return true;
     }
   }
   return false;
 }