emulationAlternative = (Alternative)alt;
}
public void runEmulation(Object rec){
if (rec instanceof SampleObject) {
SampleObject sample = (SampleObject)rec;
Alternative a = emulationAlternative;
if (!a.isExecutable()) {
// this alternative has to be evaluated manually, nothing to do here
return;
}
IPreservationAction action =
PreservationActionServiceFactory.getPreservationAction(a.getAction());
/*
* clear old run description
*/
if (action == null) {
String msg = String.format("Preservation action %s - %s is not registered or accessible and cant be executed. (Please check the registry.)",
a.getAction().getShortname(), a.getAction().getInfo());
setUniformProgramOutput(a, msg, false);
}
if (action instanceof IEmulationAction) {
// GRATE does only work on files up to 2.88 MB in size
// if (sample.getData().getSize() > (1024 * 1024 * 2.8)) {
// FacesMessages.instance().add(FacesMessage.SEVERITY_WARN,
// "Emulation actions are currently only supported on samples up to a size of 2,88 MB.");
// return;
// }
try {
DetailedExperimentInfo info = a.getExperiment().getDetailedInfo().get(sample);
String sessionID = null;
if (info == null) {
info = new DetailedExperimentInfo();
a.getExperiment().getDetailedInfo().put(sample, info);
} else {
Value sid = info.getMeasurements().get("sessionid").getValue();
if (sid != null && (sid instanceof FreeStringValue)) {
// sessionID = ((FreeStringValue)sid).getValue();
}
}
// objectTomigrate is only being read, needs to be merged to lazily get the data out
SampleObject objectToView = em.merge(sample);
byte[] b = objectToView.getData().getData();
if (sessionID == null) {
sessionID = ((IEmulationAction)action).startSession(a.getAction(), objectToView);
}
a.getExperiment().getDetailedInfo().get(sample).setSuccessful(true);
// we cannot use SETTINGS here because settings are not PER SAMPLE OBJECT!
info.getMeasurements().put("sessionid", new Measurement("sessionID",sessionID));
} catch (PlatoServiceException e) {
String errorMsg = "Could not start emulation service." + e.getMessage();
setUniformProgramOutput(a, errorMsg, false);