blob: 9aa870d2f4cff71266ad7b9fd34551fa27839b7e [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
20import java.util.Objects;
21
jaegonkime0f45b52018-10-09 20:23:26 +090022import static org.onosproject.workflow.api.CheckCondition.check;
23
jaegonkim6a7b5242018-09-12 23:09:42 +090024/**
25 * Class for event timeout task.
26 */
27public final class EventTimeoutTask extends HandlerTask {
28
29 /**
30 * Event type (Class name of event).
31 */
32 private final String eventType;
33
34 /**
35 * Event hint value for finding target event.
36 */
37 private final String eventHint;
38
39 /**
40 * Constructor of EventTimeoutTask.
41 * @param builder builder of EventTimeoutTask
42 */
43 private EventTimeoutTask(Builder builder) {
44 super(builder);
45 this.eventType = builder.eventType;
46 this.eventHint = builder.eventHint;
47 }
48
49 /**
50 * Gets event type (Class name of event).
51 * @return event type
52 */
53 public String eventType() {
54 return eventType;
55 }
56
57 /**
58 * Gets event hint value for finding target event.
59 * @return event hint string
60 */
61 public String eventHint() {
62 return eventHint;
63 }
64
65 @Override
66 public int hashCode() {
67 return Objects.hash(this.toString());
68 }
69
70 @Override
71 public boolean equals(Object obj) {
72 if (obj == this) {
73 return true;
74 }
75 if (!(obj instanceof EventTask)) {
76 return false;
77 }
78 return Objects.equals(this.eventType(), ((EventTask) obj).eventType())
79 && Objects.equals(this.eventHint(), ((EventTask) obj).eventHint());
80 }
81
82 @Override
83 public String toString() {
84 return MoreObjects.toStringHelper(getClass())
85 .add("context", context())
jaegonkime0f45b52018-10-09 20:23:26 +090086 .add("programCounter", programCounter())
jaegonkim6a7b5242018-09-12 23:09:42 +090087 .add("eventType", eventType())
88 .add("eventHint", eventHint())
89 .toString();
90 }
91
92 /**
93 * Gets a instance of builder.
94 * @return instance of builder
95 */
96 public static Builder builder() {
97 return new Builder();
98 }
99
100 /**
101 * Builder of EventTimeoutTask.
102 */
103 public static class Builder extends HandlerTask.Builder {
104 /**
105 * Event type (Class name of event).
106 */
107 private String eventType;
108
109 /**
110 * Event hint value for finding target event.
111 */
112 private String eventHint;
113
114 /**
115 * Sets Event type (Class name of event).
116 * @param eventType event type
117 * @return builder of EventTimeoutTask
118 */
119 public Builder eventType(String eventType) {
120 this.eventType = eventType;
121 return this;
122 }
123
124 /**
125 * Sets event hint string for finding target event.
126 * @param eventHint event hint string
127 * @return builder of EventTimeoutTask
128 */
129 public Builder eventHint(String eventHint) {
130 this.eventHint = eventHint;
131 return this;
132 }
133
134 @Override
135 public Builder context(WorkflowContext context) {
136 super.context(context);
137 return this;
138 }
139
140 @Override
jaegonkime0f45b52018-10-09 20:23:26 +0900141 public Builder programCounter(ProgramCounter programCounter) {
142 super.programCounter(programCounter);
jaegonkim6a7b5242018-09-12 23:09:42 +0900143 return this;
144 }
145
146 /**
147 * Builds EventTimeoutTask.
148 * @return instance of EventTimeoutTask
jaegonkime0f45b52018-10-09 20:23:26 +0900149 * @throws WorkflowException workflow exception
jaegonkim6a7b5242018-09-12 23:09:42 +0900150 */
jaegonkime0f45b52018-10-09 20:23:26 +0900151 public EventTimeoutTask build() throws WorkflowException {
152 check(eventType != null, "eventType is invalid");
153 check(eventHint != null, "eventType is invalid");
jaegonkim6a7b5242018-09-12 23:09:42 +0900154 return new EventTimeoutTask(this);
155 }
156 }
157}