public List<S> sort() {
        final Iterator<S> it = iterator();
        final List<S> sortList = new ArrayList<>();
        while (it.hasNext()) {
            sortList.add(it.next());
        }

        if (sortList.size() <= 1) {
            return sortList;
        }

        sortList.sort((o1, o2) -> {
            final SPI o1Spi = o1.getClass().getAnnotation(SPI.class);
            final SPI o2Spi = o2.getClass().getAnnotation(SPI.class);

            final int o1Priority = o1Spi == null ? 0 : o1Spi.priority();
            final int o2Priority = o2Spi == null ? 0 : o2Spi.priority();

            return -(o1Priority - o2Priority);
        });

        return sortList;
    }
A simple service-provider loading facility (SPI).

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