Skip to content

Commit f3e0994

Browse files
committed
Add explanatory comments to the new code in BackgroundFunctionExecutor.
1 parent 1055468 commit f3e0994

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

invoker/core/src/main/java/com/google/cloud/functions/invoker/BackgroundFunctionExecutor.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private BackgroundFunctionExecutor(FunctionExecutor<?> functionExecutor) {
5656
this.functionExecutor = functionExecutor;
5757
}
5858

59-
enum FunctionKind {
59+
private enum FunctionKind {
6060
BACKGROUND(BackgroundFunction.class),
6161
RAW_BACKGROUND(RawBackgroundFunction.class),
6262
CLOUD_EVENTS(ExperimentalCloudEventsFunction.class);
@@ -69,11 +69,21 @@ enum FunctionKind {
6969
this.functionClass = functionClass;
7070
}
7171

72+
/** Returns the {@link FunctionKind} that the given class implements, if any. */
7273
static Optional<FunctionKind> forClass(Class<?> functionClass) {
7374
return VALUES.stream().filter(v -> v.functionClass.isAssignableFrom(functionClass)).findFirst();
7475
}
7576
}
7677

78+
/**
79+
* Optionally makes a {@link BackgroundFunctionExecutor} for the given class, if it implements one
80+
* of {@link BackgroundFunction}, {@link RawBackgroundFunction}, or
81+
* {@link ExperimentalCloudEventsFunction}. Otherwise returns {@link Optional#empty()}.
82+
*
83+
* @param functionClass the class of a possible background function implementation.
84+
* @throws RuntimeException if the given class does implement one of the required interfaces, but we are
85+
* unable to construct an instance using its no-arg constructor.
86+
*/
7787
public static Optional<BackgroundFunctionExecutor> maybeForClass(Class<?> functionClass) {
7888
Optional<FunctionKind> maybeFunctionKind = FunctionKind.forClass(functionClass);
7989
if (!maybeFunctionKind.isPresent()) {
@@ -83,11 +93,12 @@ public static Optional<BackgroundFunctionExecutor> maybeForClass(Class<?> functi
8393
}
8494

8595
/**
86-
* Makes a {@link HttpFunctionExecutor} for the given class.
96+
* Makes a {@link BackgroundFunctionExecutor} for the given class.
8797
*
8898
* @throws RuntimeException if either the class does not implement one of
89-
* {@link BackgroundFunction} or {@link RawBackgroundFunction},
90-
* or we are unable to construct an instance using its no-arg constructor.
99+
* {@link BackgroundFunction}, {@link RawBackgroundFunction}, or
100+
* {@link ExperimentalCloudEventsFunction}; or we are unable to construct an instance using its no-arg
101+
* constructor.
91102
*/
92103
public static BackgroundFunctionExecutor forClass(Class<?> functionClass) {
93104
Optional<FunctionKind> maybeFunctionKind = FunctionKind.forClass(functionClass);

0 commit comments

Comments
 (0)