Table of Contents

Class SetupJVMWrapper

Namespace
MASES.JCOBridge.C2JBridge
Assembly
C2JBridge.dll

Main entry point for JVM languages setup and execution.

public class SetupJVMWrapper : IJVMWrapperManagement
Inheritance
SetupJVMWrapper
Implements
Derived
Inherited Members
Extension Methods

Examples

This is a basic example showing SetupJVMWrapper class usage

class JVMWrapperApp : SetupJVMWrapper
{
    public void Execute()
    {
         ImportPackage("java.lang");
         ImportPackage("java.util");

         var str = DynJVM.String.@new();
         str = str.concat("HELLO WORLD FROM JVM!!!"); // this command is executed within the JVM context
         Console.WriteLine("Output from JVM: {0}", str);
     }
}

To run use: applicationName --JVMPath:[ABSOLUTE PATH TO JRE LIBRARY (jvm.dll/libjvm.so)] Other command line switch are available on https://www.jcobridge.com/command-line-options/

Constructors

SetupJVMWrapper()

Initialize a new instance of SetupJVMWrapper

public SetupJVMWrapper()

SetupJVMWrapper(string)

Initialize a new instance of SetupJVMWrapper

public SetupJVMWrapper(string destinationPath)

Parameters

destinationPath string

The path where runtime info will be sent

Remarks

Not available using Nuget packages

Properties

ClassPath

The starting JVM class path. Further path can be added later.

public virtual string ClassPath { get; }

Property Value

string

Remarks

It is not the same classpath switch available in CLI. No wildcards expansion is made at this level. Use ClassPathBuilder in this case.

ContainerId

Return a string identifier of the container instance

public static string ContainerId { get; }

Property Value

string

DebugSuspendFlag

Enables Debug

public virtual string DebugSuspendFlag { get; }

Property Value

string

DisableOpenOnJavaNio

true to close access to java.nio module i.e. removes --add-opens=java.base/java.nio=ALL-UNNAMED on JVM parameters, default value is false

public virtual bool DisableOpenOnJavaNio { get; }

Property Value

bool

DynJVM

The dynamic entry point for JVM operations. It permits to write code in .NET languages using a syntax not far from the one available in Java.

public dynamic DynJVM { get; }

Property Value

dynamic

A dynamic entry point to interact with JVM

Examples

To instantiate a new JVM String you can use a code like:

var myStr = DynJVM.String.@new();

For an array:

var myArray = DynJVM.ArrayList.@new();
myArray.add(1);
myArray.add(2);

In general this property make the operations against the JVM very simple.

Remarks

It is marked with dynamic keyword. If during runtime an RuntimeBinderException is thrown, check the code to verify if there is a correspondance on Java side. Possible problems come from:
- A not imported package
- A not existent class
- A type in code
- A missing method on the requested Java class

EnableCriticalMethods

Always enable/disable use of critical methods within JNI interface, to get/set native type arrays, single wrapper for EnableCriticalMethodsOnGet and EnableCriticalMethodsOnSet

[Obsolete("Use the property available in Management property", true)]
public bool? EnableCriticalMethods { get; set; }

Property Value

bool?

EnableCriticalMethodsOnGet

Always enable/disable use of critical methods, within JNI interface, to get native type arrays

[Obsolete("Use the property available in Management property", true)]
public bool? EnableCriticalMethodsOnGet { get; set; }

Property Value

bool?

EnableCriticalMethodsOnGetThreshold

Enable/Disable use of critical methods, within JNI interface, to get native type arrays if the length is over the EnableCriticalMethodsOnSetThreshold. Default is MaxValue

[Obsolete("Use the property available in Management property", true)]
public int EnableCriticalMethodsOnGetThreshold { get; set; }

Property Value

int

EnableCriticalMethodsOnSet

Always enable/disable use of critical methods, within JNI interface, to set native type arrays

[Obsolete("Use the property available in Management property", true)]
public bool? EnableCriticalMethodsOnSet { get; set; }

Property Value

bool?

EnableCriticalMethodsOnSetThreshold

Enable/Disable use of critical methods, within JNI interface, to set native type arrays if the length is over the EnableCriticalMethodsOnSetThreshold. Default is MaxValue

[Obsolete("Use the property available in Management property", true)]
public int EnableCriticalMethodsOnSetThreshold { get; set; }

Property Value

int

EnableDebug

Enables Debug

public virtual bool EnableDebug { get; }

Property Value

bool

EnableNativeAccess

true to enable native access as defined in https://openjdk.org/jeps/472, default value is false for compatibility with JDK 11.

public virtual bool EnableNativeAccess { get; }

Property Value

bool

FeatureLevel

Reports the feature level of the JVM in use

[Obsolete("Use the property available in Management property", true)]
public int FeatureLevel { get; }

Property Value

int

Remarks

-1 means the feature level was not identified

FilteredArgs

The remaining arguments after applied the parsing of JCOBridge arguments. Useful when invoked application does not accept arguments related to JCOBridge.

public static string[] FilteredArgs { get; }

Property Value

string[]

GlobalHeapSize

Sets the global heap size

public virtual string GlobalHeapSize { get; }

Property Value

string

Globalize

Set to false to avoid globalization of the instance. Default is true

public virtual bool Globalize { get; }

Property Value

bool

InitialHeapSize

Sets the initial heap size

public virtual string InitialHeapSize { get; }

Property Value

string

IsContainer

Return true if the running environment is a container

public static bool IsContainer { get; }

Property Value

bool

JDKHome

The path where is located the JRE of the installed JDK

public virtual string JDKHome { get; }

Property Value

string

JNIOutputFile

The path where the JNI verbose info will be written. The file will be opened in append mode.

public virtual string JNIOutputFile { get; }

Property Value

string

JNIVerbosity

Sets the verbosity of the JNI interface. See oracle documentation.

public virtual string JNIVerbosity { get; }

Property Value

string

JVM

The entry point for direct JVM operations. Use DynJVM to write code like you made in Java

public IJVMWrapperDirect JVM { get; }

Property Value

IJVMWrapperDirect

JVMOptions

The options to pass to the JVM when a JVM will be created

public virtual IEnumerable<KeyValuePair<string, string>> JVMOptions { get; }

Property Value

IEnumerable<KeyValuePair<string, string>>

JVMPackages

The list of packages on startup. Further packages can be added later

public virtual IEnumerable<string> JVMPackages { get; }

Property Value

IEnumerable<string>

JVMPath

The path to the JRE ennvironment or full path to (jvm.dll/libjvm.so). If not set the library try to find a suitable version on the system.

public virtual string JVMPath { get; }

Property Value

string

JVMStats

The entry point for JVM statistics

protected IJVMWrapperStatistics JVMStats { get; }

Property Value

IJVMWrapperStatistics

JavaDebugOpts

Java Debug options used if EnableDebug is true

public virtual string JavaDebugOpts { get; }

Property Value

string

JavaDebugPort

Java Debug Port

public virtual short JavaDebugPort { get; }

Property Value

short

JmxPort

The JMX Port to use

public virtual short? JmxPort { get; }

Property Value

short?

LicensePath

The path where is located the license file

public virtual string LicensePath { get; }

Property Value

string

Management

The entry point for management operations

public IJVMWrapperManagement Management { get; }

Property Value

IJVMWrapperManagement

ModulePath

The starting JVM module path. Further path can be added later.

public virtual string ModulePath { get; }

Property Value

string

Remarks

It is not the same modulepath switch available in CLI. No wildcards expansion is made at this level.

RemoteBridge

Direct accessor to the JCOBridge class in the JVM context

protected IJavaType RemoteBridge { get; }

Property Value

IJavaType

A IJavaType entry point to interact with JCOBridge class within JVM context

RemoteJCOBridge

Dynamic accessor to the JCOBridge class in the JVM context

protected dynamic RemoteJCOBridge { get; }

Property Value

dynamic

A dynamic entry point to interact with JCOBridge class within JVM context

Remarks

It is marked with dynamic keyword. If during runtime an RuntimeBinderException is thrown, check the code to verify if there is a correspondance on Java side. Possible problems come from:
- A typo in code
- A missing method on the Java-side JCOBridge class

SuppressFinalize

true to suppress finalization of the class instance inherited from SetupJVMWrapper when the instance is created using CreateGlobalInstance(), the instance is globalized using Globalize(IJVMBridgeCore, bool). Default value is true.

public virtual bool SuppressFinalize { get; }

Property Value

bool

Methods

~SetupJVMWrapper()

Finalize an instance of SetupJVMWrapper

protected ~SetupJVMWrapper()

GetCLRGlobal(string)

Get previously registered object from CLR global mapper

[Obsolete("Use the method available in Management property", true)]
public object GetCLRGlobal(string key)

Parameters

key string

The key to identify the registered object

Returns

object

Previously registered global object

GetJCGraphicContainer(IJavaObject, bool)

Requests to allocate a remote graphic container to host the Component in graphicObject

[Obsolete("Use the method available in Management property", true)]
public IJCGraphicContainer GetJCGraphicContainer(IJavaObject graphicObject, bool isWPF)

Parameters

graphicObject IJavaObject

The object, in the form of IJavaObject, to be inserted in the grphical hierarchy

isWPF bool

true if the request come from a WPF host application, false for WinForms host application

Returns

IJCGraphicContainer

A IJCGraphicContainer reference to the newly allocated container

Remarks

This version supports a single JCGraphicContainer needing direct management of Windows Message Pump, other JCGraphicContainer must internally manages message pump, setting the property IsRemoteManaged to true.

GetJCGraphicContainer(string, bool)

Requests to allocate a remote graphic container to host the Component with class name className

[Obsolete("Use the method available in Management property", true)]
public IJCGraphicContainer GetJCGraphicContainer(string className, bool isWPF)

Parameters

className string

The name of the class to allocate and insert in the grphical hierarchy

isWPF bool

true if the request come from a WPF host application, false for WinForms host application

Returns

IJCGraphicContainer

A IJCGraphicContainer reference to the newly allocated container

Remarks

This version supports a single JCGraphicContainer needing direct management of Windows Message Pump, other JCGraphicContainer must internally manages message pump, setting the property IsRemoteManaged to true.

GetJVMGlobal(string)

Get previously registered IJavaObject from JVM global mapper

[Obsolete("Use the method available in Management property", true)]
public IJavaObject GetJVMGlobal(string key)

Parameters

key string

The key to identify the registered object

Returns

IJavaObject

Previously registered global IJavaObject

GetListener(IJavaObject)

Returns the IJVMBridgeBase listener reference associated to the JVM reference

[Obsolete("Use the method available in Management property", true)]
public IJVMBridgeBase GetListener(IJavaObject eventListener)

Parameters

eventListener IJavaObject

The JVM reference associated to the IJVMBridgeBase

Returns

IJVMBridgeBase

The IJVMBridgeBase associated to the eventListener

GetMainClasses(Assembly)

Retrieve all Main-Class from the assembly

[Obsolete("Use the method available in JCOBridge static class", true)]
public static IDictionary<string, Type> GetMainClasses(Assembly assembly)

Parameters

assembly Assembly

The Assembly to analyze

Returns

IDictionary<string, Type>

A IDictionary<TKey, TValue> containing the name of the Main-Class and its Type

ImportPackage(string)

Imports a Java package to be used within the program

[Obsolete("Use the method available in JVM property", true)]
public void ImportPackage(string packageName)

Parameters

packageName string

The package in the form of java.lang, java.util, etc.

Examples

To add package search use a code like:

// the following code is the Java equivalent of import java.lang.*;

ImportPackage("java.lang");

InitializeListener(IJVMBridgeBase)

Request the initialization of the Listener from the JVM. The listener is a new class which inherits from JVMBridgeListener or JVMBridgeListener

[Obsolete("Use the method available in Management property", true)]
public void InitializeListener(IJVMBridgeBase listener)

Parameters

listener IJVMBridgeBase

The IJVMBridgeBase listener reference to be initialized

Launch(Type, params string[])

Launch the type with the args arguments

[Obsolete("Use the method available in JCOBridge static class", true)]
public static void Launch(Type type, params string[] args)

Parameters

type Type

The Type extending IJVMBridgeMain

args string[]

The arguments of the main method

Launch<TClass>(params string[])

Launch the TClass with the args arguments

[Obsolete("Use the method available in JCOBridge static class", true)]
public static void Launch<TClass>(params string[] args) where TClass : IJVMBridgeMain

Parameters

args string[]

The arguments of the main method

Type Parameters

TClass

A type which is defined as Main-Class

PostInitialization()

Override the method to manage post initialization step

protected virtual void PostInitialization()

PreInitialization(ref string, ref Version)

Override the method to setup some information, this is the first virtual method invoked: some settings can be applied here like SetEventOrExceptionHandler(EventHandler<EventOrExceptionEventArgs>)

protected virtual void PreInitialization(ref string scopeOn, ref Version scopeOnVersion)

Parameters

scopeOn string

The value to return to override the value of MASES.JCOBridge.C2JBridge.SetupJVMWrapper.ScopedOn

scopeOnVersion Version

The value to return to override the value of MASES.JCOBridge.C2JBridge.SetupJVMWrapper.ScopedOnVersion

ProcessCommandLine()

Process command line arguments

protected virtual string[] ProcessCommandLine()

Returns

string[]

The filtered residual arguments

RegisterCLRGlobal(string, object)

Register the object into the global CLR mapper.

[Obsolete("Use the method available in Management property", true)]
public void RegisterCLRGlobal(string key, object obj)

Parameters

key string

The key to identify the registered

obj object

The object to register

ReleaseJCGraphicContainer(IJCGraphicContainer)

Reelase a IJCGraphicContainer from the JVM

[Obsolete("Use the method available in Management property", true)]
public void ReleaseJCGraphicContainer(IJCGraphicContainer container)

Parameters

container IJCGraphicContainer

The IJCGraphicContainer to be released

ReleaseListener(IJVMBridgeBase)

Release a IJVMBridgeBase listener reference from the JVM

[Obsolete("Use the method available in Management property", true)]
public void ReleaseListener(IJVMBridgeBase listener)

Parameters

listener IJVMBridgeBase

The IJVMBridgeBase listener reference to be released

UnregisterCLRGlobal(string)

Unregister the object from the global CLR mapper.

[Obsolete("Use the method available in Management property", true)]
public void UnregisterCLRGlobal(string key)

Parameters

key string

The key to identify the registered

UnwrapAndDemonizeOn<T>(ParameterizedThreadStart, object, ApartmentState)

Creates and unwrap the JVM instance as daemon

public T UnwrapAndDemonizeOn<T>(ParameterizedThreadStart handler, object arg = null, ApartmentState apartment = ApartmentState.STA) where T : SetupJVMWrapper

Parameters

handler ParameterizedThreadStart

An handler to the function to be invoked

arg object

The argument for handler. Default is null.

apartment ApartmentState

The ApartmentState to be used when the thread is started

Returns

T

An instance of T

Type Parameters

T

The class extending SetupJVMWrapper

Remarks

apartment is valid only on Windows

UnwrapOn<T>(ParameterizedThreadStart, object, ApartmentState)

Creates and unwrap the JVM instance

public T UnwrapOn<T>(ParameterizedThreadStart handler, object arg = null, ApartmentState apartment = ApartmentState.STA) where T : SetupJVMWrapper

Parameters

handler ParameterizedThreadStart

An handler to the function to be invoked

arg object

The argument for handler. Default is null.

apartment ApartmentState

The ApartmentState to use to start the thread

Returns

T

An instance of T

Type Parameters

T

The class extending SetupJVMWrapper