Skip to content

Commit

Permalink
A few small fixes (#489)
Browse files Browse the repository at this point in the history
* Small improvements

* Small improvements
  • Loading branch information
gvdongen authored Nov 29, 2024
1 parent 8a37a84 commit 8ae9f2f
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions code_snippets/java/src/main/java/develop/MyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
@Service
public class MyService {
@Handler
public String myHandler(Context ctx, String input) {
return "my-output";
public String myHandler(Context ctx, String greeting) {
return greeting + "!";
}

public static void main(String[] args) {
Expand Down
6 changes: 4 additions & 2 deletions code_snippets/java/src/main/java/develop/MyVirtualObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
public class MyVirtualObject {

@Handler
public String myHandler(ObjectContext ctx, String input) {
return "my-output";
public String myHandler(ObjectContext ctx, String greeting) {
String objectId = ctx.key();

return greeting + " " + objectId + "!";
}

@Shared
Expand Down
4 changes: 2 additions & 2 deletions code_snippets/kotlin/src/main/kotlin/develop/MyService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import dev.restate.sdk.kotlin.Context
@Service
class MyService {
@Handler
suspend fun myHandler(ctx: Context, input: String): String {
return "my-output"
suspend fun myHandler(ctx: Context, greeting: String): String {
return "$greeting!"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import dev.restate.sdk.kotlin.SharedObjectContext
class MyVirtualObject {

@Handler
suspend fun myHandler(ctx: ObjectContext, input: String): String {
return "my-output"
suspend fun myHandler(ctx: ObjectContext, greeting: String): String {
val objectKey = ctx.key()

return "$greeting $objectKey!"
}

@Shared
Expand Down
1 change: 1 addition & 0 deletions code_snippets/ts/src/develop/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const myWorkflow = restate.workflow({

interactWithWorkflow: async (ctx: WorkflowSharedContext) => {
// implement interaction logic here
// e.g. resolve a promise that the workflow is waiting on
},
},
});
Expand Down
5 changes: 3 additions & 2 deletions docs/develop/go/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ CODE_LOAD::go/develop/myvirtualobject/main.go
- The first argument of each handler must be the `ObjectContext` parameter.
Handlers with the `ObjectContext` parameter can write to the K/V state store.
Only one handler can be active at a time, to ensure consistency.
- You can retrieve the key of the object you are in via `restate.Key(ctx)`.
- If you want to have a handler that executes concurrently to the others and
doesn't have write access to the K/V state, instead use the
`ObjectSharedContext`. For example, you can use these handlers to read K/V
state, or interact with the blocking handler.
`ObjectSharedContext`. You can use these handlers, for example, to read K/V state and expose it to the outside world, or to interact with the blocking handler (e.g. resolve awakeables).


<Admonition type="tip" title="Prefer to start with a service definition?">
The Go SDK also supports defining handlers and input/output types using
Expand Down
7 changes: 5 additions & 2 deletions docs/develop/java/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Handlers can either be part of a [Service](/concepts/services#services-1), a [Vi
- Handlers have the `Context` parameter ([JavaDocs](https://javadoc.io/doc/dev.restate/sdk-api/latest/dev/restate/sdk/Context.html)) as the first parameter.
Within the handler, you use the `Context` to interact with Restate.
The SDK stores the actions you do on the context in the Restate journal to make them durable.
- You can retrieve the key of the object you are in via `ctx.key()`.
- The input parameter (at most one) and return type are optional and can be of any type, as long as they are serializable/deserializable using [Jackson Databind](https://github.com/FasterXML/jackson) ([see serialization docs](/develop/java/serialization)).
- The service will be reachable under the simple class name `MyService`. You can override it by using the annotation field `name`.
- Create an endpoint and bind the service(s) to the Restate endpoint. Listen on the specified port (default `9080`) for connections and requests.
Expand Down Expand Up @@ -67,8 +68,9 @@ Handlers can either be part of a [Service](/concepts/services#services-1), a [Vi
- The first argument of the handler must be the `ObjectContext` parameter ([JavaDocs](https://javadoc.io/doc/dev.restate/sdk-api/latest/dev/restate/sdk/ObjectContext.html)).
Handlers with the `ObjectContext` parameter can write to the K/V state store.
Only one handler can be active at a time, to ensure consistency.
- You can retrieve the key of the object you are in via `ctx.key()`.
- If you want to have a handler that executes concurrently to the others and doesn't have write access to the K/V state, use the `@Shared` annotation and the `SharedObjectContext`.
For example, you can use these handlers to read K/V state, or interact with the blocking handler.
You can use these handlers, for example, to read K/V state and expose it to the outside world, or to interact with the blocking handler (e.g. resolve awakeables).
</TabItem>
<TabItem value="kotlin" label="Kotlin">
```kotlin
Expand All @@ -79,8 +81,9 @@ Handlers can either be part of a [Service](/concepts/services#services-1), a [Vi
- The first argument of the handler must be the `ObjectContext` parameter ([JavaDocs](https://javadoc.io/doc/dev.restate/sdk-api/latest/dev/restate/sdk/ObjectContext.html)).
Handlers with the `ObjectContext` parameter can write to the K/V state store.
Only one handler can be active at a time, to ensure consistency.
- You can retrieve the key of the object you are in via `ctx.key()`.
- If you want to have a handler that executes concurrently to the others and doesn't have write access to the K/V state, use the `@Shared` annotation and the `SharedObjectContext`.
For example, you can use these handlers to read K/V state, or interact with the blocking handler.
You can use these handlers, for example, to read K/V state and expose it to the outside world, or to interact with the blocking handler (e.g. resolve awakeables).
</TabItem>
</Tabs>

Expand Down
2 changes: 1 addition & 1 deletion docs/develop/java/workflows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Have a look at the code example to get a better understanding of how workflows a
```shell !result
curl localhost:8080/SignupWorkflow/someone/run \
-H 'content-type: application/json' \
-d '{"email": "[email protected]"}'
-d '"[email protected]"'
```
</TextAndCode>

Expand Down
3 changes: 2 additions & 1 deletion docs/develop/python/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ CODE_LOAD::python/src/develop/my_virtual_object.py
- The first argument of each handler must be the `ObjectContext` parameter.
Handlers with the `ObjectContext` parameter can write to the K/V state store.
Only one handler can be active at a time, to ensure consistency.
- You can retrieve the key of the object you are in via `ctx.key()`.
- If you want to have a handler that executes concurrently to the others and doesn't have write access to the K/V state, add `kind="shared"` as annotation argument and use the `ObjectSharedContext`.
For example, you can use these handlers to read K/V state, or interact with the blocking handler.
You can use these handlers, for example, to read K/V state and expose it to the outside world, or to interact with the blocking handler (e.g. resolve awakeables).

## Workflows

Expand Down
5 changes: 3 additions & 2 deletions docs/develop/ts/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ CODE_LOAD::ts/src/develop/my_virtual_object.ts
- Specify that you want to create a Virtual Object via `restate.object`.
- The first argument of each handler must be the `ObjectContext` parameter.
Handlers with the `ObjectContext` parameter can write to the K/V state store.
Only one handler can be active at a time, to ensure consistency.
Only one handler can be active at a time per object, to ensure consistency.
- You can retrieve the key of the object you are in via `ctx.key`.
- If you want to have a handler that executes concurrently to the others and doesn't have write access to the K/V state, wrap the handler in `handlers.object.shared` and use the `ObjectSharedContext`.
For example, you can use these handlers to read K/V state, or interact with the blocking handler.
You can use these handlers, for example, to read K/V state and expose it to the outside world, or to interact with the blocking handler (e.g. resolve awakeables).

## Workflows

Expand Down

0 comments on commit 8ae9f2f

Please sign in to comment.