jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.workflow.api; |
| 17 | |
| 18 | import org.onosproject.event.Event; |
| 19 | |
| 20 | import java.net.URI; |
nitinanand | f3f94c6 | 2019-02-08 10:36:39 +0530 | [diff] [blame] | 21 | import java.util.Set; |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * An abstract class representing WorkflowContext. |
| 25 | */ |
| 26 | public abstract class WorkflowContext extends WorkflowData { |
| 27 | |
| 28 | /** |
| 29 | * Constructor of workflow context. |
| 30 | * @param data data model tree |
| 31 | */ |
| 32 | public WorkflowContext(DataModelTree data) { |
| 33 | super(data); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns workflow id of this workflow context. |
| 38 | * @return workflow id |
| 39 | */ |
| 40 | public abstract URI workflowId(); |
| 41 | |
| 42 | /** |
| 43 | * Returns workplace name. |
| 44 | * @return workplace name |
| 45 | */ |
| 46 | public abstract String workplaceName(); |
| 47 | |
| 48 | /** |
| 49 | * Returns the current state of workflow context. |
| 50 | * @return current state of workflow context |
| 51 | */ |
| 52 | public abstract WorkflowState state(); |
| 53 | |
| 54 | /** |
| 55 | * Sets the current state of workflow context. |
| 56 | * @param state current state of workflow context |
| 57 | */ |
| 58 | public abstract void setState(WorkflowState state); |
| 59 | |
| 60 | /** |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 61 | * Sets the current program counter of workflow context. |
| 62 | * @param pc current program counter |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 63 | */ |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 64 | public abstract void setCurrent(ProgramCounter pc); |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 65 | |
| 66 | /** |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 67 | * Returns the current program counter of workflow. |
| 68 | * @return the current program counter of workflow |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 69 | */ |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 70 | public abstract ProgramCounter current(); |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Returns the cause string of exception state. |
| 74 | * @return cause string |
| 75 | */ |
| 76 | public abstract String cause(); |
| 77 | |
| 78 | /** |
| 79 | * Sets the cause string of exception state. |
| 80 | * @param cause cause string |
| 81 | */ |
| 82 | public abstract void setCause(String cause); |
| 83 | |
| 84 | /** |
| 85 | * Indicates the worklet process become completed. |
| 86 | * By calling this, workflow triggers the next worklet selection |
| 87 | */ |
| 88 | public abstract void completed(); |
| 89 | |
| 90 | /** |
| 91 | * Waits an event which have 'eventHint' after executing executor. |
| 92 | * If the event happens, Worklet.isCompleted will be called. |
| 93 | * If the event does not happen for timeoutMs, Worklet.timeout will be called. |
| 94 | * @param eventType the class of event to wait |
| 95 | * @param eventHint the event of the event to wait |
| 96 | * @param eventGenerator a method reference to be executed after executing executor |
| 97 | * @param timeoutMs timeout millisecond |
| 98 | */ |
| 99 | public abstract void waitCompletion(Class<? extends Event> eventType, String eventHint, |
| 100 | WorkExecutor eventGenerator, long timeoutMs); |
| 101 | |
nitinanand | f3f94c6 | 2019-02-08 10:36:39 +0530 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Waits an event which has any one of eventHint from Set 'eventHintSet' after executing executor. |
| 105 | * If the event happens, Worklet.isCompleted will be called. |
| 106 | * If the event does not happen for timeoutMs, Worklet.timeout will be called. |
| 107 | * @param eventType the class of event to wait |
| 108 | * @param eventHintSet the Set of eventHints of the event to wait |
| 109 | * @param eventGenerator a method reference to be executed after executing executor |
| 110 | * @param timeoutMs timeout millisecond |
| 111 | */ |
| 112 | public abstract void waitAnyCompletion(Class<? extends Event> eventType, Set<String> eventHintSet, |
| 113 | WorkExecutor eventGenerator, long timeoutMs); |
| 114 | |
| 115 | |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 116 | /** |
| 117 | * Waits timeout milliseconds. After timeoutMs Worklet.timeout will be called. |
| 118 | * @param timeoutMs timeout millisecond |
| 119 | */ |
| 120 | public abstract void waitFor(long timeoutMs); |
| 121 | |
| 122 | /** |
| 123 | * Returns the class of a completion event to wait. |
| 124 | * @return the class of a completion event |
| 125 | */ |
| 126 | public abstract Class<? extends Event> completionEventType(); |
| 127 | |
| 128 | /** |
nitinanand | f3f94c6 | 2019-02-08 10:36:39 +0530 | [diff] [blame] | 129 | * Returns the set of event hint string to wait. |
| 130 | * @return the event hint string set |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 131 | */ |
nitinanand | f3f94c6 | 2019-02-08 10:36:39 +0530 | [diff] [blame] | 132 | public abstract Set<String> completionEventHints(); |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 133 | |
| 134 | /** |
| 135 | * Returns method reference for generating completion event. |
| 136 | * @return a method reference |
| 137 | */ |
| 138 | public abstract WorkExecutor completionEventGenerator(); |
| 139 | |
| 140 | /** |
| 141 | * Returns completion event timeout. |
| 142 | * @return completion event timeout |
| 143 | */ |
| 144 | public abstract long completionEventTimeout(); |
| 145 | |
| 146 | /** |
| 147 | * Sets workflow service. |
| 148 | * @param workflowExecutionService workflow service |
| 149 | */ |
| 150 | public abstract void setWorkflowExecutionService(WorkflowExecutionService workflowExecutionService); |
| 151 | |
| 152 | /** |
| 153 | * Gets workflow service. |
| 154 | * @return workflow service |
| 155 | */ |
| 156 | public abstract WorkflowExecutionService workflowService(); |
| 157 | |
| 158 | /** |
| 159 | * Sets workflow store. |
| 160 | * @param workflowStore workflow store. |
| 161 | */ |
| 162 | public abstract void setWorkflowStore(WorkflowStore workflowStore); |
| 163 | |
| 164 | /** |
| 165 | * Gets worklow store. |
| 166 | * @return workflow store |
| 167 | */ |
| 168 | public abstract WorkflowStore workflowStore(); |
| 169 | |
| 170 | /** |
| 171 | * Sets workplace store. |
| 172 | * @param workplaceStore work place store. |
| 173 | */ |
| 174 | public abstract void setWorkplaceStore(WorkplaceStore workplaceStore); |
| 175 | |
| 176 | /** |
| 177 | * Gets workplace store. |
| 178 | * @return workplace store |
| 179 | */ |
| 180 | public abstract WorkplaceStore workplaceStore(); |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * Get service. |
| 184 | * @param serviceClass service class |
| 185 | * @param <T> service class type |
| 186 | * @return service reference |
| 187 | * @throws WorkflowException workflow exception |
| 188 | */ |
| 189 | public abstract <T> T getService(Class<T> serviceClass) throws WorkflowException; |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 190 | } |