Add thread safe wrapper for Invocable
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -41,6 +41,11 @@
|
|||||||
<artifactId>yamlbeans</artifactId>
|
<artifactId>yamlbeans</artifactId>
|
||||||
<version>1.15</version>
|
<version>1.15</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.jcip</groupId>
|
||||||
|
<artifactId>jcip-annotations</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Logging -->
|
<!-- Logging -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
39
src/main/java/scripting/SynchronizedInvocable.java
Normal file
39
src/main/java/scripting/SynchronizedInvocable.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package scripting;
|
||||||
|
|
||||||
|
import net.jcip.annotations.ThreadSafe;
|
||||||
|
|
||||||
|
import javax.script.Invocable;
|
||||||
|
import javax.script.ScriptException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread safe wrapper around Invocable.
|
||||||
|
* Thread safety is achieved by synchronizing all methods.
|
||||||
|
*/
|
||||||
|
@ThreadSafe
|
||||||
|
public class SynchronizedInvocable implements Invocable {
|
||||||
|
private final Invocable invocable;
|
||||||
|
|
||||||
|
public SynchronizedInvocable(Invocable invocable) {
|
||||||
|
this.invocable = invocable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException {
|
||||||
|
return invocable.invokeMethod(thiz, name, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException {
|
||||||
|
return invocable.invokeFunction(name, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized <T> T getInterface(Class<T> clasz) {
|
||||||
|
return invocable.getInterface(clasz);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized <T> T getInterface(Object thiz, Class<T> clasz) {
|
||||||
|
return invocable.getInterface(thiz, clasz);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user