How Java becomes agile riding Rhino Xavier Casellato VP of engineering, Liligo.com.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Apache Struts Technology
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
XHTML Presenters : Jarkko Lunnas Sakari Laaksonen.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
Tutorial 10 Programming with JavaScript
Advanced Object-Oriented Programming Features
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Java web development Servlet & Java server pages.
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
Rhino – JavaScript for Java. Speaker: Brent Wilkins Hertz – Applications Consultant – Cobol developer – 20+ years – PowerBuilder developer – 6 years –
JavaScript Demo Presented by … Jaisingh Sumit jain Sudhindra Taran Deep arora.
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
+ Java vs. Javascript Jessi Style. + Java Compiled Can stand on its own Written once, run anywhere Two-stage debugging Java is an Object Oriented Programming.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Katanosh Morovat.   This concept is a formal approach for identifying the rules that encapsulate the structure, constraint, and control of the operation.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Java: Chapter 1 Computer Systems Computer Programming II.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
JSP Java Server Pages Softsmith Infotech.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Configuration Management (CM)
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
The Java Programming Language
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
© 2006 IBM Corporation JDojo & ScriptEngine Agile Planning’s Scripting Tools.
1 Geospatial and Business Intelligence Jean-Sébastien Turcotte Executive VP San Francisco - April 2007 Streamlining web mapping applications.
Slide 12.1 Chapter 12 Implementation. Slide 12.2 Learning outcomes Produce a plan to minimize the risks involved with the launch phase of an e-business.
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
1 final (the keyword, not the exam). 2 Motivation Suppose we’ve defined an Employee class, and we don’t want someone to come along and muck it up  E.g.,
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
“Education is a Treasure that follows you everywhere.” – Chines Proverb Methods and Functions.
Introduction of Geoprocessing Lecture 9. Geoprocessing  Geoprocessing is any GIS operation used to manipulate data. A typical geoprocessing operation.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
“The world’s most misunderstood language has become the world’s most popular programming language” Akshay Arora
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
1.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
1 Middle East Users Group 2008 Self-Service Engine & Process Rules Engine Presented by: Ryan Flemming Friday 11th at 9am - 9:45 am.
Tutorial 10 Programming with JavaScript
Scripted Page Web App Development (Java Server Pages)
JavaScript an introduction.
Java Server Pages (JSP)
JavaScript CS 4640 Programming Languages for Web Applications
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Rule Engine Concepts and Drools Expert
Presentation transcript:

How Java becomes agile riding Rhino Xavier Casellato VP of engineering, Liligo.com

Let the ride begin !

Change request : Simon says We need a white rectangle The rectangle should be blue The rectangle should be blue when it’s sunny and white when it rains The rectangle must be yellow if temperature is less than 23° Who decided it must be a rectangle ? Didn’t we say it should be orange ? The border should be yellow except if it’s sunny The rectangle is circle if temperature is less than 0° and it’s sunny The circle must be green The rectangle is blue and green every Monday Tuesday we want a circle but only if it rains Why don’t we do a triangle ?

Flexibility is required  Many inputs affect the final result  Many rules can be applied  Rules change often

Modeling flexibility Database needs a model XML needs a DTD Home made data storage ! Are you sure it’s a solution ? None of these solutions are really flexible.

Stuck !?

Constraints  Application behavior must be modified quickly  Deploying compiled code is time consuming  Compiled code required IT resources

Needs  Empower business decision  Reduce change requests delay  Introduce customizable business logic in application

Rhino, inside the beast

Rhino History  Netscape project started in 1997  First Release in 1998  Embedded in JVM since Java Standard Edition 1.6

What is Rhino ?  Full-java API  Rhino contains  All the features of JavaScript 1.6  A JavaScript shell for executing JavaScript scripts  A JavaScript compiler to transform JavaScript source files into Java class files  A JavaScript debugger for scripts executed with Rhino Embed and execute JavaScript codes inside a Java application

General concepts  Context  stores information about the execution environment of a script.  Scope  set of JavaScript objects  Host  Host objects implement special JavaScript features like dynamic properties.

How it works

Basic Rhino Execution sequence // Create Context Context cx = Context.enter(); // Initialize standard objects ScriptableObject scope = cx.initStandardObjects(); // Build scope scope.put(“input”,input1); // use Script … // Exit Context cx.exit(); // Create Context Context cx = Context.enter(); // Initialize standard objects ScriptableObject scope = cx.initStandardObjects(); // Build scope scope.put(“input”,input1); // use Script … // Exit Context cx.exit();

Access javascript variables with java Object x = scope.get("x", scope); if (x == Scriptable.NOT_FOUND) { System.out.println("x is not defined."); } else { System.out.println("x = " + Context.toString(x)); } Object x = scope.get("x", scope); if (x == Scriptable.NOT_FOUND) { System.out.println("x is not defined."); } else { System.out.println("x = " + Context.toString(x)); } “X” variable is read from script

Using javascript function in Java Object fObj = scope.get("f", scope); if (!(fObj instanceof Function)) { System.out.println("f is undefined or not a function."); } else { Object functionArgs[] = { "my arg" }; Function f = (Function)fObj; Object result = f.call(cx, scope, scope, functionArgs); String report = "f('my args') = " + Context.toString(result); System.out.println(report); } Object fObj = scope.get("f", scope); if (!(fObj instanceof Function)) { System.out.println("f is undefined or not a function."); } else { Object functionArgs[] = { "my arg" }; Function f = (Function)fObj; Object result = f.call(cx, scope, scope, functionArgs); String report = "f('my args') = " + Context.toString(result); System.out.println(report); } Call expects two scriptable objects :  scope to execute the function relative to  JavaScript this object

Create java object in Javascript String script = "var x =5; System.out.println(x);"; result = cx.evaluateString(scope, script, “ ", 1, null); String script = "var x =5; System.out.println(x);"; result = cx.evaluateString(scope, script, “ ", 1, null); “X” variable is declared in the JavaScript and console output is called from JavaScript. You can access to native java classes from JavaScript.

Sharing java object with javascript Object wrappedOut = Context.javaToJS(System.out, scope); ScriptableObject.putProperty(scope, "out", wrappedOut); Object is wrapped as a scope element. Method calls uses reflection.

Host object  Host is a java class that can be manipulated as a JavaScript prototype.  Naming pattern should be applied to the methods  Constructor  Getter and Setter  Functions

Declare a constructor for Host object Host class signature public class Counter extends ScriptableObject { public void jsConstructor(int a) { … } Javascript … var counter = new Counter(7); …

Getter and setter syntax Host class signature public int jsGet_field() { return field; } public void jsSet_field(int value) { field = value; } Javascript … var x =counter.field; counter.field = x; …

Host object : functions Host class signature public int jsFunction_increment() { field++; } Javascript … counter.increment(); …

Declare host object ScriptableObject.defineClass(scope, Counter.class); Host object definition must be declared in the scope. The line above declares the counter class a JavaScript prototype. Java class becomes a JavaScript prototype. You can refer it using as a JavaScript object.

Scope types  Shared scope Use it to share object defined in a scope without modifying their values between to concurrent scope execution.  Sealed shared scope Object sealed properties can not be added/deleted to the object and the existing object properties can not be changed  Dynamic scope Allow to enclose common functions and shared objects in a multi- threaded environment.

Rhino performances Execution time almost 3 times faster with compiled code Even compiled code is almost 10 times slower than java compiled code.

Performances concerns  There is a huge difference between evaluated script and compiled ones.  To keep good performances you must compile your script before execution and focus the Rhino usage to the relevant code part.

Rhino in action

Identify use cases Identify logical components which requires adaptive behavior.  Need to have a flexible behavior Identify complex rules  Various input data and outputs Estimate execution frequency  JavaScript is slower than compiled Java

Embedding strategy JAVA Script Java Native classes Function Host objects Out-of-box integrationDeep integration

Storing the script Flexibility works with a correct storage support ! Don’t miss your target ! SCRIPT MUST BE EASILY MANAGEABLE

Customizable function JAVA BEAN Javascript function Script Source is an attribute of the object. Script execution is a bean method.

Customizable process Java bean initial state (Host) Java bean initial state (Host) Bean Manager (Context) Bean Manager (Context) JavaScript function JavaScript function Java bean new state Host object Java bean new state Host object State change

Rhino Use case : Workflow Workflow Manager ( Context manager ) Workflow Manager ( Context manager ) Workflow task Host object Workflow task Host object Workflow definition Workflow definition Workflow task Host object Workflow task Host object

Liligo use case 1 : Categorization Storage process Script Storage rules Script Storage rules Ski Week-ends Cruises Package offers

Liligo use case 2 : Flexible processing Data processing Script Data processing Script Data Host object Data Host object HTML XML CSV Text file

A few more words  J2SE integrates a higher level of integration which allows you to decide the scripting engine you want to use.  JRuby, Jython are alternative to JavaScript and Rhino.  Helma framework embeds Rhino to provide a full JavaScript server-side framework.

To learn more    sktop/scripting/

Conclusion Rhino is a really powerful tool. Rhino is easy to integrate especially since the J2SE1.6. Performance concerns imply to clearly identify the right embedding strategy. Properly used in your application it will convert a monolithic java application into a customizable user-oriented one !!!

Any questions ? “ and don’t hesitate to contact me with questions or if you were interested in working in our team: ”