Mixing Python and Java How Python and Java can communicate and work together



Similar documents
Automation of Aircraft Pre-Design with Chameleon

RepoGuard Validation Framework for Version Control Systems

Andreas Schreiber

Advances and Work in Progress in Aerospace Predesign Data Exchange, Validation and Software Integration at the German Aerospace Center

Andreas Schreiber, Michael Meinel, Tobias Schlauch

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Scalable Distributed Schur Complement Solvers for Internal and External Flow Computations on Many-Core Architectures

EJB 3.0 and IIOP.NET. Table of contents. Stefan Jäger / stefanjaeger@bluewin.ch

Web Services Development Guide: How to build EMBRACE compliant Web Services Version 2.0, 13 December 2006

The DLR Satellite Station in Inuvik a Milestone for the Canadian-German Cooperation in Earth Observation

Chapter 6. CORBA-based Architecture. 6.1 Introduction to CORBA 6.2 CORBA-IDL 6.3 Designing CORBA Systems 6.4 Implementing CORBA Applications

ARM-BASED PERFORMANCE MONITORING FOR THE ECLIPSE PLATFORM

Invocación remota (based on M. L. Liu Distributed Computing -- Concepts and Application

How To Create A C++ Web Service

Creating Web Services in NetBeans

Java with Eclipse: Setup & Getting Started

BPM Scheduling with Job Scheduler

Web Services in.net (1)

How to use the Eclipse IDE for Java Application Development

Using EDA Databases: Milkyway & OpenAccess

Developing Web Services with Eclipse and Open Source. Claire Rogers Developer Resources and Partner Enablement, HP February, 2004

Corba. Corba services. The (very) global picture. Corba. Distributed Object Systems 3 CORBA/IDL. Corba. Features. Services

Evaluation of Load/Stress tools for Web Applications testing

Migrating Legacy Software Systems to CORBA based Distributed Environments through an Automatic Wrapper Generation Technique

Modern Software Development Tools on OpenVMS

Crash Course in Java

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Infrastructure that supports (distributed) componentbased application development

VOC Documentation. Release 0.1. Russell Keith-Magee

INTERNET-BASED COLLABORATIVE SYSTEM DESIGN USING MOSCITO

Java Application Development using Eclipse. Jezz Kelway Java Technology Centre, z/os Service IBM Hursley Park Labs, United Kingdom

Software. Programming Language. Software. Instructor Özgür ZEYDAN. Bülent Ecevit University Department of Environmental Engineering

Outline SOA. Properties of SOA. Service 2/19/2016. Definitions. Comparison of component technologies. Definitions Component technologies

Programming in Python. Basic information. Teaching. Administration Organisation Contents of the Course. Jarkko Toivonen. Overview of Python

Measuring Travel Time Reliability for an FCD-based Route Information System

Tutorial: Getting Started

Introduction to CORBA. 1. Introduction 2. Distributed Systems: Notions 3. Middleware 4. CORBA Architecture

COM 440 Distributed Systems Project List Summary

Developing Google Android Mobile Clients for Web Services: a Case Study

An Overview of Java. overview-1

Elements of Advanced Java Programming

Jonathan Worthington Scarborough Linux User Group

Ambient-oriented Programming & AmbientTalk

THE CCLRC DATA PORTAL

Web Services API Developer Guide

WIRIS quizzes web services Getting started with PHP and Java

Motivation Definitions EAI Architectures Elements Integration Technologies. Part I. EAI: Foundations, Concepts, and Architectures

Middleware Lou Somers

Layering a computing infrastructure. Middleware. The new infrastructure: middleware. Spanning layer. Middleware objectives. The new infrastructure

Project Builder for Java. (Legacy)

Instrumentation Software Profiling

Distributed Applications with CORBA. Frank Kargl Chaos Computer Club, Ulm, Germany

Introduction to Oracle WebLogic. Presented by: Fatna Belqasmi, PhD, Researcher at Ericsson

Efficiency Considerations of PERL and Python in Distributed Processing

Avaya Aura Orchestration Designer

Extreme Java G Session 3 Main Theme Java Core Technologies (Part I) Dr. Jean-Claude Franchitti

Habanero Extreme Scale Software Research Project

How To Develop A Web Service In A Microsoft J2Ee (Java) 2.5 (Oracle) 2-Year Old (Orcient) 2Dj (Oracles) 2E (Orca) 2Gj (J

Developing Java Web Services to Expose the WorkTrak RMI Server to the Web and XML-Based Clients

Getting Started with the Internet Communications Engine

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

zen Platform technical white paper

USE OF PYTHON AS A SATELLITE OPERATIONS AND TESTING AUTOMATION LANGUAGE

Eclipse with Mac OSX Getting Started Selecting Your Workspace. Creating a Project.

ITS. Java WebService. ITS Data-Solutions Pvt Ltd BENEFITS OF ATTENDANCE:

What Perl Programmers Should Know About Java

How To Write An Airplane Grid Project (Aerogrid)

CS Software Engineering for Scientific Computing. Lecture 25:Mixed Language Programming.

The Java Series Introduction to Java RMI and CORBA. The Java Series. Java RMI and CORBA Raul RAMOS / CERN-IT User Support Slide 1

Introduction CORBA Distributed COM. Sections 9.1 & 9.2. Corba & DCOM. John P. Daigle. Department of Computer Science Georgia State University

Generating Automated Test Scripts for AltioLive using QF Test

PERFORMANCE COMPARISON OF COMMON OBJECT REQUEST BROKER ARCHITECTURE(CORBA) VS JAVA MESSAGING SERVICE(JMS) BY TEAM SCALABLE

Chapter 4. Architecture. Table of Contents. J2EE Technology Application Servers. Application Models

Study of Development of Java Applications in Eclipse Environment and Development of Java Based Calendar Application with Notifications

Service-Oriented Architecture and Software Engineering

Implementing SQI via SOAP Web-Services

Alternatives to SNMP and Challenges in Management Protocols. Communication Systems Seminar Talk 10 Francesco Luminati

CS506 Web Design and Development Solved Online Quiz No. 01


Introduction into Web Services (WS)

apache.org. ApacheCon NA - Vancouver BC November :30p. husted@apache.org

T Network Application Frameworks and XML Web Services and WSDL Tancred Lindholm

Using mobile phones to access Web Services in a secure way. Dan Marinescu

GlassFish v3. Building an ex tensible modular Java EE application server. Jerome Dochez and Ludovic Champenois Sun Microsystems, Inc.

The Decaffeinated Robot

COM+ OVERVIEW OF MICROSOFTS COM, DCOM AND COM+ COMPONENT TECHNOLOGIES DCOM - COM+ Peter R. Egli INDIGOO.COM. indigoo.com. 1/20 Rev. 1.

Running a Program on an AVD

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

Writing Grid Service Using GT3 Core. Dec, Abstract

Classic Grid Architecture

GLOBAL CONSULTING SERVICES TOOLS FOR WEBMETHODS Software AG. All rights reserved. For internal use only

Building Web Services with Apache Axis2

INTERNATIONAL JOURNAL OF COMPUTER ENGINEERING & TECHNOLOGY (IJCET)

EFFICIENCY CONSIDERATIONS BETWEEN COMMON WEB APPLICATIONS USING THE SOAP PROTOCOL

Building Applications with Protégé: An Overview. Protégé Conference July 23, 2006

Lesson 4 Web Service Interface Definition (Part I)

Android Programming and Security

HEP data analysis using jhepwork and Java

IMPLEMENTATION GUIDE. API Service. More Power to You. May For more information, please contact

Capabilities of a Java Test Execution Framework by Erick Griffin

Transcription:

Mixing Python and Java How Python and Java can communicate and work together EuroPython 2009 (June 30th 2009, Birmingham) Andreas Schreiber <Andreas.Schreiber@dlr.de> German Aerospace Center (DLR), Cologne, Germany http://www.dlr.de/sc Folie 1

Follow this presentation Live! PowerPoint to Twitter! twitter.com/python_demo Folie 2

Final Version of this Slides is available on SlideShare http://tr.im/ep09java Folie 3

DLR German Aerospace Center Research Institution Space Agency Project Management Agency Folie 4

Locations and employees 6000 employees across 29 research institutes and facilities at 13 sites. Hamburg Bremen- Neustrelitz Trauen Berlin- Braunschweig Offices in Brussels, Paris and Washington. Koeln Bonn Goettingen Lampoldshausen Stuttgart Oberpfaffenhofen Weilheim Folie 5

Research Areas Aeronautics Space Transport Energy Space Agency Project Management Agency Folie 6

Mixing Python and Java? Is it all about? Folie 7

Mixing Python and Java? Outline Accessing Python from Java Jython JEPP Accessing Java from Python JPype JCC Inter-process communication CORBA SOAP Other remote object libraries Folie 8

Java Why People are Using Java? Widely used in many different application domains industry/business, research, academia Available on many different platforms Good performance good Garbage Collector (and no GIL) Many, many libraries E.g., for data base access, XML processing, PDF generation, security, or user interfaces Availability of good documentation for all aspects of Java programming Very good development tools Eclipse, NetBeans, IntelliJ IDEA, Folie 9

Python Why People are Using Python? Python in Research and Industry Scientists and engineers don t want to write software but just solve their problems If they have to write code, it must be as easy as possible I want to design planes, not software! Reasons for Python? Very easy to learn and easy to use ( = steep learning curve) Allows rapid development ( = short development time) Inherent great maintainability Folie 10

Python has the cleanest, most-scientist- or engineer friendly syntax and semantics. -Paul F. Dubois Paul F. Dubois. Ten good practices in scientific programming. Comp. In Sci. Eng., Jan/Feb 1999, pp.7-11 Folie 11

Why Mixing Java and Python? Embedded scripting and more Many mature Java applications and frameworks exists Lots of commercial and Open Source software systems and libraries For example, The Eclipse Universe, Apache-Software, Portal- Frameworks, Workflows systems, Common use cases Add embedded (Python) scripting to Java applications Use Java libraries from Python code Folie 12

Why Mixing Java and Python? Integration of Python code into Java applications Existing code or libraries exist either for Java or Python only Effort to re-implement the functionalities could be very high If the library is very well tested, it could be an enormous effort to reach a comparable level of quality Common use cases Just use an existing library from the other language Especially, use Python code (or C/Fortran/WHATEVER code with Python wrappers) from Java Its harder to wrap C codes in Java than in Python (see CTypes) Folie 13

Example QF-Test Automated GUI Testing Folie 14

Example TENT Software Integration and Workflow Management Folie 15

Use Cases for Python Scripting (1) Steering and controlling the program by user defined scripts Applications are complex parameter variations or steering multidisciplinary coupled simulations Automation of repeating tasks In most cases, this is called macro recording and replaying Extending user interfaces For example, with additional customized dialogs and other extensions In Java, this requires scripts which use the Java GUI libraries (AWT, Swing, or SWT) Integration of additional legacy tools Important and widely used for integration and workflow systems End users can integrate external codes without changing the Java program itself Folie 16

Use Cases for Python Scripting (2) Interactive experimentation and debugging of the Java program Can be easily done with an embedded interactive interpreter Allows end users and software developers to debug and analyze the Java program during runtime Creating automated tests for quality assurance Recording user actions during runtime of the Java program as a Python script ( Journaling") Editing and generalizing the recorded script Replaying the script manually or automatically Folie 17

Example: Codes with Python Interfaces Numerical Simulation Software in C++ or Fortran X-31 Eurofighter Examples for high-definition CFD-Solver with Python interfaces DLR TAU-Code (http://www.dlr.de/as) ONERA elsa-code (http://elsa.onera.fr) Integration into Java workflow systems with the following techniques Folie 18

Tools for Python-Java-Integration Python Interpreter Python Python Code Code JEPP JEPP Python Interpreter Python Python Code Code JPype JPype Jython Jython Python Python Code Code JNI Java Java Code Code (Anwendung) Java Virtual Machine (JVM) Interface/Protokoll Python Python Code Code Folie 19

Accessing Python from Java Use cases The application should have embedded scripting functionality. The application should use an external code written in Python. The application should use an external code written in Python or other languages such as C, C++, Fortran. Tools Jython JEPP Folie 20

Jython Complete re-implementation of the Python interpreter in Java Python code runs in the Java VM Website: http://www.jython.org Python Code Jython Latest version: Jython 2.5 For details & questions, catch Tobias Ivarsson Frank Wierzbicki and others here at EuroPython Java Application Code Java Virtual Machine Folie 21

Jython Code Example 1: Java code Execute Python code import org.python.util.pythoninterpreter ; import org.python.core.*; class TestClass { public static void main(string[] args) { try { org.python.util.pythoninterpreter python = new org.python.util.pythoninterpreter (); python.execfile("python_script.py"); } catch (Exception e) { System.out.println( Some error!"); } } Folie 22

Jython Code Example 2: Python code Use Swing from javax.swing import * frame = JFrame("Hello Jython") label = JLabel("Hello Jython!", JLabel.CENTER) frame.add(label) frame.setdefaultcloseoperation( JFrame.EXIT_ON_CLOSE) frame.setsize(200, 100) frame.show() Folie 23

JEPP Java Embedded Python Embeds CPython interpreter via Java Native Interface (JNI) in Java Python code runs in CPython Python Interpreter Python Code Website: http://jepp.sourceforge.net/ JNI JEPP Java Application Code Java Virtual Machine Folie 24

JEPP Code Example Execute ( evaluate ) Python statements Jep jep = new Jep(false, SCRIPT_PATH, cl); jep.eval("print 'hello'"); jep.close(); Execute a Python script file Jep jep = new Jep(false, SCRIPT_PATH, cl); jep.runscript(script_path + file); jep.close(); Folie 25

Accessing Java from Python Use cases The application should use an external Java application. The application should use a Java library. Tools JPype JCC Folie 26

JPype Java to Python Integration Interface on native level of both (Java & Python) Virtual Machines/Interpreters Starts a Java Virtual Machine Website: http://jpype.sourceforge.net Python Interpreter Python Application Code JPype JNI Java Application Code Java Virtual Machine Folie 27

JPype Code Example (1) Hello World from jpype import * # Start JVM startjvm (path to jvm.dll, "-ea") # Print "Hello World" java.lang.system.out.println("hello World") # Shutdown JVM shutdownjvm() Folie 28

JPype Code Example (2) Call Java methods from Python import jpype # Start JVM jpype.startjvm(path to jvm.dll, "-ea") # Create reference to java package javapackage = jpype.jpackage("javapackagename") # Create reference to java class javaclass = javapackage.javaclassname # Create instance of java class javaobject = javaclass() # Call java methods javaobject.javamethodname() # Shutdown JVM jpype.shutdownjvm() Folie 29

JCC PyLucene's Code Generator C++ code generator for calling Java from C++/Python C++ object interface for wrapping a Java library via JNI Generates complete CPython extension Supported on Mac OS X, Linux, Solaris and Windows, requires C++ compiler Python Interpreter Python Code Generated C++ Wrapper Code JNI JCC Code Generator Website: http://lucene.apache.org /pylucene/jcc Part of PyLucene Java Application Code pythonextension() Java Virtual Machine Folie 30

JCC Code Example Requirement: VM initialization import jcc # Start JVM jcc.initvm(maxheap= 2000m, ) Folie 31

JCC Code Example Using PyLucene: Search Lucene Index Search for Query in directory index from lucene import QueryParser, IndexSearcher, StandardAnalyzer, FSDirectory, Hit, VERSION, initvm, CLASSPATH initvm(classpath) directory = FSDirectory.getDirectory( index, False) searcher = IndexSearcher(directory) analyzer = StandardAnalyzer() command = raw_input("query:") query = QueryParser("contents", analyzer).parse(command) hits = searcher.search(query) for hit in hits: doc = Hit.cast_(hit).getDocument() print 'path:', doc.get("path"), 'name:', doc.get("name") searcher.close() Folie 32

Inter-Process Communication Inter-process communication (IPC) is data exchange between different processes on one or more computers connected by a network Typical IPC techniques are remote procedure calls (RPC) message passing. The most common APIs are Object Request Broker (ORB) or Web Services protocols based on XML. A drawback is the need for additional services, such as a directory service for registration and location of remote objects Naming Service for CORBA Universal Description, Discovery and Integration (UDDI) for Web Services Folie 33

Object Request Broker (ORBs) CORBA IDL IDL Compiler Java Generated Application Java Code Code (Stub) (Client) Java Virtual Machine ORB Python Generated Application Python Code Code (Skeleton) (Server) Python Interpreter Folie 34

CORBA Implementations for Python Fnorb Pure Python implementation that works with CPython and Jython. It is a light-weight CORBA implementation and interoperable with the standard Java ORB. The development of Fnorb has ended. omniorb An ORB implementation for C++ and Python that can be used from CPython. The Python ORB (omniorbpy) uses the C++ implementation of omniorb. omniorb is actively developed with regular releases. Website: http://omniorb.sourceforge.net Folie 35

CORBA Example Interface Hello World interface in Interface Definition Language (IDL) module HelloWorld { const string Message = "Hello CORBA World!"; }; interface Hello { string hello_world(); }; Folie 36

CORBA Example Python Server (Fnorb): Implementation of Interface # Standard/built-in modules. import sys # Fnorb modules. from Fnorb.orb import BOA, CORBA # Stubs and skeletons generated by 'fnidl'. import HelloWorld, HelloWorld_skel class HelloWorldServer(HelloWorld_skel.Hello_skel): """ Implementation of the 'Hello' interface. """ def hello_world(self): print HelloWorld.Message return HelloWorld.Message Folie 37

CORBA Example Python Server (Fnorb): Main Function def main(argv): # Initialise ORB and BOA orb = CORBA.ORB_init(argv, CORBA.ORB_ID) boa = BOA.BOA_init(argv, BOA.BOA_ID) # Create object reference obj = boa.create('fred', HelloWorldServer._FNORB_ID) # Create an instance of the implementation class. impl = HelloWorldServer() # Activate the implementation boa.obj_is_ready(obj, impl) # Write the stringified object reference to a file open('server.ref', 'w').write(orb.object_to_string(obj)) boa._fnorb_mainloop() # Start the event loop return 0 Folie 38

CORBA Example Java Client public class Client { public static void main ( String args[] ) { java.util.properties props = System.getProperties(); try { org.omg.corba.orb orb = org.omg.corba.orb.init(args,props); org.omg.corba.object obj = null; java.io.bufferedreader in = new java.io.bufferedreader( new java.io.filereader( Server.ref")); String ref = in.readline(); obj = orb.string_to_object(ref); Hello hello = HelloHelper.narrow(obj); hello.hello_world(); } orb.destroy(); } catch (Exception e) { e.printstacktrace(); } Folie 39

Web Services: SOAP WSDL WSDL Compiler Python Generated Application Python Code Code (Stub) (Client) Python Interpreter Java Generated Application Java Code Code (Skeleton) (Server) Servlet Container Java Virtual Machine Folie 40

Web Services for Python Zolera SOAP Infrastructure (ZSI) For Python the only remaining SOAP toolkit of considerable quality is the Zolera SOAP Infrastructure (ZSI) Folie 41

Other Remote Object Libraries Python Remote Objects (Pyro) Pyro is similar to Java's Remote Method Invocation (RMI). It is simple, very portable, and works with Jython. Brings its own Naming Service for locating remote objects. Pyro is actively developed with regular new releases. Simple Python Interface to Remote Objects (SPIRO) SPIRO implements an ORB and is developed as a bridge between CPython and Jython. The development has ended. Folie 42

Conclusions I Jython but there are alternatives which makes sense for certain use cases! Folie 43

Questions? Contact http://tr.im/schreiber tr.im/schreiber twitter.com/onyame python@dlr.de Folie 44