Created
February 17, 2024 10:48
-
-
Save civic/a6e6f85f43596b3740e7bc75bfc1073f to your computer and use it in GitHub Desktop.
StudyLambda1.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
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