Skip to content

add middlware logics #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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.spi.middleware;

/**
* This interface is implemented by middlewares to include middleware core logics.
*
* <p>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 Middleware {
/**
* Middlewares will override this method to include their own logics.
* @param context execution context that pass along middleware chain
* @param chain middleware chain {@link MiddlewareChain}
* @throws Exception any exception that is thrown out in next middleware
*/
void invoke(MiddlewareContext context, MiddlewareChain chain) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 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.spi.middleware;

/**
* The middleware chain.
*
* <p>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 MiddlewareChain {
/**
* Invokes next middleware in the 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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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.spi.middleware;

import com.microsoft.azure.functions.ExecutionContext;

/**
* Middleware Execution Context
*
* <p>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 {
/**
* 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
*/
//TODO: @Nullable
String getParameterName(String annotationSimpleClassName);

/**
* 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 value of customer function
*/
//TODO: @Nullable
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
*/
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
*/
//TODO: @Nullable
Object getReturnValue();

/**
* Updates the return value from customer function invocation.
* @param returnValue value that will be updated as function return value.
*/
void updateReturnValue(Object returnValue);
}