@Override
    public Iterator<S> iterator() {
        return new Iterator<S>() {

            final Iterator<Map.Entry<String, S>> knownProviders = JRaftServiceLoader.this.providers.entrySet()
                                                                    .iterator();

            @Override
            public boolean hasNext() {
                return this.knownProviders.hasNext() || JRaftServiceLoader.this.lookupIterator.hasNext();
            }

            @Override
            public S next() {
                if (this.knownProviders.hasNext()) {
                    return this.knownProviders.next().getValue();
                }
                final Class<S> cls = JRaftServiceLoader.this.lookupIterator.next();
                return newProvider(cls);
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
A simple service-provider loading facility (SPI).

@author jiachun.fjc
jraft-core/src/main/java/com/alipay/sofa/jraft/util/JRaftServiceLoader.java