Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / JobCommand.java
1 package org.onap.vid.job;
2
3 import org.onap.vid.job.impl.JobSharedData;
4
5 import java.util.Map;
6
7
8 /**
9  * A callable instance, with serializable characteristics.
10  * Represents a step in a chain of steps, which eventualy
11  * resides into a packing Job.
12  */
13 public interface JobCommand {
14
15     /**
16      * Initialize the command state
17      * @param sharedData shared data cross all job commands
18      * @param commandData An input to be set into the command. Each implementation may expect different keys in the map.
19      * @return Returns itself
20      */
21     default JobCommand init(JobSharedData sharedData, Map<String, Object> commandData) {
22         return this;
23     }
24
25     /**
26      * @return Returns the inner state of the command. This state, once passed into init(), should
27      *         bring the command back to it's state.
28      */
29     Map<String, Object> getData();
30
31     /**
32      * Execute the command represented by this instance. Assumes the instance is already init().
33      * @return A NextCommand containing the next command in chain of commands, or null if chain
34      *         should be terminated. Might return itself (packed in a NextCommand).
35      */
36     NextCommand call();
37
38     default JobType getType() {
39         return JobType.jobTypeOf(this.getClass());
40     }
41
42 }