String identifyingString = thisConnection.getDescription();
if (identifyingString == null || identifyingString.length() == 0)
identifyingString = connectionName;
// Create a request
MappingRequest mr = new MappingRequest(
thisConnection.getClassName(),identifyingString,thisConnection.getConfigParams(),thisConnection.getMaxConnections());
mappingRequests.put(connectionName, mr);
// Either start up a thread, or just fire it off immediately.
if (thisConnection.getPrerequisiteMapping() == null)
{
mr.setUserID(userID);
mappingQueue.addRequest(mr);
}
else
{
//System.out.println("Mapper: prerequisite found: '"+thisConnection.getPrerequisiteMapping()+"'");
MappingOrderThread thread = new MappingOrderThread(identifyingString,
mr, thisConnection.getPrerequisiteMapping(), mappingQueue, mappingRequests);
mappingThreads.add(thread);
String p = thisConnection.getPrerequisiteMapping();
if (mappingRequests.get(p) == null)
activeConnections.add(p);
}
activeConnections.remove(connectionName);
}
// Start threads. We have to wait until all the requests have been
// at least created before we do this.
for (MappingOrderThread thread : mappingThreads)
{
thread.start();
}
for (AuthOrderThread thread : authThreads)
{
thread.start();
}
// Wait for the threads to finish up. This will guarantee that all entities have run to completion.
for (MappingOrderThread thread : mappingThreads)
{
thread.finishUp();
}
for (AuthOrderThread thread : authThreads)
{
thread.finishUp();
}
// This is probably unnecessary, but we do it anyway just to adhere to the contract
for (MappingRequest mr : mappingRequests.values())
{
mr.waitForComplete();
}
// Handle all exceptions thrown during mapping. In general this just means logging them, because
// the downstream authorities will presumably not find what they are looking for and error out that way.
for (MappingRequest mr : mappingRequests.values())
{
Throwable exception = mr.getAnswerException();
if (exception != null)
{
Logging.authorityService.warn("Mapping exception logged from "+mr.getIdentifyingString()+": "+exception.getMessage()+"; mapper aborted", exception);
}
}
// Now, work through the returning answers.