@Override
@Transactional(readOnly = true)
public ScriptProcess getProcess(UUID pid) {
if (pid == null) {
throw new ScriptusRuntimeException("Cannot load null pid");
}
LOG.debug("loading " + pid.toString().substring(30));
Context cx = Context.enter();
cx.setClassShutter(new ScriptusClassShutter());
cx.setOptimizationLevel(-1); // must use interpreter mode
try {
ProcessDAO d;
try {
d = em.find(ProcessDAO.class, pid.toString());
} catch (PersistenceException pe) {
System.out.println("count="
+ em.createQuery("select count(*) from ProcessDAO d where d.pid = '" + pid.toString() + "'")
.getSingleResult());
throw pe;
}
if (d == null) {
throw new ProcessNotFoundException(pid.toString());
}
ScriptProcess result = createScriptProcess();
result.setPid(UUID.fromString(d.pid));
if (d.waitingPid != null) {
result.setWaiterPid(UUID.fromString(d.waitingPid));
}
result.setSource(new String(d.source, ScriptusConfig.CHARSET));
result.setSourceName(d.sourceId);
result.setUserId(d.userId);
result.setArgs(d.args);
result.setTransport(TransportType.valueOf(d.transport));
{
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(d.script_state));
result.setCompiled((Function) in.readObject());
result.setGlobalScope((ScriptableObject) in.readObject());
result.setContinuation(in.readObject());
}
result.setState(SerializableUtils.deserialiseObject(d.state));
result.setOwner(d.owner);
result.setRoot(d.isRoot);
result.setVersion(d.version);
result.setAlive(d.isAlive);
return result;
} catch (ScriptusRuntimeException e) {
throw e;
} catch (IOException e) {
throw new ScriptusRuntimeException(e);
} catch (ClassNotFoundException e) {
throw new ScriptusRuntimeException(e);
} finally {
Context.exit();
}
}