generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCallbackConfig.java
More file actions
110 lines (96 loc) · 3.72 KB
/
CallbackConfig.java
File metadata and controls
110 lines (96 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package software.amazon.lambda.durable;
import java.time.Duration;
import software.amazon.lambda.durable.serde.SerDes;
import software.amazon.lambda.durable.util.ParameterValidator;
/** Configuration for callback operations. */
public class CallbackConfig {
private final Duration timeout;
private final Duration heartbeatTimeout;
private final SerDes serDes;
private CallbackConfig(Builder builder) {
this.timeout = builder.timeout;
this.heartbeatTimeout = builder.heartbeatTimeout;
this.serDes = builder.serDes;
}
/**
* Returns the maximum duration to wait for the callback to complete.
*
* @return the timeout duration, or null if not specified
*/
public Duration timeout() {
return timeout;
}
/**
* Returns the maximum duration between heartbeats before the callback is considered failed.
*
* @return the heartbeat timeout duration, or null if not specified
*/
public Duration heartbeatTimeout() {
return heartbeatTimeout;
}
/** Returns the custom serializer for this callback, or null if not specified (uses default SerDes). */
public SerDes serDes() {
return serDes;
}
/** Creates a new builder with default values. */
public static Builder builder() {
return new Builder(null, null, null);
}
/** Creates a new builder pre-populated with this config's values. */
public Builder toBuilder() {
return new Builder(timeout, heartbeatTimeout, serDes);
}
/** Builder for {@link CallbackConfig}. */
public static class Builder {
private Duration timeout;
private Duration heartbeatTimeout;
private SerDes serDes;
private Builder(Duration timeout, Duration heartbeatTimeout, SerDes serDes) {
this.timeout = timeout;
this.heartbeatTimeout = heartbeatTimeout;
this.serDes = serDes;
}
/**
* Sets the maximum duration to wait for the callback to complete before timing out.
*
* @param timeout the timeout duration
* @return this builder for method chaining
*/
public Builder timeout(Duration timeout) {
ParameterValidator.validateOptionalDuration(timeout, "Callback timeout");
this.timeout = timeout;
return this;
}
/**
* Sets the maximum duration between heartbeats before the callback is considered failed.
*
* @param heartbeatTimeout the heartbeat timeout duration
* @return this builder for method chaining
*/
public Builder heartbeatTimeout(Duration heartbeatTimeout) {
ParameterValidator.validateOptionalDuration(heartbeatTimeout, "Heartbeat timeout");
this.heartbeatTimeout = heartbeatTimeout;
return this;
}
/**
* Sets a custom serializer for the callback.
*
* <p>If not specified, the callback will use the default SerDes configured for the handler. This allows
* per-callback customization of serialization behavior, useful for callbacks that need special handling (e.g.,
* custom date formats, encryption, compression).
*
* @param serDes the custom serializer to use, or null to use the default
* @return this builder for method chaining
*/
public Builder serDes(SerDes serDes) {
this.serDes = serDes;
return this;
}
/** Builds the {@link CallbackConfig} instance. */
public CallbackConfig build() {
return new CallbackConfig(this);
}
}
}