blob: 106466b90e23504684939d8f8e3c6b16c143a8ed [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 com.google.common.base.MoreObjects;
19
20/**
21 * Abstract class for handler task.
22 */
23public abstract class HandlerTask {
24
25 /**
26 * Workflow context of handler task.
27 */
28 private final WorkflowContext context;
29
30 /**
31 * Worklet type of handler task.
32 */
33 private final String workletType;
34
35 /**
36 * Constructor for handler task.
37 * @param builder handler task builder
38 */
39 protected HandlerTask(Builder builder) {
40 this.context = builder.context;
41 this.workletType = builder.workletType;
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 /**
53 * Returns worklet type name of this handler task.
54 * @return worklet type
55 */
56 public String workletType() {
57 return workletType;
58 }
59
60 @Override
61 public String toString() {
62 return MoreObjects.toStringHelper(getClass())
63 .add("context", context())
64 .add("workletType", workletType())
65 .toString();
66 }
67
68 /**
69 * Builder of HandlerTask.
70 */
71 public static class Builder {
72 protected WorkflowContext context;
73 protected String workletType;
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 /**
86 * Sets worklet type of handler task.
87 * @param workletType worklet type
88 * @return builder of handler task
89 */
90 public Builder workletType(String workletType) {
91 this.workletType = workletType;
92 return this;
93 }
94 }
95}