From 330ab3902cefad8af8fcdd4897ebabf20e849531 Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Thu, 22 Sep 2022 19:57:22 -0700 Subject: [PATCH 1/7] add middlware logics --- .../dihook/FunctionInstanceFactory.java | 16 ++++++ .../functions/internal/MiddlewareContext.java | 55 +++++++++++++++++++ .../middleware/FunctionWorkerChain.java | 16 ++++++ .../middleware/FunctionWorkerMiddleware.java | 15 +++++ 4 files changed, 102 insertions(+) create mode 100644 src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java create mode 100644 src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java create mode 100644 src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerChain.java create mode 100644 src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java diff --git a/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java b/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java new file mode 100644 index 0000000..0d31b8b --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java @@ -0,0 +1,16 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ +package com.microsoft.azure.functions.dihook; + +public interface FunctionInstanceFactory { + /** + * This method used by DI framework to initialize DI container. This method takes in the customer class and return + * an instance create by the DI framework, later customer function will be invoked base on this class instance. + * @param functionClass - The class that contains customer functions + * @return the Instance that will be invoked on by azure functions java worker + */ + T getInstance(Class functionClass) throws Exception; +} diff --git a/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java b/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java new file mode 100644 index 0000000..22b18f4 --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.functions.internal; + +import com.microsoft.azure.functions.ExecutionContext; +import java.lang.reflect.Parameter; +import java.util.Map; + +/** + * Middleware Execution Context + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public interface MiddlewareContext extends ExecutionContext { + // Used by durable middleware. + /** + * Returns the map with name field in parameter's annotation as key, and java.lang.reflect.Parameter type as object. + * The map usually is used for middleware to check the right function method to intercept. + * @return A hash map that contains parameter meta-data of customer function. + */ + Map getParameterMap(); + + /** + * Returns corresponding parameter payload sent from host by checking the parameter name. The return type is Object + * but the true type is String. Make it return Object to avoid break this API in the future. + * @param name - The name of parameter + * @return An object which will be String type that represents parameter payload of customer function. + */ + Object getParameterPayloadByName(String name); + + /** + * Updates the parameter payload by parameter name. This payload will be the actual payload used when invoke customer function. + * This API give middleware ability to update function input. + * @param key - The name of parameter being updated + * @param value - The value of parameter being updated + */ + void updateParameterPayloadByName(String key, Object value); + + /** + * Returns the return value from customer function invocation. + * @return An object that is the customer function return value. + */ + Object getReturnValue(); + + /** + * Updates the return value that will be eventually sent back to host. + * @param value - Middleware output value + */ + void setMiddlewareOutput(Object value); +} diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerChain.java b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerChain.java new file mode 100644 index 0000000..2324bcb --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerChain.java @@ -0,0 +1,16 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ +package com.microsoft.azure.functions.middleware; + +import com.microsoft.azure.functions.internal.MiddlewareContext; + +public interface FunctionWorkerChain { + /** + * This method invoke next middleware, usually used at the end of middleware to invoke next middleware in the chain + * @param context - Execution context that pass to along middlewares. + */ + void doNext(MiddlewareContext context) throws Exception; +} diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java new file mode 100644 index 0000000..2d3cfb7 --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java @@ -0,0 +1,15 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ +package com.microsoft.azure.functions.middleware; + +import com.microsoft.azure.functions.internal.MiddlewareContext; + +public interface FunctionWorkerMiddleware { + /** + * TODO + */ + void invoke(MiddlewareContext context, FunctionWorkerChain next) throws Exception; +} From 844f75a86b5eeacb757527ab3913a1598ef2a6c2 Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Sun, 25 Sep 2022 10:04:15 -0700 Subject: [PATCH 2/7] update javadoc - rename middleware chain --- .../dihook/FunctionInstanceFactory.java | 9 ++++-- .../functions/internal/MiddlewareContext.java | 31 +++++++++---------- ...hain.java => FunctionMiddlewareChain.java} | 11 +++++-- .../middleware/FunctionWorkerMiddleware.java | 11 +++++-- 4 files changed, 39 insertions(+), 23 deletions(-) rename src/main/java/com/microsoft/azure/functions/middleware/{FunctionWorkerChain.java => FunctionMiddlewareChain.java} (53%) diff --git a/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java b/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java index 0d31b8b..671d590 100644 --- a/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java +++ b/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java @@ -5,12 +5,17 @@ */ package com.microsoft.azure.functions.dihook; +/** + * The instance factory that used by DI framework to initialize function instance. + * + * @since 1.1.0 + */ public interface FunctionInstanceFactory { /** - * This method used by DI framework to initialize DI container. This method takes in the customer class and return + * This method is used by DI framework to initialize DI container. This method takes in the customer class and return * an instance create by the DI framework, later customer function will be invoked base on this class instance. * @param functionClass - The class that contains customer functions - * @return the Instance that will be invoked on by azure functions java worker + * @return The function instance that will be invoked on by azure functions java worker */ T getInstance(Class functionClass) throws Exception; } diff --git a/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java b/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java index 22b18f4..841a97c 100644 --- a/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java +++ b/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java @@ -7,8 +7,8 @@ package com.microsoft.azure.functions.internal; import com.microsoft.azure.functions.ExecutionContext; -import java.lang.reflect.Parameter; -import java.util.Map; + +import java.util.Optional; /** * Middleware Execution Context @@ -17,39 +17,38 @@ * at any time. */ public interface MiddlewareContext extends ExecutionContext { - // Used by durable middleware. /** - * Returns the map with name field in parameter's annotation as key, and java.lang.reflect.Parameter type as object. - * The map usually is used for middleware to check the right function method to intercept. - * @return A hash map that contains parameter meta-data of customer function. + * Returns the name of parameter defined in customer function. The input name is the simple name of desired trigger class. + * @param name - The simple name of desired trigger. + * @return The name of parameter defined in customer function. */ - Map getParameterMap(); + Optional getParameterName(String name); /** - * Returns corresponding parameter payload sent from host by checking the parameter name. The return type is Object - * but the true type is String. Make it return Object to avoid break this API in the future. + * Returns corresponding parameter payload sent from host by the given the parameter name. The return type is Object + * but the real type is String. Make it return Object to avoid break this API in the future. * @param name - The name of parameter * @return An object which will be String type that represents parameter payload of customer function. */ Object getParameterPayloadByName(String name); /** - * Updates the parameter payload by parameter name. This payload will be the actual payload used when invoke customer function. - * This API give middleware ability to update function input. - * @param key - The name of parameter being updated - * @param value - The value of parameter being updated + * Updates the parameter payload by parameter name. This payload will be the actual parameter payload + * used when invoke customer function. This API give middleware ability to update function input. + * @param key - The name of parameter to be updated + * @param value - The value of parameter to be updated */ void updateParameterPayloadByName(String key, Object value); /** * Returns the return value from customer function invocation. - * @return An object that is the customer function return value. + * @return An object that is the return value of customer functions. */ Object getReturnValue(); /** - * Updates the return value that will be eventually sent back to host. - * @param value - Middleware output value + * Updates the return value that will eventually be sent back to host. + * @param value - Middleware output value that will eventually be sent back to host */ void setMiddlewareOutput(Object value); } diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerChain.java b/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java similarity index 53% rename from src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerChain.java rename to src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java index 2324bcb..02e2b85 100644 --- a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerChain.java +++ b/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java @@ -7,10 +7,15 @@ import com.microsoft.azure.functions.internal.MiddlewareContext; -public interface FunctionWorkerChain { +/** + * The function middleware chain. + * + * @since 1.1.0 + */ +public interface FunctionMiddlewareChain { /** - * This method invoke next middleware, usually used at the end of middleware to invoke next middleware in the chain - * @param context - Execution context that pass to along middlewares. + * Invokes next middleware, usually used at the end of middleware to invoke next middleware in the middleware chain + * @param context - Execution context that pass along middleware chain. */ void doNext(MiddlewareContext context) throws Exception; } diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java index 2d3cfb7..3dc10e2 100644 --- a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java +++ b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java @@ -7,9 +7,16 @@ import com.microsoft.azure.functions.internal.MiddlewareContext; +/** + * This interface is implemented by middlewares to include middleware core logics. + * + * @since 1.1.0 + */ public interface FunctionWorkerMiddleware { /** - * TODO + * This method contains middleware logics. + * @param context - Execution context that pass along middleware chain. + * @param next - Function middleware chain {@link FunctionMiddlewareChain} */ - void invoke(MiddlewareContext context, FunctionWorkerChain next) throws Exception; + void invoke(MiddlewareContext context, FunctionMiddlewareChain next) throws Exception; } From f8ea20bb92679e2827dff00d93ad8d7b4d50bd98 Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Mon, 26 Sep 2022 20:32:10 -0700 Subject: [PATCH 3/7] update javadoc --- .../dihook/FunctionInstanceFactory.java | 2 ++ .../functions/internal/MiddlewareContext.java | 32 ++++++++++--------- .../middleware/FunctionMiddlewareChain.java | 5 +-- .../middleware/FunctionWorkerMiddleware.java | 5 +-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java b/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java index 671d590..9c406df 100644 --- a/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java +++ b/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java @@ -15,7 +15,9 @@ public interface FunctionInstanceFactory { * This method is used by DI framework to initialize DI container. This method takes in the customer class and return * an instance create by the DI framework, later customer function will be invoked base on this class instance. * @param functionClass - The class that contains customer functions + * @param - customer functions class type * @return The function instance that will be invoked on by azure functions java worker + * @throws Exception - any exception that is thrown out during DI framework create instance of function class */ T getInstance(Class functionClass) throws Exception; } diff --git a/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java b/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java index 841a97c..a86a67f 100644 --- a/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java +++ b/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java @@ -18,37 +18,39 @@ */ public interface MiddlewareContext extends ExecutionContext { /** - * Returns the name of parameter defined in customer function. The input name is the simple name of desired trigger class. - * @param name - The simple name of desired trigger. - * @return The name of parameter defined in customer function. + * Returns the name of parameter defined in customer function. + * The input is the simple class name of target annotation. + * @param annotationSimpleClassName - The simple class name of target annotation + * @return The name of parameter defined in customer function */ - Optional getParameterName(String name); + Optional getParameterName(String annotationSimpleClassName); /** - * Returns corresponding parameter payload sent from host by the given the parameter name. The return type is Object - * but the real type is String. Make it return Object to avoid break this API in the future. + * Returns corresponding parameter value sent from host by the given the parameter name. + * The return type is Object but the real type is String (currently only support get String type, + * planning to support other types in the future.) + * Make it return Object to avoid break this API in the future. * @param name - The name of parameter - * @return An object which will be String type that represents parameter payload of customer function. + * @return An object which will be String type that represents parameter value of customer function */ - Object getParameterPayloadByName(String name); + Object getParameterValue(String name); /** - * Updates the parameter payload by parameter name. This payload will be the actual parameter payload + * Updates the parameter value by parameter name. It will be the actual parameter value * used when invoke customer function. This API give middleware ability to update function input. - * @param key - The name of parameter to be updated + * @param name - The name of parameter to be updated * @param value - The value of parameter to be updated */ - void updateParameterPayloadByName(String key, Object value); + void updateParameterValue(String name, Object value); /** * Returns the return value from customer function invocation. - * @return An object that is the return value of customer functions. + * @return An object that is the return value of customer function */ Object getReturnValue(); /** - * Updates the return value that will eventually be sent back to host. - * @param value - Middleware output value that will eventually be sent back to host + * Updates the return value from customer function invocation. */ - void setMiddlewareOutput(Object value); + void setReturnValue(Object returnValue); } diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java b/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java index 02e2b85..a16a0c6 100644 --- a/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java +++ b/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java @@ -14,8 +14,9 @@ */ public interface FunctionMiddlewareChain { /** - * Invokes next middleware, usually used at the end of middleware to invoke next middleware in the middleware chain - * @param context - Execution context that pass along middleware chain. + * Invokes next middleware, usually used at the end of middleware to invoke next middleware in the middleware chain. + * @param context - Execution context that pass along middleware chain + * @throws Exception - Any exception that happen along middleware chain */ void doNext(MiddlewareContext context) throws Exception; } diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java index 3dc10e2..f9efb06 100644 --- a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java +++ b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java @@ -14,9 +14,10 @@ */ public interface FunctionWorkerMiddleware { /** - * This method contains middleware logics. - * @param context - Execution context that pass along middleware chain. + * Middlewares will override this method to include their own logics. + * @param context - Execution context that pass along middleware chain * @param next - Function middleware chain {@link FunctionMiddlewareChain} + * @throws Exception - Any exception that is thrown out in next middleware */ void invoke(MiddlewareContext context, FunctionMiddlewareChain next) throws Exception; } From 38543ca2b9f4cd1feda65b0fac4e9a619805615d Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Mon, 26 Sep 2022 20:45:08 -0700 Subject: [PATCH 4/7] update java doc --- .../functions/dihook/FunctionInstanceFactory.java | 8 ++++---- .../functions/internal/MiddlewareContext.java | 15 ++++++++------- .../middleware/FunctionMiddlewareChain.java | 4 ++-- .../middleware/FunctionWorkerMiddleware.java | 6 +++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java b/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java index 9c406df..17b66f7 100644 --- a/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java +++ b/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java @@ -14,10 +14,10 @@ public interface FunctionInstanceFactory { /** * This method is used by DI framework to initialize DI container. This method takes in the customer class and return * an instance create by the DI framework, later customer function will be invoked base on this class instance. - * @param functionClass - The class that contains customer functions - * @param - customer functions class type - * @return The function instance that will be invoked on by azure functions java worker - * @throws Exception - any exception that is thrown out during DI framework create instance of function class + * @param functionClass the class that contains customer functions + * @param customer functions class type + * @return the function instance that will be invoked on by azure functions java worker + * @throws Exception any exception that is thrown out during DI framework create instance of function class */ T getInstance(Class functionClass) throws Exception; } diff --git a/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java b/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java index a86a67f..e638356 100644 --- a/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java +++ b/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java @@ -20,8 +20,8 @@ public interface MiddlewareContext extends ExecutionContext { /** * Returns the name of parameter defined in customer function. * The input is the simple class name of target annotation. - * @param annotationSimpleClassName - The simple class name of target annotation - * @return The name of parameter defined in customer function + * @param annotationSimpleClassName the simple class name of target annotation + * @return the name of parameter defined in customer function */ Optional getParameterName(String annotationSimpleClassName); @@ -30,27 +30,28 @@ public interface MiddlewareContext extends ExecutionContext { * The return type is Object but the real type is String (currently only support get String type, * planning to support other types in the future.) * Make it return Object to avoid break this API in the future. - * @param name - The name of parameter - * @return An object which will be String type that represents parameter value of customer function + * @param name the name of parameter + * @return an object which will be String type that represents parameter value of customer function */ Object getParameterValue(String name); /** * Updates the parameter value by parameter name. It will be the actual parameter value * used when invoke customer function. This API give middleware ability to update function input. - * @param name - The name of parameter to be updated - * @param value - The value of parameter to be updated + * @param name the name of parameter to be updated + * @param value the value of parameter to be updated */ void updateParameterValue(String name, Object value); /** * Returns the return value from customer function invocation. - * @return An object that is the return value of customer function + * @return an object that is the return value of customer function */ Object getReturnValue(); /** * Updates the return value from customer function invocation. + * @param returnValue value that will be updated as function return value. */ void setReturnValue(Object returnValue); } diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java b/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java index a16a0c6..d840d39 100644 --- a/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java +++ b/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java @@ -15,8 +15,8 @@ public interface FunctionMiddlewareChain { /** * Invokes next middleware, usually used at the end of middleware to invoke next middleware in the middleware chain. - * @param context - Execution context that pass along middleware chain - * @throws Exception - Any exception that happen along middleware chain + * @param context execution context that pass along middleware chain + * @throws Exception any exception that happen along middleware chain */ void doNext(MiddlewareContext context) throws Exception; } diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java index f9efb06..40d78e6 100644 --- a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java +++ b/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java @@ -15,9 +15,9 @@ public interface FunctionWorkerMiddleware { /** * Middlewares will override this method to include their own logics. - * @param context - Execution context that pass along middleware chain - * @param next - Function middleware chain {@link FunctionMiddlewareChain} - * @throws Exception - Any exception that is thrown out in next middleware + * @param context execution context that pass along middleware chain + * @param next function middleware chain {@link FunctionMiddlewareChain} + * @throws Exception any exception that is thrown out in next middleware */ void invoke(MiddlewareContext context, FunctionMiddlewareChain next) throws Exception; } From 01d22d0b98f645a96fd2b0a69be9b053a55b365e Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Tue, 27 Sep 2022 12:47:11 -0700 Subject: [PATCH 5/7] refactor code --- .../spi/middleware/Middleware.java} | 13 ++++++------- .../spi/middleware/MiddlewareChain.java} | 13 ++++++------- .../{ => spi/middleware}/MiddlewareContext.java | 11 ++++++----- .../inject/FunctionInstanceInjector.java} | 8 ++++---- 4 files changed, 22 insertions(+), 23 deletions(-) rename src/main/java/com/microsoft/azure/functions/{middleware/FunctionWorkerMiddleware.java => internal/spi/middleware/Middleware.java} (56%) rename src/main/java/com/microsoft/azure/functions/{middleware/FunctionMiddlewareChain.java => internal/spi/middleware/MiddlewareChain.java} (53%) rename src/main/java/com/microsoft/azure/functions/internal/{ => spi/middleware}/MiddlewareContext.java (84%) rename src/main/java/com/microsoft/azure/functions/{dihook/FunctionInstanceFactory.java => spi/inject/FunctionInstanceInjector.java} (75%) diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java b/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/Middleware.java similarity index 56% rename from src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java rename to src/main/java/com/microsoft/azure/functions/internal/spi/middleware/Middleware.java index 40d78e6..b0b4602 100644 --- a/src/main/java/com/microsoft/azure/functions/middleware/FunctionWorkerMiddleware.java +++ b/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/Middleware.java @@ -3,21 +3,20 @@ * Licensed under the MIT License. See License.txt in the project root for * license information. */ -package com.microsoft.azure.functions.middleware; - -import com.microsoft.azure.functions.internal.MiddlewareContext; +package com.microsoft.azure.functions.internal.spi.middleware; /** * This interface is implemented by middlewares to include middleware core logics. * - * @since 1.1.0 + *

This class is internal and is hence not for public use at this time. Its APIs are unstable and can change + * at any time. */ -public interface FunctionWorkerMiddleware { +public interface Middleware { /** * Middlewares will override this method to include their own logics. * @param context execution context that pass along middleware chain - * @param next function middleware chain {@link FunctionMiddlewareChain} + * @param chain middleware chain {@link MiddlewareChain} * @throws Exception any exception that is thrown out in next middleware */ - void invoke(MiddlewareContext context, FunctionMiddlewareChain next) throws Exception; + void invoke(MiddlewareContext context, MiddlewareChain chain) throws Exception; } diff --git a/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java b/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareChain.java similarity index 53% rename from src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java rename to src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareChain.java index d840d39..566b6fb 100644 --- a/src/main/java/com/microsoft/azure/functions/middleware/FunctionMiddlewareChain.java +++ b/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareChain.java @@ -3,18 +3,17 @@ * Licensed under the MIT License. See License.txt in the project root for * license information. */ -package com.microsoft.azure.functions.middleware; - -import com.microsoft.azure.functions.internal.MiddlewareContext; +package com.microsoft.azure.functions.internal.spi.middleware; /** - * The function middleware chain. + * The middleware chain. * - * @since 1.1.0 + *

This class is internal and is hence not for public use at this time. Its APIs are unstable and can change + * at any time. */ -public interface FunctionMiddlewareChain { +public interface MiddlewareChain { /** - * Invokes next middleware, usually used at the end of middleware to invoke next middleware in the middleware chain. + * Invokes next middleware in the chain. * @param context execution context that pass along middleware chain * @throws Exception any exception that happen along middleware chain */ diff --git a/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java b/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java similarity index 84% rename from src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java rename to src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java index e638356..2844c49 100644 --- a/src/main/java/com/microsoft/azure/functions/internal/MiddlewareContext.java +++ b/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java @@ -4,16 +4,14 @@ * license information. */ -package com.microsoft.azure.functions.internal; +package com.microsoft.azure.functions.internal.spi.middleware; import com.microsoft.azure.functions.ExecutionContext; -import java.util.Optional; - /** * Middleware Execution Context * - *

This class is internal and is hence not for public use. Its APIs are unstable and can change + *

This class is internal and is hence not for public use at this time. Its APIs are unstable and can change * at any time. */ public interface MiddlewareContext extends ExecutionContext { @@ -23,7 +21,8 @@ public interface MiddlewareContext extends ExecutionContext { * @param annotationSimpleClassName the simple class name of target annotation * @return the name of parameter defined in customer function */ - Optional getParameterName(String annotationSimpleClassName); + //TODO: @Nullable + String getParameterName(String annotationSimpleClassName); /** * Returns corresponding parameter value sent from host by the given the parameter name. @@ -33,6 +32,7 @@ public interface MiddlewareContext extends ExecutionContext { * @param name the name of parameter * @return an object which will be String type that represents parameter value of customer function */ + //TODO: @Nullable Object getParameterValue(String name); /** @@ -47,6 +47,7 @@ public interface MiddlewareContext extends ExecutionContext { * Returns the return value from customer function invocation. * @return an object that is the return value of customer function */ + //TODO: @Nullable Object getReturnValue(); /** diff --git a/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java b/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java similarity index 75% rename from src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java rename to src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java index 17b66f7..232d317 100644 --- a/src/main/java/com/microsoft/azure/functions/dihook/FunctionInstanceFactory.java +++ b/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java @@ -3,20 +3,20 @@ * Licensed under the MIT License. See License.txt in the project root for * license information. */ -package com.microsoft.azure.functions.dihook; +package com.microsoft.azure.functions.spi.inject; /** * The instance factory that used by DI framework to initialize function instance. * * @since 1.1.0 */ -public interface FunctionInstanceFactory { +public interface FunctionInstanceInjector { /** * This method is used by DI framework to initialize DI container. This method takes in the customer class and return - * an instance create by the DI framework, later customer function will be invoked base on this class instance. + * an instance create by the DI framework, later customer functions will be invoked on this class instance. * @param functionClass the class that contains customer functions * @param customer functions class type - * @return the function instance that will be invoked on by azure functions java worker + * @return the instance that will be invoked on by azure functions java worker * @throws Exception any exception that is thrown out during DI framework create instance of function class */ T getInstance(Class functionClass) throws Exception; From 6acf964226fe5cba53ea15f75ebd89e615213951 Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Tue, 27 Sep 2022 12:47:53 -0700 Subject: [PATCH 6/7] remove di hook interface for now --- .../spi/inject/FunctionInstanceInjector.java | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java diff --git a/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java b/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java deleted file mode 100644 index 232d317..0000000 --- a/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. - */ -package com.microsoft.azure.functions.spi.inject; - -/** - * The instance factory that used by DI framework to initialize function instance. - * - * @since 1.1.0 - */ -public interface FunctionInstanceInjector { - /** - * This method is used by DI framework to initialize DI container. This method takes in the customer class and return - * an instance create by the DI framework, later customer functions will be invoked on this class instance. - * @param functionClass the class that contains customer functions - * @param customer functions class type - * @return the instance that will be invoked on by azure functions java worker - * @throws Exception any exception that is thrown out during DI framework create instance of function class - */ - T getInstance(Class functionClass) throws Exception; -} From 74c26dcf5f879f8eb93baa7fa0c291080e9f4241 Mon Sep 17 00:00:00 2001 From: kaibocai <89094811+kaibocai@users.noreply.github.com> Date: Tue, 27 Sep 2022 14:35:01 -0700 Subject: [PATCH 7/7] update method name --- .../functions/internal/spi/middleware/MiddlewareContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java b/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java index 2844c49..70f4a96 100644 --- a/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java +++ b/src/main/java/com/microsoft/azure/functions/internal/spi/middleware/MiddlewareContext.java @@ -54,5 +54,5 @@ public interface MiddlewareContext extends ExecutionContext { * Updates the return value from customer function invocation. * @param returnValue value that will be updated as function return value. */ - void setReturnValue(Object returnValue); + void updateReturnValue(Object returnValue); }