-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ Remove per-thread caching of context objects, as it provides no ben…
…efit with the use of virtual threads
- Loading branch information
Showing
3 changed files
with
18 additions
and
86 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -25,19 +25,19 @@ | |
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import com.mongodb.client.MongoClient; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.Source; | ||
import org.graalvm.polyglot.Value; | ||
import org.restheart.configuration.Configuration; | ||
import org.restheart.exchange.StringRequest; | ||
import org.restheart.exchange.StringResponse; | ||
import org.restheart.plugins.StringService; | ||
import org.restheart.plugins.RegisterPlugin.MATCH_POLICY; | ||
import org.restheart.utils.CleanerUtils; | ||
import org.restheart.plugins.StringService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.mongodb.client.MongoClient; | ||
|
||
/** | ||
* | ||
* @author Andrea Di Cesare {@literal <[email protected]>} | ||
|
@@ -72,9 +72,6 @@ export function handle(request, response) { | |
"""; | ||
|
||
JavaScriptService(Path pluginPath, Optional<MongoClient> mclient, Configuration conf) throws IOException { | ||
// register cleaner | ||
CleanerUtils.get().cleaner().register(this, new State(this.ctxs)); | ||
|
||
this.mclient = mclient; | ||
this.conf = conf; | ||
this.isService = true; | ||
|
@@ -181,8 +178,9 @@ export function handle(request, response) { | |
/** | ||
* | ||
*/ | ||
@Override | ||
public void handle(StringRequest request, StringResponse response) { | ||
_handle().executeVoid(request, response); | ||
ctx().eval(this.handleSource).executeVoid(request, response); | ||
} | ||
|
||
/** | ||
|
@@ -198,16 +196,10 @@ protected Context ctx() { | |
contextOptions.remove("js.commonjs-core-modules-replacements"); | ||
} | ||
|
||
var workingThreadName = Thread.currentThread().getName(); | ||
|
||
if (this.ctxs.get(workingThreadName) == null) { | ||
var ctx = context(engine, contextOptions); | ||
this.ctxs.put(workingThreadName, ctx); | ||
|
||
addBindings(ctx, this.name, conf, LOGGER, this.mclient); | ||
} | ||
var ctx = context(engine, contextOptions); | ||
addBindings(ctx, this.name, conf, LOGGER, this.mclient); | ||
|
||
return this.ctxs.get(workingThreadName); | ||
return ctx; | ||
} | ||
|
||
public String getModulesReplacements() { | ||
|
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