@Override
@Transactional
protected void handle(final DownloadImageMsg msg) {
final DownloadImageReply reply = new DownloadImageReply();
final ImageInventory iinv = msg.getImageInventory();
final String installPath = PathUtil.join(getSelf().getUrl(), BackupStoragePathMaker.makeImageInstallPath(iinv));
String sql = "update ImageBackupStorageRefVO set installPath = :installPath " +
"where backupStorageUuid = :bsUuid and imageUuid = :imageUuid";
Query q = dbf.getEntityManager().createQuery(sql);
q.setParameter("installPath", installPath);
q.setParameter("bsUuid", msg.getBackupStorageUuid());
q.setParameter("imageUuid", msg.getImageInventory().getUuid());
q.executeUpdate();
download(iinv.getUrl(), installPath, iinv.getUuid(), new ReturnValueCompletion<DownloadResult>(msg) {
@Override
public void success(DownloadResult res) {
reply.setInstallPath(installPath);
reply.setSize(res.size);
reply.setActualSize(res.actualSize);
reply.setMd5sum(res.md5sum);
reply.setFormat(res.format);
bus.reply(msg, reply);
}
@Override
public void fail(ErrorCode errorCode) {
reply.setError(errorCode);
bus.reply(msg, reply);
}
});
}