code: 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);
      }
docs: Adds the given service to this cache replacing an eventually existing entry.
  
  @param service The service to cache
  @return a result whose previous is the replaced service and where current is the given service