Skip to content

Instantly share code, notes, and snippets.

@civic
Created February 17, 2024 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save civic/a6e6f85f43596b3740e7bc75bfc1073f to your computer and use it in GitHub Desktop.
Save civic/a6e6f85f43596b3740e7bc75bfc1073f to your computer and use it in GitHub Desktop.
StudyLambda1.java ランタイムフック実装
package com.example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
import org.crac.Core;
import org.crac.Resource;
import java.util.UUID;
public class StudyLambda1 implements RequestHandler<SQSEvent, Void>, Resource {
private static final String hogeSeed;
static {
hogeSeed = UUID.randomUUID().toString();
}
public StudyLambda1() {
System.out.println("constructor");
Core.getGlobalContext().register(this);
}
public Void handleRequest(SQSEvent input, Context context) {
System.out.printf("function start. input=[%s] hogeSeed=[%s]%n",
input.getRecords().get(0).getBody(), hogeSeed);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("function finish.");
return null;
}
@Override
public void beforeCheckpoint(org.crac.Context<? extends Resource> context) throws Exception {
System.out.printf("beforeCheckpoint. hogeSeed=[%s]%n", hogeSeed);
}
@Override
public void afterRestore(org.crac.Context<? extends Resource> context) throws Exception {
System.out.println("afterRestore");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment