yr.java_instance_class

yr.java_instance_class#

yr.java_instance_class(class_name: str, function_urn: str) InstanceCreator[source]#

A proxy used to construct Java classes and invoke them remotely.

Parameters:
  • class_name (str) – The name of java.

  • function_urn (str, optional) – The urn of java, default is sn:cn:yrk:default:function:0-defaultservice-java:$latest.

Returns:

The corresponding instance creator. Data type is StatefulInstanceCreator.

Examples

package org.yuanrong.demo;

public class Counter {
    private int count;

    public Counter(int init) {
        System.out.println("Counter constructor with init=" + init);
        this.count = init;
    }

    public int Add(int value) {
        this.count += value;
        System.out.println("Add called, new count=" + this.count);
        return this.count;
    }

    public int Get() {
        System.out.println("Get called, count=" + this.count);
        return this.count;
    }
}
>>> import yr
>>> yr.init()
>>> java_function_urn = (
...     "sn:cn:yrk:default:"
...     "function:0-yr-defaultservice-java:$latest"
... )
>>>
>>> java_instance = yr.java_instance_class("org.yuanrong.demo.Counter", java_function_urn).invoke(1)
>>> res = java_instance.Add.invoke(5)
>>> print(yr.get(res))
>>>
>>> res = java_instance.Get.invoke()
>>> print(yr.get(res))
>>>
>>> java_instance.terminate()
>>> yr.finalize()