Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ build
.factorypath
kls_database.db
.kotlin

.restate
36 changes: 36 additions & 0 deletions examples/src/main/java/my/restate/sdk/examples/Greeter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.Context;
import dev.restate.sdk.annotation.Handler;
import dev.restate.sdk.annotation.Service;
import dev.restate.sdk.endpoint.Endpoint;
import dev.restate.sdk.http.vertx.RestateHttpServer;
import java.time.Duration;

@Service
public class Greeter {

public record Greeting(String name) {}

public record GreetingResponse(String message) {}

@Handler
public GreetingResponse greet(Context ctx, Greeting req) {
// Respond to caller
return new GreetingResponse("You said hi to " + req.name + "!");
}

public static void main(String[] args) {
RestateHttpServer.listen(
Endpoint.bind(
new Greeter(), configurator -> configurator.inactivityTimeout(Duration.ofSeconds(1))));
}
}
28 changes: 5 additions & 23 deletions sdk-core/src/main/java/dev/restate/sdk/core/ProtocolException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ public class ProtocolException extends RuntimeException {
static final int NOT_FOUND_CODE = 404;
public static final int UNSUPPORTED_MEDIA_TYPE_CODE = 415;
public static final int INTERNAL_CODE = 500;
static final int JOURNAL_MISMATCH_CODE = 570;
public static final int JOURNAL_MISMATCH_CODE = 570;
static final int PROTOCOL_VIOLATION_CODE = 571;
static final int CLOSED_CODE = 598;

@SuppressWarnings("StaticAssignmentOfThrowable")
static final ProtocolException CLOSED = new ProtocolException("Invocation closed");
static final ProtocolException CLOSED = new ProtocolException("Invocation closed", CLOSED_CODE);

private final int code;

Expand Down Expand Up @@ -54,10 +55,10 @@ public static ProtocolException unexpectedMessage(
PROTOCOL_VIOLATION_CODE);
}

public static ProtocolException unexpectedMessage(String type, MessageLite actual) {
public static ProtocolException unexpectedMessage(String expected, MessageLite actual) {
return new ProtocolException(
"Unexpected message type received from the runtime. Expected: '"
+ type
+ expected
+ "', Actual: '"
+ actual.getClass().getCanonicalName()
+ "'",
Expand All @@ -69,25 +70,6 @@ static ProtocolException unexpectedNotificationVariant(Class<?> clazz) {
"Unexpected notification variant " + clazz.getName(), PROTOCOL_VIOLATION_CODE);
}

public static ProtocolException commandDoesNotMatch(MessageLite expected, MessageLite actual) {
return new ProtocolException(
"Replayed journal doesn't match the handler code.\nThe handler code generated: "
+ expected
+ "\nwhile the replayed entry is: "
+ actual,
JOURNAL_MISMATCH_CODE);
}

public static ProtocolException commandClassDoesNotMatch(
Class<? extends MessageLite> expectedClazz, MessageLite actual) {
return new ProtocolException(
"Replayed journal doesn't match the handler code.\nThe handler code generated: "
+ expectedClazz.getName()
+ "\nwhile the replayed entry is: "
+ actual,
JOURNAL_MISMATCH_CODE);
}

public static ProtocolException commandsToProcessIsEmpty() {
return new ProtocolException("Expecting command queue to be non empty", JOURNAL_MISMATCH_CODE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ final class ClosedState implements State {

@Override
public void hitError(
Throwable throwable, @Nullable Duration nextRetryDelay, StateContext stateContext) {
Throwable throwable,
@Nullable CommandRelationship relatedCommand,
@Nullable Duration nextRetryDelay,
StateContext stateContext) {
// Ignore, as we closed already
}

Expand Down
Loading