All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.javonet.sdk.RuntimeFactory Maven / Gradle / Ivy

Go to download

Javonet allows you to reference and use modules or packages written in (Java/Kotlin/Groovy/Clojure, C#/VB.NET, Ruby, Perl, Python, JavaScript/TypeScript) like they were created in your technology. It works on Linux/Windows and MacOS for applications created in JVM, CLR/Netcore, Perl, Python, Ruby, NodeJS, C++ or GoLang and gives you unparalleled freedom and flexibility with native performance in building your mixed-technologies products. Let it be accessing best AI or cryptography libraries, devices SDKs, legacy client modules, internal custom packages or anything from public repositories available on NPM, Nuget, PyPI, Maven/Gradle, RubyGems or GitHub. Get free from programming languages barriers today! For more information check out our guides at https://www.javonet.com/guides/v2/

There is a newer version: 2.4.5
Show newest version
package com.javonet.sdk;

import com.javonet.core.runtime.IEmbeddedRuntime;
import com.javonet.core.transmitter.Transmitter;
import com.javonet.sdk.internal.AbstractRuntimeFactory;
import com.javonet.utils.BinariesUnloader;
import com.javonet.utils.RuntimeName;
import com.javonet.utils.TcpConnectionData;
import com.javonet.utils.ConnectionType;

import java.io.IOException;

/**
 * The RuntimeFactory class implements the AbstractRuntimeFactory interface and provides methods for creating runtime contexts.
 * Each method corresponds to a specific runtime (CLR, JVM, .NET Core, Perl, Ruby, Node.js, Python) and Creates RuntimeContext instance for that runtime.
 */
public class RuntimeFactory implements AbstractRuntimeFactory {
    private final ConnectionType connectionType;
    private final TcpConnectionData tcpConnectionData;

    public RuntimeFactory(ConnectionType connectionType, TcpConnectionData tcpConnectionData) {
        this.connectionType = connectionType;
        this.tcpConnectionData = tcpConnectionData;
    }


    /**
     * Creates RuntimeContext instance to interact with CLR runtime.
     *
     * @return a RuntimeContext instance for the CLR runtime
     */
    @Override
    public RuntimeContext clr() {
        return RuntimeContext.getInstance(RuntimeName.Clr, this.connectionType, this.tcpConnectionData);
    }

    /**
     * Creates RuntimeContext instance to interact with JVM runtime.
     *
     * @return a RuntimeContext instance for the JVM runtime
     */
    @Override
    public RuntimeContext jvm() {
        return RuntimeContext.getInstance(RuntimeName.Jvm, this.connectionType, this.tcpConnectionData);
    }

    /**
     * Creates RuntimeContext instance to interact with .NET Core runtime.
     *
     * @return a RuntimeContext instance for the .NET Core runtime
     */
    @Override
    public RuntimeContext netcore() {
        return RuntimeContext.getInstance(RuntimeName.Netcore, this.connectionType, this.tcpConnectionData);
    }

    /**
     * Creates RuntimeContext instance to interact with Perl runtime.
     *
     * @return a RuntimeContext instance for the Perl runtime
     */
    @Override
    public RuntimeContext perl() {
        return RuntimeContext.getInstance(RuntimeName.Perl, this.connectionType, this.tcpConnectionData);
    }

    /**
     * Creates RuntimeContext instance to interact with Ruby runtime.
     *
     * @return a RuntimeContext instance for the Ruby runtime
     */
    @Override
    public RuntimeContext ruby() {
        return RuntimeContext.getInstance(RuntimeName.Ruby, this.connectionType, this.tcpConnectionData);
    }

    /**
     * Creates RuntimeContext instance to interact with Node.js runtime.
     *
     * @return a RuntimeContext instance for the Node.js runtime
     */
    @Override
    public RuntimeContext nodejs() {
        return RuntimeContext.getInstance(RuntimeName.Nodejs, this.connectionType, this.tcpConnectionData);
    }

    /**
     * Creates RuntimeContext instance to interact with Python runtime.
     *
     * @return a RuntimeContext instance for the Python runtime
     */
    @Override
    public RuntimeContext python() {
        return RuntimeContext.getInstance(RuntimeName.Python, this.connectionType, this.tcpConnectionData);
    }

    /**
     * Sets the embedded runtime for the current RuntimeFactory instance.
     *
     * @param runtime The IEmbeddedRuntime instance representing the embedded runtime to be set. This should include the runtime library, version, and byte representation.
     * @param path The file system path where the runtime will be deployed. This should be a valid, writable path.
     * @return A RuntimeContext instance configured for the specified embedded runtime. This instance allows interaction with the set runtime.
     * @throws IOException If an I/O error occurs during the extraction, deployment, or setting of the embedded runtime.
     */
    public RuntimeContext setEmbeddedRuntime(IEmbeddedRuntime runtime, String path) throws IOException {
        BinariesUnloader.extractBinariesFromJar(runtime.getRuntimeLib());
        byte[] bytes = runtime.getRuntimeBytes();
        Transmitter.deployRuntime(bytes, path, (byte) runtime.getRuntimeVersion());
        Transmitter.setEmbeddedRuntime((byte)runtime.getRuntimeLib().ordinal(), (byte) runtime.getRuntimeVersion(), path);
        return RuntimeContext.getInstance(runtime.getRuntimeLib(), this.connectionType, this.tcpConnectionData);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy