use of org.lanternpowered.server.util.graph.CyclicGraphException in project LanternServer by LanternPowered.
the class LanternGameRegistry method syncModules.
private void syncModules() {
if (this.modulesSynced) {
return;
}
final DirectedGraph<Class<? extends RegistryModule>> graph = new DirectedGraph<>();
for (RegistryModule aModule : this.registryModules) {
if (!this.classMap.containsKey(aModule.getClass())) {
this.classMap.put(aModule.getClass(), aModule);
}
addToGraph(aModule, graph);
}
// Now we need ot do the catalog ones
for (CatalogRegistryModule<?> aModule : this.catalogRegistryMap.values()) {
if (!this.classMap.containsKey(aModule.getClass())) {
this.classMap.put(aModule.getClass(), aModule);
}
addToGraph(aModule, graph);
}
this.orderedModules.clear();
try {
this.orderedModules.addAll(TopologicalOrder.createOrderedLoad(graph));
} catch (CyclicGraphException e) {
final StringBuilder msg = new StringBuilder();
msg.append("Registry module dependencies are cyclical!\n");
msg.append("Dependency loops are:\n");
for (DirectedGraph.DataNode<?>[] cycle : e.getCycles()) {
msg.append("[");
for (DirectedGraph.DataNode<?> node : cycle) {
msg.append(node.getData().toString()).append(" ");
}
msg.append("]\n");
}
this.game.getLog4jLogger().fatal(msg.toString());
throw new RuntimeException("Registry modules dependencies error.");
}
this.modulesSynced = true;
}
Aggregations