1+ package com .databricks .sdk .service .common .lro ;
2+
3+ import java .time .Duration ;
4+ import java .util .Objects ;
5+ import java .util .Optional ;
6+
7+ /**
8+ * Options for configuring long-running operation behavior.
9+ *
10+ * <p>This class provides configuration options for long-running operations, such as timeouts and
11+ * other behavioral settings.
12+ */
13+ public class LroOptions {
14+
15+ /**
16+ * The maximum duration to wait for the operation to complete. If empty, the default timeout will
17+ * be used (typically 20 minutes).
18+ */
19+ private final Optional <Duration > timeout ;
20+
21+ /** Private constructor for builder pattern. */
22+ private LroOptions (Builder builder ) {
23+ this .timeout = Optional .ofNullable (builder .timeout );
24+ }
25+
26+ /**
27+ * Gets the timeout for the operation.
28+ *
29+ * @return the timeout duration, or empty if using the default
30+ */
31+ public Optional <Duration > getTimeout () {
32+ return timeout ;
33+ }
34+
35+ /**
36+ * Creates a new builder for LroOptions.
37+ *
38+ * @return a new Builder instance
39+ */
40+ public static Builder newBuilder () {
41+ return new Builder ();
42+ }
43+
44+ /**
45+ * Creates LroOptions with the specified timeout. Convenience method for simple timeout
46+ * configuration.
47+ *
48+ * @param timeout the maximum duration to wait for operation completion
49+ * @return a new LroOptions instance
50+ */
51+ public static LroOptions withTimeout (Duration timeout ) {
52+ return newBuilder ().setTimeout (timeout ).build ();
53+ }
54+
55+ /** Builder for LroOptions. */
56+ public static class Builder {
57+ private Duration timeout ;
58+
59+ /**
60+ * Sets the timeout for the operation.
61+ *
62+ * @param timeout the maximum duration to wait for operation completion
63+ * @return this Builder instance for method chaining
64+ */
65+ public Builder setTimeout (Duration timeout ) {
66+ this .timeout = timeout ;
67+ return this ;
68+ }
69+
70+ /**
71+ * Builds the LroOptions instance.
72+ *
73+ * @return a new LroOptions instance
74+ */
75+ public LroOptions build () {
76+ return new LroOptions (this );
77+ }
78+ }
79+
80+ @ Override
81+ public boolean equals (Object o ) {
82+ if (this == o ) return true ;
83+ if (o == null || getClass () != o .getClass ()) return false ;
84+ LroOptions that = (LroOptions ) o ;
85+ return Objects .equals (timeout , that .timeout );
86+ }
87+
88+ @ Override
89+ public int hashCode () {
90+ return Objects .hash (timeout );
91+ }
92+
93+ @ Override
94+ public String toString () {
95+ return "LroOptions{" + "timeout=" + timeout + '}' ;
96+ }
97+ }
0 commit comments