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 com.google.common.base.MoreObjects; |
| 19 | |
| 20 | /** |
| 21 | * Abstract class for handler task. |
| 22 | */ |
| 23 | public abstract class HandlerTask { |
| 24 | |
| 25 | /** |
| 26 | * Workflow context of handler task. |
| 27 | */ |
| 28 | private final WorkflowContext context; |
| 29 | |
| 30 | /** |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 31 | * Program counter of handler task. |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 32 | */ |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 33 | private final ProgramCounter programCounter; |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Constructor for handler task. |
| 37 | * @param builder handler task builder |
| 38 | */ |
| 39 | protected HandlerTask(Builder builder) { |
| 40 | this.context = builder.context; |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 41 | this.programCounter = builder.programCounter; |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns workflow context of this handler task. |
| 46 | * @return workflow context |
| 47 | */ |
| 48 | public WorkflowContext context() { |
| 49 | return context; |
| 50 | } |
| 51 | |
| 52 | /** |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 53 | * Returns program counter of this handler task. |
| 54 | * @return program counter |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 55 | */ |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 56 | public ProgramCounter programCounter() { |
| 57 | return programCounter; |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String toString() { |
| 62 | return MoreObjects.toStringHelper(getClass()) |
| 63 | .add("context", context()) |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 64 | .add("programCounter", programCounter()) |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 65 | .toString(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Builder of HandlerTask. |
| 70 | */ |
| 71 | public static class Builder { |
| 72 | protected WorkflowContext context; |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 73 | protected ProgramCounter programCounter; |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Sets workflow context of handler task. |
| 77 | * @param context workflow context |
| 78 | * @return builder of handler task |
| 79 | */ |
| 80 | public Builder context(WorkflowContext context) { |
| 81 | this.context = context; |
| 82 | return this; |
| 83 | } |
| 84 | |
| 85 | /** |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 86 | * Sets program counter of handler task. |
| 87 | * @param programCounter program counter of handler type |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 88 | * @return builder of handler task |
| 89 | */ |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 90 | public Builder programCounter(ProgramCounter programCounter) { |
| 91 | this.programCounter = programCounter; |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 92 | return this; |
| 93 | } |
| 94 | } |
| 95 | } |