├── py4j-web ├── _static │ └── empty ├── .gitignore ├── requirements-doc.txt ├── images │ ├── logic.dia │ ├── logic.png │ └── class_structure.dia ├── themes │ └── py4jdoc │ │ ├── theme.conf │ │ ├── static │ │ ├── contents.png │ │ └── navigation.png │ │ └── layout.html ├── .settings │ └── org.eclipse.core.resources.prefs ├── TODO ├── .pydevproject ├── contents.rst ├── .project ├── py4j_java.rst ├── py4j_python.rst ├── download.rst ├── py4j_java_protocol.rst ├── py4j_finalizer.rst ├── LICENSE.txt ├── py4j_signals.rst ├── about.rst ├── py4j_java_collections.rst └── py4j_client_server.rst ├── .gitignore ├── py4j-python ├── .cache │ └── v │ │ └── cache │ │ └── lastfailed ├── nose.cfg ├── src │ └── py4j │ │ ├── version.py │ │ ├── tests │ │ ├── __init__.py │ │ ├── py4j_example.py │ │ ├── py4j_callback_example2.py │ │ ├── py4j_callback_example.py │ │ ├── py4j_callback_listener_example.py │ │ ├── byte_string_test.py │ │ ├── py4j_callback_recursive_example.py │ │ ├── java_array_test.py │ │ └── java_map_test.py │ │ └── __init__.py ├── requirements-test.txt ├── tox.ini ├── .gitignore ├── .settings │ └── org.eclipse.core.resources.prefs ├── MANIFEST.in ├── setup.cfg ├── .pydevproject ├── .project ├── README.rst ├── release_process.txt ├── LICENSE.txt └── setup.py ├── requirements.txt ├── py4j-java ├── junit-4.10.jar ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ ├── test │ │ ├── resources │ │ │ └── selfsigned.jks │ │ └── java │ │ │ ├── p1 │ │ │ ├── AnObject2.java │ │ │ ├── AnObject4.java │ │ │ ├── AnObject3.java │ │ │ ├── AnObject.java │ │ │ └── p2 │ │ │ │ └── Animal.java │ │ │ └── py4j │ │ │ ├── examples │ │ │ ├── Enum2.java │ │ │ ├── InterfaceA.java │ │ │ ├── InterfaceB.java │ │ │ ├── InterfaceNone.java │ │ │ ├── ExampleListener.java │ │ │ ├── BytesOperator.java │ │ │ ├── IHello.java │ │ │ ├── IPing.java │ │ │ ├── IPong.java │ │ │ ├── ExampleEntryPoint.java │ │ │ ├── Operator.java │ │ │ ├── MultiClientServerGetThreadId.java │ │ │ ├── ExampleWithField.java │ │ │ ├── IHelloObject.java │ │ │ ├── IReturnConverter.java │ │ │ ├── EnumExample.java │ │ │ ├── InterfaceExample.java │ │ │ ├── AdditionApplication.java │ │ │ ├── TestNoneApplication.java │ │ │ ├── ListPrinter.java │ │ │ ├── StackEntryPoint.java │ │ │ ├── SingleThreadClientApplication.java │ │ │ ├── BufferGenerator.java │ │ │ ├── ReturnerExample.java │ │ │ ├── Stack.java │ │ │ ├── PingPong.java │ │ │ ├── SingleThreadClientGCApplication.java │ │ │ ├── ListenerApplication.java │ │ │ ├── SingleThreadApplication.java │ │ │ └── UTFExample.java │ │ │ ├── instrumented │ │ │ ├── InstrumentedObject.java │ │ │ ├── InstrCallbackConnection.java │ │ │ ├── InstrGatewayConnection.java │ │ │ ├── InstrCallbackClient.java │ │ │ ├── InstrClientServerConnection.java │ │ │ ├── InstrGatewayServer.java │ │ │ ├── InstrJavaServer.java │ │ │ └── InstrumentedApplication.java │ │ │ ├── reflection │ │ │ ├── MethodDescriptorTest.java │ │ │ └── ReflectionUtilTest.java │ │ │ ├── InstrGatewayTest.java │ │ │ ├── BufferGatewayTest.java │ │ │ └── EchoClientTest.java │ └── main │ │ └── java │ │ └── py4j │ │ ├── reflection │ │ ├── ClassLoadingStrategy.java │ │ ├── RootClassLoadingStrategy.java │ │ ├── CurrentThreadClassLoadingStrategy.java │ │ ├── LRUCache.java │ │ └── ReflectionUtil.java │ │ ├── Py4JServerConnection.java │ │ ├── Py4JClientConnection.java │ │ ├── DefaultApplication.java │ │ ├── Py4JPythonClientPerThread.java │ │ ├── Py4JException.java │ │ ├── Py4JJavaException.java │ │ ├── StringUtil.java │ │ ├── DefaultGatewayServerListener.java │ │ ├── model │ │ ├── Py4JMember.java │ │ └── Py4JField.java │ │ └── commands │ │ └── ExceptionCommand.java ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── py4j.importorder ├── logging.properties ├── gradle.properties ├── .gitignore ├── .project ├── .classpath ├── ant.properties ├── LICENSE.txt ├── py4j.license.java ├── pom.xml └── gradlew.bat ├── MANIFEST.in ├── AUTHORS.txt ├── LICENSE.txt ├── README.rst ├── circle.yml └── setup.py /py4j-web/_static/empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /build 3 | -------------------------------------------------------------------------------- /py4j-python/.cache/v/cache/lastfailed: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /py4j-web/.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | *.swp 3 | -------------------------------------------------------------------------------- /py4j-web/requirements-doc.txt: -------------------------------------------------------------------------------- 1 | Sphinx~=1.4 2 | -------------------------------------------------------------------------------- /py4j-python/nose.cfg: -------------------------------------------------------------------------------- 1 | [nosetests] 2 | verbosity=3 3 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.10.6' 2 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Py4J Test Package 2 | -------------------------------------------------------------------------------- /py4j-python/requirements-test.txt: -------------------------------------------------------------------------------- 1 | flake8>=2.4.1 2 | tox>=2.1.1 3 | nose>=1.3.7 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | -r py4j-python/requirements-test.txt 2 | -r py4j-web/requirements-doc.txt 3 | -------------------------------------------------------------------------------- /py4j-java/junit-4.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/batterseapower/py4j/master/py4j-java/junit-4.10.jar -------------------------------------------------------------------------------- /py4j-web/images/logic.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/batterseapower/py4j/master/py4j-web/images/logic.dia -------------------------------------------------------------------------------- /py4j-web/images/logic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/batterseapower/py4j/master/py4j-web/images/logic.png -------------------------------------------------------------------------------- /py4j-web/images/class_structure.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/batterseapower/py4j/master/py4j-web/images/class_structure.dia -------------------------------------------------------------------------------- /py4j-web/themes/py4jdoc/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = py4jdoc.css 4 | pygments_style = friendly 5 | -------------------------------------------------------------------------------- /py4j-python/tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist=py26,py27,py34,py35 3 | 4 | [testenv] 5 | deps=nose 6 | commands=nosetests -w src -c nose.cfg 7 | -------------------------------------------------------------------------------- /py4j-java/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/batterseapower/py4j/master/py4j-java/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /py4j-java/src/test/resources/selfsigned.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/batterseapower/py4j/master/py4j-java/src/test/resources/selfsigned.jks -------------------------------------------------------------------------------- /py4j-web/themes/py4jdoc/static/contents.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/batterseapower/py4j/master/py4j-web/themes/py4jdoc/static/contents.png -------------------------------------------------------------------------------- /py4j-web/themes/py4jdoc/static/navigation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/batterseapower/py4j/master/py4j-web/themes/py4jdoc/static/navigation.png -------------------------------------------------------------------------------- /py4j-java/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Wed Feb 10 10:48:09 EST 2010 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /py4j-java/py4j.importorder: -------------------------------------------------------------------------------- 1 | #Organize Import Order 2 | #Thu Mar 10 04:51:29 EST 2016 3 | 5=p1 4 | 4=py4j 5 | 3=com 6 | 2=org 7 | 1=javax 8 | 0=java 9 | -------------------------------------------------------------------------------- /py4j-python/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | doc/ 3 | *.swp 4 | *.tox/ 5 | tags 6 | dist/ 7 | MANIFEST 8 | py4j-java/ 9 | py4j.egg-info/ 10 | /build 11 | .cache 12 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/__init__.py: -------------------------------------------------------------------------------- 1 | # Py4J Package 2 | from __future__ import absolute_import 3 | from . import version 4 | 5 | __version__ = version.__version__ 6 | -------------------------------------------------------------------------------- /py4j-web/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Wed Feb 10 10:47:43 EST 2010 2 | eclipse.preferences.version=1 3 | encoding/=UTF-8 4 | encoding/conf.py=utf-8 5 | -------------------------------------------------------------------------------- /py4j-python/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Thu May 12 08:19:50 EDT 2011 2 | eclipse.preferences.version=1 3 | encoding//src/py4j/compat.py=utf-8 4 | encoding/=UTF-8 5 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include setup.py 3 | include py4j-python/LICENSE.txt 4 | include py4j-python/nose.cfg 5 | recursive-include py4j-python/doc *.* 6 | recursive-include py4j-python/py4j-java *.* 7 | -------------------------------------------------------------------------------- /py4j-java/logging.properties: -------------------------------------------------------------------------------- 1 | handlers=java.util.logging.ConsoleHandler 2 | .level=INFO 3 | java.util.logging.ConsoleHandler.level = FINEST 4 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter -------------------------------------------------------------------------------- /py4j-python/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include setup.py 3 | include LICENSE.txt 4 | include nose.cfg 5 | include src/py4j/tests/selfsigned.pem 6 | recursive-include doc *.* 7 | recursive-include py4j-java *.* 8 | -------------------------------------------------------------------------------- /py4j-web/TODO: -------------------------------------------------------------------------------- 1 | - change template so that the main content and the side bars are in a div container (easier so the sidebar can go to the side of the container instead of the side of the page, which is just plain ugly/impossible). 2 | - find colors 3 | - plan web site architecture! -------------------------------------------------------------------------------- /py4j-python/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | # This flag says that the code is written to work on both Python 2 and Python 3 | # 3. If at all possible, it is good practice to do this. If you cannot, you 4 | # will need to generate wheels for each Python version that you support. 5 | universal=1 6 | -------------------------------------------------------------------------------- /py4j-java/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Mar 14 08:48:43 EDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-bin.zip 7 | -------------------------------------------------------------------------------- /py4j-web/.pydevproject: -------------------------------------------------------------------------------- 1 | 2 | python 2.6 3 | Default 4 | -------------------------------------------------------------------------------- /py4j-web/contents.rst: -------------------------------------------------------------------------------- 1 | Py4J Documentation 2 | ================== 3 | 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | :numbered: 8 | 9 | install 10 | getting_started 11 | advanced_topics 12 | py4j_python 13 | py4j_java 14 | faq 15 | contributing 16 | professional-services 17 | changelog 18 | -------------------------------------------------------------------------------- /py4j-java/gradle.properties: -------------------------------------------------------------------------------- 1 | group=py4j 2 | bundleVersion=0.10.6 3 | version=0.10.6 4 | sourceCompatibility=1.6 5 | targetCompatibility=1.6 6 | # Define the jdk6BootClasspath in your ~/.gradle/gradle.properties 7 | jdk6BootClasspath= 8 | # Define the eclipseHomePath in your ~/.gradle/gradle.properties 9 | eclipseHomePath= 10 | -------------------------------------------------------------------------------- /py4j-java/.gitignore: -------------------------------------------------------------------------------- 1 | /classes/ 2 | /bin/ 3 | /javadoc/ 4 | *.swp 5 | .ant-targets-build.xml 6 | /dist/ 7 | /junit/ 8 | py4j*.jar 9 | target/ 10 | *.asc 11 | bundle.jar 12 | /out/ 13 | 14 | ### Gradle ### 15 | .gradle 16 | /build/ 17 | 18 | # Ignore Gradle GUI config 19 | gradle-app.setting 20 | 21 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 22 | !gradle-wrapper.jar 23 | 24 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/tests/py4j_example.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Dec 19, 2009 3 | 4 | @author: barthelemy 5 | """ 6 | from py4j.java_gateway import JavaGateway 7 | 8 | if __name__ == "__main__": 9 | gateway = JavaGateway() 10 | buffer = gateway.getStringBuffer() 11 | buffer.append(True) 12 | buffer.append(1.0) 13 | buffer.append("This is a Python {0}".format("string")) 14 | print(buffer.toString()) 15 | -------------------------------------------------------------------------------- /py4j-python/.pydevproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | /py4j-python/src 4 | 5 | python 2.6 6 | Default 7 | -------------------------------------------------------------------------------- /py4j-web/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | py4j-web 4 | 5 | 6 | 7 | 8 | 9 | org.python.pydev.PyDevBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.python.pydev.pythonNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /py4j-java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | py4j-java 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /py4j-python/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | py4j-python 4 | 5 | 6 | 7 | 8 | 9 | org.python.pydev.PyDevBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.python.pydev.pythonNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/tests/py4j_callback_example2.py: -------------------------------------------------------------------------------- 1 | from py4j.java_gateway import JavaGateway 2 | 3 | 4 | class ClassNone(object): 5 | 6 | def getName(self): 7 | return None 8 | 9 | class Java: 10 | implements = ["py4j.examples.InterfaceNone"] 11 | 12 | if __name__ == "__main__": 13 | gateway = JavaGateway(start_callback_server=True) 14 | objectNone = ClassNone() 15 | returnValue = gateway.entry_point.testNone(objectNone) 16 | print(returnValue) 17 | gateway.shutdown() 18 | -------------------------------------------------------------------------------- /py4j-java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /py4j-web/themes/py4jdoc/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "basic_layout.html" %} 2 | 3 | {# put the sidebar before the body #} 4 | {% block rootrellink %} 5 |
  • Home |
  • 6 |
  • Download |
  • 7 |
  • Doc |
  • 8 |
  • Blog |
  • 9 |
  • github |
  • 10 |
  • About »
  • 11 | {% endblock %} 12 | {% block sidebar1 %}{{ sidebar() }}{% endblock %} 13 | {% block sidebar2 %}{% endblock %} 14 | -------------------------------------------------------------------------------- /py4j-web/py4j_java.rst: -------------------------------------------------------------------------------- 1 | Py4J Java API 2 | ============= 3 | 4 | The Java API is under active development and will be refactored in the next releases. You can browse the `javadoc <_static/javadoc/index.html>`_, but most classes are not documented yet. 5 | 6 | For now, the best way to use the API is to: 7 | 8 | 1. Create a class that extends the `DefaultGateway <_static/javadoc/index.html?py4j/DefaultGateway.html>`_. 9 | 2. Initialize a `GatewayServer <_static/javadoc/index.html?py4j/GatewayServer.html>`_ with your newly created class. 10 | 3. Call the `Gateway.start() <_static/javadoc/py4j/GatewayServer.html#start(boolean)>`_ method to enable your Python program to access your gateway. -------------------------------------------------------------------------------- /py4j-java/ant.properties: -------------------------------------------------------------------------------- 1 | # Version of the software 2 | version=0.10.6 3 | 4 | # Path to the JUnit 4 jar. YOU MUST SET THIS VALUE. Otherwise, the test classes won't compile. 5 | junit.path=junit-4.10.jar 6 | 7 | # Debug level passed to the Java compiler. Set to none if you don't plan to debug (or run tests?). 8 | debug.level=source,lines,vars 9 | 10 | # Build directory. Default is usually fine. 11 | build.dir=bin 12 | 13 | # Where the junit report will be written. Default is usually fine. 14 | junit.output.dir=junit 15 | 16 | # Used to build the distribution. Default is usually fine. 17 | dist.dir=dist 18 | 19 | # Javadoc directory. Default is usually fine. 20 | javadoc.dir=javadoc 21 | -------------------------------------------------------------------------------- /py4j-java/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Wed Dec 02 15:18:02 EST 2009 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.6 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /py4j-web/py4j_python.rst: -------------------------------------------------------------------------------- 1 | .. _python_api: 2 | 3 | Py4J Python API 4 | =============== 5 | 6 | Using Py4J is usually as simple as creating a :ref:`JavaGateway ` object: 7 | 8 | :: 9 | 10 | java_gateway = JavaGateway() 11 | # you are now connected to the JVM 12 | # and you can call any method defined on the Java side. 13 | 14 | You can still customize and extend Py4J in many ways (e.g., you can choose the 15 | port to which you want to connect). The following modules are documented. Note 16 | that users are expected to only use :mod:`py4j.java_gateway` or 17 | :mod:`py4j.clientserver`. 18 | 19 | .. toctree:: 20 | 21 | py4j_java_gateway.rst 22 | py4j_client_server.rst 23 | py4j_java_protocol.rst 24 | py4j_java_collections.rst 25 | py4j_finalizer.rst 26 | py4j_signals.rst 27 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/tests/py4j_callback_example.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Apr 27, 2010 3 | 4 | @author: barthelemy 5 | """ 6 | from py4j.java_gateway import JavaGateway, CallbackServerParameters 7 | 8 | 9 | class Addition(object): 10 | def doOperation(self, i, j, k=None): 11 | if k is None: 12 | return i + j 13 | else: 14 | return 3722507311 15 | 16 | class Java: 17 | implements = ["py4j.examples.Operator"] 18 | 19 | if __name__ == "__main__": 20 | gateway = JavaGateway( 21 | callback_server_parameters=CallbackServerParameters()) 22 | operator = Addition() 23 | numbers = gateway.entry_point.randomBinaryOperator(operator) 24 | print(numbers) 25 | numbers = gateway.entry_point.randomTernaryOperator(operator) 26 | print(numbers) 27 | gateway.shutdown() 28 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/tests/py4j_callback_listener_example.py: -------------------------------------------------------------------------------- 1 | from py4j.java_gateway import JavaGateway, CallbackServerParameters 2 | 3 | 4 | class PythonListener(object): 5 | 6 | def __init__(self, gateway): 7 | self.gateway = gateway 8 | 9 | def notify(self, obj): 10 | print("Notified by Java") 11 | print(obj) 12 | gateway.jvm.System.out.println("Hello from python!") 13 | 14 | return "A Return Value" 15 | 16 | class Java: 17 | implements = ["py4j.examples.ExampleListener"] 18 | 19 | if __name__ == "__main__": 20 | gateway = JavaGateway( 21 | callback_server_parameters=CallbackServerParameters()) 22 | listener = PythonListener(gateway) 23 | gateway.entry_point.registerListener(listener) 24 | gateway.entry_point.notifyAllListeners() 25 | gateway.shutdown() 26 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Py4J was originally created in 2009 by Barthelemy Dagenais. 2 | 3 | Here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS -- 4 | people who have submitted patches, reported bugs, and generally made Py4J that 5 | much better: 6 | 7 | Peter Abeles 8 | Max Bolingbroke 9 | Christophe Buffenoir 10 | Jacek Bzdak 11 | Barthelemy Dagenais 12 | Frankie Dintino 13 | Matthew Farrellee 14 | Nicholas Gates 15 | Matthew Gerring 16 | Jonah Graham 17 | Alex Grönholm 18 | Chris Kanich 19 | Scott Lewis 20 | Chetan Narsude <@243826> 21 | Josh Rosen 22 | Isaac Sánchez Barrera 23 | David C. Sterratt 24 | Greg Warner 25 | Nick White 26 | Shixiong Zhu <@zsxwing> 27 | -------------------------------------------------------------------------------- /py4j-web/download.rst: -------------------------------------------------------------------------------- 1 | Download Py4J 2 | ============= 3 | 4 | You can download Py4J by using pip, ``pip install py4j``, or easy_install, 5 | ``easy_install py4j``. 6 | 7 | Alternatively, you can download the latest version of Py4J from `PyPI 8 | `_. 9 | 10 | After you have downloaded Py4J, you can follow the :doc:`Installation 11 | instructions ` or jump to the :doc:`Getting Started Tutorial 12 | `. 13 | 14 | Download Py4J for Eclipse 15 | ========================= 16 | 17 | You can download Py4J plug-ins from this update site: 18 | 19 | ``http://eclipse.py4j.org/`` 20 | 21 | If you have Java 7+, you can use https: 22 | 23 | ``https://eclipse.py4j.org/`` 24 | 25 | Requirements 26 | ============ 27 | 28 | Py4J requires: 29 | 30 | * A Python interpreter. Py4J has been tested with CPython 2.6, 2.7, 31 | CPython 3.4, and CPython 3.5. 32 | * Java 6.0+. 33 | 34 | Py4J for Eclipse requires: 35 | 36 | * Eclipse 3.6+ (Eclipse 3.4 and 3.5 should probably work) 37 | * Java 6.0+ 38 | 39 | If you would like a particular version of Python or Java to be supported, fill 40 | a `feature request `_. 41 | -------------------------------------------------------------------------------- /py4j-python/README.rst: -------------------------------------------------------------------------------- 1 | Py4J 2 | ==== 3 | 4 | Py4J enables Python programs running in a Python interpreter to dynamically 5 | access Java objects in a Java Virtual Machine. Methods are called as if the 6 | Java objects resided in the Python interpreter and Java collections can be 7 | accessed through standard Python collection methods. Py4J also enables Java 8 | programs to call back Python objects. 9 | 10 | The latest compiled release is available in the current-release directory. 11 | 12 | This is the source repository of Py4J projects. Please visit the `Py4J homepage 13 | `_ for more information. 14 | 15 | For help, register and then post to the Py4J mailing list at 16 | ``py4j at py4j dot org`` 17 | 18 | LICENSE 19 | ======= 20 | 21 | Py4J is distributed with the BSD 3-Clause license. See LICENSE.txt for more 22 | information. 23 | 24 | 25 | CONTRIBUTING 26 | ============ 27 | 28 | We are always happy to receive code contributions, bug reports, and 29 | documentation fixes. Please visit the `contributing guide 30 | `_ for more 31 | information. 32 | 33 | .. image:: https://circleci.com/gh/bartdag/py4j.svg?style=svg 34 | :target: https://circleci.com/gh/bartdag/py4 35 | -------------------------------------------------------------------------------- /py4j-python/release_process.txt: -------------------------------------------------------------------------------- 1 | 0. Update all versions (version.py, properties, documentation, index.rst). 2 | 1. Write changelog 3 | 2. gradle clean 4 | 5 | 3. close all bugs on github 6 | 4. tag the release on git 7 | 8 | 5. gradle buildPython 9 | 6. create signature using gpg (gpg -b --armor) 10 | 11 | 7. upload to PyPI using twine 12 | 13 | 8. mvn package javadoc:jar source:jar 14 | 9. create signature for the three jar files and the pom (gpg -b --armor py4j-....jar) 15 | 10. jar -cvf bundle.jar pom.xml ... (all files) 16 | 11. create staging release in central (https://oss.sonatype.org Staging Upload, Upload Bundle) 17 | 12. close release 18 | 13. publish release 19 | 20 | 14. gradle updateSite 21 | 15. Extract and modify artifacts.xml and content.xml to change build path to: 22 | 1. Py4J p2 Repository (repository name in artifacts and content) 23 | 2. version.Py4J (unit name and provides name in content) 24 | 16. jar -cf content.jar content.xml 25 | 17. jar -cf artifacts artifacts.xml 26 | 18. Create a release with bintray 27 | 19. Create a zip file with the version (e.g., 0.10.0.zip) 28 | 20. Upload release 29 | 21. Update symbolic links of eclipse.py4j.org to point to latest release. 30 | 31 | 22. send an email to the mailing list. 32 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/tests/byte_string_test.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | from __future__ import absolute_import 3 | 4 | import unittest 5 | import time 6 | 7 | from py4j.java_gateway import JavaGateway 8 | from py4j.protocol import smart_decode 9 | from py4j.tests.java_gateway_test import ( 10 | start_example_app_process, safe_shutdown) 11 | 12 | 13 | class ByteStringTest(unittest.TestCase): 14 | def setUp(self): 15 | self.p = start_example_app_process() 16 | # This is to ensure that the server is started before connecting to it! 17 | time.sleep(1) 18 | self.gateway = JavaGateway() 19 | 20 | def tearDown(self): 21 | safe_shutdown(self) 22 | self.p.join() 23 | 24 | def testByteString(self): 25 | # NOTE: this is only a byte string if executed by Python 2. 26 | ex = self.gateway.jvm.py4j.examples.UTFExample() 27 | s1 = "allo" 28 | s2 = smart_decode("alloé") 29 | array1 = ex.getUtfValue(s1) 30 | array2 = ex.getUtfValue(s2) 31 | self.assertEqual(len(s1), len(array1)) 32 | self.assertEqual(len(s2), len(array2)) 33 | self.assertEqual(ord(s1[0]), array1[0]) 34 | self.assertEqual(ord(s2[4]), array2[4]) 35 | 36 | if __name__ == "__main__": 37 | unittest.main() 38 | -------------------------------------------------------------------------------- /py4j-web/py4j_java_protocol.rst: -------------------------------------------------------------------------------- 1 | :mod:`py4j.protocol` --- Py4J Protocol 2 | ========================================== 3 | 4 | .. module:: py4j.protocol 5 | :synopsis: Main Py4J Protocol Python module. 6 | .. moduleauthor:: Barthelemy Dagenais 7 | 8 | The :mod:`py4j.protocol` module defines most of the types, functions, and 9 | characters used in the Py4J protocol. It does not need to be explicitly used by 10 | clients of Py4J because it is automatically loaded by the :mod:`java_gateway 11 | ` module and the :mod:`java_collections 12 | ` module. 13 | 14 | .. _api_py4jerror: 15 | 16 | Py4JError 17 | ----------- 18 | 19 | .. autoclass:: py4j.protocol.Py4JError 20 | :members: 21 | :undoc-members: 22 | 23 | Py4JJavaError 24 | ------------- 25 | 26 | .. autoclass:: py4j.protocol.Py4JJavaError 27 | :members: 28 | :undoc-members: 29 | 30 | Py4JJavaError 31 | ------------- 32 | 33 | .. autoclass:: py4j.protocol.Py4JNetworkError 34 | :members: 35 | :undoc-members: 36 | 37 | Py4J Protocol Functions 38 | ----------------------- 39 | 40 | The following functions can be used to extend Py4J (e.g., to create new commands): 41 | 42 | .. autofunction:: py4j.protocol.escape_new_line 43 | 44 | .. autofunction:: py4j.protocol.unescape_new_line 45 | 46 | .. autofunction:: py4j.protocol.get_command_part 47 | 48 | .. autofunction:: py4j.protocol.get_return_value 49 | 50 | .. autofunction:: py4j.protocol.register_output_converter 51 | 52 | .. autofunction:: py4j.protocol.register_input_converter 53 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. All 2 | rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | - Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | - The name of the author may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /py4j-web/py4j_finalizer.rst: -------------------------------------------------------------------------------- 1 | :mod:`py4j.finalizer` --- Py4J Finalizer API 2 | ===================================================== 3 | 4 | .. module:: py4j.finalizer 5 | :synopsis: Global classes to register finalizers. 6 | .. moduleauthor:: Barthelemy Dagenais 7 | 8 | The :mod:`py4j.finalizer` module contains global classes that enables the 9 | registration of finalizers, i.e., weak reference callbacks. This module is used 10 | by Py4J to register a finalizer for each JavaObject instance: once there is no 11 | more reference to a JavaObject instance on the Python side, the finalizer sends 12 | a message to the JVM to remove the reference from the Gateway to prevent memory 13 | leak. 14 | 15 | The :mod:`py4j.finalizer` module is necessary because JavaObject instances have 16 | circular references with JavaMethods and hence, they cannot keep their own 17 | finalizer. 18 | 19 | .. _api_tsfinalizer: 20 | 21 | ThreadSafeFinalizer 22 | ------------------- 23 | 24 | .. autoclass:: py4j.finalizer.ThreadSafeFinalizer 25 | :members: 26 | :undoc-members: 27 | 28 | .. 29 | Examples 30 | ^^^^^^^^ 31 | 32 | :: 33 | 34 | TBD 35 | 36 | .. _api_finalizer: 37 | 38 | Finalizer 39 | --------- 40 | 41 | .. autoclass:: py4j.finalizer.Finalizer 42 | :members: 43 | :undoc-members: 44 | 45 | .. 46 | Examples 47 | ^^^^^^^^ 48 | 49 | :: 50 | 51 | TBD 52 | 53 | 54 | Py4J Finalizer Functions 55 | ------------------------ 56 | 57 | .. _api_functions_clear_finalizers: 58 | 59 | 60 | .. autofunction:: py4j.finalizer.clear_finalizers 61 | -------------------------------------------------------------------------------- /py4j-java/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. All 2 | rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | - Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | - The name of the author may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /py4j-web/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. All 2 | rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | - Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | - The name of the author may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /py4j-python/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. All 2 | rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | - Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | - Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | - The name of the author may not be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Py4J 2 | ==== 3 | 4 | Py4J enables Python programs running in a Python interpreter to dynamically 5 | access Java objects in a Java Virtual Machine. Methods are called as if the 6 | Java objects resided in the Python interpreter and Java collections can be 7 | accessed through standard Python collection methods. Py4J also enables Java 8 | programs to call back Python objects. 9 | 10 | The latest compiled release is available in the current-release directory. 11 | 12 | This is the source repository of Py4J projects. Please visit the `Py4J homepage 13 | `_ for more information. 14 | 15 | For help, register and then post to the Py4J mailing list at 16 | ``py4j at py4j dot org`` 17 | 18 | LICENSE 19 | ======= 20 | 21 | Py4J is distributed with the BSD 3-Clause license. See LICENSE.txt for more 22 | information. 23 | 24 | 25 | CONTRIBUTING 26 | ============ 27 | 28 | We are always happy to receive code contributions, bug reports, and 29 | documentation fixes. Please visit the `contributing guide 30 | `_ for more 31 | information. 32 | 33 | .. image:: https://img.shields.io/circleci/project/bartdag/py4j.svg 34 | :target: https://circleci.com/gh/bartdag/py4j 35 | 36 | .. image:: https://img.shields.io/pypi/v/py4j.svg 37 | :target: https://pypi.python.org/pypi/py4j 38 | 39 | .. image:: https://img.shields.io/pypi/l/py4j.svg 40 | 41 | .. image:: https://img.shields.io/pypi/dm/py4j.svg 42 | 43 | .. image:: https://img.shields.io/pypi/pyversions/py4j.svg 44 | 45 | .. image:: https://img.shields.io/maven-central/v/net.sf.py4j/py4j.svg 46 | -------------------------------------------------------------------------------- /py4j-web/py4j_signals.rst: -------------------------------------------------------------------------------- 1 | :mod:`py4j.signals` --- Py4J Signals API 2 | ======================================== 3 | 4 | .. module:: py4j.signals 5 | :synopsis: Basic signals implementation (listeners/events/observers). 6 | .. moduleauthor:: Barthelemy Dagenais 7 | 8 | The :mod:`py4j.signals` module contains classes that enables the creation of 9 | signals, i.e., events that can be sent to "receivers". A receiver must connect 10 | to a signal beforehand and can optionally specify from which sender it should 11 | receive signals. 12 | 13 | Here is a full usage example: 14 | 15 | 16 | .. code-block:: python 17 | 18 | # Declare a signal 19 | server_connection_stopped = Signal() 20 | """Signal sent when a Python (Callback) Server connection is stopped. 21 | 22 | Will supply the ``connection`` argument, an instance of CallbackConnection. 23 | 24 | The sender is the CallbackServer instance. 25 | """ 26 | 27 | server = ... 28 | connection = ... 29 | 30 | # Create a receiver 31 | def on_connection_stopped(sender, **kwargs): 32 | connection = kwargs["connection"] 33 | # ... 34 | 35 | # Connect the receiver to the signal. Only signals sent from 36 | # server will be sent to on_connection_stopped. 37 | server_connection_stopped.connect(on_connection_stopped, sender=server) 38 | 39 | # Send a signal to the receivers. If one receiver raises an error, 40 | # the error is propagated back and other receivers won't receive the 41 | # signal. 42 | server_connection_stopped.send(sender=server, connection=connection) 43 | 44 | 45 | Signal 46 | ------ 47 | 48 | .. autoclass:: py4j.signals.Signal 49 | :members: 50 | :undoc-members: 51 | -------------------------------------------------------------------------------- /py4j-web/about.rst: -------------------------------------------------------------------------------- 1 | About Py4J 2 | ========== 3 | 4 | Py4J is developed by `Barthélémy Dagenais `_. The 5 | goal is to enable developers to program in Python and benefit from Python 6 | libraries such as `lxml `_ while being able to 7 | reuse Java libraries and frameworks such as `Eclipse 8 | `_. You can see Py4J as an hybrid between a glorified 9 | Remote Procedure Call and using the Java Virtual Machine to run a Python 10 | program. 11 | 12 | 13 | License 14 | ======= 15 | 16 | Py4J is distributed under the `BSD license 17 | `_. 18 | 19 | 20 | Alternatives to Py4J 21 | ==================== 22 | 23 | As opposed to `Jython `_, Py4J does not execute the 24 | Python code in the JVM so it does not need to reimplement the Python language 25 | and developers can use any libraries supported by their Python interpreter such 26 | as libraries written in Cython. Py4J is more focused than `JPype 27 | `_. For example, it does not attempt 28 | to link Python threads to Java threads. JPype also uses JNI to communicate with 29 | the JVM while Py4J uses plain old sockets, which are more portable in practice. 30 | 31 | In terms of performance, Py4J has a bigger overhead than both of the previous 32 | solutions because it relies on sockets, but if performance is critical to your 33 | application, accessing Java objects from Python programs might not be the best 34 | idea :-) If you have a particular use case that you want to speed up with Py4J, 35 | do not hesitate to write on the mailing list or open an issue and we'll see 36 | what we can do. 37 | -------------------------------------------------------------------------------- /py4j-web/py4j_java_collections.rst: -------------------------------------------------------------------------------- 1 | :mod:`py4j.java_collections` --- Py4J Collections API 2 | ===================================================== 3 | 4 | 5 | .. module:: py4j.java_collections 6 | :synopsis: Converts Java Collection Types to Python Collection Types. 7 | .. moduleauthor:: Barthelemy Dagenais 8 | 9 | The :mod:`py4j.java_collections` module maps Python collection classes with Java 10 | collection classes. These classes should practically never be directly 11 | instantiated by users: they are automatically used when receiving, for example, 12 | a Java list. 13 | 14 | .. _api_javaiterator: 15 | 16 | JavaIterator 17 | ------------ 18 | 19 | .. autoclass:: py4j.java_collections.JavaIterator 20 | :members: 21 | :undoc-members: 22 | 23 | .. 24 | Examples 25 | ^^^^^^^^ 26 | 27 | :: 28 | 29 | TBD 30 | 31 | .. _api_javalist: 32 | 33 | JavaList 34 | -------- 35 | 36 | .. autoclass:: py4j.java_collections.JavaList 37 | :members: 38 | :undoc-members: 39 | 40 | .. 41 | Examples 42 | ^^^^^^^^ 43 | 44 | :: 45 | 46 | TBD 47 | 48 | .. _api_javamap: 49 | 50 | JavaMap 51 | ------- 52 | 53 | .. autoclass:: py4j.java_collections.JavaMap 54 | :members: 55 | :undoc-members: 56 | 57 | .. 58 | Examples 59 | ^^^^^^^^ 60 | 61 | :: 62 | 63 | TBD 64 | 65 | .. _api_javaset: 66 | 67 | JavaSet 68 | ------- 69 | 70 | .. autoclass:: py4j.java_collections.JavaSet 71 | :members: 72 | :undoc-members: 73 | 74 | .. 75 | Examples 76 | ^^^^^^^^ 77 | 78 | :: 79 | 80 | TBD 81 | 82 | .. _api_javaarray: 83 | 84 | JavaArray 85 | --------- 86 | 87 | .. autoclass:: py4j.java_collections.JavaArray 88 | :members: 89 | :undoc-members: 90 | 91 | .. 92 | Examples 93 | ^^^^^^^^ 94 | 95 | :: 96 | 97 | TBD 98 | -------------------------------------------------------------------------------- /py4j-java/py4j.license.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/p1/AnObject2.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package p1; 31 | 32 | public class AnObject2 extends AnObject { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/Enum2.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public enum Enum2 { 33 | BAR, FOO; 34 | } 35 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/InterfaceA.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface InterfaceA { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/InterfaceB.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface InterfaceB { 33 | 34 | public InterfaceA getA(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/InterfaceNone.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface InterfaceNone { 33 | 34 | public String getName(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/ExampleListener.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface ExampleListener { 33 | 34 | Object notify(Object source); 35 | } 36 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/BytesOperator.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface BytesOperator { 33 | 34 | public byte[] returnBytes(byte[] bytes); 35 | } 36 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/IHello.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface IHello { 33 | public String sayHello(); 34 | 35 | public String sayHello(int i, String s); 36 | } 37 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/IPing.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface IPing { 33 | 34 | int ping1(IPong pong); 35 | 36 | int ping2(IPong pong); 37 | 38 | int ping3(IPong pong); 39 | } 40 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/IPong.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface IPong { 33 | 34 | int pong1(IPing ping); 35 | 36 | int pong2(IPing ping); 37 | 38 | int pong3(IPing ping); 39 | } 40 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/ExampleEntryPoint.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public class ExampleEntryPoint { 33 | 34 | public ExampleClass getNewExample() { 35 | return new ExampleClass(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/Operator.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface Operator { 33 | 34 | public int doOperation(int i, int j); 35 | 36 | public int doOperation(int i, int j, int k); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/MultiClientServerGetThreadId.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface MultiClientServerGetThreadId { 33 | 34 | String getThreadId(); 35 | 36 | String getJavaThreadId(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/ExampleWithField.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public class ExampleWithField { 33 | 34 | public int member = 1; 35 | 36 | public String member() { 37 | return "Hello World"; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/IHelloObject.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | /** 33 | * Created by barthelemy on 2017-06-26. 34 | */ 35 | public interface IHelloObject { 36 | 37 | String sendObject(Object obj1, Object obj2); 38 | } 39 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/p1/AnObject4.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package p1; 31 | 32 | public class AnObject4 extends AnObject3 implements Cloneable { 33 | 34 | /** 35 | * 36 | */ 37 | private static final long serialVersionUID = 463388156514450129L; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/IReturnConverter.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public interface IReturnConverter { 33 | 34 | char getChar(); 35 | 36 | float getFloat(); 37 | 38 | int getInt(); 39 | 40 | void doNothing(); 41 | 42 | Object getNull(); 43 | } 44 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/EnumExample.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public class EnumExample { 33 | 34 | public enum MyEnum { 35 | FOO; 36 | } 37 | 38 | public class InnerClass { 39 | public final static String MY_CONSTANT2 = "HELLO2"; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/reflection/ClassLoadingStrategy.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.reflection; 31 | 32 | /** 33 | *

    Strategy interface to load a class from a fully qualified name.

    34 | */ 35 | public interface ClassLoadingStrategy { 36 | 37 | Class classForName(String className) throws ClassNotFoundException; 38 | 39 | ClassLoader getClassLoader(); 40 | } 41 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/Py4JServerConnection.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | import java.net.Socket; 33 | 34 | /** 35 | * 36 | */ 37 | public interface Py4JServerConnection { 38 | 39 | /** 40 | * @return The socket used by this gateway connection. 41 | */ 42 | Socket getSocket(); 43 | 44 | void shutdown(); 45 | 46 | void shutdown(boolean reset); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/p1/AnObject3.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package p1; 31 | 32 | import java.io.Serializable; 33 | 34 | public class AnObject3 implements Runnable, Serializable { 35 | 36 | /** 37 | * 38 | */ 39 | private static final long serialVersionUID = -5574602071319098058L; 40 | 41 | @Override 42 | public void run() { 43 | // TODO Auto-generated method stub 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/InterfaceExample.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import py4j.GatewayServer; 33 | 34 | public class InterfaceExample { 35 | 36 | public void test(InterfaceB b) { 37 | InterfaceA a = b.getA(); 38 | System.out.println(a.getClass().getName()); 39 | } 40 | 41 | public static void main(String[] args) { 42 | GatewayServer server = new GatewayServer(new InterfaceExample()); 43 | server.start(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/instrumented/InstrumentedObject.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.instrumented; 31 | 32 | public class InstrumentedObject { 33 | 34 | private String name; 35 | 36 | public InstrumentedObject(String name) { 37 | this.name = name; 38 | MetricRegistry.addCreatedObject(this); 39 | } 40 | 41 | @Override 42 | protected void finalize() throws Throwable { 43 | MetricRegistry.addFinalizedObject(this); 44 | super.finalize(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | pre: 3 | - sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0 net.ipv6.conf.default.disable_ipv6=0 net.ipv6.conf.all.disable_ipv6=0 4 | environment: 5 | JDK6_BOOT_CLASSPATH: /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/jsse.jar 6 | general: 7 | artifacts: 8 | - "py4j-python/src/cover" 9 | - "py4j-java/build/reports" 10 | dependencies: 11 | override: 12 | - pyenv global 2.6.8; sudo update-alternatives --set java /usr/lib/jvm/jdk1.6.0/bin/java; sudo update-alternatives --set javac /usr/lib/jvm/java-6-openjdk-amd64/bin/javac; echo 'export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64' >> ~/.circlerc; 13 | - if [ $CIRCLE_NODE_INDEX == "1" ] ; then pyenv global 2.7.10; sudo update-alternatives --set java /usr/lib/jvm/jdk1.7.0/bin/java; sudo update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac; echo 'export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64' >> ~/.circlerc; fi 14 | - if [ $CIRCLE_NODE_INDEX == "2" ] ; then pyenv global 3.4.3; sudo update-alternatives --set java /usr/lib/jvm/jdk1.7.0/bin/java; sudo update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac; echo 'export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64' >> ~/.circlerc; fi 15 | - if [ $CIRCLE_NODE_INDEX == "3" ] ; then pyenv global 3.5.0; sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0/bin/java; sudo update-alternatives --set javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac; echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' >> ~/.circlerc; fi 16 | test: 17 | override: 18 | - if [ $CIRCLE_NODE_INDEX == "1" ] ; then pip install flake8==2.5.0; cd py4j-python; flake8; fi: 19 | parallel: true 20 | - deactivate; pip install codecov; echo `java -version` && echo `javac -version` && echo `python --version`: 21 | parallel: true 22 | - deactivate; cd py4j-java && gradle clean && gradle check && gradle assemble && if [ $CIRCLE_NODE_INDEX != "0" ] ; then gradle jacocoTestReport && codecov; fi && sleep 1: 23 | parallel: true 24 | - deactivate; cd py4j-python && nosetests --with-coverage --cover-html --cover-package=py4j -w src -c nose.cfg; if [ $CIRCLE_NODE_INDEX != "0" ] ; then codecov; fi: 25 | parallel: true 26 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/Py4JClientConnection.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | import java.io.IOException; 33 | 34 | public interface Py4JClientConnection { 35 | 36 | String sendCommand(String command); 37 | 38 | String sendCommand(String command, boolean blocking); 39 | 40 | void shutdown(); 41 | 42 | void shutdown(boolean reset); 43 | 44 | void start() throws IOException; 45 | 46 | void setUsed(boolean used); 47 | 48 | boolean wasUsed(); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/AdditionApplication.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import py4j.GatewayServer; 33 | 34 | public class AdditionApplication { 35 | 36 | public int addition(int first, int second) { 37 | return first + second; 38 | } 39 | 40 | public static void main(String[] args) { 41 | AdditionApplication app = new AdditionApplication(); 42 | GatewayServer server = new GatewayServer(app); 43 | server.start(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/DefaultApplication.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | /** 33 | * 34 | *

    35 | * Default application that can be used to quickly test Py4J. 36 | *

    37 | * 38 | * @author Barthelemy Dagenais 39 | * 40 | */ 41 | public class DefaultApplication { 42 | 43 | /** 44 | * @param args 45 | */ 46 | public static void main(String[] args) { 47 | GatewayServer server = new GatewayServer(new Object()); 48 | server.start(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/Py4JPythonClientPerThread.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | public interface Py4JPythonClientPerThread extends Py4JPythonClient { 33 | ClientServerConnection getPerThreadConnection(); 34 | 35 | void setPerThreadConnection(ClientServerConnection clientServerConnection); 36 | 37 | Gateway getGateway(); 38 | 39 | void setGateway(Gateway gateway); 40 | 41 | Py4JJavaServer getJavaServer(); 42 | 43 | void setJavaServer(Py4JJavaServer javaServer); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/p1/AnObject.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package p1; 31 | 32 | @SuppressWarnings("unused") 33 | public class AnObject { 34 | 35 | public void m1(String s1, AnObject object) { 36 | 37 | } 38 | 39 | public String m2(int i) { 40 | return null; 41 | } 42 | 43 | private void m3() { 44 | 45 | } 46 | 47 | public Integer value1; 48 | 49 | private String value2; 50 | 51 | public class InternalClass { 52 | public Boolean m1() { 53 | return true; 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/TestNoneApplication.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import py4j.GatewayServer; 33 | 34 | public class TestNoneApplication { 35 | 36 | public String testNone(InterfaceNone iNone) { 37 | String s = iNone.getName(); 38 | 39 | return s; 40 | } 41 | 42 | /** 43 | * @param args 44 | */ 45 | public static void main(String[] args) { 46 | GatewayServer server = new GatewayServer(new TestNoneApplication()); 47 | server.start(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/ListPrinter.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import java.util.List; 33 | 34 | import py4j.GatewayServer; 35 | 36 | public class ListPrinter { 37 | 38 | public String getListAsString(List list) { 39 | StringBuffer sb = new StringBuffer(); 40 | for (Object o : list) { 41 | sb.append(o.toString()); 42 | } 43 | return sb.toString(); 44 | } 45 | 46 | public static void main(String[] args) { 47 | GatewayServer server = new GatewayServer(new ListPrinter()); 48 | server.start(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /py4j-java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.sonatype.oss 6 | oss-parent 7 | 7 8 | 9 | net.sf.py4j 10 | py4j 11 | 0.10.6 12 | Py4J 13 | Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as if the Java objects resided in the Python interpreter and Java collections can be accessed through standard Python collection methods. Py4J also enables Java programs to call back Python objects. 14 | 15 | 16 | The New BSD License 17 | http://www.opensource.org/licenses/bsd-license.html 18 | 19 | 20 | 21 | 22 | bartdag 23 | Barthelemy Dagenais 24 | http://infobart.com/ 25 | 26 | 27 | 28 | scm:git:git@github.com:bartdag/py4j.git 29 | scm:git:git@github.com:bartdag/py4j.git 30 | git@github.com:bartdag/py4j.git 31 | 32 | 33 | UTF-8 34 | UTF-8 35 | 36 | 37 | 38 | junit 39 | junit 40 | 4.12 41 | test 42 | 43 | 44 | 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-compiler-plugin 49 | 3.3 50 | 51 | 1.6 52 | 1.6 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/StackEntryPoint.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import py4j.GatewayServer; 33 | 34 | public class StackEntryPoint { 35 | 36 | private Stack stack; 37 | 38 | public StackEntryPoint() { 39 | stack = new Stack(); 40 | stack.push("Initial Item"); 41 | } 42 | 43 | public Stack getStack() { 44 | return stack; 45 | } 46 | 47 | public static void main(String[] args) { 48 | GatewayServer gateway = new GatewayServer(new StackEntryPoint()); 49 | gateway.start(); 50 | System.out.println("Gateway Server Started"); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/tests/py4j_callback_recursive_example.py: -------------------------------------------------------------------------------- 1 | class HelloState(object): 2 | def __init__(self): 3 | self.calls = [] 4 | 5 | def sayHello(self, int_value=None, string_value=None): 6 | print(int_value, string_value) 7 | self.calls.append((int_value, string_value)) 8 | return "Said hello to {0}".format(string_value) 9 | 10 | class Java: 11 | implements = ["py4j.examples.IHello"] 12 | 13 | 14 | class SimpleHello(object): 15 | 16 | def sayHello(self, int_value=None, string_value=None): 17 | print(int_value, string_value) 18 | return "Said hello to {0}".format(string_value) 19 | 20 | class Java: 21 | implements = ["py4j.examples.IHello"] 22 | 23 | 24 | class RecursiveHello(object): 25 | 26 | def __init__(self, example_obj): 27 | self.example_obj = example_obj 28 | 29 | def sayHello(self, int_value=None, string_value=None): 30 | print(int_value, string_value) 31 | if int_value is None: 32 | print("Hello with no param") 33 | return self.example_obj.callHello2(self) 34 | else: 35 | print("Hello with 2 params") 36 | return "Said hello to {0}".format(string_value) 37 | 38 | class Java: 39 | implements = ["py4j.examples.IHello"] 40 | 41 | 42 | class JavaHello(object): 43 | 44 | def __init__(self): 45 | self.clientserver = None 46 | 47 | def sayHello(self, int_value=None, string_value=None): 48 | ar = self.clientserver.jvm.java.util.ArrayList() 49 | ar.append("1") 50 | print(ar) 51 | other_value = self.clientserver.jvm.java.lang.\ 52 | System.currentTimeMillis() 53 | print(int_value, string_value, other_value) 54 | return "Said hello to {0}".format(string_value) 55 | 56 | class Java: 57 | implements = ["py4j.examples.IHello"] 58 | 59 | 60 | class PythonPing(object): 61 | 62 | def __init__(self, fail=False): 63 | self.fail = fail 64 | 65 | def ping1(self, obj): 66 | return obj.pong1(self) 67 | 68 | def ping2(self, obj): 69 | return obj.pong2(self) 70 | 71 | def ping3(self, obj): 72 | if self.fail: 73 | raise ValueError("Some Exception") 74 | else: 75 | return obj.pong3(self) 76 | 77 | class Java: 78 | implements = ["py4j.examples.IPing"] 79 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/reflection/RootClassLoadingStrategy.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.reflection; 31 | 32 | /** 33 | *

    This class loading strategy just uses the class current class loader 34 | * to load a class from a fully qualified name.

    35 | */ 36 | public class RootClassLoadingStrategy implements ClassLoadingStrategy { 37 | 38 | @Override 39 | public Class classForName(String className) throws ClassNotFoundException { 40 | return Class.forName(className); 41 | } 42 | 43 | @Override 44 | public ClassLoader getClassLoader() { 45 | return RootClassLoadingStrategy.class.getClassLoader(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/SingleThreadClientApplication.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import py4j.ClientServer; 33 | import py4j.GatewayServer; 34 | 35 | public class SingleThreadClientApplication { 36 | 37 | public static void main(String[] args) { 38 | GatewayServer.turnLoggingOff(); 39 | ClientServer clientServer = new ClientServer(null); 40 | IHello hello = (IHello) clientServer.getPythonServerEntryPoint(new Class[] { IHello.class }); 41 | try { 42 | hello.sayHello(); 43 | hello.sayHello(2, "Hello World"); 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/BufferGenerator.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import py4j.GatewayServer; 33 | 34 | public class BufferGenerator { 35 | 36 | private static GatewayServer server; 37 | 38 | public StringBuffer getStringBuffer() { 39 | StringBuffer sb = new StringBuffer("FromJava"); 40 | return sb; 41 | } 42 | 43 | public static void main(String[] args) { 44 | GatewayServer.turnLoggingOff(); 45 | server = new GatewayServer(new BufferGenerator()); 46 | server.start(); 47 | } 48 | 49 | // Useful for unit tests 50 | public static void shutdownGateway() { 51 | server.shutdown(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/ReturnerExample.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public class ReturnerExample { 33 | 34 | public float computeFloat(IReturnConverter returner) { 35 | return returner.getFloat(); 36 | } 37 | 38 | public char computeChar(IReturnConverter returner) { 39 | return returner.getChar(); 40 | } 41 | 42 | public int computeInt(IReturnConverter returner) { 43 | return returner.getInt(); 44 | } 45 | 46 | public int computeNothing(IReturnConverter returner) { 47 | return 1; 48 | } 49 | 50 | public Object computeNull(IReturnConverter returner) { 51 | return returner.getNull(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/Stack.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import java.util.LinkedList; 33 | import java.util.List; 34 | 35 | public class Stack { 36 | private List internalList = new LinkedList(); 37 | 38 | public void push(String element) { 39 | internalList.add(0, element); 40 | } 41 | 42 | public String pop() { 43 | return internalList.remove(0); 44 | } 45 | 46 | public List getInternalList() { 47 | return internalList; 48 | } 49 | 50 | public void pushAll(List elements) { 51 | for (String element : elements) { 52 | this.push(element); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/instrumented/InstrCallbackConnection.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.instrumented; 31 | 32 | import java.net.InetAddress; 33 | 34 | import javax.net.SocketFactory; 35 | 36 | import py4j.CallbackConnection; 37 | 38 | public class InstrCallbackConnection extends CallbackConnection { 39 | 40 | public InstrCallbackConnection(int port, InetAddress address, SocketFactory socketFactory) { 41 | super(port, address, socketFactory); 42 | MetricRegistry.addCreatedObject(this); 43 | } 44 | 45 | @Override 46 | protected void finalize() throws Throwable { 47 | MetricRegistry.addFinalizedObject(this); 48 | super.finalize(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /py4j-python/setup.py: -------------------------------------------------------------------------------- 1 | try: 2 | from setuptools import setup 3 | except ImportError: 4 | from distutils.core import setup 5 | import os 6 | 7 | DOC_DIR = "doc" 8 | DIST_DIR = "dist" 9 | VERSION_PATH = os.path.join("src", "py4j", "version.py") 10 | # For Python 3 compatibility, we can't use execfile; this is 2to3's conversion: 11 | exec(compile(open(VERSION_PATH).read(), 12 | VERSION_PATH, "exec")) 13 | VERSION = __version__ # noqa 14 | RELEASE = "py4j-" + VERSION 15 | JAR_FILE = "py4j" + VERSION + ".jar" 16 | # Note: please do "./gradlew buildPython" before doing setup.py sdist. 17 | # Otherwise the jar files won't be created 18 | JAR_FILE_PATH = os.path.join("py4j-java", JAR_FILE) 19 | 20 | setup( 21 | name="py4j", 22 | packages=["py4j", "py4j.tests"], 23 | package_dir={"": "src"}, 24 | data_files=[("share/py4j", [JAR_FILE_PATH])], 25 | version=VERSION, 26 | description="Enables Python programs to dynamically access arbitrary " 27 | "Java objects", 28 | long_description="Py4J enables Python programs running in a Python " 29 | "interpreter to dynamically " 30 | "access Java objects in a Java Virtual Machine. " 31 | "Methods are called as if the Java " 32 | "objects resided in the Python interpreter and Java " 33 | "collections can be accessed " 34 | "through standard Python collection methods. Py4J also " 35 | "enables Java programs to call back Python objects.", 36 | url="https://www.py4j.org/", 37 | author="Barthelemy Dagenais", 38 | author_email="barthelemy@infobart.com", 39 | license="BSD License", 40 | classifiers=[ 41 | "Development Status :: 4 - Beta", 42 | "Intended Audience :: Developers", 43 | "License :: OSI Approved :: BSD License", 44 | "Operating System :: OS Independent", 45 | "Programming Language :: Python", 46 | "Programming Language :: Python :: 2", 47 | "Programming Language :: Python :: 2.6", 48 | "Programming Language :: Python :: 2.7", 49 | "Programming Language :: Python :: 3", 50 | "Programming Language :: Python :: 3.4", 51 | "Programming Language :: Python :: 3.5", 52 | "Programming Language :: Java", 53 | "Topic :: Software Development :: Libraries", 54 | "Topic :: Software Development :: Object Brokering", 55 | ], 56 | ) 57 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/Py4JException.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | /** 33 | *

    34 | * Exception raised when an error is encountered while using Py4J. 35 | *

    36 | * 37 | * @author Barthelemy Dagenais 38 | * 39 | */ 40 | public class Py4JException extends RuntimeException { 41 | 42 | private static final long serialVersionUID = -2457373060192300387L; 43 | 44 | public Py4JException() { 45 | } 46 | 47 | public Py4JException(String arg0) { 48 | super(arg0); 49 | } 50 | 51 | public Py4JException(String arg0, Throwable arg1) { 52 | super(arg0, arg1); 53 | } 54 | 55 | public Py4JException(Throwable arg0) { 56 | super(arg0); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/reflection/CurrentThreadClassLoadingStrategy.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.reflection; 31 | 32 | /** 33 | *

    This class loading strategy uses the current thread's ClassLoader to 34 | * load a class from a fully qualified name.

    35 | */ 36 | public class CurrentThreadClassLoadingStrategy implements ClassLoadingStrategy { 37 | 38 | @Override 39 | public Class classForName(String className) throws ClassNotFoundException { 40 | return Class.forName(className, true, this.getClassLoader()); 41 | } 42 | 43 | @Override 44 | public ClassLoader getClassLoader() { 45 | ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 46 | return classLoader; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/PingPong.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public class PingPong implements IPong { 33 | private boolean fail; 34 | 35 | public PingPong() { 36 | this(false); 37 | 38 | } 39 | 40 | public PingPong(boolean fail) { 41 | this.fail = fail; 42 | } 43 | 44 | public int start(IPing ping) { 45 | return ping.ping1(this); 46 | } 47 | 48 | @Override 49 | public int pong1(IPing ping) { 50 | return ping.ping2(this); 51 | } 52 | 53 | @Override 54 | public int pong2(IPing ping) { 55 | return ping.ping3(this); 56 | } 57 | 58 | @Override 59 | public int pong3(IPing ping) { 60 | if (fail) { 61 | return 1 / 0; 62 | } else { 63 | return 2; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/Py4JJavaException.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | /** 33 | *

    34 | * Exception raised when an exception is thrown in the client code. 35 | *

    36 | * 37 | * @author Barthelemy Dagenais 38 | * 39 | */ 40 | public class Py4JJavaException extends Py4JException { 41 | 42 | /** 43 | * 44 | */ 45 | private static final long serialVersionUID = -8121049552991788743L; 46 | 47 | public Py4JJavaException() { 48 | } 49 | 50 | public Py4JJavaException(String message) { 51 | super(message); 52 | } 53 | 54 | public Py4JJavaException(String message, Throwable cause) { 55 | super(message, cause); 56 | } 57 | 58 | public Py4JJavaException(Throwable cause) { 59 | super(cause); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/tests/java_array_test.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Mar 24, 2010 3 | 4 | @author: Barthelemy Dagenais 5 | """ 6 | from __future__ import unicode_literals, absolute_import 7 | 8 | import time 9 | import unittest 10 | 11 | from py4j.java_gateway import JavaGateway 12 | from py4j.tests.java_gateway_test import ( 13 | start_example_app_process) 14 | 15 | 16 | class ArrayTest(unittest.TestCase): 17 | def setUp(self): 18 | self.p = start_example_app_process() 19 | time.sleep(0.5) 20 | self.gateway = JavaGateway() 21 | 22 | def tearDown(self): 23 | self.p.terminate() 24 | self.gateway.shutdown() 25 | time.sleep(0.5) 26 | 27 | def testArray(self): 28 | example = self.gateway.entry_point.getNewExample() 29 | array1 = example.getStringArray() 30 | array2 = example.getIntArray() 31 | self.assertEqual(3, len(array1)) 32 | self.assertEqual(4, len(array2)) 33 | 34 | self.assertEqual("333", array1[2]) 35 | self.assertEqual(5, array2[1]) 36 | 37 | array1[2] = "aaa" 38 | array2[1] = 6 39 | self.assertEqual("aaa", array1[2]) 40 | self.assertEqual(6, array2[1]) 41 | 42 | new_array = array2[1:3] 43 | self.assertEqual(2, len(new_array)) 44 | self.assertEqual(1, new_array[1]) 45 | 46 | def testCreateArray(self): 47 | int_class = self.gateway.jvm.int 48 | string_class = self.gateway.jvm.java.lang.String 49 | int_array = self.gateway.new_array(int_class, 2) 50 | string_array = self.gateway.new_array(string_class, 3, 5) 51 | self.assertEqual(2, len(int_array)) 52 | self.assertEqual(3, len(string_array)) 53 | self.assertEqual(5, len(string_array[0])) 54 | 55 | def testDoubleArray(self): 56 | double_class = self.gateway.jvm.double 57 | double_array = self.gateway.new_array(double_class, 2) 58 | double_array[0] = 2.2 59 | self.assertAlmostEqual(double_array[0], 2.2) 60 | 61 | def testFloatArray(self): 62 | float_class = self.gateway.jvm.float 63 | float_array = self.gateway.new_array(float_class, 2) 64 | float_array[0] = 2.2 65 | self.assertAlmostEqual(float_array[0], 2.2) 66 | 67 | def testCharArray(self): 68 | char_class = self.gateway.jvm.char 69 | char_array = self.gateway.new_array(char_class, 2) 70 | char_array[0] = "a" 71 | self.assertEqual(char_array[0], "a") 72 | 73 | 74 | if __name__ == "__main__": 75 | unittest.main() 76 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/SingleThreadClientGCApplication.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import py4j.ClientServer; 33 | import py4j.GatewayServer; 34 | 35 | /** 36 | * Created by barthelemy on 2017-06-26. 37 | */ 38 | public class SingleThreadClientGCApplication { 39 | 40 | public static void main(String[] args) { 41 | GatewayServer.turnLoggingOff(); 42 | ClientServer clientServer = new ClientServer(null); 43 | IHelloObject hello = (IHelloObject) clientServer.getPythonServerEntryPoint(new Class[] { IHelloObject.class }); 44 | try { 45 | for (int i = 0; i < 1000; i++) { 46 | hello.sendObject(new Object(), new Object()); 47 | } 48 | 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | clientServer.shutdown(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/instrumented/InstrGatewayConnection.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.instrumented; 31 | 32 | import java.io.IOException; 33 | import java.net.Socket; 34 | import java.util.List; 35 | 36 | import py4j.Gateway; 37 | import py4j.GatewayConnection; 38 | import py4j.GatewayServerListener; 39 | import py4j.commands.Command; 40 | 41 | public class InstrGatewayConnection extends GatewayConnection { 42 | public InstrGatewayConnection(Gateway gateway, Socket socket, List> customCommands, 43 | List listeners) throws IOException { 44 | super(gateway, socket, customCommands, listeners); 45 | MetricRegistry.addCreatedObject(this); 46 | } 47 | 48 | @Override 49 | protected void finalize() throws Throwable { 50 | MetricRegistry.addFinalizedObject(this); 51 | super.finalize(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | try: 2 | from setuptools import setup 3 | except ImportError: 4 | from distutils.core import setup 5 | import os 6 | import subprocess 7 | 8 | 9 | DOC_DIR = os.path.join("py4j-python", "doc") 10 | DIST_DIR = os.path.join("py4j-python", "dist") 11 | VERSION_PATH = os.path.join("py4j-python", "src", "py4j", "version.py") 12 | # For Python 3 compatibility, we can't use execfile; this is 2to3's conversion: 13 | exec(compile(open(VERSION_PATH).read(), 14 | VERSION_PATH, "exec")) 15 | VERSION = __version__ # noqa 16 | RELEASE = "py4j-" + VERSION 17 | JAR_FILE = "py4j" + VERSION + ".jar" 18 | 19 | os.chdir("py4j-java") 20 | if os.name == "nt": 21 | subprocess.call("./gradlew.bat buildPython", shell=True) 22 | else: 23 | subprocess.call("./gradlew buildPython", shell=True) 24 | os.chdir("..") 25 | 26 | JAR_FILE_PATH = os.path.join("py4j-python", "py4j-java", JAR_FILE) 27 | 28 | setup( 29 | name="py4j", 30 | packages=["py4j", "py4j.tests"], 31 | package_dir={"": "py4j-python/src"}, 32 | data_files=[("share/py4j", [JAR_FILE_PATH])], 33 | version=VERSION, 34 | description="Enables Python programs to dynamically access arbitrary " 35 | "Java objects", 36 | long_description="Py4J enables Python programs running in a Python " 37 | "interpreter to dynamically " 38 | "access Java objects in a Java Virtual Machine. " 39 | "Methods are called as if the Java " 40 | "objects resided in the Python interpreter and Java " 41 | "collections can be accessed " 42 | "through standard Python collection methods. Py4J also " 43 | "enables Java programs to call back Python objects.", 44 | url="https://www.py4j.org/", 45 | author="Barthelemy Dagenais", 46 | author_email="barthelemy@infobart.com", 47 | license="BSD License", 48 | classifiers=[ 49 | "Development Status :: 4 - Beta", 50 | "Intended Audience :: Developers", 51 | "License :: OSI Approved :: BSD License", 52 | "Operating System :: OS Independent", 53 | "Programming Language :: Python", 54 | "Programming Language :: Python :: 2", 55 | "Programming Language :: Python :: 2.6", 56 | "Programming Language :: Python :: 2.7", 57 | "Programming Language :: Python :: 3", 58 | "Programming Language :: Python :: 3.4", 59 | "Programming Language :: Python :: 3.5", 60 | "Programming Language :: Java", 61 | "Topic :: Software Development :: Libraries", 62 | "Topic :: Software Development :: Object Brokering", 63 | ], 64 | 65 | ) 66 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/instrumented/InstrCallbackClient.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.instrumented; 31 | 32 | import java.io.IOException; 33 | 34 | import py4j.CallbackClient; 35 | import py4j.Py4JClientConnection; 36 | 37 | public class InstrCallbackClient extends CallbackClient { 38 | 39 | public InstrCallbackClient(int port) { 40 | super(port); 41 | MetricRegistry.addCreatedObject(this); 42 | } 43 | 44 | @Override 45 | protected void finalize() throws Throwable { 46 | MetricRegistry.addFinalizedObject(this); 47 | super.finalize(); 48 | } 49 | 50 | @Override 51 | protected Py4JClientConnection getConnection() throws IOException { 52 | Py4JClientConnection connection = null; 53 | 54 | connection = this.connections.pollLast(); 55 | if (connection == null) { 56 | connection = new InstrCallbackConnection(port, address, socketFactory); 57 | connection.start(); 58 | } 59 | 60 | return connection; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/ListenerApplication.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import java.util.ArrayList; 33 | import java.util.List; 34 | 35 | import py4j.GatewayServer; 36 | 37 | public class ListenerApplication { 38 | 39 | List listeners = new ArrayList(); 40 | 41 | public void registerListener(ExampleListener listener) { 42 | listeners.add(listener); 43 | } 44 | 45 | public void notifyAllListeners() { 46 | for (ExampleListener listener : listeners) { 47 | Object returnValue = listener.notify(this); 48 | System.out.println(returnValue); 49 | } 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return " instance"; 55 | } 56 | 57 | public static void main(String[] args) { 58 | ListenerApplication application = new ListenerApplication(); 59 | GatewayServer server = new GatewayServer(application); 60 | server.start(true); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/reflection/MethodDescriptorTest.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.reflection; 31 | 32 | import static org.junit.Assert.assertEquals; 33 | import static org.junit.Assert.fail; 34 | 35 | import org.junit.Test; 36 | 37 | import p1.Cat; 38 | 39 | public class MethodDescriptorTest { 40 | 41 | @Test 42 | public void testInternalRepresentation() { 43 | try { 44 | MethodDescriptor mDesc1 = new MethodDescriptor("meowmeow", Cat.class, new Class[] { String.class }); 45 | MethodDescriptor mDesc2 = new MethodDescriptor("meowmeow", Cat.class, new Class[] { String.class }); 46 | assertEquals(mDesc1, mDesc2); 47 | assertEquals(mDesc1.hashCode(), mDesc2.hashCode()); 48 | assertEquals(mDesc1.getInternalRepresentation(), "p1.Cat.meowmeow(java.lang.String.)"); 49 | assertEquals(mDesc1.toString(), "p1.Cat.meowmeow(java.lang.String.)"); 50 | } catch (Exception e) { 51 | e.printStackTrace(); 52 | fail(); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/reflection/LRUCache.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.reflection; 31 | 32 | import java.util.LinkedHashMap; 33 | import java.util.Map; 34 | 35 | /** 36 | *

    37 | * Implementation of a Least Recently Used cache. Currently used by the 38 | * ReflectionEngine to cache resolution of Java members. 39 | *

    40 | * 41 | * @author Barthelemy Dagenais 42 | * 43 | * @param 44 | * @param 45 | */ 46 | public class LRUCache extends LinkedHashMap { 47 | 48 | public static final int DEFAULT_CACHE_SIZE = 100; 49 | private static final long serialVersionUID = -3090703237387586885L; 50 | private int cacheSize; 51 | 52 | public LRUCache() { 53 | this(DEFAULT_CACHE_SIZE); 54 | } 55 | 56 | public LRUCache(int cacheSize) { 57 | super(16, 0.75f, true); 58 | this.cacheSize = cacheSize; 59 | } 60 | 61 | protected boolean removeEldestEntry(Map.Entry eldest) { 62 | return size() > cacheSize; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/reflection/ReflectionUtil.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.reflection; 31 | 32 | /** 33 | *

    34 | * Global utility to load classes and perform general reflection operations 35 | * that can be customized by Strategy classes. 36 | *

    37 | */ 38 | public class ReflectionUtil { 39 | 40 | private static ClassLoadingStrategy classLoadingStrategy = new CurrentThreadClassLoadingStrategy(); 41 | 42 | public static ClassLoadingStrategy getClassLoadingStrategy() { 43 | return classLoadingStrategy; 44 | } 45 | 46 | public static void setClassLoadingStrategy(ClassLoadingStrategy classLoadingStrategy) { 47 | ReflectionUtil.classLoadingStrategy = classLoadingStrategy; 48 | } 49 | 50 | public static Class classForName(String className) throws ClassNotFoundException { 51 | return classLoadingStrategy.classForName(className); 52 | } 53 | 54 | public static ClassLoader getClassLoader() { 55 | return classLoadingStrategy.getClassLoader(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /py4j-python/src/py4j/tests/java_map_test.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Feb 5, 2010 3 | 4 | @author: barthelemy 5 | """ 6 | from __future__ import unicode_literals, absolute_import 7 | 8 | import unittest 9 | 10 | from py4j.java_gateway import JavaGateway, GatewayParameters 11 | from py4j.tests.java_gateway_test import ( 12 | start_example_app_process, safe_shutdown, sleep) 13 | 14 | 15 | def get_map(): 16 | return {"a": 1, "b": 2.0, "c": "z"} 17 | 18 | 19 | class AutoConvertTest(unittest.TestCase): 20 | def setUp(self): 21 | self.p = start_example_app_process() 22 | self.gateway = JavaGateway( 23 | gateway_parameters=GatewayParameters(auto_convert=True)) 24 | 25 | def tearDown(self): 26 | safe_shutdown(self) 27 | self.p.join() 28 | sleep() 29 | 30 | def testAutoConvert(self): 31 | dj = self.gateway.jvm.java.util.HashMap() 32 | dj["b"] = 2 33 | dj["a"] = 1 34 | dp = {"a": 1, "b": 2} 35 | self.assertTrue(dj.equals(dp)) 36 | 37 | 38 | class MapTest(unittest.TestCase): 39 | def setUp(self): 40 | self.p = start_example_app_process() 41 | self.gateway = JavaGateway() 42 | 43 | def tearDown(self): 44 | safe_shutdown(self) 45 | self.p.join() 46 | sleep() 47 | 48 | def equal_maps(self, m1, m2): 49 | if len(m1) == len(m2): 50 | equal = True 51 | for k in m1: 52 | equal = m1[k] == m2[k] 53 | if not equal: 54 | break 55 | return equal 56 | else: 57 | return False 58 | 59 | def testMap(self): 60 | dp0 = {} 61 | dp = get_map() 62 | dj = self.gateway.jvm.java.util.HashMap() 63 | self.equal_maps(dj, dp0) 64 | dj["a"] = 1 65 | dj["b"] = 2.0 66 | dj["c"] = "z" 67 | self.equal_maps(dj, dp) 68 | 69 | del(dj["a"]) 70 | del(dp["a"]) 71 | 72 | dj2 = self.gateway.jvm.java.util.HashMap() 73 | dj2["b"] = 2.0 74 | dj2["c"] = "z" 75 | 76 | dj3 = self.gateway.jvm.java.util.HashMap() 77 | dj3["a"] = 1 78 | dj3["b"] = 2.0 79 | dj3["c"] = "z" 80 | 81 | self.equal_maps(dj, dp) 82 | self.assertTrue(dj == dj) 83 | self.assertTrue(dj == dj2) 84 | # Does not always work for some reason... 85 | # Probably not worth supporting for now... 86 | # self.assertTrue(dj < dj3) 87 | self.assertTrue(dj != dp) 88 | 89 | dps = {1: 1, 2: 2} 90 | djs = self.gateway.jvm.java.util.HashMap() 91 | djs[1] = 1 92 | djs[2] = 2 93 | self.assertEqual(str(djs), str(dps)) 94 | 95 | 96 | if __name__ == "__main__": 97 | unittest.main() 98 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/instrumented/InstrClientServerConnection.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.instrumented; 31 | 32 | import java.io.IOException; 33 | import java.net.Socket; 34 | import java.util.List; 35 | 36 | import py4j.ClientServerConnection; 37 | import py4j.Gateway; 38 | import py4j.Py4JJavaServer; 39 | import py4j.Py4JPythonClientPerThread; 40 | import py4j.commands.Command; 41 | 42 | public class InstrClientServerConnection extends ClientServerConnection { 43 | 44 | public InstrClientServerConnection(Gateway gateway, Socket socket, List> customCommands, 45 | Py4JPythonClientPerThread pythonClient, Py4JJavaServer javaServer, int readTimeout) throws IOException { 46 | super(gateway, socket, customCommands, pythonClient, javaServer, readTimeout); 47 | MetricRegistry.addCreatedObject(this); 48 | } 49 | 50 | @Override 51 | protected void finalize() throws Throwable { 52 | MetricRegistry.addFinalizedObject(this); 53 | super.finalize(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /py4j-java/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/InstrGatewayTest.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | import static org.junit.Assert.assertEquals; 33 | 34 | import org.junit.Test; 35 | 36 | import py4j.instrumented.InstrGatewayServer; 37 | import py4j.instrumented.MetricRegistry; 38 | 39 | public class InstrGatewayTest { 40 | 41 | private void startServer() { 42 | InstrGatewayServer server = new InstrGatewayServer(null, GatewayServer.DEFAULT_PORT, 43 | GatewayServer.DEFAULT_PYTHON_PORT); 44 | server.start(); 45 | server.shutdown(); 46 | } 47 | 48 | @Test 49 | public void testLifecycle() { 50 | startServer(); 51 | MetricRegistry.forceFinalization(); 52 | try { 53 | Thread.currentThread().sleep(1000); 54 | } catch (Exception e) { 55 | 56 | } 57 | assertEquals(2, MetricRegistry.getCreatedObjectsKeySet().size()); 58 | assertEquals(2, MetricRegistry.getFinalizedObjectsKeySet().size()); 59 | assertEquals(MetricRegistry.getCreatedObjectsKeySet(), MetricRegistry.getFinalizedObjectsKeySet()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/BufferGatewayTest.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | import static org.junit.Assert.assertEquals; 33 | import static org.junit.Assert.fail; 34 | 35 | import org.junit.Test; 36 | 37 | import py4j.examples.BufferGenerator; 38 | 39 | public class BufferGatewayTest { 40 | 41 | @Test 42 | public void testBufferedGateway1() { 43 | EchoClient client = new EchoClient(); 44 | 45 | try { 46 | Thread.sleep(500); 47 | BufferGenerator.main(null); 48 | 49 | Thread.sleep(500); 50 | client.connect(); 51 | 52 | client.write("c\nt\ngetStringBuffer\ne\n"); 53 | assertEquals(client.getResponse(), "!yro0\n"); 54 | client.write("c\no0\nappend\nd1.1\ne\n"); 55 | assertEquals(client.getResponse(), "!yro1\n"); 56 | client.write("c\no0\ntoString\ne\n"); 57 | assertEquals(client.getResponse(), "!ysFromJava1.1\n"); 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | fail(); 61 | } finally { 62 | client.close(); 63 | BufferGenerator.shutdownGateway(); 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /py4j-web/py4j_client_server.rst: -------------------------------------------------------------------------------- 1 | :mod:`py4j.clientserver` --- Py4J Single Threading Model Implementation 2 | ======================================================================= 3 | 4 | .. module:: py4j.clientserver 5 | :synopsis: Py4J single threading model implementation 6 | .. moduleauthor:: Barthelemy Dagenais 7 | 8 | The :mod:`py4j.clientserver` module defines an implementation of Python Server 9 | and Java client that ensures that commands started from a Python or Java thread 10 | are always executed on the same Java or Python thread. 11 | 12 | For example, if a command to Python is sent from Java UI thread and the Python 13 | code calls some Java code, the Java code will be executed in the UI thread. 14 | 15 | Py4J users are expected to only use explicitly :class:`ClientServer 16 | ` and optionally, :class:`JavaParameters 17 | ` and :class:`PythonParameters 18 | `. The other module members are documented 19 | to support the extension of Py4J. 20 | 21 | .. _api_clientserver: 22 | 23 | ClientServer 24 | ------------ 25 | 26 | .. autoclass:: py4j.clientserver.ClientServer 27 | :members: 28 | :undoc-members: 29 | 30 | 31 | .. _api_clientserver_examples: 32 | 33 | Examples 34 | ^^^^^^^^ 35 | 36 | Using the ``jvm`` property: 37 | :: 38 | 39 | >>> clientserver = ClientServer() 40 | >>> l = clientserver.jvm.java.util.ArrayList() 41 | >>> l.append(10) 42 | >>> l.append(1) 43 | >>> jvm.java.util.Collections.sort(l) 44 | >>> l 45 | [1, 10] 46 | 47 | The :class:`ClientServer ` class is a subclass 48 | of :class:`JavaGateway ` is fully compatible 49 | with all examples and code written for a `JavaGateway`.` 50 | 51 | 52 | .. _api_javaparameters: 53 | 54 | JavaParameters 55 | -------------- 56 | 57 | .. autoclass:: py4j.clientserver.JavaParameters 58 | :members: 59 | :undoc-members: 60 | 61 | 62 | .. _api_pythonparameters: 63 | 64 | PythonParameters 65 | ---------------- 66 | 67 | .. autoclass:: py4j.clientserver.PythonParameters 68 | :members: 69 | :undoc-members: 70 | 71 | 72 | .. _api_javaclient: 73 | 74 | JavaClient 75 | ---------- 76 | 77 | .. autoclass:: py4j.clientserver.JavaClient 78 | :members: 79 | :undoc-members: 80 | 81 | 82 | .. _api_pythonserver: 83 | 84 | PythonServer 85 | ------------ 86 | 87 | .. autoclass:: py4j.clientserver.PythonServer 88 | :members: 89 | :undoc-members: 90 | 91 | 92 | .. _api_clientserverconnection: 93 | 94 | ClientServerConnection 95 | ---------------------- 96 | 97 | .. autoclass:: py4j.clientserver.ClientServerConnection 98 | :members: 99 | :undoc-members: 100 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/reflection/ReflectionUtilTest.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.reflection; 31 | 32 | import static org.junit.Assert.assertTrue; 33 | import static org.junit.Assert.fail; 34 | 35 | import org.junit.Test; 36 | 37 | public class ReflectionUtilTest { 38 | 39 | @Test 40 | public void testRootClassLoading() { 41 | try { 42 | ReflectionUtil.setClassLoadingStrategy(new RootClassLoadingStrategy()); 43 | Class stringClass = ReflectionUtil.classForName("java.lang" + ".String"); 44 | Object obj = stringClass.newInstance(); 45 | assertTrue(obj instanceof String); 46 | } catch (Exception e) { 47 | fail(); 48 | } 49 | } 50 | 51 | @Test 52 | public void testCurrentThreadClassLoading() { 53 | try { 54 | ReflectionUtil.setClassLoadingStrategy(new CurrentThreadClassLoadingStrategy()); 55 | Class stringClass = ReflectionUtil.classForName("java.lang" + ".String"); 56 | Object obj = stringClass.newInstance(); 57 | assertTrue(obj instanceof String); 58 | } catch (Exception e) { 59 | fail(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/StringUtil.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | /** 33 | *

    34 | * String utility class providing operations to escape and unescape new lines. 35 | *

    36 | * 37 | * @author Barthelemy Dagenais 38 | * 39 | */ 40 | public class StringUtil { 41 | 42 | public final static char ESCAPE_CHAR = '\\'; 43 | 44 | public static String escape(String original) { 45 | return original.replace("\\", "\\\\").replace("\r", "\\r").replace("\n", "\\n"); 46 | } 47 | 48 | public static String unescape(String escaped) { 49 | boolean escaping = false; 50 | StringBuilder newString = new StringBuilder(); 51 | 52 | for (char c : escaped.toCharArray()) { 53 | if (!escaping) { 54 | if (c == ESCAPE_CHAR) { 55 | escaping = true; 56 | } else { 57 | newString.append(c); 58 | } 59 | } else { 60 | if (c == 'n') { 61 | newString.append('\n'); 62 | } else if (c == 'r') { 63 | newString.append('\r'); 64 | } else { 65 | newString.append(c); 66 | } 67 | escaping = false; 68 | } 69 | } 70 | 71 | return newString.toString(); 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/DefaultGatewayServerListener.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | /** 33 | *

    34 | * This class implements a default {@link py4j.GatewayServerListener 35 | * GatewayServerListener}. All operations do nothing by default. Clients can 36 | * extend this class to only override the methods they need. 37 | *

    38 | * 39 | * 40 | * @author Barthelemy Dagenais 41 | * 42 | */ 43 | public class DefaultGatewayServerListener implements GatewayServerListener { 44 | 45 | @Override 46 | public void connectionError(Exception e) { 47 | } 48 | 49 | @Override 50 | public void connectionStarted(Py4JServerConnection gatewayConnection) { 51 | } 52 | 53 | @Override 54 | public void connectionStopped(Py4JServerConnection gatewayConnection) { 55 | } 56 | 57 | @Override 58 | public void serverError(Exception e) { 59 | } 60 | 61 | @Override 62 | public void serverPostShutdown() { 63 | } 64 | 65 | @Override 66 | public void serverPreShutdown() { 67 | } 68 | 69 | @Override 70 | public void serverStarted() { 71 | } 72 | 73 | @Override 74 | public void serverStopped() { 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/SingleThreadApplication.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | import py4j.ClientServer; 33 | import py4j.GatewayServer; 34 | 35 | public class SingleThreadApplication { 36 | 37 | public static void main(String[] args) { 38 | GatewayServer.turnLoggingOff(); 39 | ExampleEntryPoint point = new ExampleEntryPoint(); 40 | ClientServer clientServer = new ClientServer(point); 41 | // Wait for Python side to shut down Java side 42 | clientServer.startServer(true); 43 | 44 | // Shut down after 5 seconds 45 | // clientServer.startServer(true); 46 | // try { 47 | // Thread.currentThread().sleep(5000); 48 | // } catch (Exception e) { 49 | // e.printStackTrace(); 50 | // } 51 | // clientServer.shutdown(); 52 | // 53 | // System.out.println("Stopping"); 54 | } 55 | 56 | public static class SingleThreadShortTimeoutApplication { 57 | public static void main(String[] args) { 58 | GatewayServer.turnLoggingOff(); 59 | ClientServer clientServer = new ClientServer.ClientServerBuilder().readTimeout(250) 60 | .entryPoint(new ExampleEntryPoint()).build(); 61 | clientServer.startServer(true); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/p1/p2/Animal.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package p1.p2; 31 | 32 | import p1.Cat; 33 | 34 | public class Animal { 35 | 36 | private int age = 10; 37 | 38 | public String age2 = ""; 39 | 40 | public int age0 = 15; 41 | 42 | public Animal() { 43 | System.out.println("Animal"); 44 | } 45 | 46 | public Animal(String s) { 47 | System.out.println("Animal1"); 48 | } 49 | 50 | public void meow(String s, int i) { 51 | System.out.println("meowmeow"); 52 | } 53 | 54 | public int age() { 55 | return this.age; 56 | } 57 | 58 | public void meow(String s) { 59 | System.out.println("meowstring"); 60 | } 61 | 62 | public void meow(char s) { 63 | System.out.println("meowchar"); 64 | } 65 | 66 | public void meow(int s) { 67 | System.out.println("meowint"); 68 | } 69 | 70 | public void meow(long s) { 71 | System.out.println("meowlong"); 72 | } 73 | 74 | public void meow(boolean s) { 75 | System.out.println("meowbool"); 76 | } 77 | 78 | public void meow(Object o) { 79 | System.out.println("meowobject"); 80 | } 81 | 82 | public void meow(Animal a) { 83 | System.out.println("meowanim"); 84 | } 85 | 86 | public void meow(Cat a) { 87 | System.out.println("meowcat"); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/model/Py4JMember.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.model; 31 | 32 | /** 33 | *

    34 | * Model of a Java member (class, method, or field) used to create a help page. 35 | *

    36 | * 37 | * @author Barthelemy Dagenais 38 | * 39 | */ 40 | public abstract class Py4JMember implements Comparable { 41 | 42 | // Currently not supported 43 | private final String javadoc; 44 | 45 | private final String name; 46 | 47 | public Py4JMember(String name, String javadoc) { 48 | super(); 49 | this.name = name; 50 | this.javadoc = javadoc; 51 | } 52 | 53 | @Override 54 | public int compareTo(Py4JMember o) { 55 | return this.getName().compareTo(o.getName()); 56 | } 57 | 58 | @Override 59 | public boolean equals(Object obj) { 60 | if (obj == null || !(obj instanceof Py4JMember)) { 61 | return false; 62 | } 63 | return this.getSignature(false).equals(((Py4JMember) obj).getSignature(false)); 64 | } 65 | 66 | @Override 67 | public int hashCode() { 68 | return getSignature(false).hashCode(); 69 | } 70 | 71 | public String getJavadoc() { 72 | return javadoc; 73 | } 74 | 75 | public String getName() { 76 | return name; 77 | } 78 | 79 | public abstract String getSignature(boolean shortName); 80 | 81 | } 82 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/instrumented/InstrGatewayServer.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.instrumented; 31 | 32 | import java.io.IOException; 33 | import java.net.Socket; 34 | 35 | import py4j.Gateway; 36 | import py4j.GatewayServer; 37 | import py4j.Py4JServerConnection; 38 | 39 | public class InstrGatewayServer extends GatewayServer { 40 | 41 | public InstrGatewayServer(Object entryPoint, int port, int pythonPort) { 42 | super(entryPoint, port, DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT, null, 43 | new InstrCallbackClient(pythonPort)); 44 | MetricRegistry.addCreatedObject(this); 45 | } 46 | 47 | @Override 48 | protected void finalize() throws Throwable { 49 | MetricRegistry.addFinalizedObject(this); 50 | super.finalize(); 51 | } 52 | 53 | /** 54 | *

    55 | * Creates a server connection from a Python call to the Java side. 56 | *

    57 | * 58 | * @param gateway 59 | * @param socket 60 | * @return 61 | * @throws IOException 62 | */ 63 | protected Py4JServerConnection createConnection(Gateway gateway, Socket socket) throws IOException { 64 | InstrGatewayConnection connection = new InstrGatewayConnection(gateway, socket, getCustomCommands(), 65 | getListeners()); 66 | connection.startConnection(); 67 | return connection; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/model/Py4JField.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.model; 31 | 32 | import java.lang.reflect.Field; 33 | 34 | import py4j.reflection.TypeUtil; 35 | 36 | /** 37 | *

    38 | * Model of a Java field used to create a help page. 39 | *

    40 | * 41 | * @author Barthelemy Dagenais 42 | * 43 | */ 44 | public class Py4JField extends Py4JMember { 45 | 46 | public final static Py4JField buildField(Field field) { 47 | return new Py4JField(field.getName(), null, field.getType().getCanonicalName(), 48 | field.getDeclaringClass().getCanonicalName()); 49 | } 50 | 51 | private final String type; 52 | 53 | private final String container; 54 | 55 | public Py4JField(String name, String javadoc, String type, String container) { 56 | super(name, javadoc); 57 | this.type = type; 58 | this.container = container; 59 | } 60 | 61 | public String getContainer() { 62 | return container; 63 | } 64 | 65 | @Override 66 | public String getSignature(boolean shortName) { 67 | StringBuilder builder = new StringBuilder(); 68 | 69 | builder.append(getName()); 70 | builder.append(" : "); 71 | builder.append(TypeUtil.getName(type, shortName)); 72 | 73 | return builder.toString(); 74 | } 75 | 76 | public String getType() { 77 | return type; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/EchoClientTest.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j; 31 | 32 | import static org.junit.Assert.assertEquals; 33 | import static org.junit.Assert.fail; 34 | 35 | import java.io.BufferedWriter; 36 | import java.io.OutputStreamWriter; 37 | import java.net.Socket; 38 | 39 | import org.junit.Test; 40 | 41 | public class EchoClientTest { 42 | 43 | @Test 44 | public void testConnection() { 45 | try { 46 | Thread.sleep(500); 47 | EchoServer.main(null); 48 | Thread.sleep(500); 49 | Socket testSocket = new Socket(GatewayServer.DEFAULT_ADDRESS, EchoServer.TEST_PORT); 50 | BufferedWriter testWriter = new BufferedWriter(new OutputStreamWriter(testSocket.getOutputStream())); 51 | testWriter.write("yi7\n"); 52 | testWriter.flush(); 53 | testWriter.write("x\n"); 54 | testWriter.flush(); 55 | testWriter.close(); 56 | testSocket.close(); 57 | 58 | EchoClient client = new EchoClient(); 59 | client.connect(); 60 | client.write("c\ng\ngetExample\ne\n"); 61 | assertEquals(client.getResponse(), "yi7\n"); 62 | client.write("c\no1\nmethod1\ni1\nbtrue\ne\n"); 63 | assertEquals(client.getResponse(), "x\n"); 64 | client.close(); 65 | } catch (Exception e) { 66 | e.printStackTrace(); 67 | fail(); 68 | } finally { 69 | 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /py4j-java/src/main/java/py4j/commands/ExceptionCommand.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.commands; 31 | 32 | import java.io.BufferedReader; 33 | import java.io.BufferedWriter; 34 | import java.io.IOException; 35 | import java.util.logging.Logger; 36 | 37 | import py4j.Protocol; 38 | import py4j.Py4JException; 39 | import py4j.ReturnObject; 40 | 41 | public class ExceptionCommand extends AbstractCommand { 42 | 43 | private final Logger logger = Logger.getLogger(ExceptionCommand.class.getName()); 44 | 45 | public final static String EXCEPTION_COMMAND_NAME = "p"; 46 | 47 | public ExceptionCommand() { 48 | super(); 49 | this.commandName = EXCEPTION_COMMAND_NAME; 50 | } 51 | 52 | @Override 53 | public void execute(String commandName, BufferedReader reader, BufferedWriter writer) 54 | throws Py4JException, IOException { 55 | String returnCommand = null; 56 | Throwable exception = (Throwable) Protocol.getObject(reader.readLine(), this.gateway); 57 | // EOQ 58 | reader.readLine(); 59 | 60 | String stackTrace = Protocol.getThrowableAsString(exception); 61 | ReturnObject rObject = ReturnObject.getPrimitiveReturnObject(stackTrace); 62 | returnCommand = Protocol.getOutputCommand(rObject); 63 | 64 | logger.finest("Returning command: " + returnCommand); 65 | writer.write(returnCommand); 66 | writer.flush(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/examples/UTFExample.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.examples; 31 | 32 | public class UTFExample { 33 | 34 | private Byte[] array = new Byte[] { 0, 1, 10, 127, -1, -128 }; 35 | 36 | public int strangeMéthod() { 37 | return 2; 38 | } 39 | 40 | public Byte[] getSurrogateBytes() { 41 | return new Byte[] { (byte) 0xD8, (byte) 0xD9, (byte) 0xDF }; 42 | } 43 | 44 | public byte[] getSurrogatebytes() { 45 | return new byte[] { (byte) 0xD8, (byte) 0xD9, (byte) 0xDF }; 46 | } 47 | 48 | public int getPositiveByteValue(byte b) { 49 | return (int) (b & 0xff); 50 | } 51 | 52 | public int getJavaByteValue(byte b) { 53 | return (int) b; 54 | } 55 | 56 | public int[] getUtfValue(String s) { 57 | int length = s.length(); 58 | int[] values = new int[length]; 59 | 60 | for (int i = 0; i < length; i++) { 61 | values[i] = s.charAt(i); 62 | } 63 | 64 | return values; 65 | } 66 | 67 | public int[] getBytesValue(byte[] bytes) { 68 | int length = bytes.length; 69 | int[] values = new int[length]; 70 | 71 | for (int i = 0; i < length; i++) { 72 | values[i] = bytes[i] & 0xff; 73 | } 74 | 75 | return values; 76 | } 77 | 78 | public byte[] getBytesValue() { 79 | return new byte[] { 0, 1, 10, 127, -1, -128 }; 80 | } 81 | 82 | public Byte[] getBytesArray() { 83 | return array; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/instrumented/InstrJavaServer.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.instrumented; 31 | 32 | import java.io.IOException; 33 | import java.net.Socket; 34 | import java.util.List; 35 | 36 | import py4j.ClientServerConnection; 37 | import py4j.Gateway; 38 | import py4j.JavaServer; 39 | import py4j.Py4JPythonClientPerThread; 40 | import py4j.Py4JServerConnection; 41 | import py4j.commands.Command; 42 | 43 | public class InstrJavaServer extends JavaServer { 44 | 45 | public InstrJavaServer(Object entryPoint, int port, int connectTimeout, int readTimeout, 46 | List> customCommands, Py4JPythonClientPerThread pythonClient) { 47 | super(entryPoint, port, connectTimeout, readTimeout, customCommands, pythonClient); 48 | MetricRegistry.addCreatedObject(this); 49 | } 50 | 51 | @Override 52 | protected void finalize() throws Throwable { 53 | MetricRegistry.addFinalizedObject(this); 54 | super.finalize(); 55 | } 56 | 57 | @Override 58 | protected Py4JServerConnection createConnection(Gateway gateway, Socket socket) throws IOException { 59 | ClientServerConnection connection = new InstrClientServerConnection(gateway, socket, getCustomCommands(), 60 | (Py4JPythonClientPerThread) getCallbackClient(), this, getReadTimeout()); 61 | connection.startServerConnection(); 62 | return connection; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /py4j-java/src/test/java/py4j/instrumented/InstrumentedApplication.java: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2009-2016, Barthelemy Dagenais and individual contributors. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * - The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | *****************************************************************************/ 30 | package py4j.instrumented; 31 | 32 | import py4j.GatewayServer; 33 | import py4j.examples.IHello; 34 | 35 | public class InstrumentedApplication { 36 | 37 | public void startServer2() { 38 | InstrGatewayServer server2 = new InstrGatewayServer(this, GatewayServer.DEFAULT_PORT + 5, 39 | GatewayServer.DEFAULT_PYTHON_PORT + 5); 40 | server2.start(); 41 | } 42 | 43 | private void sayHello(GatewayServer server) { 44 | IHello hello = (IHello) server.getPythonServerEntryPoint(new Class[] { IHello.class }); 45 | try { 46 | hello.sayHello(); 47 | hello.sayHello(2, "Hello World"); 48 | } catch (Exception e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | 53 | public void startServerWithPythonEntry(boolean shutdown) { 54 | InstrGatewayServer server2 = new InstrGatewayServer(this, GatewayServer.DEFAULT_PORT + 5, 55 | GatewayServer.DEFAULT_PYTHON_PORT + 5); 56 | server2.start(); 57 | 58 | sayHello(server2); 59 | 60 | MetricRegistry.forceFinalization(); 61 | MetricRegistry.sleep(); 62 | 63 | if (shutdown) { 64 | server2.shutdown(); 65 | } 66 | } 67 | 68 | public static void main(String[] args) { 69 | InstrumentedApplication app = new InstrumentedApplication(); 70 | GatewayServer server = new GatewayServer(app); 71 | server.start(); 72 | } 73 | } 74 | --------------------------------------------------------------------------------