Search for and add any LogHandler ServiceReferences that were already started
by the time we registered our ServiceListener.
184064
@SuppressWarnings("unchecked")
    protected void processInitialTraceHandlerServices() throws InvalidSyntaxException {
        ServiceReference<WsTraceHandler>[] servRefs = (ServiceReference<WsTraceHandler>[])
                        bundleContext.getServiceReferences(WsTraceHandler.class.getName(), null);

        if (servRefs != null) {
            for (ServiceReference<WsTraceHandler> servRef : servRefs) {
                setWsTraceHandler(servRef);
            }
        }
    }
187873
public static void saveService(final RegisteredService service, final ServicesManager servicesManager) {
        servicesManager.load();

        if (servicesManager.findServiceBy(registeredService -> registeredService instanceof SamlRegisteredService
            && registeredService.getServiceId().equals(service.getServiceId())).isEmpty()) {
            LOGGER.info("Service [{}] does not exist in the registry and will be added.", service.getServiceId());
            servicesManager.save(service);
            servicesManager.load();
        } else {
            LOGGER.info("Service [{}] exists in the registry and will not be added again.", service.getServiceId());
        }
    }
773506
private Object getServiceHandler(IScope scope, String serviceName) {
        // get application scope handler first
        Object service = scope.getHandler();
        if (serviceName == null || serviceName.equals("")) {
            // no service requested, return application scope handler
            log.trace("No service requested, return application scope handler: {}", service);
            return service;
        }
        // search service resolver that knows about service name
        for (IServiceResolver resolver : serviceResolvers) {
            service = resolver.resolveService(scope, serviceName);
            if (service != null) {
                return service;
            }
        }
        // requested service does not exist
        return null;
    }
970380
public synchronized static void addHandler(Handler handler) {
      java.util.logging.Logger root = java.util.logging.LogManager.getLogManager().getLogger(StringUtils.EMPTY);
      root.addHandler(handler);
   }
702203
function(serviceRegistry) {
			this._serviceRegistry = serviceRegistry;
			this._prefService = serviceRegistry.getService("orion.core.preference"); //$NON-NLS-1$

			if (this._prefService) {
				// Get the overrides from the preference store
				this._getBindingOverrides().then(function(overrides) {
					this._bindingOverrides = overrides;
					
					// Update all folks that are listening
					this._updateBindingOverrides();
				}.bind(this));
	
				// listen for changes from other pages
				this._prefService.addEventListener("changed", function (e) {
					if (e.namespace === "/KeyBindings") { //$NON-NLS-1$
						// Refresh the binding overrides
						this._getBindingOverrides().then(function(overrides) {
							if (overrides.length > this._bindingOverrides.length) {
								// handle any new changes
								for (var i = this._bindingOverrides.length; i < overrides.length; i++) {
									var override = overrides[i];
									var bindingChangeEvent = {type: "bindingChanged", id: override.id, newBinding: override.newBinding,  //$NON-NLS-1$
																prevBinding: override.prevBinding};
									this.dispatchEvent(bindingChangeEvent);
								}
							}
							this._bindingOverrides = overrides;
						}.bind(this));
					}
				}.bind(this));
			}
		}
903372
protected void notifyInit () {
		final String sourceMethod = "notifyInit"; //$NON-NLS-1$
		IServiceReference[] refs = null;
		try {
			if(_aggregator != null && _aggregator.getPlatformServices() != null){
				refs = _aggregator.getPlatformServices().getServiceReferences(ICacheManagerListener.class.getName(),"(name=" + _aggregator.getName() + ")");	//$NON-NLS-1$ //$NON-NLS-2$
				if (refs != null) {
					for (IServiceReference ref : refs) {
						ICacheManagerListener listener = (ICacheManagerListener)_aggregator.getPlatformServices().getService(ref);
						if (listener != null) {
							try {
								listener.initialized(this);
							} catch (Throwable t) {
								if (log.isLoggable(Level.WARNING)) {
									log.logp(Level.WARNING, CacheManagerImpl.class.getName(), sourceMethod, t.getMessage(), t);
								}
							} finally {
								_aggregator.getPlatformServices().ungetService(ref);
							}
						}
					}
				}
			}
		} catch (PlatformServicesException e) {
			if (log.isLoggable(Level.SEVERE)) {
				log.log(Level.SEVERE, e.getMessage(), e);
			}
		}
	}
1080001
def service_changed(self, event):
        # type: (ServiceEvent) -> None
        
        # Call sub-methods
        kind = event.get_kind()
        svc_ref = event.get_service_reference()

        if kind == ServiceEvent.REGISTERED:
            # Service coming
            with self.__instances_lock:
                self.__add_handler_factory(svc_ref)

        elif kind == ServiceEvent.UNREGISTERING:
            # Service gone
            with self.__instances_lock:
                self.__remove_handler_factory(svc_ref)
1270808
@Override
	public void injectServices(ServiceRegistryImplementor serviceRegistry) {
		if ( gridDialect instanceof ServiceRegistryAwareService ) {
			( (ServiceRegistryAwareService) gridDialect ).injectServices( serviceRegistry );
		}
	}
174964
protected void addListeners() {
    // Listen for result changes, including the one we monitor
    context.addResultListener(this);
    context.addVisualizationListener(this);
    // Listen for database events only when needed.
    if(task.has(UpdateFlag.ON_DATA)) {
      context.addDataStoreListener(this);
    }
  }
413152
protected void updatedMonitor(ServiceReference<FileMonitor> monitorRef) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "CoreServiceImpl updatedMonitor", monitorRef);
        MonitorHolder existing = fileMonitors.get(monitorRef);
        if (existing == null)
            return;

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "CoreServiceImpl updatedMonitor, existing found");
        // Only initialize and start the monitor if the component has been activated
        if (cContext != null) {
            try {
                // Create a root cache location for the bundle that registered this service;
                // there could be multiple monitors associated with a bundle, but all should be destroyed
                // if/when the bundle is uninstalled, so keep them "together"..
                //TODO n.b. cacheRoot is unused
                File cacheRoot = cContext.getBundleContext().getDataFile(Long.toString(monitorRef.getBundle().getBundleId()));
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc, "CoreServiceImpl updatedMonitor, about to refresh");
                existing.refresh(cacheRoot);
            } catch (RuntimeException re) {
                // Generated FFDC, rethrow to fail the bind
                fileMonitors.remove(monitorRef);
                throw re;
            }
        }
    }
339161
@Override
    public ServiceReference<?> getServiceReference(String clazz) {
    	Collection<ServiceReference<?>> servrefs = serviceRegistrations.get(clazz);
    	if (servrefs == null || servrefs.size() == 0) {
            return null;
    	}

        return servrefs.iterator().next();
    }
731968
protected void addServerEventHandlers() {
		Map<Object, Class<?>> handlers =  getServerEventHandlers();
		Set<Entry<Object, Class<?>>> entries = handlers.entrySet();
		for(Entry<Object, Class<?>> entry : entries) {
			SFSEventType type = SFSEventType.valueOf(
					entry.getKey().toString());
			ServerEventHandler handler = createServerEventHandler(
					type, entry.getValue());
			addEventHandler(type, handler);
		}
	}
228685
def start(self):
        
        self._context.add_service_listener(
            self, self.requirement.filter, self.requirement.specification
        )
1171302
public void addListeners()
    {
        super.addListeners();
        
        // Link the screen field to the passed in record
        ((ReferenceField)this.getScreenRecord().getField(MessageInfoScreenRecord.MESSAGE_INFO_ID)).syncReference(this.getHeaderRecord());
        this.getScreenRecord().getField(MessageInfoScreenRecord.MESSAGE_INFO_ID).addListener(new FieldReSelectHandler(this));
        
        this.getMainRecord().addListener(new CompareFileFilter(this.getMainRecord().getField(MessageProcessInfo.MESSAGE_TYPE_ID), this.getScreenRecord().getField(MessageInfoScreenRecord.MESSAGE_TYPE_ID), DBConstants.EQUALS, null, true));
        this.getScreenRecord().getField(MessageInfoScreenRecord.MESSAGE_TYPE_ID).addListener(new FieldReSelectHandler(this));
        this.getMainRecord().addListener(new CompareFileFilter(this.getMainRecord().getField(MessageProcessInfo.PROCESS_TYPE_ID), this.getScreenRecord().getField(MessageInfoScreenRecord.PROCESS_TYPE_ID), DBConstants.EQUALS, null, true));
        this.getScreenRecord().getField(MessageInfoScreenRecord.PROCESS_TYPE_ID).addListener(new FieldReSelectHandler(this));
        
        this.getScreenRecord().getField(MessageInfoScreenRecord.MESSAGE_INFO_TYPE_ID).addListener(new FieldReSelectHandler(this));
        this.getScreenRecord().getField(MessageInfoScreenRecord.CONTACT_TYPE_ID).addListener(new FieldReSelectHandler(this));
        this.getScreenRecord().getField(MessageInfoScreenRecord.REQUEST_TYPE_ID).addListener(new FieldReSelectHandler(this));
        // This is a little inefficient, but this filter is not used much.
        this.getMainRecord().addListener(new FileFilter(null)
        {
            /**
             * Set up/do the remote criteria.
             * @param strbFilter The SQL query string to add to.
             * @param bIncludeFileName Include the file name with this query?
             * @param vParamList The param list to add the raw data to (for prepared statements).
             * @return True if you should not skip this record (does a check on the local data).
             */
            public boolean doLocalCriteria(StringBuffer strbFilter, boolean bIncludeFileName, Vector<BaseField> vParamList)
            {
                Record recMessageInfoScreenRecord = getScreenRecord();
                if (recMessageInfoScreenRecord != null)
                    if ((!recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.MESSAGE_INFO_TYPE_ID).isNull())
                        || (!recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.CONTACT_TYPE_ID).isNull())
                        || (!recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.REQUEST_TYPE_ID).isNull()))
                {
                    // Note I move the MessageInfoField to a temp field since the reference is a header filter.
                            recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.MESSAGE_INFO_COMPARE_ID).moveFieldToThis(this.getOwner().getField(MessageProcessInfo.MESSAGE_INFO_ID));
                            Record recMessageInfo = ((ReferenceField)recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.MESSAGE_INFO_COMPARE_ID)).getReference();
                            if (recMessageInfo != null)
                            {
                                if (!recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.MESSAGE_INFO_TYPE_ID).isNull())
                                    if (!recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.MESSAGE_INFO_TYPE_ID).equals(recMessageInfo.getField(MessageInfo.MESSAGE_INFO_TYPE_ID)))
                                        return false;
                                if (!recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.CONTACT_TYPE_ID).isNull())
                                    if (!recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.CONTACT_TYPE_ID).equals(recMessageInfo.getField(MessageInfo.CONTACT_TYPE_ID)))
                                        return false;
                                if (!recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.REQUEST_TYPE_ID).isNull())
                                    if (!recMessageInfoScreenRecord.getField(MessageInfoScreenRecord.REQUEST_TYPE_ID).equals(recMessageInfo.getField(MessageInfo.REQUEST_TYPE_ID)))
                                        return false;
                            }
                        }
                        return super.doLocalCriteria(strbFilter, bIncludeFileName, vParamList);                
                    }
         
                });
    }
1229247
void addMessageHandler(SubscriptionMessageHandler messageHandler)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "addMessageHandler", messageHandler);

    final boolean inserted = _subscriptionMessagePool.add(messageHandler);
    // If the message wasn't inserted, then the pool was exceeded
    if (!inserted)
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
        SibTr.debug(
          tc,
         "SubscriptionObjectPool size exceeded");

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "addMessageHandler");
  }
575470
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
1170413
@Override
	public IServiceReference[] getServiceReferences(String clazz, String filter) throws PlatformServicesException {
		final String sourceMethod = "getServiceReferences"; //$NON-NLS-1$
		boolean isTraceLogging = log.isLoggable(Level.FINER);
		if (isTraceLogging) {
			log.entering(PlatformServicesImpl.class.getName(), sourceMethod, new Object[]{clazz, filter});
		}
		ServiceReferenceOSGi[] refs = null;
		try {
			BundleContext bundleContext = Activator.getBundleContext();
			if (bundleContext != null) {
				ServiceReference<?>[] platformRefs = bundleContext.getServiceReferences(clazz, filter);
				if (platformRefs != null) {
					refs = new ServiceReferenceOSGi[platformRefs.length];
					for (int i = 0; i < platformRefs.length; i++) {
						refs[i] = new ServiceReferenceOSGi(platformRefs[i]);
					}
				}
			}
		} catch (InvalidSyntaxException e) {
			throw new PlatformServicesException(e);
		}
		if (isTraceLogging) {
			log.exiting(PlatformServicesImpl.class.getName(), sourceMethod, refs != null ? Arrays.asList(new IServiceReference[refs.length]) : null);
		}
		return refs;

	}