def test_multiple_jpy_create_destroy_jvm(self):
   self.assertFalse(jpy.has_jvm())
   jpy.create_jvm([])
   self.assertTrue(jpy.has_jvm())
   jpy.destroy_jvm()
   self.assertFalse(jpy.has_jvm())
   jpy.create_jvm([])
   self.assertTrue(jpy.has_jvm())
   jpy.destroy_jvm()
   self.assertFalse(jpy.has_jvm())
예제 #2
0
def _defineSymbols():
    """
    Defines appropriate java symbol, which requires that the jvm has been initialized through the :class:`jpy` module,
    for use throughout the module AT RUNTIME. This is versus static definition upon first import, which would lead to an
    exception if the jvm wasn't initialized BEFORE importing the module.
    """

    if not jpy.has_jvm():
        raise SystemError("No java functionality can be used until the JVM has been initialized through the jpy module")

    global _java_type_MetricsManager
    if _java_type_MetricsManager is None:
        # This will raise an exception if the desired object is not the classpath
        _java_type_MetricsManager = jpy.get_type("io.deephaven.db.v2.utils.metrics.MetricsManager")

    global _java_type_PerformanceQueries
    if _java_type_PerformanceQueries is None:
        # This will raise an exception if the desired object is not the classpath
        _java_type_PerformanceQueries = jpy.get_type("io.deephaven.db.util.PerformanceQueries")

    global _java_type_PerformanceQueriesPerformanceOverviewQueryBuilder
    if _java_type_PerformanceQueriesPerformanceOverviewQueryBuilder is None:
        # This will raise an exception if the desired object is not the classpath
        _java_type_PerformanceQueriesPerformanceOverviewQueryBuilder = jpy.get_type("io.deephaven.db.util.PerformanceQueries$PerformanceOverview$QueryBuilder")

    global _java_type_PerformanceQueriesPersistentQueryStatusMonitor
    if _java_type_PerformanceQueriesPersistentQueryStatusMonitor is None:
        # This will raise an exception if the desired object is not the classpath
        _java_type_PerformanceQueriesPersistentQueryStatusMonitor = jpy.get_type("io.deephaven.db.util.PerformanceQueries$PersistentQueryStatusMonitor")

    global _java_type_DBTimeUtils
    if _java_type_DBTimeUtils is None:
        # This will raise an exception if the desired object is not the classpath
        _java_type_DBTimeUtils = jpy.get_type("io.deephaven.db.tables.utils.DBTimeUtils")
예제 #3
0
def main(args):
    if args.insert_python_head is not None:
        # short circuit which module is being used, for testing
        # intended to allow short circuiting of Deephaven python module
        sys.path.insert(0, args.insert_python_head)

    from deephaven_legacy import start_jvm

    if not jpy.has_jvm():
        # we will try to initialize the jvm
        kwargs = {
            'workspace': args.workspace,
            'devroot': args.devroot,
            'verbose': False,
            'propfile': args.propfile,
            'java_home': os.environ.get('JDK_HOME', None),
            'jvm_properties': {},
            'jvm_options': {
                '-Djava.awt.headless=true',
                '-Xms1g',
                '-Xmn512m',
                # '-verbose:gc', '-XX:+PrintGCDetails',
            },
            'jvm_maxmem': '1g'
        }
        if args.classpath:
            kwargs['jvm_classpath'] = args.classpath
            kwargs['skip_default_classpath'] = True
            # kwargs['verbose'] = True
        # initialize the jvm
        start_jvm(**kwargs)
예제 #4
0
def _defineSymbols():
    """
    Defines appropriate java symbol, which requires that the jvm has been initialized through the :class:`jpy` module,
    for use throughout the module AT RUNTIME. This is versus static definition upon first import, which would lead to an
    exception if the jvm wasn't initialized BEFORE importing the module.
    """

    if not jpy.has_jvm():
        raise SystemError("No java functionality can be used until the JVM has been initialized through the jpy module")

    global _java_type_, _stream_table_tools_, _avro_schema_jtype_, \
        SEEK_TO_BEGINNING, DONT_SEEK, SEEK_TO_END, FROM_PROPERTIES, IGNORE, \
        ALL_PARTITIONS, ALL_PARTITIONS_SEEK_TO_BEGINNING, ALL_PARTITIONS_DONT_SEEK, ALL_PARTITIONS_SEEK_TO_END
    if _java_type_ is None:
        # This will raise an exception if the desired object is not the classpath
        _java_type_ = jpy.get_type("io.deephaven.kafka.KafkaTools")
        _stream_table_tools_ = jpy.get_type("io.deephaven.db.v2.StreamTableTools")
        _avro_schema_jtype_ = jpy.get_type("org.apache.avro.Schema")
        SEEK_TO_BEGINNING = getattr(_java_type_, 'SEEK_TO_BEGINNING')
        DONT_SEEK = getattr(_java_type_, 'DONT_SEEK')
        SEEK_TO_END = getattr(_java_type_, 'SEEK_TO_END')
        FROM_PROPERTIES = getattr(_java_type_, 'FROM_PROPERTIES')
        IGNORE = getattr(_java_type_, 'IGNORE')
        ALL_PARTITIONS = getattr(_java_type_, 'ALL_PARTITIONS')
        ALL_PARTITIONS_SEEK_TO_BEGINNING = getattr(_java_type_, 'ALL_PARTITIONS_SEEK_TO_BEGINNING')
        ALL_PARTITIONS_DONT_SEEK = getattr(_java_type_, 'ALL_PARTITIONS_DONT_SEEK')
        ALL_PARTITIONS_SEEK_TO_END = getattr(_java_type_, 'ALL_PARTITIONS_SEEK_TO_END')
예제 #5
0
def _defineSymbols():
    """
    Defines appropriate java symbols, which requires that the jvm has been initialized through the :class:`jpy` module,
    for use throughout the module AT RUNTIME. This is versus static definition upon first import, which would lead to an
    exception if the jvm wasn't initialized BEFORE importing the module.
    """

    if not jpy.has_jvm():
        raise SystemError(
            "No java functionality can be used until the JVM has been initialized through the jpy module"
        )

    global _Type_, _Mode_, _BadDataBehavior_, _TimeUnit_, _ByEmaSimple_, _Ema_, _EmaArray_, _ExponentiallyDecayedSum_

    if _Type_ is None:
        # This will raise an exception if the desired object is not the classpath
        _Type_ = jpy.get_type(
            'io.deephaven.numerics.movingaverages.AbstractMa$Type')
        _Mode_ = jpy.get_type(
            'io.deephaven.numerics.movingaverages.AbstractMa$Mode')
        _BadDataBehavior_ = jpy.get_type(
            'io.deephaven.numerics.movingaverages.ByEma$BadDataBehavior')
        _TimeUnit_ = jpy.get_type('java.util.concurrent.TimeUnit')
        _ByEmaSimple_ = jpy.get_type(
            'io.deephaven.numerics.movingaverages.ByEmaSimple')
        _Ema_ = jpy.get_type('io.deephaven.numerics.movingaverages.Ema')
        _EmaArray_ = jpy.get_type(
            'io.deephaven.numerics.movingaverages.EmaArray')
        _ExponentiallyDecayedSum_ = jpy.get_type(
            'io.deephaven.numerics.movingaverages.ExponentiallyDecayedSum')
예제 #6
0
def _defineSymbols():
    """
    Defines appropriate java symbols, which requires that the jvm has been initialized through the :class:`jpy` module,
    for use throughout the module AT RUNTIME. This is versus static definition upon first import, which would lead to an
    exception if the jvm wasn't initialized BEFORE importing the module.
    """

    if not jpy.has_jvm():
        raise SystemError(
            "No java functionality can be used until the JVM has been initialized through the jpy module"
        )

    global ColumnRenderersBuilder, DistinctFormatter, DownsampledWhereFilter, DynamicTableWriter, \
        LayoutHintBuilder, SmartKey, TotalsTableBuilder, SortPair

    if ColumnRenderersBuilder is None:
        # This will raise an exception if the desired object is not the classpath
        ColumnRenderersBuilder = jpy.get_type(
            'io.deephaven.db.v2.ColumnRenderersBuilder')
        DistinctFormatter = jpy.get_type(
            'io.deephaven.db.util.DBColorUtil$DistinctFormatter')
        DynamicTableWriter = jpy.get_type(
            'io.deephaven.db.v2.utils.DynamicTableWriter')
        DownsampledWhereFilter = jpy.get_type(
            'io.deephaven.db.v2.select.DownsampledWhereFilter')
        LayoutHintBuilder = jpy.get_type(
            'io.deephaven.db.tables.utils.LayoutHintBuilder')
        SmartKey = jpy.get_type('io.deephaven.datastructures.util.SmartKey')
        TotalsTableBuilder = jpy.get_type(
            'io.deephaven.db.v2.TotalsTableBuilder')
        SortPair = jpy.get_type("io.deephaven.db.tables.SortPair")
예제 #7
0
def ping_pong_java(result, remaining):
    if not jpy.has_jvm():
        raise Exception('Expected JVM to already be running')
    if remaining <= 0:
        return result
    PingPongStack = jpy.get_type('io.deephaven.jpy.integration.PingPongStack')
    return PingPongStack.pingPongPython(
        '{}(python,{})'.format(result, remaining), remaining - 1)
예제 #8
0
def init_jvm(java_home=None,
             jvm_dll=None,
             jvm_maxmem=None,
             jvm_classpath=None,
             jvm_properties=None,
             jvm_options=None,
             config_file=None,
             config=None):
    """
    Creates a configured Java virtual machine which will be used by jpy.

    :param java_home: The Java JRE or JDK home directory used to search JVM shared library, if 'jvm_dll' is omitted.
    :param jvm_dll: The JVM shared library file. My be inferred from 'java_home'.
    :param jvm_maxmem: The JVM maximum heap space, e.g. '400M', '8G'. Refer to the java executable '-Xmx' option.
    :param jvm_classpath: The JVM search paths for Java class files. Separated by colons (Unix) or semicolons
                          (Windows). Refer to the java executable '-cp' option.
    :param jvm_properties: A dictionary of key -> value pairs passed to the JVM as Java system properties.
                        Refer to the java executable '-D' option.
    :param jvm_options: A list of extra options for the JVM. Refer to the java executable options.
    :param config_file: Extra configuration file (e.g. 'jpyconfig.py') to be loaded if 'config' parameter is omitted.
    :param config: An optional default configuration object providing default attributes
                   for the 'jvm_maxmem', 'jvm_classpath', 'jvm_properties', 'jvm_options' parameters.
    :return: a tuple (cdll, actual_jvm_options) on success, None otherwise.
    """
    if not config:
        config = _get_python_api_config(config_file=config_file)

    cdll = preload_jvm_dll(jvm_dll_file=jvm_dll,
                           java_home_dir=java_home,
                           config_file=config_file,
                           config=config,
                           fail=False)

    import jpy

    if not jpy.has_jvm():
        jvm_options = get_jvm_options(jvm_maxmem=jvm_maxmem,
                                      jvm_classpath=jvm_classpath,
                                      jvm_properties=jvm_properties,
                                      jvm_options=jvm_options,
                                      config=config)
        logger.debug('Creating JVM with options %s' % repr(jvm_options))
        jpy.create_jvm(options=jvm_options)

        py_lib_initializer = jpy.get_type('org.jpy.PyLibInitializer')
        py_lib_initializer.initPyLib(
            _find_python_dll_file(fail=True),
            _get_module_path('jpy', fail=True),
            _get_module_path('jdl', fail=True)
        )
    else:
        jvm_options = None

    # print('jvm_dll =', jvm_dll)
    # print('jvm_options =', jvm_options)
    return cdll, jvm_options
예제 #9
0
def _defineSymbols():
    """
    Defines appropriate java symbol, which requires that the jvm has been initialized through the :class:`jpy` module,
    for use throughout the module AT RUNTIME. This is versus static definition upon first import, which would lead to an
    exception if the jvm wasn't initialized BEFORE importing the module.
    """

    if not jpy.has_jvm():
        raise SystemError("No java functionality can be used until the JVM has been initialized through the jpy module")

    global _java_type_
    if _java_type_ is None:
        # This will raise an exception if the desired object is not the classpath
        _java_type_ = jpy.get_type("io.deephaven.db.v2.utils.TableLoggers")
예제 #10
0
파일: jpyutil.py 프로젝트: francbartoli/jpy
def init_jvm(java_home=None,
             jvm_dll=None,
             jvm_maxmem=None,
             jvm_classpath=None,
             jvm_properties=None,
             jvm_options=None,
             config_file=None,
             config=None):
    """
    Creates a configured Java virtual machine which will be used by jpy.

    :param java_home: The Java JRE or JDK home directory used to search JVM shared library, if 'jvm_dll' is omitted.
    :param jvm_dll: The JVM shared library file. My be inferred from 'java_home'.
    :param jvm_maxmem: The JVM maximum heap space, e.g. '400M', '8G'. Refer to the java executable '-Xmx' option.
    :param jvm_classpath: The JVM search paths for Java class files. Separated by colons (Unix) or semicolons
                          (Windows). Refer to the java executable '-cp' option.
    :param jvm_properties: A dictionary of key -> value pairs passed to the JVM as Java system properties.
                        Refer to the java executable '-D' option.
    :param jvm_options: A list of extra options for the JVM. Refer to the java executable options.
    :param config_file: Extra configuration file (e.g. 'jpyconfig.py') to be loaded if 'config' parameter is omitted.
    :param config: An optional default configuration object providing default attributes
                   for the 'jvm_maxmem', 'jvm_classpath', 'jvm_properties', 'jvm_options' parameters.
    :return: a tuple (cdll, actual_jvm_options) on success, None otherwise.
    """
    if not config:
        config = _get_python_api_config(config_file=config_file)

    cdll = preload_jvm_dll(jvm_dll_file=jvm_dll,
                           java_home_dir=java_home,
                           config_file=config_file,
                           config=config,
                           fail=False)

    import jpy

    if not jpy.has_jvm():
        jvm_options = get_jvm_options(jvm_maxmem=jvm_maxmem,
                                      jvm_classpath=jvm_classpath,
                                      jvm_properties=jvm_properties,
                                      jvm_options=jvm_options,
                                      config=config)
        logging.debug('Creating JVM with options %s' % repr(jvm_options))
        jpy.create_jvm(options=jvm_options)
    else:
        jvm_options = None

    # print('jvm_dll =', jvm_dll)
    # print('jvm_options =', jvm_options)
    return cdll, jvm_options
def _defineSymbols():
    if not jpy.has_jvm():
        raise SystemError(
            "No java functionality can be used until the JVM has been initialized through the jpy module"
        )

    global _table_tools_, _col_def_, _jprops_, _jmap_, _python_tools_, IDENTITY
    if _table_tools_ is None:
        # This will raise an exception if the desired object is not the classpath
        _table_tools_ = jpy.get_type("io.deephaven.db.tables.utils.TableTools")
        _col_def_ = jpy.get_type("io.deephaven.db.tables.ColumnDefinition")
        _jprops_ = jpy.get_type("java.util.Properties")
        _jmap_ = jpy.get_type("java.util.HashMap")
        _python_tools_ = jpy.get_type(
            "io.deephaven.integrations.python.PythonTools")
        IDENTITY = object()  # Ensure IDENTITY is unique.
예제 #12
0
def build_py_session():
    if not jpy.has_jvm():
        DEFAULT_DEVROOT = os.environ.get('DEEPHAVEN_DEVROOT',
                                         "/tmp/pyintegration")
        DEFAULT_WORKSPACE = os.environ.get('DEEPHAVEN_WORKSPACE', "/tmp")
        DEFAULT_PROPFILE = os.environ.get('DEEPHAVEN_PROPFILE',
                                          'dh-defaults.prop')
        DEFAULT_CLASSPATH = os.environ.get('DEEPHAVEN_CLASSPATH',
                                           "/app/classese/*:/app/libs/*")
        os.environ['JAVA_VERSION'] = '1.8'
        os.environ['JDK_HOME'] = '/usr/lib/jvm/zulu8/jre/'

        # we will try to initialize the jvm
        kwargs = {
            'workspace': DEFAULT_WORKSPACE,
            'devroot': DEFAULT_DEVROOT,
            'verbose': False,
            'propfile': DEFAULT_PROPFILE,
            'java_home': os.environ.get('JDK_HOME', None),
            'jvm_properties': {
                'PyObject.cleanup_on_thread': 'false'
            },
            'jvm_options': {
                '-Djava.awt.headless=true',
                '-Xms1g',
                '-Xmn512m',
                # '-verbose:gc', '-XX:+PrintGCDetails',
            },
            'jvm_maxmem': '1g',
            'jvm_classpath': DEFAULT_CLASSPATH,
            'skip_default_classpath': True
        }
        # initialize the jvm
        start_jvm(**kwargs)

        # set up a Deephaven Python session
        py_scope_jpy = jpy.get_type(
            "io.deephaven.db.util.PythonScopeJpyImpl").ofMainGlobals()
        py_dh_session = jpy.get_type(
            "io.deephaven.db.util.PythonDeephavenSession")(py_scope_jpy)
        jpy.get_type("io.deephaven.db.tables.select.QueryScope").setScope(
            py_dh_session.newQueryScope())
예제 #13
0
def _defineSymbols():
    """
    Defines appropriate java symbol, which requires that the jvm has been initialized through the :class:`jpy` module,
    for use throughout the module AT RUNTIME. This is versus static definition upon first import, which would lead to an
    exception if the jvm wasn't initialized BEFORE importing the module.
    """

    if not jpy.has_jvm():
        raise SystemError(
            "No java functionality can be used until the JVM has been initialized through the jpy module"
        )

    global _java_type_, _java_file_type_, _dh_config_, _compression_codec_
    if _java_type_ is None:
        # This will raise an exception if the desired object is not the classpath
        _java_type_ = jpy.get_type("io.deephaven.db.tables.utils.ParquetTools")
        _java_file_type_ = jpy.get_type("java.io.File")
        _dh_config_ = jpy.get_type("io.deephaven.configuration.Configuration")
        _compression_codec_ = jpy.get_type(
            "org.apache.parquet.hadoop.metadata.CompressionCodecName")
예제 #14
0
def _defineSymbols():
    """
    Defines appropriate java symbol, which requires that the jvm has been initialized through the :class:`jpy` module,
    for use throughout the module AT RUNTIME. This is versus static definition upon first import, which would lead to an
    exception if the jvm wasn't initialized BEFORE importing the module.

    Raises:
        SystemError : if no JVM has been initialized.
    """

    if not jpy.has_jvm():
        raise SystemError("No java functionality can be used until the JVM has been initialized through the jpy module")

    global _Input_, _Output_, _Computer_, _Scatterer_

    if _Input_ is None:
        _Input_ = jpy.get_type("io.deephaven.integrations.learn.Input")
        _Output_ = jpy.get_type("io.deephaven.integrations.learn.Output")
        _Computer_ = jpy.get_type("io.deephaven.integrations.learn.Computer")
        _Scatterer_ = jpy.get_type("io.deephaven.integrations.learn.Scatterer")
예제 #15
0
def _defineSymbols():
    """
    Defines appropriate java symbol, which requires that the jvm has been initialized through the :class:`jpy` module,
    for use throughout the module AT RUNTIME. This is versus static definition upon first import, which would lead to an
    exception if the jvm wasn't initialized BEFORE importing the module.
    """

    if not jpy.has_jvm():
        raise SystemError(
            "No java functionality can be used until the JVM has been initialized through the jpy module"
        )

    global _java_type_, _avro_schema_jtype_, _produce_jtype_, IGNORE
    if _java_type_ is None:
        # This will raise an exception if the desired object is not the classpath
        _java_type_ = jpy.get_type("io.deephaven.kafka.KafkaTools")
        _stream_table_tools_ = jpy.get_type(
            "io.deephaven.engine.table.impl.StreamTableTools")
        _avro_schema_jtype_ = jpy.get_type("org.apache.avro.Schema")
        _produce_jtype_ = jpy.get_type("io.deephaven.kafka.KafkaTools$Produce")
        IGNORE = getattr(_produce_jtype_, 'IGNORE')
예제 #16
0
def _defineSymbols():
    """
    Defines appropriate java symbol, which requires that the jvm has been initialized through the :class:`jpy` module,
    for use throughout the module AT RUNTIME. This is versus static definition upon first import, which would lead to an
    exception if the jvm wasn't initialized BEFORE importing the module.
    """

    if not jpy.has_jvm():
        raise SystemError(
            "No java functionality can be used until the JVM has been initialized through the jpy module"
        )

    global _JCsvHelpers, _JTableHeader, _JCsvTools, _JParsers, _JArrays

    if _JCsvHelpers is None:
        # This will raise an exception if the desired object is not the classpath
        _JCsvHelpers = jpy.get_type("io.deephaven.csv.CsvTools")
        _JTableHeader = jpy.get_type("io.deephaven.qst.table.TableHeader")
        _JCsvTools = jpy.get_type("io.deephaven.csv.CsvTools")
        _JParsers = jpy.get_type("io.deephaven.csv.parsers.Parsers")
        _JArrays = jpy.get_type("java.util.Arrays")
예제 #17
0
def start_jvm(jvm_props: Dict[str, str] = None):
    """ This function uses the default DH property file to embed the Deephaven server and starts a Deephaven Python
    Script session. """
    if not jpy.has_jvm():

        # we will try to initialize the jvm
        workspace = os.environ.get('DEEPHAVEN_WORKSPACE', '.')
        devroot = os.environ.get('DEEPHAVEN_DEVROOT', '.')
        propfile = os.environ.get('DEEPHAVEN_PROPFILE', 'dh-defaults.prop')

        # validate devroot & workspace
        if devroot is None:
            raise IOError("dh.init: devroot is not specified.")
        if not os.path.isdir(devroot):
            raise IOError(
                "dh.init: devroot={} does not exist.".format(devroot))

        if workspace is None:
            raise IOError("dh.init: workspace is not specified.")
        if not os.path.isdir(workspace):
            raise IOError(
                "dh.init: workspace={} does not exist.".format(workspace))

        dtemp = workspace
        for entry in ['', 'cache', 'classes']:
            dtemp = os.path.join(dtemp, entry)
            if os.path.exists(dtemp):
                if not (os.path.isdir(dtemp)
                        and os.access(dtemp, os.W_OK | os.X_OK)):
                    # this is silly, but a directory must be both writable and executible by a user for a
                    # file to be written there - write without executible is delete only
                    raise IOError(
                        "dh.init: workspace directory={} does exists, but is "
                        "not writeable by your user.".format(dtemp))
            else:
                # Log potentially helpful warning - in case of failure.
                warnings.warn(
                    "dh.init: workspace directory={} does not exist, and its absence may "
                    "lead to an error. When required, it SHOULD get created with appropriate "
                    "permissions by the Deephaven class DynamicCompileUtils. If strange errors arise "
                    "from jpy about inability to find some java class, then check "
                    "the existence/permissions of the directory.".format(
                        dtemp), RuntimeWarning)

        jvm_properties = {
            'PyObject.cleanup_on_thread': 'false',
            'java.awt.headless': 'true',
            'MetricsManager.enabled': 'true',
            'Configuration.rootFile': propfile,
            'devroot': os.path.realpath(devroot),
            'workspace': os.path.realpath(workspace),
        }

        if jvm_props:
            jvm_properties.update(jvm_props)

        jvm_options = {
            '-XX:+UseG1GC',
            '-XX:MaxGCPauseMillis=100',
            '-XX:+UseStringDeduplication',
            '-XX:InitialRAMPercentage=25.0',
            '-XX:MinRAMPercentage=70.0',
            '-XX:MaxRAMPercentage=80.0',
            '--add-opens=java.base/java.nio=ALL-UNNAMED',
        }
        jvm_classpath = os.environ.get('DEEPHAVEN_CLASSPATH', '')

        # Start up the JVM
        jpy.VerboseExceptions.enabled = True
        jpyutil.init_jvm(jvm_classpath=_expandWildcardsInList(
            jvm_classpath.split(os.path.pathsep)),
                         jvm_properties=jvm_properties,
                         jvm_options=jvm_options)

        # Set up a Deephaven Python session
        py_scope_jpy = jpy.get_type(
            "io.deephaven.engine.util.PythonScopeJpyImpl").ofMainGlobals()
        py_dh_session = jpy.get_type(
            "io.deephaven.engine.util.PythonDeephavenSession")(py_scope_jpy)
        jpy.get_type("io.deephaven.engine.table.lang.QueryScope").setScope(
            py_dh_session.newQueryScope())
예제 #18
0
    options = [
        '-Djava.awt.headless=true',
        '-Djava.class.path=' + os.pathsep.join(class_path),
        '-Djava.library.path=' + os.pathsep.join(library_path),
        '-Xmx' + max_mem
    ]

    if config.has_option('DEFAULT', 'java_options'):
        extra_options = config.get('DEFAULT', 'java_options')
        options += extra_options.split('|')

    return options


# Figure out if this module is called from a Java VM. If not, derive a list of Java VM options and create the Java VM.
called_from_java = jpy.has_jvm()
if not called_from_java:
    jpy.create_jvm(options=_get_snap_jvm_options())

# Don't need these functions anymore
del _get_snap_jvm_options
del _get_snap_jvm_env
del _collect_snap_jvm_env


# noinspection PyUnusedLocal
def annotate_RasterDataNode_methods(type_name, method):
    index = -1

    if sys.version_info >= (
            3,
예제 #19
0
        max_mem = config.get('DEFAULT', 'java_max_mem')

    options = ['-Djava.awt.headless=true',
               '-Djava.class.path=' + os.pathsep.join(class_path),
               '-Djava.library.path=' + os.pathsep.join(library_path),
               '-Xmx' + max_mem]

    if config.has_option('DEFAULT', 'java_options'):
        extra_options = config.get('DEFAULT', 'java_options')
        options += extra_options.split('|')

    return options


# Figure out if this module is called from a Java VM. If not, derive a list of Java VM options and create the Java VM.
called_from_java = jpy.has_jvm()
if not called_from_java:
    jpy.create_jvm(options=_get_snap_jvm_options())


# Don't need these functions anymore
del _get_snap_jvm_options
del _get_snap_jvm_env
del _collect_snap_jvm_env


# noinspection PyUnusedLocal
def annotate_RasterDataNode_methods(type_name, method):
    index = -1

    if sys.version_info >= (3, 0, 0,):
 def test_start_jvm(self):
     build_py_session()
     self.assertTrue(jpy.has_jvm())
예제 #21
0
if __name__ != '__main__':
    quit()

import jpyutil
import jpy

print(jpy.has_jvm())
print(jpyutil.init_jvm())
print(jpy.has_jvm())

System = jpy.get_type('java.lang.System')
File = jpy.get_type('java.io.File')

classpath = System.getProperty('java.class.path')
separator = File.pathSeparator
classpathEntries = classpath.split(separator)
for entry in classpathEntries:
    print(entry)
예제 #22
0
def _defineSymbols():
    if not jpy.has_jvm():
        raise SystemError(
            "No java functionality can be used until the JVM has been initialized through the jpy module"
        )

    global _table_tools_, _table_factory_, _col_def_, _python_tools_, _qst_col_header_, \
        _qst_column_, _qst_newtable_, _qst_type_, _table_, \
        DataType, bool_, byte, short, int16, char, int_, int32, long_, int64, \
        float_, single, float32, double, float64, \
        string, bigdecimal, biginteger, stringset, datetime, timeperiod, \
        byte_array, short_array, int16_array, int_array, int32_array, long_array, int64_array, \
        float_array, single_array, float32_array, double_array, float64_array, string_array, \
        _type2jtype

    if _table_tools_ is None:
        # This will raise an exception if the desired object is not the classpath
        _table_tools_ = jpy.get_type("io.deephaven.engine.util.TableTools")
        _table_factory_ = jpy.get_type(
            "io.deephaven.engine.table.TableFactory")
        _col_def_ = jpy.get_type("io.deephaven.engine.table.ColumnDefinition")
        _python_tools_ = jpy.get_type(
            "io.deephaven.integrations.python.PythonTools")
        _qst_col_header_ = jpy.get_type(
            "io.deephaven.qst.column.header.ColumnHeader")
        _qst_column_ = jpy.get_type("io.deephaven.qst.column.Column")
        _qst_newtable_ = jpy.get_type("io.deephaven.qst.table.NewTable")
        _qst_type_ = jpy.get_type("io.deephaven.qst.type.Type")
        _table_ = jpy.get_type("io.deephaven.engine.table.Table")

    if DataType is None:
        DataType = NewType('DataType', _qst_type_)
        bool_ = DataType(_qst_type_.booleanType())
        byte = DataType(_qst_type_.byteType())
        short = DataType(_qst_type_.shortType())
        int16 = short  # make life simple for people who are used to pyarrow
        char = DataType(_qst_type_.charType())
        int_ = DataType(_qst_type_.intType())
        int32 = int_  # make life simple for people who are used to pyarrow
        long_ = DataType(_qst_type_.longType())
        int64 = long_  # make life simple for people who are used to pyarrow
        float_ = DataType(_qst_type_.floatType())
        single = float_  # make life simple for people who are used to NumPy
        float32 = float_  # make life simple for people who are used to pyarrow
        double = DataType(_qst_type_.doubleType())
        float64 = double  # make life simple for people who are used to pyarrow
        string = DataType(_qst_type_.stringType())
        bigdecimal = _typeFromJavaClassName('java.math.BigDecimal')
        biginteger = _typeFromJavaClassName('java.math.BigInteger')
        stringset = _typeFromJavaClassName('io.deephaven.stringset.StringSet')
        datetime = _typeFromJavaClassName('io.deephaven.time.DateTime')
        timeperiod = _typeFromJavaClassName('io.deephaven.time.Period')

        # Array types.
        byte_array = DataType(byte.arrayType())
        short_array = DataType(short.arrayType())
        int16_array = short_array
        int_array = DataType(int_.arrayType())
        int32_array = int_array
        long_array = DataType(long_.arrayType())
        int64_array = long_array
        float_array = DataType(float_.arrayType())
        single_array = float_array
        float32_array = float_array
        double_array = DataType(double.arrayType())
        float64_array = double_array
        string_array = DataType(string.arrayType())

        _type2jtype = {
            bool_: jpy.get_type('java.lang.Boolean'),
            byte: jpy.get_type('byte'),
            short: jpy.get_type('short'),
            int_: jpy.get_type('int'),
            long_: jpy.get_type('long'),
            float_: jpy.get_type('float'),
            double: jpy.get_type('double'),
            string: jpy.get_type('java.lang.String'),
            bigdecimal: jpy.get_type('java.math.BigDecimal'),
            biginteger: jpy.get_type('java.math.BigInteger'),
            stringset: jpy.get_type('io.deephaven.stringset.StringSet'),
            datetime: jpy.get_type('io.deephaven.time.DateTime'),
            timeperiod: jpy.get_type('io.deephaven.time.Period'),
            byte_array: jpy.get_type('[B'),
            short_array: jpy.get_type('[S'),
            int_array: jpy.get_type('[I'),
            long_array: jpy.get_type('[J'),
            float_array: jpy.get_type('[S'),
            double_array: jpy.get_type('[D'),
            string_array: jpy.get_type('[Ljava.lang.String;')
        }
예제 #23
0
    if config.has_option('DEFAULT', 'extra_options'):
        max_mem = config.get('DEFAULT', 'max_mem')

    options = [
        '-Djava.awt.headless=true',
        '-Djava.class.path=' + os.pathsep.join(classpath), '-Xmx' + max_mem
    ]

    if config.has_option('DEFAULT', 'extra_options'):
        extra_options = config.get('DEFAULT', 'extra_options')
        options += extra_options.split('|')

    return options


if not jpy.has_jvm():
    jpy.create_jvm(options=_get_jvm_options())

# Don't need these functions anymore
del _get_jvm_options
del _get_beam_jar_locations
del _create_classpath
del _collect_classpath


def annotate_RasterDataNode_methods(type, method):
    index = -1

    if sys.version_info >= (
            3,
            0,
예제 #24
0
 def test_has_jvm_again(self):
   self.assertTrue(jpy.has_jvm())
예제 #25
0
    # pprint.pprint(classpath)

    max_mem = "512M"
    if config.has_option("DEFAULT", "extra_options"):
        max_mem = config.get("DEFAULT", "max_mem")

    options = ["-Djava.awt.headless=true", "-Djava.class.path=" + os.pathsep.join(classpath), "-Xmx" + max_mem]

    if config.has_option("DEFAULT", "extra_options"):
        extra_options = config.get("DEFAULT", "extra_options")
        options += extra_options.split("|")

    return options


if not jpy.has_jvm():
    jpy.create_jvm(options=_get_jvm_options())


# Don't need these functions anymore
del _get_jvm_options
del _get_beam_jar_locations
del _create_classpath
del _collect_classpath


def annotate_RasterDataNode_methods(type, method):
    index = -1

    if sys.version_info >= (3, 0, 0):
        arr_z_type_str = "<class '[Z'>"