/** * All the search requests are sent out in parallel.... wait for all of them to be done. This * method can be called as-is from a waiter thread with push ...that is if the push can work more * reliably. */ private void waitForSearchResults(PatientSearchCompletionService completionService) { try { System.out.println("#################" + completionService.getNodesToSearch().size()); List<NBIANode> noResponseNode = new ArrayList<NBIANode>(); for (NBIANode node : completionService.getNodesToSearch()) { noResponseNode.add(node); } for (int i = 0; i < completionService.getNodesToSearch().size(); i++) { try { // this is a blocking call Future<PatientSearchResults> future = completionService .getCompletionService() .poll(NCIAConfig.getTimeoutInMin(), TimeUnit.MINUTES); // this is a blocking call PatientSearchResults result = null; if (future != null) { result = future.get(); System.out.println( "got response from node " + result.getNode().getDisplayName() + " so remove it"); noResponseNode.remove(result.getNode()); // got response so remove it logResult(result); addNodeResult(result); } } catch (CancellationException e) { e.printStackTrace(); } // pushToBrowser(); } if (noResponseNode != null && !noResponseNode.isEmpty()) { // check is there are any node from where, no response came with configurable minutes. for (NBIANode node : noResponseNode) { System.out.println("no response Node" + node.getDisplayName()); Exception searchError = new Exception("no response from node"); PatientSearchResults result = new PatientSearchResults(node, searchError); logResult(result); addNodeResult(result); } } System.out.println("done waiting for results"); } // catch(InterruptedException ie) { // System.out.println("interrupted the async result waiter"); // } catch (Exception ex) { // shouldnt get here, the search result service should capture // any exceptions and results a search result that indicates // there was an error ex.printStackTrace(); } }
private static void logResult(PatientSearchResults result) { if (result.getResults() != null) { System.out.println( "PatientSearchResults num results:" + result.getResults().length + " - Node " + result.getNode().getDisplayName()); } if (result.getSearchError() != null) { System.out.println( "PatientSearchResults error:" + result.getSearchError() + " - Node " + result.getNode().getDisplayName()); } }
private void addNodeResult(PatientSearchResults patientSearchResults) { NodeTableWrapper foundWrapper = null; for (NodeTableWrapper wrapperIter : nodeTableWrappers) { if (wrapperIter.getNBIANode().getURL().equals(patientSearchResults.getNode().getURL())) { foundWrapper = wrapperIter; break; } } foundWrapper.setPatientSearchResults(patientSearchResults); }