-
- g.forOrderedSet(data, new AsyncMultiProcedure<Resource>() {
-
- @Override
- public void execute(AsyncReadGraph graph, final Resource component) {
-
- // Must add the elements to the result set here in order to
- // keep their order the same as in the ordered set.
- final int elementIndex = index.getAndIncrement();
- result.elements.add(component);
-
- graph.forTypes(component, new AsyncProcedure<Set<Resource>>() {
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable t) {
- if (errorHandler != null)
- errorHandler.error(t.getMessage(), t);
- }
-
- @Override
- public void execute(AsyncReadGraph graph, Set<Resource> types) {
- if (types.contains(DIA.Connection)) {
- if (types.contains(DIA.RouteGraphConnection)) {
- graph.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component),
- new ProcedureAdapter<RouteGraphConnectionPartData>() {
- @Override
- public void execute(RouteGraphConnectionPartData partData) {
- synchronized (result) {
- for (EdgeResource link : partData.links) {
- result.routeLinks.add(link);
- result.partToConnection.put(link, component);
- result.connectionToParts.add(component, link);
- }
- for (Resource line : partData.routeLines) {
- result.routeLines.add(line);
- result.connectionToParts.add(component, line);
- result.partToConnection.put(line, component);
- }
- for (Resource point : partData.routePoints) {
- result.routePoints.add(point);
- result.connectionToParts.add(component, point);
- result.partToConnection.put(point, component);
- }
- }
- }
- });
-
- synchronized (result.routeGraphConnectionSet) {
- result.routeGraphConnectionSet.add(component);
- }
- } else {
- graph.asyncRequest(new ConnectionPartRequest(errorHandler, DIA, component),
- new ProcedureAdapter<ConnectionPartData>() {
- @Override
- public void execute(ConnectionPartData partData) {
- synchronized (result) {
- for (EdgeResource er : partData.edges) {
- result.connectionSegments.add(er);
- result.partToConnection.put(er, component);
- result.connectionToParts.add(component, er);
- }
- for (Resource bp : partData.branchPoints) {
- result.branchPoints.add(bp);
- result.connectionToParts.add(component, bp);
- result.partToConnection.put(bp, component);
- }
- }
- }
- });
-
- synchronized (result.connectionSet) {
- result.connectionSet.add(component);
- }
- }
- }
- else if (types.contains(DIA.Element)) {
- synchronized (result.nodeSet) {
- result.nodeSet.add(component);
- }
- }
- else {
- synchronized (unrecognizedElementIndices) {
- // Unrecognized element, mark it to be
- // removed after everything is processed.
- unrecognizedElementIndices.add(elementIndex);
- }
- }
- }
-
- });
-
- }
-
+
+ Collection<Resource> components = OrderedSetUtils.toList(g, data);
+
+ Semaphore s = new Semaphore(0);
+
+ for(Resource component : components) {
+
+ // Must add the elements to the result set here in order to
+ // keep their order the same as in the ordered set.
+ final int elementIndex = index.getAndIncrement();
+ result.elements.add(component);
+
+ Set<Resource> types = g.getTypes(component);
+
+ if (types.contains(DIA.Connection)) {
+ if (types.contains(DIA.RouteGraphConnection)) {
+ g.asyncRequest(new RouteGraphConnectionPartRequest(errorHandler, DIA, component),
+ new ProcedureAdapter<RouteGraphConnectionPartData>() {
+ @Override
+ public void execute(RouteGraphConnectionPartData partData) {
+ synchronized (result) {
+ for (EdgeResource link : partData.links) {
+ result.routeLinks.add(link);
+ result.partToConnection.put(link, component);
+ result.connectionToParts.add(component, link);
+ }
+ for (Resource line : partData.routeLines) {
+ result.routeLines.add(line);
+ result.connectionToParts.add(component, line);
+ result.partToConnection.put(line, component);
+ }
+ for (Resource point : partData.routePoints) {
+ result.routePoints.add(point);
+ result.connectionToParts.add(component, point);
+ result.partToConnection.put(point, component);
+ }
+ }
+ s.release();
+ }
+ });
+
+ synchronized (result.routeGraphConnectionSet) {
+ result.routeGraphConnectionSet.add(component);
+ }
+ } else {
+ g.asyncRequest(new ConnectionPartRequest(errorHandler, DIA, component),
+ new ProcedureAdapter<ConnectionPartData>() {
+ @Override
+ public void execute(ConnectionPartData partData) {
+ synchronized (result) {
+ for (EdgeResource er : partData.edges) {
+ result.connectionSegments.add(er);
+ result.partToConnection.put(er, component);
+ result.connectionToParts.add(component, er);
+ }
+ for (Resource bp : partData.branchPoints) {
+ result.branchPoints.add(bp);
+ result.connectionToParts.add(component, bp);
+ result.partToConnection.put(bp, component);
+ }
+ }
+ s.release();
+ }
+ });
+
+ synchronized (result.connectionSet) {
+ result.connectionSet.add(component);
+ }
+ }
+ }
+ else if (types.contains(DIA.Element)) {
+ synchronized (result.nodeSet) {
+ result.nodeSet.add(component);
+ }
+ s.release();
+
+ }
+ else {
+ synchronized (unrecognizedElementIndices) {
+ // Unrecognized element, mark it to be
+ // removed after everything is processed.
+ unrecognizedElementIndices.add(elementIndex);
+ }
+ s.release();
+ }
+
+ }
+
+ try {
+ s.acquire(components.size());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ // Remove elements that were not recognized in descending order.
+ unrecognizedElementIndices.sort();
+ unrecognizedElementIndices.forEachDescending(new TIntProcedure() {