-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Codegen for Handler API * Reuse code between workflow and sdk-api * Use ServiceLoader to load the ServiceAdapter * Add explicit key passing * Put in place basic stuff for the new manifest * Renamings all around.
- Loading branch information
1 parent
b8f05e2
commit bb0612e
Showing
112 changed files
with
2,936 additions
and
924 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
examples/src/main/java/my/restate/sdk/examples/Counter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package my.restate.sdk.examples; | ||
|
||
import dev.restate.sdk.ObjectContext; | ||
import dev.restate.sdk.annotation.Handler; | ||
import dev.restate.sdk.annotation.VirtualObject; | ||
import dev.restate.sdk.common.CoreSerdes; | ||
import dev.restate.sdk.common.StateKey; | ||
import dev.restate.sdk.http.vertx.RestateHttpEndpointBuilder; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
@VirtualObject | ||
public class Counter { | ||
|
||
private static final Logger LOG = LogManager.getLogger(Counter.class); | ||
|
||
private static final StateKey<Long> TOTAL = StateKey.of("total", CoreSerdes.JSON_LONG); | ||
|
||
@Handler | ||
public void reset(ObjectContext ctx) { | ||
ctx.clearAll(); | ||
} | ||
|
||
@Handler | ||
public void add(ObjectContext ctx, Long request) { | ||
long currentValue = ctx.get(TOTAL).orElse(0L); | ||
long newValue = currentValue + request; | ||
ctx.set(TOTAL, newValue); | ||
} | ||
|
||
@Handler | ||
public Long get(ObjectContext ctx) { | ||
return ctx.get(TOTAL).orElse(0L); | ||
} | ||
|
||
@Handler | ||
public CounterUpdateResult getAndAdd(ObjectContext ctx, Long request) { | ||
LOG.info("Invoked get and add with " + request); | ||
|
||
long currentValue = ctx.get(TOTAL).orElse(0L); | ||
long newValue = currentValue + request; | ||
ctx.set(TOTAL, newValue); | ||
|
||
return new CounterUpdateResult(newValue, currentValue); | ||
} | ||
|
||
public static void main(String[] args) { | ||
RestateHttpEndpointBuilder.builder().with(new Counter()).buildAndListen(); | ||
} | ||
|
||
public static class CounterUpdateResult { | ||
private final Long newValue; | ||
private final Long oldValue; | ||
|
||
public CounterUpdateResult(Long newValue, Long oldValue) { | ||
this.newValue = newValue; | ||
this.oldValue = oldValue; | ||
} | ||
|
||
public Long getNewValue() { | ||
return newValue; | ||
} | ||
|
||
public Long getOldValue() { | ||
return oldValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.