This commit is contained in:
kaibocai 2022-12-16 18:11:09 -06:00
Родитель 305a00a0ce
Коммит a909a7b9ed
7 изменённых файлов: 55 добавлений и 38 удалений

Просмотреть файл

@ -70,6 +70,11 @@
<artifactId>azure-functions-java-core-library</artifactId>
<version>${azure.functions.java.core.library.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-spi</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library</artifactId>

Просмотреть файл

@ -3,7 +3,7 @@ package com.microsoft.azure.functions.worker.binding;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.RetryContext;
import com.microsoft.azure.functions.TraceContext;
import com.microsoft.azure.functions.middleware.MiddlewareExecutionContext;
import com.microsoft.azure.functions.internal.spi.middleware.MiddlewareContext;
import com.microsoft.azure.functions.worker.WorkerLogManager;
import com.microsoft.azure.functions.worker.binding.model.ExecutionParameter;
import com.microsoft.azure.functions.worker.broker.MethodBindInfo;
@ -13,7 +13,7 @@ import java.lang.reflect.Parameter;
import java.util.*;
import java.util.logging.Logger;
public final class ExecutionContextDataSource extends DataSource<ExecutionContext> implements MiddlewareExecutionContext {
public final class ExecutionContextDataSource extends DataSource<ExecutionContext> implements MiddlewareContext {
private final String invocationId;
private final TraceContext traceContext;
@ -69,7 +69,6 @@ public final class ExecutionContextDataSource extends DataSource<ExecutionContex
return methodBindInfo;
}
@Override
public Class<?> getContainingClass() {
return containingClass;
}
@ -89,7 +88,6 @@ public final class ExecutionContextDataSource extends DataSource<ExecutionContex
return arguments;
}
@Override
public Map<String, Parameter> getParameterMap(){
Map<String, Parameter> map = new HashMap<>();
for (Map.Entry<String, ExecutionParameter> entry : this.argumentsMap.entrySet()){
@ -98,7 +96,6 @@ public final class ExecutionContextDataSource extends DataSource<ExecutionContex
return map;
}
@Override
public Object getParameterPayloadByName(String name){
return this.argumentsMap.get(name).getPayload();
}
@ -111,12 +108,31 @@ public final class ExecutionContextDataSource extends DataSource<ExecutionContex
this.returnValue = retValue;
}
@Override
public String getParameterName(String annotationSimpleClassName) {
return null;
}
@Override
public Object getParameterValue(String name) {
return null;
}
@Override
public void updateParameterValue(String name, Object value) {
}
@Override
public Object getReturnValue(){
return this.returnValue;
}
@Override
public void updateReturnValue(Object returnValue) {
}
public void setMiddlewareOutput(Object value) {
this.middlewareOutput = value;
}
@ -126,7 +142,6 @@ public final class ExecutionContextDataSource extends DataSource<ExecutionContex
this.dataStore.setDataTargetValue(BindingDataStore.RETURN_NAME, this.middlewareOutput);
}
@Override
public void setFunctionInstance(Object functionInstance) {
this.functionInstance = functionInstance;
}

Просмотреть файл

@ -7,7 +7,7 @@ import java.net.URL;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import com.microsoft.azure.functions.middleware.FunctionWorkerMiddleware;
import com.microsoft.azure.functions.internal.spi.middleware.Middleware;
import com.microsoft.azure.functions.rpc.messages.*;
import com.microsoft.azure.functions.worker.Constants;
import com.microsoft.azure.functions.worker.WorkerLogManager;
@ -17,7 +17,6 @@ import com.microsoft.azure.functions.worker.binding.ExecutionRetryContext;
import com.microsoft.azure.functions.worker.binding.ExecutionTraceContext;
import com.microsoft.azure.functions.worker.chain.FunctionArgumentsResolverMiddleware;
import com.microsoft.azure.functions.worker.chain.FunctionExecutionMiddleware;
import com.microsoft.azure.functions.worker.chain.InvocationChain;
import com.microsoft.azure.functions.worker.chain.InvocationChainFactory;
import com.microsoft.azure.functions.worker.description.FunctionMethodDescriptor;
import com.microsoft.azure.functions.worker.reflect.ClassLoaderProvider;
@ -55,12 +54,12 @@ public class JavaFunctionBroker {
if (loadMiddleware) {
synchronized (JavaFunctionBroker.class) {
if (loadMiddleware) {
ArrayList<FunctionWorkerMiddleware> middlewares = new ArrayList<>();
ArrayList<Middleware> middlewares = new ArrayList<>();
loadFunctionResolverMiddleWare(middlewares);
try {
Thread.currentThread().setContextClassLoader(classLoaderProvider.createClassLoader());
ServiceLoader<FunctionWorkerMiddleware> middlewareServiceLoader = ServiceLoader.load(FunctionWorkerMiddleware.class);
for (FunctionWorkerMiddleware middleware : middlewareServiceLoader) {
ServiceLoader<Middleware> middlewareServiceLoader = ServiceLoader.load(Middleware.class);
for (Middleware middleware : middlewareServiceLoader) {
middlewares.add(middleware);
}
//TODO: why exception is not caught when no implementation is there.
@ -77,12 +76,12 @@ public class JavaFunctionBroker {
}
}
private void loadFunctionResolverMiddleWare(ArrayList<FunctionWorkerMiddleware> middlewares) {
private void loadFunctionResolverMiddleWare(ArrayList<Middleware> middlewares) {
FunctionArgumentsResolverMiddleware functionArgumentsResolverMiddleware = new FunctionArgumentsResolverMiddleware(new ParameterResovler());
middlewares.add(functionArgumentsResolverMiddleware);
}
private void loadFunctionExecutionMiddleWare(ArrayList<FunctionWorkerMiddleware> middlewares) {
private void loadFunctionExecutionMiddleWare(ArrayList<Middleware> middlewares) {
FunctionExecutionMiddleware functionExecutionMiddleware =
new FunctionExecutionMiddleware(new FunctionMethodExecutorImpl(this.classLoaderProvider.createClassLoader()));
middlewares.add(functionExecutionMiddleware);

Просмотреть файл

@ -1,12 +1,12 @@
package com.microsoft.azure.functions.worker.chain;
import com.microsoft.azure.functions.middleware.FunctionWorkerChain;
import com.microsoft.azure.functions.middleware.FunctionWorkerMiddleware;
import com.microsoft.azure.functions.middleware.MiddlewareExecutionContext;
import com.microsoft.azure.functions.internal.spi.middleware.Middleware;
import com.microsoft.azure.functions.internal.spi.middleware.MiddlewareChain;
import com.microsoft.azure.functions.internal.spi.middleware.MiddlewareContext;
import com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource;
import com.microsoft.azure.functions.worker.broker.ParameterResovler;
public class FunctionArgumentsResolverMiddleware implements FunctionWorkerMiddleware {
public class FunctionArgumentsResolverMiddleware implements Middleware {
private final ParameterResovler parameterResovler;
public FunctionArgumentsResolverMiddleware(ParameterResovler parameterResovler) {
@ -14,7 +14,7 @@ public class FunctionArgumentsResolverMiddleware implements FunctionWorkerMiddle
}
@Override
public void invoke(MiddlewareExecutionContext context, FunctionWorkerChain next) throws Exception {
public void invoke(MiddlewareContext context, MiddlewareChain chain) throws Exception {
this.parameterResovler.resolve((ExecutionContextDataSource) context);
}
}

Просмотреть файл

@ -1,13 +1,12 @@
package com.microsoft.azure.functions.worker.chain;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.middleware.FunctionWorkerChain;
import com.microsoft.azure.functions.middleware.FunctionWorkerMiddleware;
import com.microsoft.azure.functions.middleware.MiddlewareExecutionContext;
import com.microsoft.azure.functions.internal.spi.middleware.Middleware;
import com.microsoft.azure.functions.internal.spi.middleware.MiddlewareChain;
import com.microsoft.azure.functions.internal.spi.middleware.MiddlewareContext;
import com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource;
import com.microsoft.azure.functions.worker.broker.FunctionMethodExecutorImpl;
public class FunctionExecutionMiddleware implements FunctionWorkerMiddleware {
public class FunctionExecutionMiddleware implements Middleware {
private final FunctionMethodExecutorImpl functionMethodExecutor;
@ -16,7 +15,7 @@ public class FunctionExecutionMiddleware implements FunctionWorkerMiddleware {
}
@Override
public void invoke(MiddlewareExecutionContext context, FunctionWorkerChain next) throws Exception{
public void invoke(MiddlewareContext context, MiddlewareChain chain) throws Exception {
this.functionMethodExecutor.execute((ExecutionContextDataSource) context);
}
}

Просмотреть файл

@ -1,23 +1,22 @@
package com.microsoft.azure.functions.worker.chain;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.middleware.FunctionWorkerChain;
import com.microsoft.azure.functions.middleware.FunctionWorkerMiddleware;
import com.microsoft.azure.functions.middleware.MiddlewareExecutionContext;
import com.microsoft.azure.functions.internal.spi.middleware.Middleware;
import com.microsoft.azure.functions.internal.spi.middleware.MiddlewareChain;
import com.microsoft.azure.functions.internal.spi.middleware.MiddlewareContext;
import java.util.Iterator;
import java.util.List;
public class InvocationChain implements FunctionWorkerChain {
private final Iterator<FunctionWorkerMiddleware> middlewareIterator;
public class InvocationChain implements MiddlewareChain {
private final Iterator<Middleware> middlewareIterator;
public InvocationChain(List<FunctionWorkerMiddleware> middlewares){
public InvocationChain(List<Middleware> middlewares){
this.middlewareIterator = middlewares.iterator();
}
@Override
public void doNext(MiddlewareExecutionContext context) throws Exception {
while (middlewareIterator.hasNext()) {
public void doNext(MiddlewareContext context) throws Exception {
if (middlewareIterator.hasNext()) {
middlewareIterator.next().invoke(context, this);
}
}

Просмотреть файл

@ -1,19 +1,19 @@
package com.microsoft.azure.functions.worker.chain;
import com.microsoft.azure.functions.middleware.FunctionWorkerChain;
import com.microsoft.azure.functions.middleware.FunctionWorkerMiddleware;
import com.microsoft.azure.functions.internal.spi.middleware.Middleware;
import com.microsoft.azure.functions.internal.spi.middleware.MiddlewareChain;
import java.util.List;
public class InvocationChainFactory {
private final List<FunctionWorkerMiddleware> middlewares;
private final List<Middleware> middlewares;
public InvocationChainFactory(List<FunctionWorkerMiddleware> middlewares) {
public InvocationChainFactory(List<Middleware> middlewares) {
this.middlewares = middlewares;
}
public FunctionWorkerChain create(){
public MiddlewareChain create(){
return new InvocationChain(middlewares);
}
}