-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Set Thread context classloder for entire middleware chain (#717…
- Loading branch information
1 parent
1db515f
commit 74bbe0f
Showing
5 changed files
with
77 additions
and
28 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...main/java/com/microsoft/azure/functions/worker/broker/EnhancedJavaMethodExecutorImpl.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.microsoft.azure.functions.worker.broker; | ||
|
||
import com.microsoft.azure.functions.worker.binding.*; | ||
|
||
/** | ||
* Used to executor of arbitrary Java method in any JAR using reflection. | ||
* Thread-Safety: Multiple thread. | ||
*/ | ||
public class EnhancedJavaMethodExecutorImpl implements JavaMethodExecutor { | ||
|
||
private final ClassLoader classLoader; | ||
|
||
public EnhancedJavaMethodExecutorImpl(ClassLoader classLoader) { | ||
this.classLoader = classLoader; | ||
} | ||
|
||
public void execute(ExecutionContextDataSource executionContextDataSource) throws Exception { | ||
try { | ||
Thread.currentThread().setContextClassLoader(this.classLoader); | ||
Object retValue = ParameterResolver.resolveArguments(executionContextDataSource) | ||
.orElseThrow(() -> new NoSuchMethodException("Cannot locate the method signature with the given input")) | ||
.invoke(executionContextDataSource::getFunctionInstance); | ||
executionContextDataSource.updateReturnValue(retValue); | ||
} finally { | ||
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); | ||
} | ||
} | ||
} |
This file contains 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
21 changes: 5 additions & 16 deletions
21
src/main/java/com/microsoft/azure/functions/worker/broker/JavaMethodExecutor.java
This file contains 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,25 +1,14 @@ | ||
package com.microsoft.azure.functions.worker.broker; | ||
|
||
|
||
import java.util.*; | ||
import com.microsoft.azure.functions.worker.binding.*; | ||
|
||
|
||
/** | ||
* Used to executor of arbitrary Java method in any JAR using reflection. | ||
* Thread-Safety: Multiple thread. | ||
*/ | ||
public class JavaMethodExecutor { | ||
|
||
private static final JavaMethodExecutor INSTANCE = new JavaMethodExecutor(); | ||
|
||
public static JavaMethodExecutor getInstance(){ | ||
return INSTANCE; | ||
} | ||
|
||
private JavaMethodExecutor() {} | ||
|
||
public void execute(ExecutionContextDataSource executionContextDataSource) throws Exception { | ||
Object retValue = ParameterResolver.resolveArguments(executionContextDataSource) | ||
.orElseThrow(() -> new NoSuchMethodException("Cannot locate the method signature with the given input")) | ||
.invoke(executionContextDataSource::getFunctionInstance); | ||
executionContextDataSource.updateReturnValue(retValue); | ||
} | ||
public interface JavaMethodExecutor { | ||
void execute(ExecutionContextDataSource executionContextDataSource) throws Exception; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/microsoft/azure/functions/worker/broker/JavaMethodExecutorImpl.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.microsoft.azure.functions.worker.broker; | ||
|
||
import com.microsoft.azure.functions.worker.binding.*; | ||
|
||
/** | ||
* Used to executor of arbitrary Java method in any JAR using reflection. | ||
* Thread-Safety: Multiple thread. | ||
*/ | ||
public class JavaMethodExecutorImpl implements JavaMethodExecutor { | ||
|
||
private static final JavaMethodExecutorImpl INSTANCE = new JavaMethodExecutorImpl(); | ||
|
||
public static JavaMethodExecutorImpl getInstance(){ | ||
return INSTANCE; | ||
} | ||
|
||
private JavaMethodExecutorImpl () {} | ||
|
||
public void execute(ExecutionContextDataSource executionContextDataSource) throws Exception { | ||
Object retValue = ParameterResolver.resolveArguments(executionContextDataSource) | ||
.orElseThrow(() -> new NoSuchMethodException("Cannot locate the method signature with the given input")) | ||
.invoke(executionContextDataSource::getFunctionInstance); | ||
executionContextDataSource.updateReturnValue(retValue); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/microsoft/azure/functions/worker/broker/JavaMethodExecutors.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.microsoft.azure.functions.worker.broker; | ||
|
||
import com.microsoft.azure.functions.worker.WorkerLogManager; | ||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
public class JavaMethodExecutors { | ||
public static JavaMethodExecutor createJavaMethodExecutor(ClassLoader classLoader) { | ||
if(SystemUtils.IS_JAVA_1_8) { | ||
WorkerLogManager.getSystemLogger().info("Loading JavaMethodExecutorImpl"); | ||
return JavaMethodExecutorImpl.getInstance(); | ||
} else { | ||
WorkerLogManager.getSystemLogger().info("Loading EnhancedJavaMethodExecutorImpl"); | ||
return new EnhancedJavaMethodExecutorImpl(classLoader); | ||
} | ||
} | ||
} |