Class GoogleCloudEventsFunction<T>

  • Type Parameters:
    T - Google Cloud Events Type
    All Implemented Interfaces:
    com.google.cloud.functions.CloudEventsFunction, io.micronaut.context.ApplicationContextProvider, java.io.Closeable, java.lang.AutoCloseable

    public abstract class GoogleCloudEventsFunction<T>
    extends GoogleFunctionInitializer
    implements com.google.cloud.functions.CloudEventsFunction
    A super class that extends GoogleFunctionInitializer and can be used to map cloud events payloads. To be used with CloudEvents POJOs issued by Google.
    Since:
    4.8.0
    Author:
    Guillermo Calvo
    See Also:
    Google Cloud Events.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class io.micronaut.function.executor.FunctionInitializer

        io.micronaut.function.executor.FunctionInitializer.ParseContext
    • Field Summary

      • Fields inherited from class io.micronaut.function.executor.FunctionInitializer

        closeContext
      • Fields inherited from class io.micronaut.function.executor.AbstractExecutor

        applicationContext
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void accept​(io.cloudevents.CloudEvent event)  
      protected abstract void accept​(io.cloudevents.CloudEventContext context, T data)
      Called to service an incoming event.
      protected java.lang.Class<T> getType()  
      protected java.util.Optional<T> map​(io.cloudevents.CloudEvent event, java.lang.Class<T> type)
      Maps a cloud event to the target type.
      • Methods inherited from class io.micronaut.function.executor.FunctionInitializer

        close, injectThis, run, startThis
      • Methods inherited from class io.micronaut.function.executor.AbstractExecutor

        buildApplicationContext, getApplicationContext, resolveFunction, resolveFunctionName, startEnvironment
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GoogleCloudEventsFunction

        protected GoogleCloudEventsFunction()
    • Method Detail

      • accept

        public void accept​(io.cloudevents.CloudEvent event)
                    throws java.lang.Exception
        Specified by:
        accept in interface com.google.cloud.functions.CloudEventsFunction
        Throws:
        java.lang.Exception
      • accept

        protected abstract void accept​(@NonNull
                                       io.cloudevents.CloudEventContext context,
                                       @Nullable
                                       T data)
                                throws java.lang.Exception
        Called to service an incoming event. If this method throws any exception (including any Error) then the HTTP response will have a 500 status code.
        Parameters:
        context - Cloud Event context
        data - Google Cloud Event
        Throws:
        java.lang.Exception - to produce a 500 status code in the HTTP response.
      • getType

        @NonNull
        protected java.lang.Class<T> getType()
        Returns:
        Google Cloud Event Type.
      • map

        @NonNull
        protected java.util.Optional<T> map​(@NonNull
                                            io.cloudevents.CloudEvent event,
                                            @NonNull
                                            java.lang.Class<T> type)
        Maps a cloud event to the target type.
        Parameters:
        event - The Cloud Event
        type - The target mapping type.
        Returns:
        The bound type if possible, or an empty optional in case of error.