Skip to content

Commit 65e7729

Browse files
Rename UnkeyedContext to Context (#220)
1 parent 5e4c94a commit 65e7729

File tree

14 files changed

+68
-70
lines changed

14 files changed

+68
-70
lines changed

examples/src/main/java/my/restate/sdk/examples/Loan.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import com.fasterxml.jackson.annotation.JsonCreator;
1212
import com.fasterxml.jackson.annotation.JsonProperty;
13-
import dev.restate.sdk.UnkeyedContext;
13+
import dev.restate.sdk.Context;
1414
import dev.restate.sdk.annotation.Service;
1515
import dev.restate.sdk.annotation.ServiceType;
1616
import dev.restate.sdk.annotation.Shared;
@@ -221,7 +221,7 @@ private static void askHumanApproval(String workflowKey) throws InterruptedExcep
221221

222222
private static class MockBank extends BankRestate.BankRestateImplBase {
223223
@Override
224-
public TransferResult transfer(UnkeyedContext context, TransferRequest request)
224+
public TransferResult transfer(Context context, TransferRequest request)
225225
throws TerminalException {
226226
boolean shouldAccept = context.random().nextInt(3) != 1;
227227
if (shouldAccept) {

protoc-gen-restate/src/main/java/dev/restate/sdk/protocgen/RestateGen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private ServiceContext buildServiceContext(
124124
// Resolve context type
125125
serviceContext.contextType =
126126
serviceProto.getOptions().getExtension(Ext.serviceType) == ServiceType.UNKEYED
127-
? "UnkeyedContext"
127+
? "Context"
128128
: "KeyedContext";
129129

130130
// Resolve javadoc

protoc-gen-restate/src/main/resources/javaStub.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
package {{packageName}};
33
{{/packageName}}
44

5-
import dev.restate.sdk.UnkeyedContext;
5+
import dev.restate.sdk.Context;
66
import dev.restate.sdk.KeyedContext;
77
import dev.restate.sdk.Awaitable;
88
import dev.restate.sdk.common.syscalls.Syscalls;
@@ -18,15 +18,15 @@ public class {{className}} {
1818
/**
1919
* Create a new client from the given {@link KeyedContext}.
2020
*/
21-
public static {{serviceName}}RestateClient newClient(UnkeyedContext ctx) {
21+
public static {{serviceName}}RestateClient newClient(Context ctx) {
2222
return new {{serviceName}}RestateClient(ctx);
2323
}
2424

2525
{{{apidoc}}}
2626
public static final class {{serviceName}}RestateClient {
27-
private final UnkeyedContext ctx;
27+
private final Context ctx;
2828
29-
{{serviceName}}RestateClient(UnkeyedContext ctx) {
29+
{{serviceName}}RestateClient(Context ctx) {
3030
this.ctx = ctx;
3131
}
3232

@@ -51,9 +51,9 @@ public class {{className}} {
5151
}
5252

5353
public static final class {{serviceName}}RestateOneWayClient {
54-
private final UnkeyedContext ctx;
54+
private final Context ctx;
5555
56-
{{serviceName}}RestateOneWayClient(UnkeyedContext ctx) {
56+
{{serviceName}}RestateOneWayClient(Context ctx) {
5757
this.ctx = ctx;
5858
}
5959

@@ -68,10 +68,10 @@ public class {{className}} {
6868
}
6969

7070
public static final class {{serviceName}}RestateDelayedClient {
71-
private final UnkeyedContext ctx;
71+
private final Context ctx;
7272
private final Duration delay;
7373
74-
{{serviceName}}RestateDelayedClient(UnkeyedContext ctx, Duration delay) {
74+
{{serviceName}}RestateDelayedClient(Context ctx, Duration delay) {
7575
this.ctx = ctx;
7676
this.delay = delay;
7777
}

protoc-gen-restate/src/main/resources/ktStub.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
package {{packageName}};
33
{{/packageName}}
44

5-
import dev.restate.sdk.kotlin.UnkeyedContext;
5+
import dev.restate.sdk.kotlin.Context;
66
import dev.restate.sdk.kotlin.KeyedContext;
77
import dev.restate.sdk.kotlin.Awaitable;
88
import dev.restate.sdk.kotlin.RestateKtService;
@@ -18,14 +18,14 @@ import kotlin.time.Duration
1818
public object {{className}} {
1919
2020
/**
21-
* Create a new client from the given [UnkeyedContext].
21+
* Create a new client from the given [Context].
2222
*/
23-
fun newClient(ctx: UnkeyedContext): {{serviceName}}RestateKtClient {
23+
fun newClient(ctx: Context): {{serviceName}}RestateKtClient {
2424
return {{serviceName}}RestateKtClient(ctx);
2525
}
2626

2727
{{{javadoc}}}
28-
public class {{serviceName}}RestateKtClient(private val ctx: UnkeyedContext) {
28+
public class {{serviceName}}RestateKtClient(private val ctx: Context) {
2929
// Create a variant of this client to execute oneWay calls.
3030
public fun oneWay(): {{serviceName}}RestateKtOneWayClient {
3131
return {{serviceName}}RestateKtOneWayClient(ctx);
@@ -46,7 +46,7 @@ public object {{className}} {
4646
{{/methods}}
4747
}
4848

49-
public class {{serviceName}}RestateKtOneWayClient(private val ctx: UnkeyedContext) {
49+
public class {{serviceName}}RestateKtOneWayClient(private val ctx: Context) {
5050
{{#methods}}
5151
{{#deprecated}}@Deprecated{{/deprecated}}
5252
{{{javadoc}}}
@@ -57,7 +57,7 @@ public object {{className}} {
5757
{{/methods}}
5858
}
5959

60-
public class {{serviceName}}RestateKtDelayedClient(private val ctx: UnkeyedContext, private val delay: Duration) {
60+
public class {{serviceName}}RestateKtDelayedClient(private val ctx: Context, private val delay: Duration) {
6161
{{#methods}}
6262
{{#deprecated}}@Deprecated{{/deprecated}}
6363
{{{javadoc}}}

sdk-api-gen/src/main/resources/templates/RestateClient.hbs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import dev.restate.sdk.common.StateKey;
44
import dev.restate.sdk.common.Serde;
55
import dev.restate.sdk.Awaitable;
6-
import dev.restate.sdk.UnkeyedContext;
6+
import dev.restate.sdk.Context;
77
import dev.restate.sdk.workflow.impl.WorkflowCodegenUtil;
88
import java.util.Optional;
99
import java.time.Duration;
@@ -21,36 +21,36 @@ public class {{className}}RestateClient {
2121
{{^outputEmpty}}private static final Serde<{{{outputFqcn}}}> {{outputSerdeFieldName}} = {{{outputSerdeDecl}}};{{/outputEmpty}}
2222
{{/methods}}
2323

24-
private final UnkeyedContext restateContext;
24+
private final Context ctx;
2525
private final String workflowKey;
2626

27-
public {{className}}RestateClient(UnkeyedContext restateContext, String workflowKey) {
28-
this.restateContext = restateContext;
27+
public {{className}}RestateClient(Context ctx, String workflowKey) {
28+
this.ctx = ctx;
2929
this.workflowKey = workflowKey;
3030
}
3131

3232
{{#methods}}{{#if isWorkflow}}
3333
public Awaitable<dev.restate.sdk.workflow.generated.WorkflowExecutionState> submit({{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
34-
return WorkflowCodegenUtil.RestateClient.submit(restateContext, WF_SUBMIT_METHOD_DESC, workflowKey, {{#if inputEmpty}}null{{else}}WorkflowCodegenUtil.tToValue({{inputSerdeFieldName}}, req){{/if}});
34+
return WorkflowCodegenUtil.RestateClient.submit(ctx, WF_SUBMIT_METHOD_DESC, workflowKey, {{#if inputEmpty}}null{{else}}WorkflowCodegenUtil.tToValue({{inputSerdeFieldName}}, req){{/if}});
3535
}
3636

3737
public Awaitable<Boolean> isCompleted() {
38-
return WorkflowCodegenUtil.RestateClient.isCompleted(restateContext, WF_MANAGER_GET_OUTPUT_METHOD_DESC, workflowKey);
38+
return WorkflowCodegenUtil.RestateClient.isCompleted(ctx, WF_MANAGER_GET_OUTPUT_METHOD_DESC, workflowKey);
3939
}
4040

4141
{{^outputEmpty}}
4242
public Awaitable<Optional<{{{outputFqcn}}}>> getOutput() {
43-
return WorkflowCodegenUtil.RestateClient.getOutput(restateContext, WF_MANAGER_GET_OUTPUT_METHOD_DESC, workflowKey, {{outputSerdeFieldName}});
43+
return WorkflowCodegenUtil.RestateClient.getOutput(ctx, WF_MANAGER_GET_OUTPUT_METHOD_DESC, workflowKey, {{outputSerdeFieldName}});
4444
}{{/outputEmpty}}
4545
{{/if}}{{/methods}}
4646

4747
public <T> Awaitable<Optional<T>> getState(StateKey<T> key) {
48-
return WorkflowCodegenUtil.RestateClient.getState(restateContext, WF_MANAGER_GET_STATE_METHOD_DESC, workflowKey, key);
48+
return WorkflowCodegenUtil.RestateClient.getState(ctx, WF_MANAGER_GET_STATE_METHOD_DESC, workflowKey, key);
4949
}
5050

5151
{{#methods}}{{#if isShared}}
5252
public {{#if outputEmpty}}Awaitable<Void>{{else}}Awaitable<{{{outputFqcn}}}>{{/if}} {{name}}({{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
53-
Awaitable<com.google.protobuf.Value> response = WorkflowCodegenUtil.RestateClient.invokeShared(restateContext, {{descFieldName}}, workflowKey, {{#if inputEmpty}}null{{else}}WorkflowCodegenUtil.tToValue({{inputSerdeFieldName}}, req){{/if}});
53+
Awaitable<com.google.protobuf.Value> response = WorkflowCodegenUtil.RestateClient.invokeShared(ctx, {{descFieldName}}, workflowKey, {{#if inputEmpty}}null{{else}}WorkflowCodegenUtil.tToValue({{inputSerdeFieldName}}, req){{/if}});
5454
{{#if outputEmpty}}
5555
return response.map(v -> { return null; });
5656
{{else}}
@@ -71,7 +71,7 @@ public class {{className}}RestateClient {
7171

7272
{{#methods}}{{#if isShared}}
7373
public void {{name}}({{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
74-
WorkflowCodegenUtil.RestateClient.invokeSharedOneWay(restateContext, {{descFieldName}}, workflowKey, {{#if inputEmpty}}null{{else}}WorkflowCodegenUtil.tToValue({{inputSerdeFieldName}}, req){{/if}});
74+
WorkflowCodegenUtil.RestateClient.invokeSharedOneWay(ctx, {{descFieldName}}, workflowKey, {{#if inputEmpty}}null{{else}}WorkflowCodegenUtil.tToValue({{inputSerdeFieldName}}, req){{/if}});
7575
}
7676
{{/if}}{{/methods}}
7777

@@ -87,7 +87,7 @@ public class {{className}}RestateClient {
8787

8888
{{#methods}}{{#if isShared}}
8989
public void {{name}}({{^inputEmpty}}{{{inputFqcn}}} req{{/inputEmpty}}) {
90-
WorkflowCodegenUtil.RestateClient.invokeSharedDelayed(restateContext, {{descFieldName}}, workflowKey, {{#if inputEmpty}}null{{else}}WorkflowCodegenUtil.tToValue({{inputSerdeFieldName}}, req){{/if}}, delay);
90+
WorkflowCodegenUtil.RestateClient.invokeSharedDelayed(ctx, {{descFieldName}}, workflowKey, {{#if inputEmpty}}null{{else}}WorkflowCodegenUtil.tToValue({{inputSerdeFieldName}}, req){{/if}}, delay);
9191
}
9292
{{/if}}{{/methods}}
9393

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import kotlin.time.Duration
3232
* NOTE: This interface MUST NOT be accessed concurrently since it can lead to different orderings
3333
* of user actions, corrupting the execution of the invocation.
3434
*/
35-
sealed interface UnkeyedContext {
35+
sealed interface Context {
3636

3737
/**
3838
* Causes the current execution of the function invocation to sleep for the given duration.
@@ -191,26 +191,25 @@ sealed interface UnkeyedContext {
191191
companion object {
192192

193193
/**
194-
* Create a [UnkeyedContext]. This will look up the thread-local/async-context storage for the
194+
* Create a [Context]. This will look up the thread-local/async-context storage for the
195195
* underlying context implementation, so make sure to call it always from the same context where
196196
* the service is executed.
197197
*/
198-
fun current(): UnkeyedContext {
198+
fun current(): Context {
199199
return fromSyscalls(Syscalls.current())
200200
}
201201

202202
/** Build a context from the underlying [Syscalls] object. */
203-
fun fromSyscalls(syscalls: Syscalls): UnkeyedContext {
203+
fun fromSyscalls(syscalls: Syscalls): Context {
204204
return ContextImpl(syscalls)
205205
}
206206
}
207207
}
208208

209209
/**
210-
* This interface extends [UnkeyedContext] adding access to the service instance key-value state
211-
* storage.
210+
* This interface extends [Context] adding access to the service instance key-value state storage.
212211
*/
213-
sealed interface KeyedContext : UnkeyedContext {
212+
sealed interface KeyedContext : Context {
214213

215214
/**
216215
* Gets the state stored under key, deserializing the raw value using the registered

sdk-api-kotlin/src/test/kotlin/dev/restate/sdk/kotlin/RestateCodegenTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@ class RestateCodegenTest : RestateCodegenTestSuite() {
3030
}
3131

3232
private class Codegen : CodegenRestateKtImplBase() {
33-
override suspend fun emptyInput(context: UnkeyedContext): MyMessage {
33+
override suspend fun emptyInput(context: Context): MyMessage {
3434
val client = CodegenRestateKt.newClient(context)
3535
return client.emptyInput().await()
3636
}
3737

38-
override suspend fun emptyOutput(context: UnkeyedContext, request: MyMessage) {
38+
override suspend fun emptyOutput(context: Context, request: MyMessage) {
3939
val client = CodegenRestateKt.newClient(context)
4040
client.emptyOutput(request).await()
4141
}
4242

43-
override suspend fun emptyInputOutput(context: UnkeyedContext) {
43+
override suspend fun emptyInputOutput(context: Context) {
4444
val client = CodegenRestateKt.newClient(context)
4545
client.emptyInputOutput().await()
4646
}
4747

48-
override suspend fun oneWay(context: UnkeyedContext, request: MyMessage): MyMessage {
48+
override suspend fun oneWay(context: Context, request: MyMessage): MyMessage {
4949
val client = CodegenRestateKt.newClient(context)
5050
return client._oneWay(request).await()
5151
}
5252

53-
override suspend fun delayed(context: UnkeyedContext, request: MyMessage): MyMessage {
53+
override suspend fun delayed(context: Context, request: MyMessage): MyMessage {
5454
val client = CodegenRestateKt.newClient(context)
5555
return client._delayed(request).await()
5656
}

sdk-api/src/main/java/dev/restate/sdk/UnkeyedContext.java renamed to sdk-api/src/main/java/dev/restate/sdk/Context.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* orderings of user actions, corrupting the execution of the invocation.
3131
*/
3232
@NotThreadSafe
33-
public interface UnkeyedContext {
33+
public interface Context {
3434

3535
/**
3636
* Invoke another Restate service method.
@@ -185,12 +185,12 @@ default void sideEffect(ThrowingRunnable runnable) throws TerminalException {
185185
* underlying context implementation, so make sure to call it always from the same context where
186186
* the service is executed.
187187
*/
188-
static UnkeyedContext current() {
188+
static Context current() {
189189
return fromSyscalls(Syscalls.current());
190190
}
191191

192192
/** Build a RestateContext from the underlying {@link Syscalls} object. */
193-
static UnkeyedContext fromSyscalls(Syscalls syscalls) {
193+
static Context fromSyscalls(Syscalls syscalls) {
194194
return new ContextImpl(syscalls);
195195
}
196196
}

sdk-api/src/main/java/dev/restate/sdk/GrpcChannelAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
* <p>Keep in mind that this channel should be used only with generated blocking stubs.
1919
*/
2020
public class GrpcChannelAdapter extends Channel {
21-
private final UnkeyedContext ctx;
21+
private final Context ctx;
2222

23-
GrpcChannelAdapter(UnkeyedContext ctx) {
23+
GrpcChannelAdapter(Context ctx) {
2424
this.ctx = ctx;
2525
}
2626

sdk-api/src/main/java/dev/restate/sdk/KeyedContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
import javax.annotation.concurrent.NotThreadSafe;
1717

1818
/**
19-
* This interface extends {@link UnkeyedContext} adding access to the service instance key-value
20-
* state storage
19+
* This interface extends {@link Context} adding access to the service instance key-value state
20+
* storage
2121
*
22-
* @see UnkeyedContext
22+
* @see Context
2323
*/
2424
@NotThreadSafe
25-
public interface KeyedContext extends UnkeyedContext {
25+
public interface KeyedContext extends Context {
2626

2727
/**
2828
* Gets the state stored under key, deserializing the raw value using the {@link Serde} in the

0 commit comments

Comments
 (0)