backgroundFunction) {
- this.targetType = targetType;
- this.backgroundFunction = backgroundFunction;
+ /**
+ * A background function, either "raw" or "typed". A raw background function is one where the user
+ * code receives a String parameter that is the JSON payload of the triggering event. A typed
+ * background function is one where the payload is deserialized into a user-provided class whose
+ * field names correspond to the keys of the JSON object.
+ *
+ * In addition to these two flavours, events can be either "legacy events" or "CloudEvents".
+ * Legacy events are the only kind that GCF originally supported, and use proprietary encodings
+ * for the various triggers. CloudEvents are ones that follow the standards defined by
+ * cloudevents.io.
+ *
+ * @param the type to be used in the {@link Unmarshallers} call when
+ * unmarshalling this event, if it is a CloudEvent.
+ */
+ private abstract static class FunctionExecutor {
+ private final String functionName;
+
+ FunctionExecutor(String functionName) {
+ this.functionName = functionName;
+ }
+
+ final String functionName() {
+ return functionName;
+ }
+
+ abstract void serviceLegacyEvent(HttpServletRequest req)
+ throws IOException;
+
+ abstract void serviceCloudEvent(
+ HttpServletRequest req,
+ HeadersStep unmarshaller)
+ throws IOException;
+
+ abstract Class cloudEventDataType();
+ }
+
+ private static class RawFunctionExecutor extends FunctionExecutor