17
17
package org .apache .kafka .connect .runtime ;
18
18
19
19
import org .apache .kafka .connect .connector .Connector ;
20
- import org .apache .kafka .connect .connector .Task ;
21
20
22
21
import java .util .Objects ;
23
22
24
23
/**
25
24
* A request to restart a connector and/or task instances.
26
25
* <p>
27
26
* The natural order is based first upon the connector name and then requested restart behaviors.
28
- * If two requests have the same connector name, then the requests are ordered based on the
27
+ * If two requests have the same connector name, then the requests are ordered based on the
29
28
* probable number of tasks/connector this request is going to restart.
29
+ * @param connectorName the name of the connector; may not be null
30
+ * @param onlyFailed true if only failed instances should be restarted
31
+ * @param includeTasks true if tasks should be restarted, or false if only the connector should be restarted
30
32
*/
31
- public class RestartRequest implements Comparable <RestartRequest > {
33
+ public record RestartRequest (String connectorName ,
34
+ boolean onlyFailed ,
35
+ boolean includeTasks ) implements Comparable <RestartRequest > {
32
36
33
- private final String connectorName ;
34
- private final boolean onlyFailed ;
35
- private final boolean includeTasks ;
36
-
37
- /**
38
- * Create a new request to restart a connector and optionally its tasks.
39
- *
40
- * @param connectorName the name of the connector; may not be null
41
- * @param onlyFailed true if only failed instances should be restarted
42
- * @param includeTasks true if tasks should be restarted, or false if only the connector should be restarted
43
- */
44
- public RestartRequest (String connectorName , boolean onlyFailed , boolean includeTasks ) {
45
- this .connectorName = Objects .requireNonNull (connectorName , "Connector name may not be null" );
46
- this .onlyFailed = onlyFailed ;
47
- this .includeTasks = includeTasks ;
48
- }
49
-
50
- /**
51
- * Get the name of the connector.
52
- *
53
- * @return the connector name; never null
54
- */
55
- public String connectorName () {
56
- return connectorName ;
57
- }
58
-
59
- /**
60
- * Determine whether only failed instances be restarted.
61
- *
62
- * @return true if only failed instances should be restarted, or false if all applicable instances should be restarted
63
- */
64
- public boolean onlyFailed () {
65
- return onlyFailed ;
66
- }
67
-
68
- /**
69
- * Determine whether {@link Task} instances should also be restarted in addition to the {@link Connector} instance.
70
- *
71
- * @return true if the connector and task instances should be restarted, or false if just the connector should be restarted
72
- */
73
- public boolean includeTasks () {
74
- return includeTasks ;
37
+ public RestartRequest {
38
+ Objects .requireNonNull (connectorName , "Connector name may not be null" );
75
39
}
76
40
77
41
/**
@@ -108,6 +72,7 @@ public int compareTo(RestartRequest o) {
108
72
int result = connectorName .compareTo (o .connectorName );
109
73
return result == 0 ? impactRank () - o .impactRank () : result ;
110
74
}
75
+
111
76
//calculates an internal rank for the restart request based on the probable number of tasks/connector this request is going to restart
112
77
private int impactRank () {
113
78
if (onlyFailed && !includeTasks ) { //restarts only failed connector so least impactful
@@ -121,23 +86,6 @@ private int impactRank() {
121
86
return 3 ;
122
87
}
123
88
124
- @ Override
125
- public boolean equals (Object o ) {
126
- if (this == o ) {
127
- return true ;
128
- }
129
- if (o == null || getClass () != o .getClass ()) {
130
- return false ;
131
- }
132
- RestartRequest that = (RestartRequest ) o ;
133
- return onlyFailed == that .onlyFailed && includeTasks == that .includeTasks && Objects .equals (connectorName , that .connectorName );
134
- }
135
-
136
- @ Override
137
- public int hashCode () {
138
- return Objects .hash (connectorName , onlyFailed , includeTasks );
139
- }
140
-
141
89
@ Override
142
90
public String toString () {
143
91
return "restart request for {" + "connectorName='" + connectorName + "', onlyFailed=" + onlyFailed + ", includeTasks=" + includeTasks + '}' ;
0 commit comments