-
Notifications
You must be signed in to change notification settings - Fork 64
refactor java worker - add middleware support #652
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5dc65fd
decouple function definition and function executor
kaibocai e74de50
add function exceptions
kaibocai c5485f2
remove unnecessary synchronized block
kaibocai f5728e5
review updates
kaibocai dc819fc
fix invocatioid error
kaibocai cf983c3
rename factory get method
kaibocai 9547726
middleware support logics (#659)
kaibocai 3c179c1
update core lib version to 1.1.0
kaibocai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 7 additions & 49 deletions
56
...main/java/com/microsoft/azure/functions/worker/broker/EnhancedJavaMethodExecutorImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,28 @@ | ||
package com.microsoft.azure.functions.worker.broker; | ||
|
||
import java.lang.reflect.*; | ||
import java.util.*; | ||
|
||
import com.microsoft.azure.functions.worker.binding.*; | ||
import com.microsoft.azure.functions.worker.description.*; | ||
import com.microsoft.azure.functions.worker.reflect.*; | ||
import com.microsoft.azure.functions.rpc.messages.*; | ||
|
||
/** | ||
* Used to executor of arbitrary Java method in any JAR using reflection. | ||
* Thread-Safety: Multiple thread. | ||
*/ | ||
public class EnhancedJavaMethodExecutorImpl implements JavaMethodExecutor { | ||
public EnhancedJavaMethodExecutorImpl(FunctionMethodDescriptor descriptor, Map<String, BindingInfo> bindingInfos, ClassLoaderProvider classLoaderProvider) | ||
throws ClassNotFoundException, NoSuchMethodException | ||
{ | ||
descriptor.validateMethodInfo(); | ||
|
||
this.classLoader = classLoaderProvider.createClassLoader(); | ||
this.containingClass = getContainingClass(descriptor.getFullClassName()); | ||
this.overloadResolver = new ParameterResolver(); | ||
|
||
for (Method method : this.containingClass.getMethods()) { | ||
if (method.getDeclaringClass().getName().equals(descriptor.getFullClassName()) && method.getName().equals(descriptor.getMethodName())) { | ||
this.overloadResolver.addCandidate(method); | ||
} | ||
} | ||
|
||
if (!this.overloadResolver.hasCandidates()) { | ||
throw new NoSuchMethodException("There are no methods named \"" + descriptor.getName() + "\" in class \"" + descriptor.getFullClassName() + "\""); | ||
} | ||
|
||
if (this.overloadResolver.hasMultipleCandidates()) { | ||
throw new UnsupportedOperationException("Found more than one function with method name \"" + descriptor.getName() + "\" in class \"" + descriptor.getFullClassName() + "\""); | ||
} | ||
|
||
this.bindingDefinitions = new HashMap<>(); | ||
private final ClassLoader classLoader; | ||
|
||
for (Map.Entry<String, BindingInfo> entry : bindingInfos.entrySet()) { | ||
this.bindingDefinitions.put(entry.getKey(), new BindingDefinition(entry.getKey(), entry.getValue())); | ||
} | ||
public EnhancedJavaMethodExecutorImpl(ClassLoader classLoader) { | ||
this.classLoader = classLoader; | ||
} | ||
|
||
public Map<String, BindingDefinition> getBindingDefinitions() { return this.bindingDefinitions; } | ||
|
||
public ParameterResolver getOverloadResolver() { return this.overloadResolver; } | ||
|
||
public void execute(BindingDataStore dataStore) throws Exception { | ||
public void execute(ExecutionContextDataSource executionContextDataSource) throws Exception { | ||
try { | ||
Thread.currentThread().setContextClassLoader(this.classLoader); | ||
Object retValue = this.overloadResolver.resolve(dataStore) | ||
Object retValue = ParameterResolver.resolveArguments(executionContextDataSource) | ||
.orElseThrow(() -> new NoSuchMethodException("Cannot locate the method signature with the given input")) | ||
.invoke(() -> this.containingClass.newInstance()); | ||
dataStore.setDataTargetValue(BindingDataStore.RETURN_NAME, retValue); | ||
.invoke(() -> executionContextDataSource.getContainingClass().newInstance()); | ||
executionContextDataSource.updateReturnValue(retValue); | ||
} finally { | ||
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); | ||
} | ||
} | ||
|
||
private Class<?> getContainingClass(String className) throws ClassNotFoundException { | ||
return Class.forName(className, false, this.classLoader); | ||
} | ||
|
||
private final Class<?> containingClass; | ||
private final ClassLoader classLoader; | ||
private final ParameterResolver overloadResolver; | ||
private final Map<String, BindingDefinition> bindingDefinitions; | ||
} |
23 changes: 0 additions & 23 deletions
23
src/main/java/com/microsoft/azure/functions/worker/broker/FactoryJavaMethodExecutor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.