use of org.ow2.proactive.scheduler.task.containers.ExecutableContainer in project scheduling by ow2-proactive.
the class InternalTask method replicate.
/**
* {@inheritDoc}
*/
@Override
public TaskState replicate() throws ExecutableCreationException {
/*
* this implementation deep copies everything using serialization. however the new
* InternalTask cannot be strictly identical and we have to handle the following special
* cases:
*
* - ExecutableContainer is transient and not copied during serialization. It needs to be
* manually copied, and added to the InternalTask replica
*
* - Using the TaskInfo of _this_ gives us a FINISHED task, need to explicitely create a new
* clean one.
*
* - InternalTask dependencies need to be nulled as they contain references to other
* InternalTasks, and will be rewritten later anyway
*
* - Most of the objects down the object graph contain Hibernate @Id fields. If all those
* fields are not set to 0 when inserting the object in DB, insertion will fail.
*
* - Collections are mapped to specific Hibernate internal collections at runtime, which
* contain references to the @Id fields mentionned above. They need to be reset too.
*/
InternalTask replicatedTask = null;
// ExecutableContainer replicatedContainer = null;
try {
// Deep copy of the InternalTask using proactive serialization
replicatedTask = (InternalTask) ProActiveMakeDeepCopy.WithProActiveObjectStream.makeDeepCopy(this);
} catch (Throwable t) {
throw new ExecutableCreationException("Failed to serialize task", t);
}
replicatedTask.internalJob = internalJob;
// internalTasksDependencies contain references to other InternalTasks, it needs to be removed.
// anyway, dependencies for the new task will not be the same as the original
replicatedTask.internalTasksDependencies = null;
// the taskinfo needs to be cleaned so that we don't tag this task as finished
TaskId repId = replicatedTask.taskInfo.getTaskId();
replicatedTask.taskInfo = new TaskInfoImpl();
// we only need this id for the HashSet comparisons...
replicatedTask.taskInfo.setTaskId(repId);
replicatedTask.taskInfo.setNumberOfExecutionLeft(getMaxNumberOfExecution());
replicatedTask.taskInfo.setNumberOfExecutionOnFailureLeft(getMaxNumberOfExecutionOnFailure());
replicatedTask.setReplicatedFrom(this);
// The next DB.update(InternalJob) will take care of it
return replicatedTask;
}
Aggregations