Package com.amazonaws.serverless.proxy
Class AsyncInitializationWrapper
java.lang.Object
com.amazonaws.serverless.proxy.InitializationWrapper
com.amazonaws.serverless.proxy.AsyncInitializationWrapper
An async implementation of the
InitializationWrapper interface. This initializer calls the
InitializableLambdaContainerHandler.initialize() in a separate thread. Then uses a latch to wait for the maximum Lambda
initialization time of 10 seconds, if the initialize method takes longer than 10 seconds to return, the
start(InitializableLambdaContainerHandler) returns control to the caller and lets the initialization thread continue in
the background. The LambdaContainerHandler.proxy(Object, Context) automatically waits for the latch of the
initializer to be released.
The constructor of this class expects an epoch long. This is meant to be as close as possible to the time the Lambda
function actually started. In most cases, the first action in the constructor of the handler class should be to populate
this long value (Instant.now().toEpochMs();). This class uses the value to estimate how much of the init 10
seconds has already been used up.-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of the async initializer using the actual JVM start time as the starting point to measure the 10 seconds timeout.AsyncInitializationWrapper(long startTime) Creates a new instance of the async initializer. -
Method Summary
Modifier and TypeMethodDescriptionlongAsynchronous implementations of the framework should return a latch that the container handler can use to decide whether it can start handling events.voidstart(InitializableLambdaContainerHandler handler) This is the main entry point.
-
Constructor Details
-
AsyncInitializationWrapper
public AsyncInitializationWrapper(long startTime) Creates a new instance of the async initializer.- Parameters:
startTime- The epoch ms start time of the Lambda function, this should be measured as close as possible to the initialization of the function.
-
AsyncInitializationWrapper
public AsyncInitializationWrapper()Creates a new instance of the async initializer using the actual JVM start time as the starting point to measure the 10 seconds timeout.
-
-
Method Details
-
start
public void start(InitializableLambdaContainerHandler handler) throws ContainerInitializationException Description copied from class:InitializationWrapperThis is the main entry point. Container handler builder and the staticgetAwsProxyHandler()methods of the various implementations will call this to initialize the underlying framework- Overrides:
startin classInitializationWrapper- Parameters:
handler- The container handler to be initializer- Throws:
ContainerInitializationException- If anything goes wrong during container initialization.
-
getActualStartTimeMs
public long getActualStartTimeMs() -
getInitializationLatch
Description copied from class:InitializationWrapperAsynchronous implementations of the framework should return a latch that the container handler can use to decide whether it can start handling events. Synchronous implementations of this interface should returnnull.- Overrides:
getInitializationLatchin classInitializationWrapper- Returns:
- An initialized latch if the underlying container is starting in a separate thread, null otherwise.
-