Skip to content
Open
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
25 changes: 25 additions & 0 deletions powertools-batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
<artifactId>sdk-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.crac</groupId>
<artifactId>crac</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down Expand Up @@ -94,4 +98,25 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>generate-classesloaded-file</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
-Xlog:class+load=info:classesloaded.txt
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

package software.amazon.lambda.powertools.batch;

import org.crac.Context;
import org.crac.Core;
import org.crac.Resource;
import software.amazon.lambda.powertools.batch.builder.DynamoDbBatchMessageHandlerBuilder;
import software.amazon.lambda.powertools.batch.builder.KinesisBatchMessageHandlerBuilder;
import software.amazon.lambda.powertools.batch.builder.SqsBatchMessageHandlerBuilder;
import software.amazon.lambda.powertools.common.internal.ClassPreLoader;

/**
* A builder-style interface we can use to build batch processing handlers for SQS, Kinesis Streams,
Expand All @@ -27,7 +31,15 @@
*
* @see <a href="https://docs.powertools.aws.dev/lambda/java/utilities/batch/">Powertools for AWS Lambda (Java) Batch Documentation</a>
**/
public class BatchMessageHandlerBuilder {
public class BatchMessageHandlerBuilder implements Resource {

// Dummy instance to register BatchMessageHandlerBuilder with CRaC
private static final BatchMessageHandlerBuilder INSTANCE = new BatchMessageHandlerBuilder();

// Static block to ensure CRaC registration happens at class loading time
static {
Core.getGlobalContext().register(INSTANCE);
}

/**
* Build an SQS-batch message handler.
Expand Down Expand Up @@ -55,4 +67,14 @@ public DynamoDbBatchMessageHandlerBuilder withDynamoDbBatchHandler() {
public KinesisBatchMessageHandlerBuilder withKinesisBatchHandler() {
return new KinesisBatchMessageHandlerBuilder();
}

@Override
public void beforeCheckpoint(Context<? extends Resource> context) throws Exception {
ClassPreLoader.preloadClasses();
}

@Override
public void afterRestore(Context<? extends Resource> context) throws Exception {
// No action needed after restore
}
}
Loading