Skip to content

Commit

Permalink
add middlware logics (#11)
Browse files Browse the repository at this point in the history
* add middlware logics

* update javadoc - rename middleware chain

* update javadoc

* update java doc

* refactor code

* remove di hook interface for now

* update method name
  • Loading branch information
kaibocai authored Sep 27, 2022
1 parent 5306e86 commit 80af1af
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
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);
}

0 comments on commit 80af1af

Please sign in to comment.