Add double-check for #610

This commit is contained in:
James 2017-04-17 18:10:57 -04:00
parent e9a1069c9d
commit 6a5d0f95ae
2 changed files with 50 additions and 41 deletions

View File

@ -164,7 +164,8 @@ public class FhirContext {
}
if (theVersion == null) {
ourLog.info("Creating new FhirContext with auto-detected version [{}]. It is recommended to explicitly select a version for future compatibility by invoking FhirContext.forDstuX()", myVersion.getVersion().name());
ourLog.info("Creating new FhirContext with auto-detected version [{}]. It is recommended to explicitly select a version for future compatibility by invoking FhirContext.forDstuX()",
myVersion.getVersion().name());
} else {
ourLog.info("Creating new FHIR context for FHIR version [{}]", myVersion.getVersion().name());
}
@ -187,7 +188,6 @@ public class FhirContext {
ourLog.trace("Android mode not detected");
}
}
private String createUnknownResourceNameError(String theResourceName, FhirVersionEnum theVersion) {
@ -393,19 +393,19 @@ public class FhirContext {
return myIdToResourceDefinition.get(theId);
}
// /**
// * Return an unmodifiable collection containing all known resource definitions
// */
// public Collection<RuntimeResourceDefinition> getResourceDefinitions() {
//
// Set<Class<? extends IBase>> datatypes = Collections.emptySet();
// Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> existing = Collections.emptyMap();
// HashMap<String, Class<? extends IBaseResource>> types = new HashMap<String, Class<? extends IBaseResource>>();
// ModelScanner.scanVersionPropertyFile(datatypes, types, myVersion.getVersion(), existing);
// for (int next : types.)
//
// return Collections.unmodifiableCollection(myIdToResourceDefinition.values());
// }
// /**
// * Return an unmodifiable collection containing all known resource definitions
// */
// public Collection<RuntimeResourceDefinition> getResourceDefinitions() {
//
// Set<Class<? extends IBase>> datatypes = Collections.emptySet();
// Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> existing = Collections.emptyMap();
// HashMap<String, Class<? extends IBaseResource>> types = new HashMap<String, Class<? extends IBaseResource>>();
// ModelScanner.scanVersionPropertyFile(datatypes, types, myVersion.getVersion(), existing);
// for (int next : types.)
//
// return Collections.unmodifiableCollection(myIdToResourceDefinition.values());
// }
/**
* Returns the scanned runtime models. This is an advanced feature which is generally only needed for extending the
@ -438,6 +438,7 @@ public class FhirContext {
* Returns the validation support module configured for this context, creating a default
* implementation if no module has been passed in via the {@link #setValidationSupport(IContextValidationSupport)}
* method
*
* @see #setValidationSupport(IContextValidationSupport)
*/
public IContextValidationSupport<?, ?, ?, ?, ?, ?> getValidationSupport() {
@ -778,7 +779,8 @@ public class FhirContext {
* Sets the parser options object which will be used to supply default
* options to newly created parsers
*
* @param theParserOptions The parser options object - Must not be <code>null</code>
* @param theParserOptions
* The parser options object - Must not be <code>null</code>
*/
public void setParserOptions(ParserOptions theParserOptions) {
Validate.notNull(theParserOptions, "theParserOptions must not be null");
@ -841,11 +843,16 @@ public class FhirContext {
return resTypes;
}
private synchronized void validateInitialized() {
private void validateInitialized() {
// See #610
if (!myInitialized) {
synchronized (this) {
if (!myInitialized) {
scanResourceTypes(toElementList(myResourceTypesToScan));
}
}
}
}
/**
* Creates and returns a new FhirContext with version {@link FhirVersionEnum#DSTU1 DSTU1}

View File

@ -91,7 +91,7 @@ public class FhirContextDstu3Test {
public void testInitialisationThreadSafety() {
final FhirContext ctx = FhirContext.forDstu3();
final int numThreads = 4;
final int numThreads = 40;
final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
final ExecutorService threadPool = Executors.newFixedThreadPool(numThreads);
try {
@ -105,7 +105,9 @@ public class FhirContextDstu3Test {
threadsReady.countDown();
try {
threadsReady.await();
ctx.getResourceDefinition("patient");
RuntimeResourceDefinition def = ctx.getResourceDefinition("patient");
ourLog.info(def.toString());
assertNotNull(def);
} catch(final Exception e) {
exceptions.add(e);
}