private static void buildInvertedDependencyGraph(IServiceManager manager, List<DependencyNode> roots,
			List<Service> infraServices, List<Service> freeServices, Accessors accessors) {
		final Map<Class<? extends Service>, DependencyNode> dependentServices = new TreeMap<>(Comparators.CLASS_COMPARATOR);
		final Map<Class<? extends Service>, DependencyNode> rootServices = new TreeMap<>(Comparators.CLASS_COMPARATOR);

		Service service;
		for (final Entry<State, Service> entry : manager.servicesByState().entries()) {
			if (accessors.matches(entry.getKey())) {
				service = entry.getValue();
				if (service instanceof InfrastructureService) {
					infraServices.add(service);
				} else if (service instanceof DependentService) {
					final DependentService depServ = (DependentService) service;
					final Class<? extends Service> type = depServ.getServiceType();
					DependencyNode node = dependentServices.get(type);
					boolean isRoot = true;
					if (node == null) {
						node = new DependencyNode(depServ, type);
						dependentServices.put(type, node);
					} else {
						assert node.getService() == null;
						node.setService(depServ);
						isRoot = false;
					}

					Collection<Class<? extends Service>> deps = depServ.getServiceDependencies();
					for (final Class<? extends Service> dep : deps) {
						DependencyNode depNode = dependentServices.get(dep);
						if (depNode == null) {
							depNode = new DependencyNode(dep);
							dependentServices.put(dep, depNode);
						}
						node.getNextServices().add(depNode);
						rootServices.remove(depNode.getType());
					}

					deps = depServ.getServiceWeakDependencies();
					for (final Class<? extends Service> dep : deps) {
						DependencyNode depNode = dependentServices.get(dep);
						if (depNode == null) {
							depNode = new DependencyNode(dep);
							dependentServices.put(dep, depNode);
						}
						node.getNextWeakServices().add(depNode);
						rootServices.remove(depNode.getType());
					}

					if (isRoot) {
						rootServices.put(type, node);
					}
				} else {
					freeServices.add(service);
				}
			}
		}

		roots.addAll(rootServices.values());
	}
private static void buildInvertedDependencyGraph ( IServiceManager manager , List < DependencyNode > roots , List < Service > infraServices , List < Service > freeServices , Accessors accessors ) { final Map < Class < ? extends Service > , DependencyNode > dependentServices = new TreeMap < > ( Comparators . CLASS_COMPARATOR ) ; final Map < Class < ? extends Service > , DependencyNode > rootServices = new TreeMap < > ( Comparators . CLASS_COMPARATOR ) ; Service service ; for ( final Entry < State , Service > entry : manager . servicesByState ( ) . entries ( ) ) { if ( accessors . matches ( entry . getKey ( ) ) ) { service = entry . getValue ( ) ; if ( service instanceof InfrastructureService ) { infraServices . add ( service ) ; } else if ( service instanceof DependentService ) { final DependentService depServ = ( DependentService ) service ; final Class < ? extends Service > type = depServ . getServiceType ( ) ; DependencyNode node = dependentServices . get ( type ) ; boolean isRoot = true ; if ( node == null ) { node = new DependencyNode ( depServ , type ) ; dependentServices . put ( type , node ) ; } else { assert node . getService ( ) == null ; node . setService ( depServ ) ; isRoot = false ; } Collection < Class < ? extends Service > > deps = depServ . getServiceDependencies ( ) ; for ( final Class < ? extends Service > dep : deps ) { DependencyNode depNode = dependentServices . get ( dep ) ; if ( depNode == null ) { depNode = new DependencyNode ( dep ) ; dependentServices . put ( dep , depNode ) ; } node . getNextServices ( ) . add ( depNode ) ; rootServices . remove ( depNode . getType ( ) ) ; } deps = depServ . getServiceWeakDependencies ( ) ; for ( final Class < ? extends Service > dep : deps ) { DependencyNode depNode = dependentServices . get ( dep ) ; if ( depNode == null ) { depNode = new DependencyNode ( dep ) ; dependentServices . put ( dep , depNode ) ; } node . getNextWeakServices ( ) . add ( depNode ) ; rootServices . remove ( depNode . getType ( ) ) ; } if ( isRoot ) { rootServices . put ( type , node ) ; } } else { freeServices . add ( service ) ; } } } roots . addAll ( rootServices . values ( ) ) ; }
Build the dependency graph for the services.

@param manager lsit of the services.
@param roots filled with the services that have no dependency.
@param infraServices filled with the infrastructure services.
@param freeServices filled with the services that are executed before/after all the dependent services.
@param accessors permits to retreive information on the services.