Skip to content

Commit 80af1af

Browse files
authored
add middlware logics (#11)
* add middlware logics * update javadoc - rename middleware chain * update javadoc * update java doc * refactor code * remove di hook interface for now * update method name
1 parent 5306e86 commit 80af1af

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
package com.microsoft.azure.functions.internal.spi.middleware;
7+
8+
/**
9+
* This interface is implemented by middlewares to include middleware core logics.
10+
*
11+
* <p>This class is internal and is hence not for public use at this time. Its APIs are unstable and can change
12+
* at any time.
13+
*/
14+
public interface Middleware {
15+
/**
16+
* Middlewares will override this method to include their own logics.
17+
* @param context execution context that pass along middleware chain
18+
* @param chain middleware chain {@link MiddlewareChain}
19+
* @throws Exception any exception that is thrown out in next middleware
20+
*/
21+
void invoke(MiddlewareContext context, MiddlewareChain chain) throws Exception;
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
package com.microsoft.azure.functions.internal.spi.middleware;
7+
8+
/**
9+
* The middleware chain.
10+
*
11+
* <p>This class is internal and is hence not for public use at this time. Its APIs are unstable and can change
12+
* at any time.
13+
*/
14+
public interface MiddlewareChain {
15+
/**
16+
* Invokes next middleware in the chain.
17+
* @param context execution context that pass along middleware chain
18+
* @throws Exception any exception that happen along middleware chain
19+
*/
20+
void doNext(MiddlewareContext context) throws Exception;
21+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
7+
package com.microsoft.azure.functions.internal.spi.middleware;
8+
9+
import com.microsoft.azure.functions.ExecutionContext;
10+
11+
/**
12+
* Middleware Execution Context
13+
*
14+
* <p>This class is internal and is hence not for public use at this time. Its APIs are unstable and can change
15+
* at any time.
16+
*/
17+
public interface MiddlewareContext extends ExecutionContext {
18+
/**
19+
* Returns the name of parameter defined in customer function.
20+
* The input is the simple class name of target annotation.
21+
* @param annotationSimpleClassName the simple class name of target annotation
22+
* @return the name of parameter defined in customer function
23+
*/
24+
//TODO: @Nullable
25+
String getParameterName(String annotationSimpleClassName);
26+
27+
/**
28+
* Returns corresponding parameter value sent from host by the given the parameter name.
29+
* The return type is Object but the real type is String (currently only support get String type,
30+
* planning to support other types in the future.)
31+
* Make it return Object to avoid break this API in the future.
32+
* @param name the name of parameter
33+
* @return an object which will be String type that represents parameter value of customer function
34+
*/
35+
//TODO: @Nullable
36+
Object getParameterValue(String name);
37+
38+
/**
39+
* Updates the parameter value by parameter name. It will be the actual parameter value
40+
* used when invoke customer function. This API give middleware ability to update function input.
41+
* @param name the name of parameter to be updated
42+
* @param value the value of parameter to be updated
43+
*/
44+
void updateParameterValue(String name, Object value);
45+
46+
/**
47+
* Returns the return value from customer function invocation.
48+
* @return an object that is the return value of customer function
49+
*/
50+
//TODO: @Nullable
51+
Object getReturnValue();
52+
53+
/**
54+
* Updates the return value from customer function invocation.
55+
* @param returnValue value that will be updated as function return value.
56+
*/
57+
void updateReturnValue(Object returnValue);
58+
}

0 commit comments

Comments
 (0)