Skip to content
Snippets Groups Projects
Commit a438cf0b authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

extensions to prevent further useless constraint verifications

refs 2726
parent 1c32ba07
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ import org.fortiss.tooling.kernel.service.IPersistencyService;
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 1FC7269BEBCFB91D0029CCD01E2F5741
* @ConQAT.Rating YELLOW Hash: 6FA0E127A084C9499349FB4014005422
*/
public final class ConstraintService implements IIntrospectiveKernelService, IConstraintService {
......@@ -148,10 +148,18 @@ public final class ConstraintService implements IIntrospectiveKernelService, ICo
// And we also update the checksums after in case the verification had some side
// effects...
updateChecksums(ci);
currentlyUpdating.remove(ci);
});
}
}
/** Returns the short name of the constraint of the given instance. */
private String cstrShortName(ConstraintInstance ci) {
int dolIndex = ci.getConstraintName().lastIndexOf('$');
int dotIndex = ci.getConstraintName().lastIndexOf('.');
return ci.getConstraintName().substring(Math.max(dotIndex, dolIndex) + 1);
}
/** {@inheritDoc} */
@Override
public List<IFix> fixes(ConstraintInstance ci) {
......@@ -191,14 +199,14 @@ public final class ConstraintService implements IIntrospectiveKernelService, ICo
* This string should however only be set to a non-empty string on a local machine, never
* commited!
*/
private static final String DEBUG_FILE = "";
private static final String DEBUG_FOLDER = "/home/vincent/temp/cstr";
/** Number used to annotate the traces when debugging is active. */
private int debug_trace_number = 0;
/**
* @return the checksum of <code>constrained</code>. Note that <code>ci</code> is necessary
* because it has a potential impact on what is relevant for the checksum or not.
* Returns the checksum of <code>constrained</code>. Note that <code>ci</code> is necessary
* because it has a potential impact on what is relevant for the checksum or not.
*/
protected BigInteger computeCheckSum(IConstrained constrained, ConstraintInstance ci) {
if(constrained == null) {
......@@ -210,8 +218,8 @@ public final class ConstraintService implements IIntrospectiveKernelService, ICo
try {
final ResourceSet rset = new ResourceSetImpl();
oos = new ObjectOutputStream(baos);
Resource res = rset.createResource(URI.createURI("temp"));
res.getContents().add(hashRelevant);
Resource resource = rset.createResource(URI.createURI("temp"));
resource.getContents().add(hashRelevant);
Map<String, String> options = new HashMap<>();
// The option below is to allow computing the hashsum of an incomplete ecore sub-model,
......@@ -219,27 +227,27 @@ public final class ConstraintService implements IIntrospectiveKernelService, ICo
// referred to.
options.put(OPTION_PROCESS_DANGLING_HREF, OPTION_PROCESS_DANGLING_HREF_DISCARD);
res.save(oos, options);
if(!DEBUG_FILE.isEmpty()) {
String filePrefix = DEBUG_FILE + "/trace" + debug_trace_number++;
String nameConstraint =
ci instanceof INamedElement ? ((INamedElement)ci).getName() : ci.toString();
String nameConstrained =
resource.save(oos, options);
oos.close();
MessageDigest m = MessageDigest.getInstance("SHA1");
m.update(baos.toByteArray());
BigInteger res = new BigInteger(1, m.digest());
if(DEBUG_FOLDER != null) {
String filePrefix = DEBUG_FOLDER + "/trace" + debug_trace_number++ + null;
String nameCstr = cstrShortName(ci);
String nameCstrd =
constrained instanceof INamedElement ? ((INamedElement)constrained)
.getName() : constrained.toString();
String fileName =
filePrefix + "_" + nameConstraint + "_" + nameConstrained + ".xml";
String fileName = filePrefix + "_" + nameCstr + "_" + nameCstrd + ".xml";
FileOutputStream file = new FileOutputStream(fileName);
ObjectOutputStream oos2 = new ObjectOutputStream(file);
res.save(oos2, options);
resource.save(oos2, options);
oos2.writeUTF("\nCHECKSUM: " + res.toString());
oos2.close();
}
oos.close();
MessageDigest m = MessageDigest.getInstance("SHA1");
m.update(baos.toByteArray());
res.getContents().remove(hashRelevant);
res.delete(options);
return new BigInteger(1, m.digest());
resource.getContents().remove(hashRelevant);
resource.delete(options);
return res;
} catch(Exception e) {
e.printStackTrace();
return null;
......@@ -326,4 +334,22 @@ public final class ConstraintService implements IIntrospectiveKernelService, ICo
public Class<? extends IConstraint> getConstraintByName(String name) {
return handlerMap.get(name);
}
/**
* List of constraint instances being currently updated, to prevent triggering twice an update
* which is already on its way.
*/
List<ConstraintInstance> currentlyUpdating = new ArrayList<>();
/** {@inheritDoc} */
@Override
public boolean isUpdating(ConstraintInstance ci) {
return currentlyUpdating.contains(ci);
}
/** {@inheritDoc} */
@Override
public void markAsUpdating(ConstraintInstance ci) {
currentlyUpdating.add(ci);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment