Skip to content

Commit 53d38fa

Browse files
Add extension properties for Kotlin
1 parent 0a4e525 commit 53d38fa

File tree

4 files changed

+358
-171
lines changed

4 files changed

+358
-171
lines changed

examples/src/main/kotlin/my/restate/sdk/examples/CounterKt.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import dev.restate.sdk.kotlin.endpoint.*
1717
import kotlinx.serialization.Serializable
1818
import org.apache.logging.log4j.LogManager
1919
import org.apache.logging.log4j.Logger
20+
import kotlin.time.Duration.Companion.seconds
2021

2122
@VirtualObject
2223
class CounterKt {
@@ -57,6 +58,10 @@ class CounterKt {
5758
}
5859

5960
fun main() {
60-
val endpoint = endpoint { bind(CounterKt()) }
61+
val endpoint = endpoint {
62+
bind(CounterKt()) {
63+
it.abortTimeout = 30.seconds
64+
}
65+
}
6166
RestateHttpServer.listen(endpoint)
6267
}

sdk-api-kotlin/src/main/kotlin/dev/restate/sdk/kotlin/endpoint/endpoint.kt

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,300 @@
99
package dev.restate.sdk.kotlin.endpoint
1010

1111
import dev.restate.sdk.endpoint.Endpoint
12+
import dev.restate.sdk.endpoint.definition.HandlerDefinition
13+
import dev.restate.sdk.endpoint.definition.ServiceDefinition
14+
import kotlin.time.Duration
15+
import kotlin.time.toJavaDuration
16+
import kotlin.time.toKotlinDuration
1217

1318
/** Endpoint builder function. */
1419
fun endpoint(init: Endpoint.Builder.() -> Unit): Endpoint {
1520
val builder = Endpoint.builder()
1621
builder.init()
1722
return builder.build()
1823
}
24+
25+
/**
26+
* Documentation as shown in the UI, Admin REST API, and the generated OpenAPI documentation of
27+
* this service.
28+
*/
29+
var ServiceDefinition.Configurator.documentation: String?
30+
get() {
31+
return this.documentation()
32+
}
33+
set(value) {
34+
this.documentation (value)
35+
}
36+
37+
/**
38+
* Service metadata, as propagated in the Admin REST API.
39+
*/
40+
var ServiceDefinition.Configurator.metadata: Map<String, String>?
41+
get() {
42+
return this.metadata()
43+
}
44+
set(value) {
45+
this.metadata(value)
46+
}
47+
48+
/**
49+
* This timer guards against stalled invocations. Once it expires, Restate triggers a graceful
50+
* termination by asking the invocation to suspend (which preserves intermediate progress).
51+
*
52+
* The [abortTimeout] is used to abort the invocation, in case it doesn't
53+
* react to the request to suspend.
54+
*
55+
* This overrides the default inactivity timeout configured in the restate-server for all
56+
* invocations to this service.
57+
*
58+
* *NOTE:* You can set this field only if you register this service against
59+
* restate-server >= 1.4, otherwise the service discovery will fail.
60+
*/
61+
var ServiceDefinition.Configurator.inactivityTimeout: Duration?
62+
get() {
63+
return this.inactivityTimeout()?.toKotlinDuration()
64+
}
65+
set(value) {
66+
this.inactivityTimeout (value?.toJavaDuration())
67+
}
68+
69+
/**
70+
* This timer guards against stalled service/handler invocations that are supposed to terminate.
71+
* The abort timeout is started after the [inactivityTimeout] has expired and
72+
* the service/handler invocation has been asked to gracefully terminate. Once the timer
73+
* expires, it will abort the service/handler invocation.
74+
*
75+
* This timer potentially *interrupts* user code. If the user code needs longer to
76+
* gracefully terminate, then this value needs to be set accordingly.
77+
*
78+
* This overrides the default abort timeout configured in the restate-server for all
79+
* invocations to this service.
80+
*
81+
* *NOTE:* You can set this field only if you register this service against
82+
* restate-server >= 1.4, otherwise the service discovery will fail.
83+
*/
84+
var ServiceDefinition.Configurator.abortTimeout: Duration?
85+
get() {
86+
return this.abortTimeout()?.toKotlinDuration()
87+
}
88+
set(value) {
89+
this.abortTimeout( value?.toJavaDuration())
90+
}
91+
92+
/**
93+
* The retention duration of idempotent requests to this service.
94+
*
95+
* *NOTE:* You can set this field only if you register this service against
96+
* restate-server >= 1.4, otherwise the service discovery will fail.
97+
*/
98+
var ServiceDefinition.Configurator.idempotencyRetention: Duration?
99+
get() {
100+
return this.idempotencyRetention()?.toKotlinDuration()
101+
}
102+
set(value) {
103+
this.idempotencyRetention (value?.toJavaDuration())
104+
}
105+
106+
/**
107+
* The journal retention. When set, this applies to all requests to all handlers of this
108+
* service.
109+
*
110+
* In case the request has an idempotency key, the [idempotencyRetention]
111+
* caps the journal retention time.
112+
*
113+
* *NOTE:* You can set this field only if you register this service against
114+
* restate-server >= 1.4, otherwise the service discovery will fail.
115+
*
116+
* @return this
117+
*/
118+
var ServiceDefinition.Configurator.journalRetention: Duration?
119+
get() {
120+
return this.journalRetention()?.toKotlinDuration()
121+
}
122+
set(value) {
123+
this.journalRetention ( value?.toJavaDuration())
124+
}
125+
126+
/**
127+
* When set to `true`, lazy state will be enabled for all invocations to this service.
128+
* This is relevant only for workflows and virtual objects.
129+
*
130+
* *NOTE:* You can set this field only if you register this service against
131+
* restate-server >= 1.4, otherwise the service discovery will fail.
132+
*/
133+
var ServiceDefinition.Configurator.enableLazyState: Boolean?
134+
get() {
135+
return this.enableLazyState()
136+
}
137+
set(value) {
138+
this.enableLazyState(value)
139+
}
140+
141+
/**
142+
* When set to `true` this service, with all its handlers, cannot be invoked from the
143+
* restate-server HTTP and Kafka ingress, but only from other services.
144+
*
145+
* *NOTE:* You can set this field only if you register this service against
146+
* restate-server >= 1.4, otherwise the service discovery will fail.
147+
*/
148+
var ServiceDefinition.Configurator.ingressPrivate: Boolean?
149+
get() {
150+
return this.ingressPrivate()
151+
}
152+
set(value) {
153+
this.ingressPrivate (value)
154+
}
155+
156+
/**
157+
* Set the acceptable content type when ingesting HTTP requests. Wildcards can be used, e.g.
158+
* `application/*` or `*/*`.
159+
*/
160+
var HandlerDefinition.Configurator.acceptContentType: String?
161+
get() {
162+
return this.acceptContentType()
163+
}
164+
set(value) {
165+
this.acceptContentType(value)
166+
}
167+
168+
/**
169+
* Documentation as shown in the UI, Admin REST API, and the generated OpenAPI documentation of
170+
* this handler.
171+
*/
172+
var HandlerDefinition.Configurator.documentation: String?
173+
get() {
174+
return this.documentation()
175+
}
176+
set(value) {
177+
this.documentation(value)
178+
}
179+
180+
/**
181+
* Handler metadata, as propagated in the Admin REST API.
182+
*/
183+
var HandlerDefinition.Configurator.metadata: Map<String, String>?
184+
get() {
185+
return this.metadata()
186+
}
187+
set(value) {
188+
this.metadata(value)
189+
}
190+
191+
/**
192+
* This timer guards against stalled invocations. Once it expires, Restate triggers a graceful
193+
* termination by asking the invocation to suspend (which preserves intermediate progress).
194+
*
195+
* The [abortTimeout] is used to abort the invocation, in case it doesn't
196+
* react to the request to suspend.
197+
*
198+
* This overrides the inactivity timeout set for the service and the default set in
199+
* restate-server.
200+
*
201+
* *NOTE:* You can set this field only if you register this service against
202+
* restate-server >= 1.4, otherwise the service discovery will fail.
203+
*/
204+
var HandlerDefinition.Configurator.inactivityTimeout: Duration?
205+
get() {
206+
return this.inactivityTimeout()?.toKotlinDuration()
207+
}
208+
set(value) {
209+
this.inactivityTimeout(value?.toJavaDuration())
210+
}
211+
212+
/**
213+
* This timer guards against stalled invocations that are supposed to terminate. The abort
214+
* timeout is started after the [inactivityTimeout] has expired and the
215+
* invocation has been asked to gracefully terminate. Once the timer expires, it will abort the
216+
* invocation.
217+
*
218+
* This timer potentially *interrupts* user code. If the user code needs longer to
219+
* gracefully terminate, then this value needs to be set accordingly.
220+
*
221+
* This overrides the abort timeout set for the service and the default set in
222+
* restate-server.
223+
*
224+
* *NOTE:* You can set this field only if you register this service against
225+
* restate-server >= 1.4, otherwise the service discovery will fail.
226+
*/
227+
var HandlerDefinition.Configurator.abortTimeout: Duration?
228+
get() {
229+
return this.abortTimeout()?.toKotlinDuration()
230+
}
231+
set(value) {
232+
this.abortTimeout(value?.toJavaDuration())
233+
}
234+
235+
/**
236+
* The retention duration of idempotent requests to this service.
237+
*
238+
* *NOTE:* You can set this field only if you register this service against
239+
* restate-server >= 1.4, otherwise the service discovery will fail.
240+
*/
241+
var HandlerDefinition.Configurator.idempotencyRetention: Duration?
242+
get() {
243+
return this.idempotencyRetention()?.toKotlinDuration()
244+
}
245+
set(value) {
246+
this.idempotencyRetention(value?.toJavaDuration())
247+
}
248+
249+
/**
250+
* The retention duration for this workflow handler.
251+
*
252+
* *NOTE:* You can set this field only if you register this service against
253+
* restate-server >= 1.4, otherwise the service discovery will fail.
254+
*/
255+
var HandlerDefinition.Configurator.workflowRetention: Duration?
256+
get() {
257+
return this.workflowRetention()?.toKotlinDuration()
258+
}
259+
set(value) {
260+
this.workflowRetention(value?.toJavaDuration())
261+
}
262+
263+
/**
264+
* The journal retention for invocations to this handler.
265+
*
266+
* In case the request has an idempotency key, the [idempotencyRetention]
267+
* caps the journal retention time.
268+
*
269+
* *NOTE:* You can set this field only if you register this service against
270+
* restate-server >= 1.4, otherwise the service discovery will fail.
271+
*/
272+
var HandlerDefinition.Configurator.journalRetention: Duration?
273+
get() {
274+
return this.journalRetention()?.toKotlinDuration()
275+
}
276+
set(value) {
277+
this.journalRetention(value?.toJavaDuration())
278+
}
279+
280+
/**
281+
* When set to `true` this handler cannot be invoked from the restate-server HTTP and
282+
* Kafka ingress, but only from other services.
283+
*
284+
* *NOTE:* You can set this field only if you register this service against
285+
* restate-server >= 1.4, otherwise the service discovery will fail.
286+
*/
287+
var HandlerDefinition.Configurator.ingressPrivate: Boolean?
288+
get() {
289+
return this.ingressPrivate()
290+
}
291+
set(value) {
292+
this.ingressPrivate(value)
293+
}
294+
295+
/**
296+
* When set to `true`, lazy state will be enabled for all invocations to this handler.
297+
* This is relevant only for workflows and virtual objects.
298+
*
299+
* *NOTE:* You can set this field only if you register this service against
300+
* restate-server >= 1.4, otherwise the service discovery will fail.
301+
*/
302+
var HandlerDefinition.Configurator.enableLazyState: Boolean?
303+
get() {
304+
return this.enableLazyState()
305+
}
306+
set(value) {
307+
this.enableLazyState(value)
308+
}

0 commit comments

Comments
 (0)