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

com.javonet.sdk.ConfigRuntimeFactory 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.transmitter.Transmitter;
import com.javonet.sdk.internal.AbstractConfigRuntimeFactory;
import com.javonet.sdk.tools.JsonFileResolver;
import com.javonet.utils.ConnectionType;
import com.javonet.utils.RuntimeName;
import com.javonet.utils.RuntimeNameHandler;
import com.javonet.utils.TcpConnectionData;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.Objects;

/**
 * The ConfigRuntimeFactory class implements the AbstractConfigRuntimeFactory 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 ConfigRuntimeFactory implements AbstractConfigRuntimeFactory {
    private final String path_;

    public ConfigRuntimeFactory(String path) {
        this.path_ = path;
    }

    /**
     * Creates RuntimeContext instance to interact with CLR runtime.
     *
     * @param configName the name of the configuration to use.
     * @return a RuntimeContext instance for the CLR runtime
     */
    @Override
    public RuntimeContext clr(String configName) {
        return this.getRuntimeContext(RuntimeName.Clr, configName);
    }

    /**
     * Creates RuntimeContext instance to interact with JVM runtime.
     *
     * @param configName the name of the configuration to use.
     * @return a RuntimeContext instance for the JVM runtime
     */
    @Override
    public RuntimeContext jvm(String configName) {
        return this.getRuntimeContext(RuntimeName.Jvm, configName);
    }

    /**
     * Creates RuntimeContext instance to interact with .NET Core runtime.
     *
     * @param configName the name of the configuration to use.
     * @return a RuntimeContext instance for the .NET Core runtime
     */
    @Override
    public RuntimeContext netcore(String configName) {
        return this.getRuntimeContext(RuntimeName.Netcore, configName);
    }

    /**
     * Creates RuntimeContext instance to interact with Perl runtime.
     *
     * @param configName the name of the configuration to use.
     * @return a RuntimeContext instance for the Perl runtime
     */
    @Override
    public RuntimeContext perl(String configName) {
        return this.getRuntimeContext(RuntimeName.Perl, configName);
    }

    /**
     * Creates RuntimeContext instance to interact with Ruby runtime.
     *
     * @param configName the name of the configuration to use.
     * @return a RuntimeContext instance for the Ruby runtime
     */
    @Override
    public RuntimeContext ruby(String configName) {
        return this.getRuntimeContext(RuntimeName.Ruby, configName);
    }

    /**
     * Creates RuntimeContext instance to interact with Node.js runtime.
     *
     * @param configName the name of the configuration to use.
     * @return a RuntimeContext instance for the Node.js runtime
     */
    @Override
    public RuntimeContext nodejs(String configName) {
        return this.getRuntimeContext(RuntimeName.Nodejs, configName);
    }

    /**
     * Creates RuntimeContext instance to interact with Python runtime.
     *
     * @param configName the name of the configuration to use.
     * @return a RuntimeContext instance for the Python runtime
     */
    @Override
    public RuntimeContext python(String configName) {
        return this.getRuntimeContext(RuntimeName.Python, configName);
    }

    private RuntimeContext getRuntimeContext(RuntimeName runtime, String configName) {
        JsonFileResolver jfr = new JsonFileResolver(path_);

        try {
            String licenseKey = jfr.getLicenseKey();
            Transmitter.activateWithCredentials(licenseKey);
        } catch (Exception e) {
            // licenseKey not found - do nothing
        }

        String connType = jfr.getChannelType(RuntimeNameHandler.getName(runtime), configName);
        if ("tcp".equals(connType)) {
            TcpConnectionData connData = null;
            try {
                connData = new TcpConnectionData(jfr.getChannelHost(RuntimeNameHandler.getName(runtime), configName), jfr.getChannelPort(RuntimeNameHandler.getName(runtime), configName));
            } catch (UnknownHostException e) {
                throw new RuntimeException(e);
            }
            return RuntimeContext.getInstance(runtime, ConnectionType.TCP, connData);
        } else if ("inMemory".equals(connType)) {
            return RuntimeContext.getInstance(runtime, ConnectionType.IN_MEMORY, null);
        } else {
            throw new RuntimeException("Invalid connection type");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy