aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/main/java/org/onap/policy/apex/core/engine/executor/Executor.java
blob: 7ebed1d49e95a185fc39797fc19d031e54325c3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2019 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.apex.core.engine.executor;

import java.util.Properties;
import org.onap.policy.apex.core.engine.ExecutorParameters;
import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;

/**
 * This interface defines what operations must be provided by an executing entity in Apex. It is
 * implemented by classes that execute logic in a state machine. Each executor has an incoming
 * entity {@code IN} that triggers execution, an outgoing entity {@code OUT} that is produced by
 * execution, a subject {@code SUBJECT} that is being executed, and a context {@code CONTEXT} in
 * which execution is being carried out. An executor can be part of a chain of executors and the
 * {@code setNext} method is used to set the next executor to be executed after this executor has
 * completed.
 *
 * @author Sven van der Meer (sven.van.der.meer@ericsson.com)
 * @author Liam Fallon (liam.fallon@ericsson.com)
 *
 * @param <I> type of the incoming entity
 * @param <O> type of the outgoing entity
 * @param <S> type that is the subject of execution
 * @param <C> context holding the context of execution
 */

public interface Executor<I, O, S, C> {
    /**
     * Save the subject and context of the executor.
     *
     * @param parent the parent executor of this executor or null if this executor is the top
     *        executor
     * @param executorSubject the executor subject, the subject of execution
     * @param executorContext the executor context, the context in which execution takes place
     */
    void setContext(Executor<?, ?, ?, ?> parent, S executorSubject, C executorContext);

    /**
     * Prepares the processing.
     *
     * @throws StateMachineException thrown when a state machine execution error occurs
     */
    void prepare() throws StateMachineException;

    /**
     * Executes the executor, running through its context in its natural order.
     *
     * @param executionId the execution ID of the current APEX execution policy thread
     * @param executionProperties the execution properties to set
     * @param incomingEntity the incoming entity that triggers execution
     * @return The outgoing entity that is the result of execution
     * @throws ApexException on an execution error
     */
    O execute(long executionId, Properties executionProperties, I incomingEntity) throws ApexException;

    /**
     * Carry out the preparatory work for execution.
     *
     * @param executionId the execution ID of the current APEX execution policy thread
     * @param executionProperties the execution properties to set
     * @param incomingEntity the incoming entity that triggers execution
     * @throws ApexException on an execution error
     */
    void executePre(long executionId, Properties executionProperties, I incomingEntity) throws ApexException;

    /**
     * Carry out the post work for execution, the returning entity should be set by the child
     * execution object.
     *
     * @param returnValue the return value indicates whether the execution was successful and, if it
     *        failed, how it failed
     * @throws ApexException on an execution error
     */
    void executePost(boolean returnValue) throws ApexException;

    /**
     * Cleans up after processing.
     *
     * @throws StateMachineException thrown when a state machine execution error occurs
     */
    void cleanUp() throws StateMachineException;

    /**
     * Get the key associated with the executor.
     *
     * @return The key associated with the executor
     */
    AxConcept getKey();

    /**
     * Get the parent executor of the executor.
     *
     * @return The parent executor of this executor
     */
    @SuppressWarnings("rawtypes")
    Executor getParent();

    /**
     * Get the subject of the executor.
     *
     * @return The subject for the executor
     */
    S getSubject();

    /**
     * Get the context of the executor.
     *
     * @return The context for the executor
     */
    C getContext();

    /**
     * Get the incoming object of the executor.
     *
     * @return The incoming object for the executor
     */
    I getIncoming();

    /**
     * Get the outgoing object of the executor.
     *
     * @return The outgoing object for the executor
     */
    O getOutgoing();

    /**
     * Save the next executor for this executor.
     *
     * @param nextExecutor the next executor
     */
    void setNext(Executor<I, O, S, C> nextExecutor);

    /**
     * Get the next executor to be run after this executor completes its execution.
     *
     * @return The next executor
     */
    Executor<I, O, S, C> getNext();

    /**
     * Set parameters for this executor, overloaded by executors that use parameters.
     *
     * @param parameters executor parameters
     */
    void setParameters(ExecutorParameters parameters);
}