JavaCallerMixin

class negmas.java.JavaCallerMixin[source]

Bases: object

A mixin to enable calling a java counterpart. This mixin can ONLY be used with a NamedObject because it uses its id property.

Other than inheriting this mixin, you should call its init_java_bridge in your __init__ (or whenever your object is initialized and you need to create the Java counterpart). You should then implement all your functions as calls to java_object.

If for example you have a function do_this, you can just define it as follows:

Notice that you cannot use named arguments when calling the function in java_object and that the names are converted to camelCase instead of snake_case. Moreover, property x will be implemented as a pair getX, setX on the Java side.

If your class needs just to call the corresponding java object but is never called back from it then you are done after inheriting from this mixin.

If your objects need to be called from the java counterpart, then you need to add the following to your class definition

This assumes that your class is named ClassName and that there is an interface called ClassName defined in jnegmas that has the same public interface as your class (or whatever part of it to be called from Java).

Methods Summary

from_dict(java_object, *args, **kwargs)

Creates a Python object representing the corresponding Java object

init_java_bridge(java_object, java_class_name)

initializes a connection to the java bridge creating a member called java_object that can be used to access the counterpart object in Java

Methods Documentation

classmethod from_dict(java_object, *args, **kwargs)[source]

Creates a Python object representing the corresponding Java object

init_java_bridge(java_object, java_class_name: str, auto_load_java: bool = False, python_shadow_object: Optional[Any] = None)[source]

initializes a connection to the java bridge creating a member called java_object that can be used to access the counterpart object in Java

Parameters
  • java_object – A java object that already exists of the correct type. If given no new objects will be created

  • java_class_name – The type of the Java object to be created

  • auto_load_java – When true, a JVM will be automatically created (if one is not available)

  • python_shadow_object – A python object to shadow the java object. The object will just call the corresponding

  • on this shadow object whenever it needs. (method) –

Remarks:

  • sets a member called java_object that can be used to access the corresponding Java object crated

  • if python_shadow_object is given, it must be an object of a type that has an internal class called Java which has a single member called ‘implements’ which is a list of one string element representing the Java interface being implemented (it must be either jnegmas.PyCallable or an extension of it).