Save service only if it's not already found in the registry.

@param service         the service
@param servicesManager the services manager
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());
        }
    }
173978
public void setServices(List<ServiceInfo> services) {
        if (services == null || services.size() == 0) {
            throw new IllegalArgumentException("services is empty!");
        }
        this.services = services;
        serviceReset = true;
    }
226089
private void updateSortedServices() {
    List<T> copiedList = new ArrayList<T>(serviceMap.values());
    sortedServices = Collections.unmodifiableList(copiedList);
    if (changeListener != null) {
      changeListener.changed();
    }
  }
1218452
def save_ready(self, service_name):
        
        self._load_ready_file()
        self._ready.add(service_name)
        self._save_ready_file()
1116045
@Override
    public boolean clearRegistry() throws SalException {
        boolean result = this.serviceManager.clearServices();
        // Only try if we could delete the services
        if (result)
            result = result & this.docManager.clearDocuments();

        // Only try if we could delete the services and the docs
        if (result)
            result = result & this.kbManager.clearKnowledgeBase();

        return result;
    }
1100521
public void registerServiceHandler(String name, Object handler) {
        Map<String, Object> serviceHandlers = getServiceHandlers();
        serviceHandlers.put(name, handler);
    }
260310
private void createManagedService(final BundleContext context) {
		ManagedService service = this::scheduleUpdateConfig;
		final Dictionary<String, String> props = new Hashtable<>();
		props.put(Constants.SERVICE_PID, org.ops4j.pax.web.service.WebContainerConstants.PID);
		context.registerService(ManagedService.class, service, props);

		// If ConfigurationAdmin service is not available, then do a default configuration.
		// In other cases, ConfigurationAdmin service will always call the ManagedService.
		if (context.getServiceReference(ConfigurationAdmin.class.getName()) == null) {
			try {
				service.updated(null);
			} catch (ConfigurationException ignore) {
				// this should never happen
				LOG.error("Internal error. Cannot set initial configuration resolver.", ignore);
			}
		}
	}
498174
@Override
    public void registerService(ServiceInstance<T> service) throws Exception
    {
        Entry<T> newEntry = new Entry<T>(service);
        Entry<T> oldEntry = services.putIfAbsent(service.getId(), newEntry);
        Entry<T> useEntry = (oldEntry != null) ? oldEntry : newEntry;
        synchronized(useEntry)
        {
            if ( useEntry == newEntry ) // i.e. is new
            {
                useEntry.cache = makeNodeCache(service);
            }
            internalRegisterService(service);
        }
    }
1233514
public static boolean isServiceRunning(Context context, Class<? extends Service> service) {
        return isServiceRunning(context, service, Integer.MAX_VALUE);
    }
772105
@Reference(
            name = "carbon.metrics.management.service",
            service = MetricManagementService.class,
            cardinality = ReferenceCardinality.MANDATORY,
            policy = ReferencePolicy.DYNAMIC,
            unbind = "unsetMetricManagementService"
    )
    protected void setMetricManagementService(MetricManagementService metricManagementService) {
        DataHolder.getInstance().setMetricManagementService(metricManagementService);
    }
246659
public void setServices(java.util.Collection<Service> services) {
        if (services == null) {
            this.services = null;
            return;
        }

        this.services = new com.amazonaws.internal.SdkInternalList<Service>(services);
    }
548185
private RegisteredService update(final RegisteredService rs) {
        val currentDn = getCurrentDnForRegisteredService(rs);

        if (StringUtils.isNotBlank(currentDn)) {
            LOGGER.debug("Updating registered service at [{}]", currentDn);
            val entry = this.ldapServiceMapper.mapFromRegisteredService(this.baseDn, rs);
            LdapUtils.executeModifyOperation(currentDn, this.connectionFactory, entry);
        } else {
            LOGGER.debug("Failed to locate DN for registered service by id [{}]. Attempting to save the service anew", rs.getId());
            insert(rs);
        }
        return rs;
    }
759290
public void setServices(java.util.Collection<Service> services) {
        if (services == null) {
            this.services = null;
            return;
        }

        this.services = new java.util.ArrayList<Service>(services);
    }
138237
public void removeService(ServiceReference reference, Object service) {
        if (serviceRegistration != null) {
            serviceRegistration.unregister();
            serviceRegistration = null;
        }

        String alias = this.getAlias();
        ((HttpService) service).unregister(alias);
        if (servlet instanceof WebappServlet)
            ((WebappServlet)servlet).free();
        servlet = null;
    }
1261875
@Nullable
  public ServerServiceDefinition addService(ServerServiceDefinition service) {
    return services.put(service.getServiceDescriptor().getName(), service);
  }
1373494
@Override
    protected K addService(S service, ServiceProperties props) {
        K key = keyFunction.apply(service, props);
        if (key != null) {
            if (serviceMap.putIfAbsent(key, service) != null) {
                getLogger().error("Duplicate key \"{}\" detected for service {}.", key, props.getServiceId());
                return null;
            }
            return key;
        }
        return null;
    }
1046103
private void snapshotService(SnapshotWriter writer, RaftServiceContext service) {
    writer.writeLong(service.serviceId().id());
    writer.writeString(service.serviceType().name());
    writer.writeString(service.serviceName());
    byte[] config = Serializer.using(service.serviceType().namespace()).encode(service.serviceConfig());
    writer.writeInt(config.length).writeBytes(config);
    try {
      service.takeSnapshot(writer);
    } catch (Exception e) {
      logger.error("Failed to take snapshot of service {}", service.serviceId(), e);
    }
  }