Top Description Inners Fields Constructors Methods
org.apache.logging.log4j.util

public final Class ServiceLoaderUtil

extends Object
Class Inheritance
Annotations
@InternalApi
Imports
java.lang.invoke.CallSite, .LambdaMetafactory, .MethodHandle, .MethodHandles.Lookup, .MethodType, java.security.AccessController, .PrivilegedAction, java.util.Collections, .HashSet, .Iterator, .ServiceConfigurationError, .ServiceLoader, .Set, .Spliterator, java.util.function.Consumer, java.util.stream.Stream, .StreamSupport, org.apache.logging.log4j.Logger, org.apache.logging.log4j.status.StatusLogger

This class should be considered internal.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static <T> Iterable<T>
callServiceLoader(final MethodHandles.Lookup lookup, final Class<T> serviceType, final ClassLoader classLoader, final boolean verbose)

pack-priv static <T> Stream<T>
loadClassloaderServices(final Class<T> serviceType, final MethodHandles.Lookup lookup, final ClassLoader classLoader, final boolean verbose)

public static <
The service type.
T
>
Stream<T>

Returns:

A stream of service instances.
loadServices
(final Class<T>
The class of the service.
serviceType
,
final MethodHandles.Lookup
The calling class data.
lookup
)

Retrieves the available services from the caller's classloader.

public static <
The service type.
T
>
Stream<T>

Returns:

A stream of service instances.
loadServices
(final Class<T>
The class of the service.
serviceType
,
final MethodHandles.Lookup
The calling class data.
lookup
,
final boolean
If true the thread context classloader will also be used.
useTccl
)

Retrieves the available services from the caller's classloader and possibly the thread context classloader.

pack-priv static <T> Stream<T>
loadServices(final Class<T> serviceType, final MethodHandles.Lookup lookup, final boolean useTccl, final boolean verbose)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MAX_BROKEN_SERVICESback to summary
private static final int MAX_BROKEN_SERVICES

Constructor Detail

ServiceLoaderUtilback to summary
private ServiceLoaderUtil()

Method Detail

callServiceLoaderback to summary
pack-priv static <T> Iterable<T> callServiceLoader(final MethodHandles.Lookup lookup, final Class<T> serviceType, final ClassLoader classLoader, final boolean verbose)
loadClassloaderServicesback to summary
pack-priv static <T> Stream<T> loadClassloaderServices(final Class<T> serviceType, final MethodHandles.Lookup lookup, final ClassLoader classLoader, final boolean verbose)
loadServicesback to summary
public static <T> Stream<T> loadServices(final Class<T> serviceType, final MethodHandles.Lookup lookup)

Retrieves the available services from the caller's classloader. Broken services will be ignored.

Parameters
<T>
The service type.
serviceType:Class<T>

The class of the service.

lookup:MethodHandles.Lookup

The calling class data.

Returns:Stream<T>

A stream of service instances.

loadServicesback to summary
public static <T> Stream<T> loadServices(final Class<T> serviceType, final MethodHandles.Lookup lookup, final boolean useTccl)

Retrieves the available services from the caller's classloader and possibly the thread context classloader. Broken services will be ignored.

Parameters
<T>
The service type.
serviceType:Class<T>

The class of the service.

lookup:MethodHandles.Lookup

The calling class data.

useTccl:boolean

If true the thread context classloader will also be used.

Returns:Stream<T>

A stream of service instances.

loadServicesback to summary
pack-priv static <T> Stream<T> loadServices(final Class<T> serviceType, final MethodHandles.Lookup lookup, final boolean useTccl, final boolean verbose)
org.apache.logging.log4j.util back to summary

private Class ServiceLoaderUtil.ServiceLoaderSpliterator<S>

extends Object
implements Spliterator<S>
Class Inheritance
  • java.lang.Object
  • org.apache.logging.log4j.util.ServiceLoaderUtil.ServiceLoaderSpliterator
All Implemented Interfaces
java.util.Spliterator

Field Summary

Modifier and TypeField and Description
private final Logger
private final Iterator<S>
private final String

Constructor Summary

AccessConstructor and Description
public
ServiceLoaderSpliterator(final Class<S> serviceType, final MethodHandles.Lookup lookup, final ClassLoader classLoader, final boolean verbose)

Method Summary

Modifier and TypeMethod and Description
public int
characteristics()

Implements java.util.Spliterator.characteristics.

Returns a set of characteristics of this Spliterator and its elements.

public long
estimateSize()

Implements java.util.Spliterator.estimateSize.

Returns an estimate of the number of elements that would be encountered by a forEachRemaining traversal, or returns Long#MAX_VALUE if infinite, unknown, or too expensive to compute.

public boolean
tryAdvance(final Consumer<? super S>
The action whose operation is performed at-most once
action
)

Implements java.util.Spliterator.tryAdvance.

If a remaining element exists: performs the given action on it, returning true; else returns false.

public Spliterator<S>
trySplit()

Implements java.util.Spliterator.trySplit.

If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
private final Logger logger
serviceIteratorback to summary
private final Iterator<S> serviceIterator
serviceNameback to summary
private final String serviceName

Constructor Detail

ServiceLoaderSpliteratorback to summary
public ServiceLoaderSpliterator(final Class<S> serviceType, final MethodHandles.Lookup lookup, final ClassLoader classLoader, final boolean verbose)

Method Detail

characteristicsback to summary
public int characteristics()

Implements java.util.Spliterator.characteristics.

Doc from java.util.Spliterator.characteristics.

Returns a set of characteristics of this Spliterator and its elements. The result is represented as ORed values from ORDERED, DISTINCT, SORTED, SIZED, NONNULL, IMMUTABLE, CONCURRENT, SUBSIZED. Repeated calls to characteristics() on a given spliterator, prior to or in-between calls to trySplit, should always return the same result.

If a Spliterator reports an inconsistent set of characteristics (either those returned from a single invocation or across multiple invocations), no guarantees can be made about any computation using this Spliterator.

Returns:int

a representation of characteristics

Annotations
@Override
estimateSizeback to summary
public long estimateSize()

Implements java.util.Spliterator.estimateSize.

Doc from java.util.Spliterator.estimateSize.

Returns an estimate of the number of elements that would be encountered by a forEachRemaining traversal, or returns Long#MAX_VALUE if infinite, unknown, or too expensive to compute.

If this Spliterator is SIZED and has not yet been partially traversed or split, or this Spliterator is SUBSIZED and has not yet been partially traversed, this estimate must be an accurate count of elements that would be encountered by a complete traversal. Otherwise, this estimate may be arbitrarily inaccurate, but must decrease as specified across invocations of trySplit.

Returns:long

the estimated size, or Long.MAX_VALUE if infinite, unknown, or too expensive to compute.

Annotations
@Override
tryAdvanceback to summary
public boolean tryAdvance(final Consumer<? super S> action)

Implements java.util.Spliterator.tryAdvance.

Doc from java.util.Spliterator.tryAdvance.

If a remaining element exists: performs the given action on it, returning true; else returns false. If this Spliterator is ORDERED the action is performed on the next element in encounter order. Exceptions thrown by the action are relayed to the caller.

Subsequent behavior of a spliterator is unspecified if the action throws an exception.

Parameters
action:Consumer<? super S>

The action whose operation is performed at-most once

Returns:boolean

false if no remaining elements existed upon entry to this method, else true.

Annotations
@Override
trySplitback to summary
public Spliterator<S> trySplit()

Implements java.util.Spliterator.trySplit.

Doc from java.util.Spliterator.trySplit.

If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

If this Spliterator is ORDERED, the returned Spliterator must cover a strict prefix of the elements.

Unless this Spliterator covers an infinite number of elements, repeated calls to trySplit() must eventually return null. Upon non-null return:

  • the value reported for estimateSize() before splitting, must, after splitting, be greater than or equal to estimateSize() for this and the returned Spliterator; and
  • if this Spliterator is SUBSIZED, then estimateSize() for this spliterator before splitting must be equal to the sum of estimateSize() for this and the returned Spliterator after splitting.

This method may return null for any reason, including emptiness, inability to split after traversal has commenced, data structure constraints, and efficiency considerations.

Returns:Spliterator<S>

a Spliterator covering some portion of the elements, or null if this spliterator cannot be split

Annotations
@Override