Replies: 3 comments 2 replies
-
From our discussion on Slack, we've agreed that these APIs are a good structure, but should be exposed in a More feedback etc. coming soon |
Beta Was this translation helpful? Give feedback.
-
A first implementation for this proposal is being added in #382. |
Beta Was this translation helpful? Give feedback.
-
Update: This has moved from implementation to adoption internally within Elide, and will be closed at such time as it ships in the next release 👍🏻 |
Beta Was this translation helpful? Give feedback.
-
This discussion seeks to explore different approaches we can take to improve the current public API offered by Elide, as well as new ways to organize the source code for ease of maintenance and collaboration.
Separation of concerns
Currently there are three main parts to the Elide project: the Runtime, the Library, and the Framework.
These components are tightly coupled with each other and with external frameworks (e.g. the
VMFacade
, in the runtime core, has a specific method for rendering HTTP requests, specifically Micronaut'sHttpRequest
instances).To solve this issue, first we need to define the scope covered by each component, so that we may refactor as appropriate.
Runtime
The Elide runtime provides an API for running guest languages with minimal effort (while still allowing advanced configuration of the polyglot engine):
The base
PolyglotEngine
API can be used when there is a need to execute dynamic guest code, i.e. sources that are resolved in runtime, as opposed to compile-time code:Framework
The Elide framework uses the Runtime API to provide a Polyglot server framework:
Sample usage
Run the application using:
elide run app.js # or elide run app.py
You can define your application in JavaScript:
or in Python:
or even in Kotlin:
Threading
Route handlers defined as in the previous examples will not be able to benefit from concurrency-related features provided by the underlying server engine.
This is because, in order to invoke a single handler from multiple threads at the same time, it would be necessary to re-evaluate the entire initialization script for each VM in the pool.
Isolated (strict) handlers
The solution is to avoid external references in the handler function: any required values may be passed through the context API (configurable by the initialization script):
Then in the handler function we only use values provided by the context:
This way, the initialization script is called only once, and only handler dependencies registered via
context.use
are duplicated for each context, reducing the overhead involved in spinning up a new VM in the pool.Elide project structure
Rather than implementing all features in a single module, we should split language support features to allow users to depend only on the libraries they need for the target language.
For example, the following modules can be used as dependencies by user code:
elide-core
: provides access to the "core" polyglot API, allowing the development of new language integrations, intrinsics, etc.elide-js
: extends the core API and implements JavaScript support, providing an API for developing custom module replacements, which can be used to develop custom Express.js drop-in solutions, for example.elide-js-express
: adds a Netty-backed Express.js implementation that plugs into the core polyglot API using the tools provided by theelide-js
module.We should also consider separating the framework into its own repository:
elide-framework-core
: base API for configuring polyglot applications from the guest languages, without HTTP. This module may also include dependency injection features.elide-framework-http
: introduces an API for polyglot HTTP servers.What about the library?
Elide as a library currently provides utilities like logging and multiplatform annotations for DI. These features have a place at the core of the Framework, rather than as an independent component.
Progressive migration
Rather than a full rewrite of the project, we must take small steps to repurpose and cleanup the code we currently have. What follows is in incomplete list of the stages that must be applied in this migration.
TBD
Beta Was this translation helpful? Give feedback.
All reactions