Invoke to find all services for given service type using specified class loader

@param classLoader specified class loader
@param serviceType given service type
@return List of found services
557322
public static <T> List<T> load(ClassLoader classLoader, Class<T> serviceType) {
        List<T> foundServices = new ArrayList<>();
        Iterator<T> iterator = ServiceLoader.load(serviceType, classLoader).iterator();

        while (checkHasNextSafely(iterator)) {
            try {
                T item = iterator.next();
                foundServices.add(item);
                LOGGER.debug(String.format("Found %s [%s]", serviceType.getSimpleName(), item.toString()));
            } catch (ServiceConfigurationError e) {
                LOGGER.trace("Can't find services using Java SPI", e);
                LOGGER.error(e.getMessage());
            }
        }
        return foundServices;
    }
808434
public static <T> PluggableProviderService<T> getPluginProviderService(
        Class<T> serviceType,
        String serviceName,
        ServiceProviderLoader loader
    )
    {
        for (PluginProviderServices pluginProviderServices : pluginProviderServiceLoader) {
            if (pluginProviderServices.hasServiceFor(serviceType, serviceName)) {
                return pluginProviderServices.getServiceProviderFor(serviceType, serviceName, loader);
            }
        }
        return null;
    }
369732
static <T> Optional<T> findFirst(final Class<T> service) {
        final ServiceLoader<T> loader = load(service);
        if (loader == null) return empty();
        final Iterator<T> services = loader.iterator();
        return services.hasNext() ? of(services.next()) : empty();
    }
835419
private static List<String> loadServicesImplementations(
            final Class<?> ofClass) {
        List<String> result = new ArrayList<String>();

        // Allow a sysprop to specify the first candidate
        String override = System.getProperty(ofClass.getName());
        if (override != null) {
            result.add(override);
        }

        ClassLoader loader = ServiceLib.class.getClassLoader();
        URL url = loader.getResource("org.igniterealtime.jbosh/" + ofClass.getName());
        if (url == null) {
            // Early-out
            return result;
        }

        InputStream inStream = null;
        InputStreamReader reader = null;
        BufferedReader bReader = null;
        try {
            inStream = url.openStream();
            reader = new InputStreamReader(inStream);
            bReader = new BufferedReader(reader);
            String line;
            while ((line = bReader.readLine()) != null) {
                if (!line.matches("\\s*(#.*)?")) {
                    // not a comment or blank line
                    result.add(line.trim());
                }
            }
        } catch (IOException iox) {
            LOG.log(Level.WARNING,
                    "Could not load services descriptor: " + url.toString(),
                    iox);
        } finally {
            finalClose(bReader);
            finalClose(reader);
            finalClose(inStream);
        }
        return result;
    }
1123015
public static <T> List<T> loadAll(
      Class<T> klass,
      Iterable<Class<?>> hardCodedClasses,
      ClassLoader classLoader,
      PriorityAccessor<T> priorityAccessor) {
    return ServiceProviders.loadAll(klass, hardCodedClasses, classLoader, priorityAccessor);
  }
754996
public Iterator getCurrentServiceSelectors(Class serviceClass)
	{
		BeanContextServiceProvider provider = getLocalServiceProvider(serviceClass);
		return provider == null ? null : new BCSIterator(provider.getCurrentServiceSelectors(getBeanContextServicesPeer(), serviceClass));
	}
353490
@VisibleForTesting
  public static <T> Iterable<T> getCandidatesViaServiceLoader(Class<T> klass, ClassLoader cl) {
    Iterable<T> i = ServiceLoader.load(klass, cl);
    // Attempt to load using the context class loader and ServiceLoader.
    // This allows frameworks like http://aries.apache.org/modules/spi-fly.html to plug in.
    if (!i.iterator().hasNext()) {
      i = ServiceLoader.load(klass);
    }
    return i;
  }
78115
@Override
  public <T> ServiceRef.ServiceBuilder service(Class<T> serviceClass)
  {
    Objects.requireNonNull(serviceClass);

    validator().serviceClass(serviceClass);

    Key<?> key = Key.of(serviceClass, ServiceImpl.class);

    ServiceBuilderWebImpl service
      = new ServiceBuilderWebImpl(this, key, serviceClass);

    _includes.add(service);

    return service;
  }
727163
public <S extends Service> S getService(Class<S> type) {
		for (final Service serv : this.serviceManager.servicesByState().values()) {
			if (serv.isRunning() && type.isInstance(serv)) {
				return type.cast(serv);
			}
		}
		return null;
	}
904454
private Iterable<URL> createServiceFileIterator() {
        if (classLoader == null) {
            ClassLoader classLoader = SchemaFactoryFinder.class.getClassLoader();
            return Collections.singleton(classLoader.getResource(SERVICE_ID));
        } else {
            try {
                Enumeration<URL> e = classLoader.getResources(SERVICE_ID);
                if (debug && !e.hasMoreElements()) {
                    debugPrintln("no "+SERVICE_ID+" file was found");
                }

                // wrap it into an Iterator.
                return Collections.list(e);
            } catch (IOException e) {
                if (debug) {
                    debugPrintln("failed to enumerate resources "+SERVICE_ID);
                    e.printStackTrace();
                }
                return Collections.emptySet();
            }
        }
    }
429528
@Override
    @Trivial
    public void addClassLoader(ClassLoader classLoader) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "addClassLoader - " + classLoader);
        }

        if (classLoader instanceof ContainerClassLoader) {
            synchronized (classLoaders) {
                classLoaders.add((ContainerClassLoader) classLoader);
            }
        } else {
            throw new IllegalArgumentException("classLoader is not a ContainerClassLoader");
        }
    }
519004
public static <T> Collection<T> getServices(Class<T> serviceType) {
        return getServiceProvider().getServices(serviceType);
    }
277699
private static ClassLoader[] getClassLoaders(ClassLoader classLoader) {
		return new ClassLoader[] { classLoader, Thread.currentThread().getContextClassLoader(), ClassLoaderUtils.class.getClassLoader(),
				systemClassLoader };
	}
1148416
public <S> ServiceBinder<S> bindServices(final Class<S> type) {
        ServiceBinderImpl<S> binder = new ServiceBinderImpl<S>(type);
        binders.add(binder);
        return binder;
    }
222896
public List<String> getServiceImplementations(String serviceTypeName) {
        final List<String> strings = services.get(serviceTypeName);
        return strings == null ? Collections.<String>emptyList() : Collections.unmodifiableList(strings);
    }
355461
public List<V> getAllServices(){
        if(cache == null || cache.size() == 0){
            return Collections.emptyList();
        }

        List<V> list = new ArrayList<V>();
        for(V svc : cache.values()){
            list.add(svc);
        }
        return list;
    }
824422
@Override
    public <T> Collection<T> all(Class<T> serviceClass) {
        List<T> serviceImpls = new ArrayList<T>();
        Set<Class<? extends T>> serviceImplClasses = registry.getServiceImpls(serviceClass);
        for (Class<? extends T> serviceImplClass : serviceImplClasses) {
            T serviceImpl = createServiceInstance(serviceImplClass);
            serviceImpls.add(serviceImpl);
        }
        return serviceImpls;
    }