Skip to content

Commit

Permalink
JNG-5995 Direct lock object
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcsakany committed Nov 28, 2024
1 parent 5caf9f3 commit afbf669
Showing 1 changed file with 44 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
@Getter
public class WrappedEmfModelContext implements ModelContext {

private static final Object $LOCK = new Object[0];
Logger log;

Resource resource;
Expand Down Expand Up @@ -115,60 +116,62 @@ public WrappedEmfModelContext() {
}
@Override
public IModel load(Logger log, ResourceSet resourceSet, ModelRepository repository, Map<String, URI> uris, Map<URI, URI> uriConverterMap) throws EolModelLoadingException, ModelValidationException {
synchronized (resource) {
emfModel = new InMemoryEmfModel(name, resource, resource.getResourceSet().getPackageRegistry().values().stream().map(o -> (EPackage) o).toList()) {
@Override
public Object getCacheKeyForType(String type) throws EolModelElementTypeNotFoundException {
try {
return super.getCacheKeyForType(type);
} catch (EolModelElementTypeNotFoundException ex) {
}
return type;
emfModel = new InMemoryEmfModel(name, resource, resource.getResourceSet().getPackageRegistry().values().stream().map(o -> (EPackage) o).toList()) {
@Override
public Object getCacheKeyForType(String type) throws EolModelElementTypeNotFoundException {
try {
return super.getCacheKeyForType(type);
} catch (EolModelElementTypeNotFoundException ex) {
}
return type;
}

@Override
synchronized public void setupContainmentChangeListeners() {
@Override
synchronized public void setupContainmentChangeListeners() {
synchronized ($LOCK) {
super.setupContainmentChangeListeners();
}
};
emfModel.setName(name);
this.resourceSet = emfModel.getResource().getResourceSet();

final StringProperties properties = new StringProperties();
properties.put(EmfModel.PROPERTY_NAME, emfModel.getName() + "");
if (emfModel.getAliases() != null && emfModel.getAliases().size() > 0) {
properties.put(EmfModel.PROPERTY_ALIASES, emfModel.getAliases().stream().collect(joining(",")) + "");
} else {
properties.put(EmfModel.PROPERTY_ALIASES, "");
}
properties.put(EmfModel.PROPERTY_MODEL_URI, resource.getURI());

if (getReferenceUri() != null && !getReferenceUri().trim().equals("")) {
properties.put(EmfModel.PROPERTY_MODEL_URI, getReferenceUri());
log.debug(String.format("Registering MODEL_URI: %s Alias URI: %s", resource.getURI().toString(), getReferenceUri().toString()));
resourceSet.getURIConverter().getURIMap().put(URI.createURI(getReferenceUri()), resource.getURI());
} else {
log.debug(String.format("Registering MODEL_URI: %s", resource.getURI().toString()));
}
if (parallel) {
properties.put(EmfModel.PROPERTY_CONCURRENT, true);
emfModel.setParallelAllOf(true);
emfModel.setConcurrent(true);
}
if (useCache) {
properties.put(EmfModel.PROPERTY_CACHED, true);
emfModel.setCachingEnabled(true);
}
};
emfModel.setName(name);
this.resourceSet = emfModel.getResource().getResourceSet();

final StringProperties properties = new StringProperties();
properties.put(EmfModel.PROPERTY_NAME, emfModel.getName() + "");
if (emfModel.getAliases() != null && emfModel.getAliases().size() > 0) {
properties.put(EmfModel.PROPERTY_ALIASES, emfModel.getAliases().stream().collect(joining(",")) + "");
} else {
properties.put(EmfModel.PROPERTY_ALIASES, "");
}
properties.put(EmfModel.PROPERTY_MODEL_URI, resource.getURI());

if (getReferenceUri() != null && !getReferenceUri().trim().equals("")) {
properties.put(EmfModel.PROPERTY_MODEL_URI, getReferenceUri());
log.debug(String.format("Registering MODEL_URI: %s Alias URI: %s", resource.getURI().toString(), getReferenceUri().toString()));
resourceSet.getURIConverter().getURIMap().put(URI.createURI(getReferenceUri()), resource.getURI());
} else {
log.debug(String.format("Registering MODEL_URI: %s", resource.getURI().toString()));
}
if (parallel) {
properties.put(EmfModel.PROPERTY_CONCURRENT, true);
emfModel.setParallelAllOf(true);
emfModel.setConcurrent(true);
}
if (useCache) {
properties.put(EmfModel.PROPERTY_CACHED, true);
emfModel.setCachingEnabled(true);
}

synchronized ($LOCK) {
emfModel.load(properties);

if (validateModel) {
ModelValidator.validate(emfModel);
}
repository.addModel(emfModel);

return emfModel;
}

return emfModel;
}

@Override
Expand Down

0 comments on commit afbf669

Please sign in to comment.