Associates the reference with the key.

@param key Key associated with this reference
@param reference ServiceReference for the target service
@return true if this is replacing a previous (non-null) service reference
199446
public boolean putReference(K key, ServiceReference<V> reference) {
        if (key == null || reference == null)
            return false;

        ConcurrentServiceReferenceElement<V> element = new ConcurrentServiceReferenceElement<V>(referenceName, reference);
        return (elementMap.put(key, element) != null);
    }
942001
public <T> ServiceGraphModule registerForSpecificKey(Key<T> key, ServiceAdapter<T> factory) {
		keys.put(key, factory);
		return this;
	}
304870
public ServiceReference<V> getReference(K key) {
        if (key == null)
            return null;

        ConcurrentServiceReferenceElement<V> e = elementMap.get(key);
        if (e == null) {
            return null;
        } else {
            return e.getReference();
        }
    }
1316895
public List<ServiceReference> getReferences(String resourceType) {
		List<ServiceReference> references = new ArrayList<ServiceReference>();
		if (containsKey(resourceType)) {
			references.addAll(get(resourceType));
			Collections.sort(references, new Comparator<ServiceReference>() {
				@Override
				public int compare(ServiceReference r0, ServiceReference r1) {
					Integer p0 = OsgiUtil.toInteger(
							r0.getProperty(ComponentBindingsProvider.PRIORITY),
							0);
					Integer p1 = OsgiUtil.toInteger(
							r1.getProperty(ComponentBindingsProvider.PRIORITY),
							0);
					return -1 * p0.compareTo(p1);
				}

			});
		}
		return references;
	}
534365
@Nullable
  public CloseableReference<V> get(final K key) {
    Preconditions.checkNotNull(key);
    Entry<K, V> oldExclusive;
    CloseableReference<V> clientRef = null;
    synchronized (this) {
      oldExclusive = mExclusiveEntries.remove(key);
      Entry<K, V> entry = mCachedEntries.get(key);
      if (entry != null) {
        clientRef = newClientReference(entry);
      }
    }
    maybeNotifyExclusiveEntryRemoval(oldExclusive);
    maybeUpdateCacheParams();
    maybeEvictEntries();
    return clientRef;
  }
989869
public boolean containsKey(Object key) {
	if (key == null) {
	    throw new NullPointerException("key cannot be null");
	}
	else if (key instanceof String) {
	    Node<V> n = lookup((String)key);
	    return n != null && n.isTerminal();
	}
	else {
	    throw new ClassCastException("The provided key does not implement" +
					 " String: " + key);
	}
    }
572894
public Object addingService(ServiceReference reference)
    {
        HttpService httpService = (HttpService) context.getService(reference);

        this.properties = this.updateDictionaryConfig(this.properties, true);
        try {
            String alias = this.getAlias();
            String servicePid = this.properties.get(BundleConstants.SERVICE_PID);
            if (servlet == null)
            {
                servlet = this.makeServlet(alias, this.properties);
                if (servlet instanceof WebappServlet)
                    ((WebappServlet) servlet).init(context, servicePid, this.properties);
            }
            else
                if (servlet instanceof WebappServlet)
                    ((WebappServlet) servlet).setProperties(properties);
            if (servicePid != null)   // Listen for configuration changes
                serviceRegistration = context.registerService(ManagedService.class.getName(), new HttpConfigurator(context, servicePid), this.properties);

            httpService.registerServlet(alias, servlet, this.properties, httpContext);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return httpService;
    }
509261
protected Map<String, Object> unsetUserRegistry(ServiceReference<UserRegistryService> ref) {
        userRegistry.removeReference((String) ref.getProperty(KEY_ID), ref);
        userRegistry.removeReference(String.valueOf(ref.getProperty(KEY_SERVICE_ID)), ref);

        // determine a new user registry service
        userRegistryService.set(null);
        return getServiceProperties();
    }
160193
@Reference(name = KEY_CONFIG_ADMIN, service = ConfigurationAdmin.class)
    protected void setConfigAdmin(ServiceReference<ConfigurationAdmin> ref) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            SibTr.entry(tc, "setConfigAdmin", ref);
        configAdminRef.setReference(ref);
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            SibTr.exit(tc, "setConfigAdmin");
    }
766247
protected Map<String, Object> unsetConfiguration(ServiceReference<SecurityConfiguration> ref) {
        configs.removeReference((String) ref.getProperty(KEY_ID), ref);
        return getServiceProperties();
    }
269541
@Reference(name = KEY_GENERATOR, service = DDLGenerationParticipant.class, policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE)
    protected void setGenerator(ServiceReference<DDLGenerationParticipant> ref) {
        generators.addReference(ref);
    }
232599
@Reference(service = Application.class,
               cardinality = ReferenceCardinality.MULTIPLE,
               policy = ReferencePolicy.DYNAMIC,
               target = "(application.state=STARTING)")
    protected void addStartingApplication(ServiceReference<Application> ref) {
        String appName = (String) ref.getProperty(NAME);
        lock.writeLock().lock();
        try {
            if (!appStates.containsKey(appName))
                appStates.put(appName, ApplicationState.STARTING);
        } finally {
            lock.writeLock().unlock();
        }
    }
539849
@SuppressWarnings("unchecked")
    @Override
    public <S> S getService(ServiceReference<S> reference) {
        return (S) serviceImplementations.get(reference);
    }
566614
public Result<T> put(T service)
    {
        check(service);

        ServiceType serviceType = service.resolveServiceType();
        T previous = null;

        lock();
        try
        {
            ServiceType existingServiceType = keysToServiceTypes.get(service.getKey());
            if (existingServiceType != null && !existingServiceType.equals(serviceType))
                throw new ServiceLocationException("Invalid registration of service " + service.getKey() +
                                                   ": already registered under service type " + existingServiceType +
                                                   ", cannot be registered also under service type " + serviceType, SLPError.INVALID_REGISTRATION);
            keysToServiceTypes.put(service.getKey(), serviceType);
            previous = keysToServiceInfos.put(service.getKey(), service);
            service.setRegistered(true);
            if (previous != null) previous.setRegistered(false);
        }
        finally
        {
            unlock();
        }

        notifyServiceAdded(previous, service);
        return new Result<T>(previous, service);
    }
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;
    }
478514
protected void setSsl(ServiceReference<Object> reference) {
        sslConfigurationRef.setReference(reference);
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(this, tc, "sslRef set to " + reference.getProperty(CONFIG_DISPLAY_ID));
        }
    }
1268177
public void addServiceDescriptor(KEY key, MethodDescriptor<KEY> serviceDescriptor) {
        Preconditions.checkNotNull(key, "Key cannot be null");
        Preconditions.checkState(instance != null, "ServiceRegistry not init yet");

        //        if (serviceDescriptors.containsKey(key)) {
        //            LOG.warn("Ignore key=" + key + " since it is already registered with "
        //                    + serviceDescriptor);
        //        }

        this.serviceDescriptors.putIfAbsent(key, serviceDescriptor);
    }