Class AsyncInitializationWrapper

java.lang.Object
com.amazonaws.serverless.proxy.InitializationWrapper
com.amazonaws.serverless.proxy.AsyncInitializationWrapper

public class AsyncInitializationWrapper extends InitializationWrapper
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 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

      Description copied from class: InitializationWrapper
      This is the main entry point. Container handler builder and the static getAwsProxyHandler() methods of the various implementations will call this to initialize the underlying framework
      Overrides:
      start in class InitializationWrapper
      Parameters:
      handler - The container handler to be initializer
      Throws:
      ContainerInitializationException - If anything goes wrong during container initialization.
    • getActualStartTimeMs

      public long getActualStartTimeMs()
    • getInitializationLatch

      public CountDownLatch getInitializationLatch()
      Description copied from class: InitializationWrapper
      Asynchronous 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 return null.
      Overrides:
      getInitializationLatch in class InitializationWrapper
      Returns:
      An initialized latch if the underlying container is starting in a separate thread, null otherwise.