code: def _filter_with_hooks(self, svc_event, listeners):
          
          svc_ref = svc_event.get_service_reference()
          # Get EventListenerHooks service refs from registry
          hook_refs = self._registry.find_service_references(
              SERVICE_EVENT_LISTENER_HOOK
          )
          # only do something if there are some hook_refs
          if hook_refs:
              # Associate bundle context to hooks
              ctx_listeners = {}
              for listener in listeners:
                  context = listener.bundle_context
                  ctx_listeners.setdefault(context, []).append(listener)
  
              # Convert the dictionary to a shrinkable one,
              # with shrinkable lists of listeners
              shrinkable_ctx_listeners = ShrinkableMap(
                  {
                      context: ShrinkableList(value)
                      for context, value in ctx_listeners.items()
                  }
              )
  
              for hook_ref in hook_refs:
                  if not svc_ref == hook_ref:
                      # Get the bundle of the hook service
                      hook_bundle = hook_ref.get_bundle()
                      # lookup service from registry
                      hook_svc = self._registry.get_service(hook_bundle, hook_ref)
                      if hook_svc is not None:
                          # call event method of the hook service,
                          # pass in svc_event and shrinkable_ctx_listeners
                          # (which can be modified by hook)
                          try:
                              hook_svc.event(svc_event, shrinkable_ctx_listeners)
                          except:
                              self._logger.exception(
                                  "Error calling EventListenerHook"
                              )
                          finally:
                              # Clean up the service
                              self._registry.unget_service(hook_bundle, hook_ref)
  
              # Convert the shrinkable_ctx_listeners back to a list of listeners
              # before returning
              ret_listeners = set()
              for bnd_listeners in shrinkable_ctx_listeners.values():
                  ret_listeners.update(bnd_listeners)
  
              return ret_listeners
  
          # No hook ref
          return listeners
docs: Filters listeners with EventListenerHooks
  
          :param svc_event: ServiceEvent being triggered
          :param listeners: Listeners to filter
          :return: A list of listeners with hook references