@Test public void loadServices() { Map<String, UserSystemService> result = UserSystemServiceLoader.loadServices(getClass().getClassLoader()); assertEquals(3, result.size()); assertContains(result, UserSystemService1.NAME, UserSystemService1.class); assertContains(result, UserSystemService2.NAME, UserSystemService2.class); assertContains(result, SimpleUserSystemService.NAME, SimpleUserSystemService.class); }
public static Map<String, UserSystemService> loadServices(ClassLoader cl) { final Map<String, UserSystemService> result = new HashMap<>(); final ServiceLoader<UserSystemService> availableServices = ServiceLoader.load(UserSystemService.class, cl); for (UserSystemService service : availableServices) { Object existed = result.putIfAbsent(service.getName(), service); if (existed == null) { LOGGER.debug("UserSystemService {} was added to the result", service.getName()); } else { LOGGER.warn("UserSystemService {} was already added to the result, this another instance will be discarded.", service); } } return result; }
UserSystemServiceLoader { public static Map<String, UserSystemService> loadServices(ClassLoader cl) { final Map<String, UserSystemService> result = new HashMap<>(); final ServiceLoader<UserSystemService> availableServices = ServiceLoader.load(UserSystemService.class, cl); for (UserSystemService service : availableServices) { Object existed = result.putIfAbsent(service.getName(), service); if (existed == null) { LOGGER.debug("UserSystemService {} was added to the result", service.getName()); } else { LOGGER.warn("UserSystemService {} was already added to the result, this another instance will be discarded.", service); } } return result; } }
UserSystemServiceLoader { public static Map<String, UserSystemService> loadServices(ClassLoader cl) { final Map<String, UserSystemService> result = new HashMap<>(); final ServiceLoader<UserSystemService> availableServices = ServiceLoader.load(UserSystemService.class, cl); for (UserSystemService service : availableServices) { Object existed = result.putIfAbsent(service.getName(), service); if (existed == null) { LOGGER.debug("UserSystemService {} was added to the result", service.getName()); } else { LOGGER.warn("UserSystemService {} was already added to the result, this another instance will be discarded.", service); } } return result; } private  UserSystemServiceLoader(); }
UserSystemServiceLoader { public static Map<String, UserSystemService> loadServices(ClassLoader cl) { final Map<String, UserSystemService> result = new HashMap<>(); final ServiceLoader<UserSystemService> availableServices = ServiceLoader.load(UserSystemService.class, cl); for (UserSystemService service : availableServices) { Object existed = result.putIfAbsent(service.getName(), service); if (existed == null) { LOGGER.debug("UserSystemService {} was added to the result", service.getName()); } else { LOGGER.warn("UserSystemService {} was already added to the result, this another instance will be discarded.", service); } } return result; } private  UserSystemServiceLoader(); static Map<String, UserSystemService> loadServices(ClassLoader cl); }
UserSystemServiceLoader { public static Map<String, UserSystemService> loadServices(ClassLoader cl) { final Map<String, UserSystemService> result = new HashMap<>(); final ServiceLoader<UserSystemService> availableServices = ServiceLoader.load(UserSystemService.class, cl); for (UserSystemService service : availableServices) { Object existed = result.putIfAbsent(service.getName(), service); if (existed == null) { LOGGER.debug("UserSystemService {} was added to the result", service.getName()); } else { LOGGER.warn("UserSystemService {} was already added to the result, this another instance will be discarded.", service); } } return result; } private  UserSystemServiceLoader(); static Map<String, UserSystemService> loadServices(ClassLoader cl);  }