1515
1616@ Internal
1717public class SchemaDiffing {
18-
19-
18+ private final SchemaDiffingRunningCheck runningCheck = new SchemaDiffingRunningCheck ();
2019
2120 SchemaGraph sourceGraph ;
2221 SchemaGraph targetGraph ;
2322
23+ /**
24+ * Tries to stop the algorithm from execution ASAP by throwing a
25+ * {@link SchemaDiffingCancelledException}.
26+ */
27+ public void stop () {
28+ runningCheck .stop ();
29+ }
30+
2431 public List <EditOperation > diffGraphQLSchema (GraphQLSchema graphQLSchema1 , GraphQLSchema graphQLSchema2 ) throws Exception {
2532 sourceGraph = new SchemaGraphFactory ("source-" ).createGraph (graphQLSchema1 );
2633 targetGraph = new SchemaGraphFactory ("target-" ).createGraph (graphQLSchema2 );
@@ -32,7 +39,7 @@ public EditOperationAnalysisResult diffAndAnalyze(GraphQLSchema graphQLSchema1,
3239 targetGraph = new SchemaGraphFactory ("target-" ).createGraph (graphQLSchema2 );
3340 DiffImpl .OptimalEdit optimalEdit = diffImpl (sourceGraph , targetGraph );
3441 EditOperationAnalyzer editOperationAnalyzer = new EditOperationAnalyzer (graphQLSchema1 , graphQLSchema1 , sourceGraph , targetGraph );
35- return editOperationAnalyzer .analyzeEdits (optimalEdit .listOfEditOperations .get (0 ),optimalEdit .mappings .get (0 ));
42+ return editOperationAnalyzer .analyzeEdits (optimalEdit .listOfEditOperations .get (0 ), optimalEdit .mappings .get (0 ));
3643 }
3744
3845 public DiffImpl .OptimalEdit diffGraphQLSchemaAllEdits (GraphQLSchema graphQLSchema1 , GraphQLSchema graphQLSchema2 ) throws Exception {
@@ -45,9 +52,9 @@ public DiffImpl.OptimalEdit diffGraphQLSchemaAllEdits(GraphQLSchema graphQLSchem
4552 private DiffImpl .OptimalEdit diffImpl (SchemaGraph sourceGraph , SchemaGraph targetGraph ) throws Exception {
4653 int sizeDiff = targetGraph .size () - sourceGraph .size ();
4754 System .out .println ("graph diff: " + sizeDiff );
48- FillupIsolatedVertices fillupIsolatedVertices = new FillupIsolatedVertices (sourceGraph , targetGraph );
55+ FillupIsolatedVertices fillupIsolatedVertices = new FillupIsolatedVertices (sourceGraph , targetGraph , runningCheck );
4956 fillupIsolatedVertices .ensureGraphAreSameSize ();
50- FillupIsolatedVertices .IsolatedVertices isolatedVertices = fillupIsolatedVertices .isolatedVertices ;
57+ FillupIsolatedVertices .IsolatedVertices isolatedVertices = fillupIsolatedVertices .getIsolatedVertices () ;
5158
5259 assertTrue (sourceGraph .size () == targetGraph .size ());
5360// if (sizeDiff != 0) {
@@ -60,7 +67,8 @@ private DiffImpl.OptimalEdit diffImpl(SchemaGraph sourceGraph, SchemaGraph targe
6067 editorialCostForMapping (fixedMappings , sourceGraph , targetGraph , result );
6168 return new DiffImpl .OptimalEdit (singletonList (fixedMappings ), singletonList (result ), result .size ());
6269 }
63- DiffImpl diffImpl = new DiffImpl (sourceGraph , targetGraph , isolatedVertices );
70+
71+ DiffImpl diffImpl = new DiffImpl (sourceGraph , targetGraph , isolatedVertices , runningCheck );
6472 List <Vertex > nonMappedSource = new ArrayList <>(sourceGraph .getVertices ());
6573 nonMappedSource .removeAll (fixedMappings .getSources ());
6674// for(Vertex vertex: nonMappedSource) {
@@ -74,6 +82,7 @@ private DiffImpl.OptimalEdit diffImpl(SchemaGraph sourceGraph, SchemaGraph targe
7482 List <Vertex > nonMappedTarget = new ArrayList <>(targetGraph .getVertices ());
7583 nonMappedTarget .removeAll (fixedMappings .getTargets ());
7684
85+ runningCheck .check ();
7786 sortListBasedOnPossibleMapping (nonMappedSource , isolatedVertices );
7887
7988 // the non mapped vertices go to the end
@@ -141,6 +150,4 @@ private List<EditOperation> calcEdgeOperations(Mapping mapping) {
141150 }
142151 return result ;
143152 }
144-
145-
146153}
0 commit comments