blob: 9f0b4fe0ea84ab2ad3eb51cb28056af9b35c3b88 [file] [log] [blame]
jaegonkim6a7b5242018-09-12 23:09:42 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.workflow.api;
17
18import org.onosproject.event.Event;
19
20import java.net.URI;
21
22/**
23 * An abstract class representing WorkflowContext.
24 */
25public abstract class WorkflowContext extends WorkflowData {
26
27 /**
28 * Constructor of workflow context.
29 * @param data data model tree
30 */
31 public WorkflowContext(DataModelTree data) {
32 super(data);
33 }
34
35 /**
36 * Returns workflow id of this workflow context.
37 * @return workflow id
38 */
39 public abstract URI workflowId();
40
41 /**
42 * Returns workplace name.
43 * @return workplace name
44 */
45 public abstract String workplaceName();
46
47 /**
48 * Returns the current state of workflow context.
49 * @return current state of workflow context
50 */
51 public abstract WorkflowState state();
52
53 /**
54 * Sets the current state of workflow context.
55 * @param state current state of workflow context
56 */
57 public abstract void setState(WorkflowState state);
58
59 /**
jaegonkime0f45b52018-10-09 20:23:26 +090060 * Sets the current program counter of workflow context.
61 * @param pc current program counter
jaegonkim6a7b5242018-09-12 23:09:42 +090062 */
jaegonkime0f45b52018-10-09 20:23:26 +090063 public abstract void setCurrent(ProgramCounter pc);
jaegonkim6a7b5242018-09-12 23:09:42 +090064
65 /**
jaegonkime0f45b52018-10-09 20:23:26 +090066 * Returns the current program counter of workflow.
67 * @return the current program counter of workflow
jaegonkim6a7b5242018-09-12 23:09:42 +090068 */
jaegonkime0f45b52018-10-09 20:23:26 +090069 public abstract ProgramCounter current();
jaegonkim6a7b5242018-09-12 23:09:42 +090070
71 /**
72 * Returns the cause string of exception state.
73 * @return cause string
74 */
75 public abstract String cause();
76
77 /**
78 * Sets the cause string of exception state.
79 * @param cause cause string
80 */
81 public abstract void setCause(String cause);
82
83 /**
84 * Indicates the worklet process become completed.
85 * By calling this, workflow triggers the next worklet selection
86 */
87 public abstract void completed();
88
89 /**
90 * Waits an event which have 'eventHint' after executing executor.
91 * If the event happens, Worklet.isCompleted will be called.
92 * If the event does not happen for timeoutMs, Worklet.timeout will be called.
93 * @param eventType the class of event to wait
94 * @param eventHint the event of the event to wait
95 * @param eventGenerator a method reference to be executed after executing executor
96 * @param timeoutMs timeout millisecond
97 */
98 public abstract void waitCompletion(Class<? extends Event> eventType, String eventHint,
99 WorkExecutor eventGenerator, long timeoutMs);
100
101 /**
102 * Waits timeout milliseconds. After timeoutMs Worklet.timeout will be called.
103 * @param timeoutMs timeout millisecond
104 */
105 public abstract void waitFor(long timeoutMs);
106
107 /**
108 * Returns the class of a completion event to wait.
109 * @return the class of a completion event
110 */
111 public abstract Class<? extends Event> completionEventType();
112
113 /**
114 * Returns the event hint string to wait.
115 * @return the event hint string
116 */
117 public abstract String completionEventHint();
118
119 /**
120 * Returns method reference for generating completion event.
121 * @return a method reference
122 */
123 public abstract WorkExecutor completionEventGenerator();
124
125 /**
126 * Returns completion event timeout.
127 * @return completion event timeout
128 */
129 public abstract long completionEventTimeout();
130
131 /**
132 * Sets workflow service.
133 * @param workflowExecutionService workflow service
134 */
135 public abstract void setWorkflowExecutionService(WorkflowExecutionService workflowExecutionService);
136
137 /**
138 * Gets workflow service.
139 * @return workflow service
140 */
141 public abstract WorkflowExecutionService workflowService();
142
143 /**
144 * Sets workflow store.
145 * @param workflowStore workflow store.
146 */
147 public abstract void setWorkflowStore(WorkflowStore workflowStore);
148
149 /**
150 * Gets worklow store.
151 * @return workflow store
152 */
153 public abstract WorkflowStore workflowStore();
154
155 /**
156 * Sets workplace store.
157 * @param workplaceStore work place store.
158 */
159 public abstract void setWorkplaceStore(WorkplaceStore workplaceStore);
160
161 /**
162 * Gets workplace store.
163 * @return workplace store
164 */
165 public abstract WorkplaceStore workplaceStore();
jaegonkime0f45b52018-10-09 20:23:26 +0900166
167 /**
168 * Get service.
169 * @param serviceClass service class
170 * @param <T> service class type
171 * @return service reference
172 * @throws WorkflowException workflow exception
173 */
174 public abstract <T> T getService(Class<T> serviceClass) throws WorkflowException;
jaegonkim6a7b5242018-09-12 23:09:42 +0900175}