blob: 94203bc97955b858ccd14f79606945d6dc65bcc4 [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 /**
jaegonkime0f45b52018-10-09 20:23:26 +090031 * Program counter of handler task.
jaegonkim6a7b5242018-09-12 23:09:42 +090032 */
jaegonkime0f45b52018-10-09 20:23:26 +090033 private final ProgramCounter programCounter;
jaegonkim6a7b5242018-09-12 23:09:42 +090034
35 /**
36 * Constructor for handler task.
37 * @param builder handler task builder
38 */
39 protected HandlerTask(Builder builder) {
40 this.context = builder.context;
jaegonkime0f45b52018-10-09 20:23:26 +090041 this.programCounter = builder.programCounter;
jaegonkim6a7b5242018-09-12 23:09:42 +090042 }
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 /**
jaegonkime0f45b52018-10-09 20:23:26 +090053 * Returns program counter of this handler task.
54 * @return program counter
jaegonkim6a7b5242018-09-12 23:09:42 +090055 */
jaegonkime0f45b52018-10-09 20:23:26 +090056 public ProgramCounter programCounter() {
57 return programCounter;
jaegonkim6a7b5242018-09-12 23:09:42 +090058 }
59
60 @Override
61 public String toString() {
62 return MoreObjects.toStringHelper(getClass())
63 .add("context", context())
jaegonkime0f45b52018-10-09 20:23:26 +090064 .add("programCounter", programCounter())
jaegonkim6a7b5242018-09-12 23:09:42 +090065 .toString();
66 }
67
68 /**
69 * Builder of HandlerTask.
70 */
71 public static class Builder {
72 protected WorkflowContext context;
jaegonkime0f45b52018-10-09 20:23:26 +090073 protected ProgramCounter programCounter;
jaegonkim6a7b5242018-09-12 23:09:42 +090074
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 /**
jaegonkime0f45b52018-10-09 20:23:26 +090086 * Sets program counter of handler task.
87 * @param programCounter program counter of handler type
jaegonkim6a7b5242018-09-12 23:09:42 +090088 * @return builder of handler task
89 */
jaegonkime0f45b52018-10-09 20:23:26 +090090 public Builder programCounter(ProgramCounter programCounter) {
91 this.programCounter = programCounter;
jaegonkim6a7b5242018-09-12 23:09:42 +090092 return this;
93 }
94 }
95}