SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Scripting your Java Application
         with BSF 3.0
        Felix Meschberger
        ApacheCon EU 09
About
    Senior Developer at Day
•
    fmeschbe@apache.org
•
•   http://blog.meschberger.ch
•   Apache Projects:
    – Sling
    – Felix
    – Jackrabbit
Contents
    Scope
•
    BSF 3.0
•
                          TM
•   Scripting for the Java Platform
•   OSGi Framework
•   Demo
Scope
                        TM
•   Scripting for the Java Platform
•   Using BSF 3
•   Not using BSF 2 API
•   Example: Apache Sling
Contents
    Scope
•
    BSF 3.0
•
                          TM
•   Scripting for the Java Platform
•   OSGi Framework
•   Demo
About BSF
• Bean Scripting Framework
• http://jakarta.apache.org/bsf/
• Timeline
  – 1999 Sanjiva Weerawarana, IBM
  – 2002 Subproject of Jakarta (Version 2.3)
  – 2006 BSF 2.4
  – 2007 BSF 3.0 beta2
  – 2009 BSF 3.0 beta3 (right now!)
BSF 3.0
• Java Scripting API (JSR-223)
• Stable
• Beta due to TCK issues
Contents
    Scope
•
    BSF 3.0
•
                          TM
•   Scripting for the Java Platform
•   OSGi Framework
•   Demo
TM
Scripting for the Java            Platform
    JSR-223
•
    Approved November 2006
•
•   Builds on BSF 2.4 and BeanShell
•   Included in Java 6
•   BSF 3.0 for Java 1.4 and Java 5
Three Steps for Scripting
1. Get the ScriptEngineManager
  ScriptEngineManager mgr = new
    ScriptEngineManager();
2. Get the ScriptEngine
  ScriptEngine eng =
    mgr.getEngineByExtension(„js“);
3. Evaluate the Script
  Object result = eng.eval(„'Hello World'“);
Demo 1
• Scripting in Three Steps
  – Sample0.java
  – Call Class from Command Line
Main API
• javax.script.ScriptEngineManager
  – Manages ScriptEngineFactory
  – Provides access to ScriptEngine
  – Manages Global Scope
• javax.script.ScriptEngineFactory
  – Registered with ScriptEngineManager
  – Creates ScriptEngine
• javax.script.ScriptEngine
  – Evaluates Scripts
Helper API
• javax.script.Bindings
  – Variable Binding between Scripts and App.
• javax.script.ScriptContext
  – Context for evaluating Scripts
  – Bindings (Scopes)
  – Input/Output
• javax.script.ScriptException
  – Thrown on Script Execution Errors
Advanced API
• javax.script.Invocable
  – Optionally implemented by ScriptEngine
  – Allows calling functions in scripts
• javax.script.Compilable
  – Optionally implemented by ScriptEngine
  – Allows precompiling scripts
  – Generates CompiledScript
• javax.script.CompiledScript
  – Generated by Compilable.compile()
Issues
• Missing Lifecycle Support
  – ScriptEngineFactory can only be added
  – Cleanup of ScriptEngineManager only on GC
• Missing API
  – ScriptEngineManager.unregisterXXX()
  – ScriptEngineManager.destroy()
  – ScriptEngineFactory.destroy()
• META-INF/services
  – ClassLoader Dependency
Script Language Support
• Implement 2 Interfaces
  – ScriptEngineFactory
  – ScriptEngine
• Register
  – Manually
    ScriptEngineManager.registerEngineExtension()
    ScriptEngineManager.registerEngineMimeType()
    ScriptEngineManager.registerEngineName()
  – Automatically
    META-INF/services/javax.scripting.ScriptEngineFactory
„Demo“ Script Engine Factory
public class DemoScriptEngineFactory
        implements ScriptEngineFactory {

     public ScriptEngine getScriptEngine() {
         return new DemoScriptEngine(this);
     }

     public List<String> getExtensions() {
         return Arrays.asList(quot;demoquot;);
     }
     // more methods not shown
}
„Demo“ Script Engine
public class DemoScriptEngine
        extends AbstractScriptEngine {

    public Object eval(String script,
            ScriptContext context) {
        return script;
    }
    // more methods not shown
}
„Demo“ Registration
META-INF/services/javax.script.ScriptEngineFactory
  ch.meschberger.demo.engine.DemoScriptEngineFactory




ScriptEngineManager.registerEngine*()
  ScriptEngineManager mgr =
    new ScriptEngineManager();
  mgr.registerEngineName(engineName,
    new DemoScriptEngineFactory());
Demo 2
• Automatic Registration of „Demo“ Engine
  – Sample1.java
  – Call Class from Commandline
• Manual Registration of „Demo“ Engine
  – Sample2.java
  – Call Class from Commandline
Interaction
• Variable Bindings
  – Global Scope
  – Engine Scope
  – Runtime Scope
• Return Values
Demo 3
• Simple Script Executor
  – Sample4
  – Reads and executes <lang>: <script>
• Return Value From Script
• Global Scope – Shared Bindings
• Runtime Scope – Non-shared Bindings
Contents
    Scope
•
    BSF 3.0
•
                          TM
•   Scripting for the Java Platform
•   OSGi Framework
•   Demo
OSGi Quick Shot

The Framework forms the core of the
OSGi Service Platform Specifications. It
provides a general-purpose, secure, and
managed Java framework that supports
the deployment of extensible and
downloadable applications known as
bundles.
  OSGi Service Platform Core Specification, Release 4, Version 4.1,
    The OSGi Alliance, April 2007
OSGi Layers
• Security Layer
  – Java 2 Security based
• Module Layer
  – Bundles and Classloaders
• Life Cycle Layer
  – Installation, Start, Stop, Uninstallation, ...
• Service Layer
  – Service Registry
• Actual Services
Sling and Java Scripting
• Provide BSF 3.0 API (Java 5 only)
• Manage ScriptEngineFactory
  – Create ScriptEngineManager
  – Update ScriptEngineManager
• Automatic Registration
  – META-INF/services/j.s.ScriptEngineFactory
  – ScriptEngineFactory services
ScriptEngine for Sling
• Create a Bundle
  – Export-Package: None required
  – Import-Package: javax.script plus required
  – DynamicImport-Package: *
• ClassLoader Issues
  – Create Bridging ClassLoader
    http://wiki.eclipse.org/BundleProxyClassLoader_recipe
  – Set Thread's context ClassLoader
Sling, Java Scripting: Lifecycle
• Problem:
  – Lifecycle required for Cleanup
  – META-INF/services required for Interoperability
• Solution:
  – BundleActivator
Contents
    Scope
•
    BSF 3.0
•
                          TM
•   Scripting for the Java Platform
•   OSGi Framework
•   Demo
How Sling finds Scripts

/content/cars/audi/s4.details.html
Demo: Sleep
• http://sleep.dashnine.org/
• Perl-like
• Provides ScriptEngineFactory with
  automatic registration
• ch.meschberger.demo.sleep
  – Downloads and Bundles Sleep
Demo 3
• Sling Running
• Web Console shows known Engines
• Show Scripts
Links
    http://jakarta.apache.org/bsf/
•
    http://www.jcp.org/en/jsr/detail?id=223
•
•   http://incubator.apache.org/sling/
•   http://felix.apache.org/
•   http://scripting.dev.java.net/
Questions ?
Thank You !
Famous Last Words
• Rate this talk at
  – http://apacheconus2008.crowdvine.com/talks/s
    how/1348
• Join the Sling Community at
  – http://incubator.apache.org/sling
  – mailto:sling-dev@incubator.apache.org

Weitere ähnliche Inhalte

Was ist angesagt?

快快樂樂用Homestead
快快樂樂用Homestead快快樂樂用Homestead
快快樂樂用HomesteadChen Cheng-Wei
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다Arawn Park
 
Running and Scaling Magento on AWS
Running and Scaling Magento on AWSRunning and Scaling Magento on AWS
Running and Scaling Magento on AWSAOE
 
Introduction to selenium_grid_workshop
Introduction to selenium_grid_workshopIntroduction to selenium_grid_workshop
Introduction to selenium_grid_workshopseleniumconf
 
Controlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonControlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonYurii Vasylenko
 
Selenium Grid
Selenium GridSelenium Grid
Selenium Gridnirvdrum
 
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)Simon Boulet
 
MongoDB Server Provisioning - From 2 Months to 2 Minutes
MongoDB Server Provisioning - From 2 Months to 2 MinutesMongoDB Server Provisioning - From 2 Months to 2 Minutes
MongoDB Server Provisioning - From 2 Months to 2 MinutesMongoDB
 
Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Chen Cheng-Wei
 
Introduction to vSphere APIs Using pyVmomi
Introduction to vSphere APIs Using pyVmomiIntroduction to vSphere APIs Using pyVmomi
Introduction to vSphere APIs Using pyVmomiMichael Rice
 
[Perforce] Adventures in Build
[Perforce] Adventures in Build[Perforce] Adventures in Build
[Perforce] Adventures in BuildPerforce
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REXSaewoong Lee
 
Embedding GlassFish v3 in Ehcache Server
Embedding GlassFish v3 in Ehcache ServerEmbedding GlassFish v3 in Ehcache Server
Embedding GlassFish v3 in Ehcache ServerEduardo Pelegri-Llopart
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magentoMathew Beane
 
Backup workflow for SMHV on windows 2008R2 HYPER-V
Backup workflow for SMHV on windows 2008R2 HYPER-VBackup workflow for SMHV on windows 2008R2 HYPER-V
Backup workflow for SMHV on windows 2008R2 HYPER-VAshwin Pawar
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPMax Romanovsky
 

Was ist angesagt? (20)

快快樂樂用Homestead
快快樂樂用Homestead快快樂樂用Homestead
快快樂樂用Homestead
 
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
잘 키운 모노리스 하나 열 마이크로서비스 안 부럽다
 
Running and Scaling Magento on AWS
Running and Scaling Magento on AWSRunning and Scaling Magento on AWS
Running and Scaling Magento on AWS
 
Introduction to selenium_grid_workshop
Introduction to selenium_grid_workshopIntroduction to selenium_grid_workshop
Introduction to selenium_grid_workshop
 
Controlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonControlling multiple VMs with the power of Python
Controlling multiple VMs with the power of Python
 
Selenium Grid
Selenium GridSelenium Grid
Selenium Grid
 
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)
 
MongoDB Server Provisioning - From 2 Months to 2 Minutes
MongoDB Server Provisioning - From 2 Months to 2 MinutesMongoDB Server Provisioning - From 2 Months to 2 Minutes
MongoDB Server Provisioning - From 2 Months to 2 Minutes
 
Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀
 
Introduction to vSphere APIs Using pyVmomi
Introduction to vSphere APIs Using pyVmomiIntroduction to vSphere APIs Using pyVmomi
Introduction to vSphere APIs Using pyVmomi
 
GlassFish v3 at JavaZone 09
GlassFish v3 at JavaZone 09GlassFish v3 at JavaZone 09
GlassFish v3 at JavaZone 09
 
[Perforce] Adventures in Build
[Perforce] Adventures in Build[Perforce] Adventures in Build
[Perforce] Adventures in Build
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
 
WebSockets with Spring 4
WebSockets with Spring 4WebSockets with Spring 4
WebSockets with Spring 4
 
Embedding GlassFish v3 in Ehcache Server
Embedding GlassFish v3 in Ehcache ServerEmbedding GlassFish v3 in Ehcache Server
Embedding GlassFish v3 in Ehcache Server
 
Ansible 2.2
Ansible 2.2Ansible 2.2
Ansible 2.2
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
Devops madrid: successful case in AWS
Devops madrid: successful case in AWSDevops madrid: successful case in AWS
Devops madrid: successful case in AWS
 
Backup workflow for SMHV on windows 2008R2 HYPER-V
Backup workflow for SMHV on windows 2008R2 HYPER-VBackup workflow for SMHV on windows 2008R2 HYPER-V
Backup workflow for SMHV on windows 2008R2 HYPER-V
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
 

Andere mochten auch

Tarpm Clustering
Tarpm ClusteringTarpm Clustering
Tarpm Clusteringday
 
Embrace OSGi Apache Con Europe2009
Embrace OSGi Apache Con Europe2009Embrace OSGi Apache Con Europe2009
Embrace OSGi Apache Con Europe2009day
 
Java Persistence Frameworks
Java Persistence FrameworksJava Persistence Frameworks
Java Persistence Frameworksday
 
Scala for scripting
Scala for scriptingScala for scripting
Scala for scriptingday
 
Testing Zen
Testing ZenTesting Zen
Testing Zenday
 
Scala4sling
Scala4slingScala4sling
Scala4slingday
 

Andere mochten auch (7)

Tarpm Clustering
Tarpm ClusteringTarpm Clustering
Tarpm Clustering
 
Embrace OSGi Apache Con Europe2009
Embrace OSGi Apache Con Europe2009Embrace OSGi Apache Con Europe2009
Embrace OSGi Apache Con Europe2009
 
Java Persistence Frameworks
Java Persistence FrameworksJava Persistence Frameworks
Java Persistence Frameworks
 
Apache jMeter
Apache jMeterApache jMeter
Apache jMeter
 
Scala for scripting
Scala for scriptingScala for scripting
Scala for scripting
 
Testing Zen
Testing ZenTesting Zen
Testing Zen
 
Scala4sling
Scala4slingScala4sling
Scala4sling
 

Ähnlich wie Scripting Yor Java Application with BSF3

Java ScriptingJava Scripting: One VM, Many Languages
Java ScriptingJava Scripting: One VM, Many LanguagesJava ScriptingJava Scripting: One VM, Many Languages
Java ScriptingJava Scripting: One VM, Many Languageselliando dias
 
New Features of Java7 SE
New Features of Java7 SENew Features of Java7 SE
New Features of Java7 SEdogangoko
 
How to generate a REST CXF3 application from Swagger ApacheConEU 2016
How to generate a REST CXF3 application from Swagger ApacheConEU 2016How to generate a REST CXF3 application from Swagger ApacheConEU 2016
How to generate a REST CXF3 application from Swagger ApacheConEU 2016johannes_fiala
 
Jcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applicationsJcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applicationsjohannes_fiala
 
Dynamic Languages Web Frameworks Indicthreads 2009
Dynamic Languages Web Frameworks Indicthreads 2009Dynamic Languages Web Frameworks Indicthreads 2009
Dynamic Languages Web Frameworks Indicthreads 2009Arun Gupta
 
How to generate a rest application - DevFest Vienna 2016
How to generate a rest application - DevFest Vienna 2016How to generate a rest application - DevFest Vienna 2016
How to generate a rest application - DevFest Vienna 2016johannes_fiala
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascriptrajivmordani
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
Tuning and development with SIP Servlets on Mobicents
Tuning and development with SIP Servlets on MobicentsTuning and development with SIP Servlets on Mobicents
Tuning and development with SIP Servlets on MobicentsJean Deruelle
 
Plugins 2.0: The Overview
Plugins 2.0: The OverviewPlugins 2.0: The Overview
Plugins 2.0: The OverviewAtlassian
 
Application Architecture Trends
Application Architecture TrendsApplication Architecture Trends
Application Architecture TrendsSrini Penchikala
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010JUG Lausanne
 
Deep Dive Azure Functions - Global Azure Bootcamp 2019
Deep Dive Azure Functions - Global Azure Bootcamp 2019Deep Dive Azure Functions - Global Azure Bootcamp 2019
Deep Dive Azure Functions - Global Azure Bootcamp 2019Andrea Tosato
 
Isomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornIsomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornMaxime Najim
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)Fabien Potencier
 
Chris Omland - AWS Code Deploy - BSDC 2016
Chris Omland - AWS Code Deploy - BSDC 2016Chris Omland - AWS Code Deploy - BSDC 2016
Chris Omland - AWS Code Deploy - BSDC 2016roblund
 
How to deploy a Java application on Google App engine Flexible environment
How to deploy a Java application on Google App engine Flexible environmentHow to deploy a Java application on Google App engine Flexible environment
How to deploy a Java application on Google App engine Flexible environmentMichelantonio Trizio
 
Java @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SPJava @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SPIlan Salviano
 

Ähnlich wie Scripting Yor Java Application with BSF3 (20)

Java ScriptingJava Scripting: One VM, Many Languages
Java ScriptingJava Scripting: One VM, Many LanguagesJava ScriptingJava Scripting: One VM, Many Languages
Java ScriptingJava Scripting: One VM, Many Languages
 
New Features of Java7 SE
New Features of Java7 SENew Features of Java7 SE
New Features of Java7 SE
 
AppengineJS
AppengineJSAppengineJS
AppengineJS
 
How to generate a REST CXF3 application from Swagger ApacheConEU 2016
How to generate a REST CXF3 application from Swagger ApacheConEU 2016How to generate a REST CXF3 application from Swagger ApacheConEU 2016
How to generate a REST CXF3 application from Swagger ApacheConEU 2016
 
Jcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applicationsJcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applications
 
Dynamic Languages Web Frameworks Indicthreads 2009
Dynamic Languages Web Frameworks Indicthreads 2009Dynamic Languages Web Frameworks Indicthreads 2009
Dynamic Languages Web Frameworks Indicthreads 2009
 
How to generate a rest application - DevFest Vienna 2016
How to generate a rest application - DevFest Vienna 2016How to generate a rest application - DevFest Vienna 2016
How to generate a rest application - DevFest Vienna 2016
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascript
 
GlassFish v3 : En Route Java EE 6
GlassFish v3 : En Route Java EE 6GlassFish v3 : En Route Java EE 6
GlassFish v3 : En Route Java EE 6
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Tuning and development with SIP Servlets on Mobicents
Tuning and development with SIP Servlets on MobicentsTuning and development with SIP Servlets on Mobicents
Tuning and development with SIP Servlets on Mobicents
 
Plugins 2.0: The Overview
Plugins 2.0: The OverviewPlugins 2.0: The Overview
Plugins 2.0: The Overview
 
Application Architecture Trends
Application Architecture TrendsApplication Architecture Trends
Application Architecture Trends
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
 
Deep Dive Azure Functions - Global Azure Bootcamp 2019
Deep Dive Azure Functions - Global Azure Bootcamp 2019Deep Dive Azure Functions - Global Azure Bootcamp 2019
Deep Dive Azure Functions - Global Azure Bootcamp 2019
 
Isomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornIsomorphic JavaScript with Nashorn
Isomorphic JavaScript with Nashorn
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
 
Chris Omland - AWS Code Deploy - BSDC 2016
Chris Omland - AWS Code Deploy - BSDC 2016Chris Omland - AWS Code Deploy - BSDC 2016
Chris Omland - AWS Code Deploy - BSDC 2016
 
How to deploy a Java application on Google App engine Flexible environment
How to deploy a Java application on Google App engine Flexible environmentHow to deploy a Java application on Google App engine Flexible environment
How to deploy a Java application on Google App engine Flexible environment
 
Java @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SPJava @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SP
 

Mehr von day

Tech Summit 08 Support Initiative
Tech Summit 08 Support InitiativeTech Summit 08 Support Initiative
Tech Summit 08 Support Initiativeday
 
Non Cms For Web Apps
Non Cms For Web AppsNon Cms For Web Apps
Non Cms For Web Appsday
 
Getting Into The Flow With Cq Dam
Getting Into The Flow With Cq DamGetting Into The Flow With Cq Dam
Getting Into The Flow With Cq Damday
 
Dispatcher Oom
Dispatcher OomDispatcher Oom
Dispatcher Oomday
 
Advanced Collaboration And Beyond
Advanced Collaboration And BeyondAdvanced Collaboration And Beyond
Advanced Collaboration And Beyondday
 
Wc Mand Connectors2
Wc Mand Connectors2Wc Mand Connectors2
Wc Mand Connectors2day
 
Jackrabbit Roadmap
Jackrabbit RoadmapJackrabbit Roadmap
Jackrabbit Roadmapday
 
Doc Book Vs Dita
Doc Book Vs DitaDoc Book Vs Dita
Doc Book Vs Ditaday
 
Doc Book Vs Dita Teresa
Doc Book Vs Dita TeresaDoc Book Vs Dita Teresa
Doc Book Vs Dita Teresaday
 
862
862862
862day
 
Apache Con Us2007 Sanselan
Apache Con Us2007 SanselanApache Con Us2007 Sanselan
Apache Con Us2007 Sanselanday
 
Apache Con Us2007 Jcr In Action
Apache Con Us2007 Jcr In ActionApache Con Us2007 Jcr In Action
Apache Con Us2007 Jcr In Actionday
 
Apache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei BatisApache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei Batisday
 
Apache Con U S07 F F T Sling
Apache Con U S07  F F T  SlingApache Con U S07  F F T  Sling
Apache Con U S07 F F T Slingday
 
200711 R E S T Apache Con
200711  R E S T  Apache Con200711  R E S T  Apache Con
200711 R E S T Apache Conday
 

Mehr von day (15)

Tech Summit 08 Support Initiative
Tech Summit 08 Support InitiativeTech Summit 08 Support Initiative
Tech Summit 08 Support Initiative
 
Non Cms For Web Apps
Non Cms For Web AppsNon Cms For Web Apps
Non Cms For Web Apps
 
Getting Into The Flow With Cq Dam
Getting Into The Flow With Cq DamGetting Into The Flow With Cq Dam
Getting Into The Flow With Cq Dam
 
Dispatcher Oom
Dispatcher OomDispatcher Oom
Dispatcher Oom
 
Advanced Collaboration And Beyond
Advanced Collaboration And BeyondAdvanced Collaboration And Beyond
Advanced Collaboration And Beyond
 
Wc Mand Connectors2
Wc Mand Connectors2Wc Mand Connectors2
Wc Mand Connectors2
 
Jackrabbit Roadmap
Jackrabbit RoadmapJackrabbit Roadmap
Jackrabbit Roadmap
 
Doc Book Vs Dita
Doc Book Vs DitaDoc Book Vs Dita
Doc Book Vs Dita
 
Doc Book Vs Dita Teresa
Doc Book Vs Dita TeresaDoc Book Vs Dita Teresa
Doc Book Vs Dita Teresa
 
862
862862
862
 
Apache Con Us2007 Sanselan
Apache Con Us2007 SanselanApache Con Us2007 Sanselan
Apache Con Us2007 Sanselan
 
Apache Con Us2007 Jcr In Action
Apache Con Us2007 Jcr In ActionApache Con Us2007 Jcr In Action
Apache Con Us2007 Jcr In Action
 
Apache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei BatisApache Con Us2007 Apachei Batis
Apache Con Us2007 Apachei Batis
 
Apache Con U S07 F F T Sling
Apache Con U S07  F F T  SlingApache Con U S07  F F T  Sling
Apache Con U S07 F F T Sling
 
200711 R E S T Apache Con
200711  R E S T  Apache Con200711  R E S T  Apache Con
200711 R E S T Apache Con
 

Kürzlich hochgeladen

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Kürzlich hochgeladen (20)

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

Scripting Yor Java Application with BSF3

  • 1. Scripting your Java Application with BSF 3.0 Felix Meschberger ApacheCon EU 09
  • 2. About Senior Developer at Day • fmeschbe@apache.org • • http://blog.meschberger.ch • Apache Projects: – Sling – Felix – Jackrabbit
  • 3. Contents Scope • BSF 3.0 • TM • Scripting for the Java Platform • OSGi Framework • Demo
  • 4. Scope TM • Scripting for the Java Platform • Using BSF 3 • Not using BSF 2 API • Example: Apache Sling
  • 5. Contents Scope • BSF 3.0 • TM • Scripting for the Java Platform • OSGi Framework • Demo
  • 6. About BSF • Bean Scripting Framework • http://jakarta.apache.org/bsf/ • Timeline – 1999 Sanjiva Weerawarana, IBM – 2002 Subproject of Jakarta (Version 2.3) – 2006 BSF 2.4 – 2007 BSF 3.0 beta2 – 2009 BSF 3.0 beta3 (right now!)
  • 7. BSF 3.0 • Java Scripting API (JSR-223) • Stable • Beta due to TCK issues
  • 8. Contents Scope • BSF 3.0 • TM • Scripting for the Java Platform • OSGi Framework • Demo
  • 9. TM Scripting for the Java Platform JSR-223 • Approved November 2006 • • Builds on BSF 2.4 and BeanShell • Included in Java 6 • BSF 3.0 for Java 1.4 and Java 5
  • 10. Three Steps for Scripting 1. Get the ScriptEngineManager ScriptEngineManager mgr = new ScriptEngineManager(); 2. Get the ScriptEngine ScriptEngine eng = mgr.getEngineByExtension(„js“); 3. Evaluate the Script Object result = eng.eval(„'Hello World'“);
  • 11. Demo 1 • Scripting in Three Steps – Sample0.java – Call Class from Command Line
  • 12. Main API • javax.script.ScriptEngineManager – Manages ScriptEngineFactory – Provides access to ScriptEngine – Manages Global Scope • javax.script.ScriptEngineFactory – Registered with ScriptEngineManager – Creates ScriptEngine • javax.script.ScriptEngine – Evaluates Scripts
  • 13. Helper API • javax.script.Bindings – Variable Binding between Scripts and App. • javax.script.ScriptContext – Context for evaluating Scripts – Bindings (Scopes) – Input/Output • javax.script.ScriptException – Thrown on Script Execution Errors
  • 14. Advanced API • javax.script.Invocable – Optionally implemented by ScriptEngine – Allows calling functions in scripts • javax.script.Compilable – Optionally implemented by ScriptEngine – Allows precompiling scripts – Generates CompiledScript • javax.script.CompiledScript – Generated by Compilable.compile()
  • 15. Issues • Missing Lifecycle Support – ScriptEngineFactory can only be added – Cleanup of ScriptEngineManager only on GC • Missing API – ScriptEngineManager.unregisterXXX() – ScriptEngineManager.destroy() – ScriptEngineFactory.destroy() • META-INF/services – ClassLoader Dependency
  • 16. Script Language Support • Implement 2 Interfaces – ScriptEngineFactory – ScriptEngine • Register – Manually ScriptEngineManager.registerEngineExtension() ScriptEngineManager.registerEngineMimeType() ScriptEngineManager.registerEngineName() – Automatically META-INF/services/javax.scripting.ScriptEngineFactory
  • 17. „Demo“ Script Engine Factory public class DemoScriptEngineFactory implements ScriptEngineFactory { public ScriptEngine getScriptEngine() { return new DemoScriptEngine(this); } public List<String> getExtensions() { return Arrays.asList(quot;demoquot;); } // more methods not shown }
  • 18. „Demo“ Script Engine public class DemoScriptEngine extends AbstractScriptEngine { public Object eval(String script, ScriptContext context) { return script; } // more methods not shown }
  • 19. „Demo“ Registration META-INF/services/javax.script.ScriptEngineFactory ch.meschberger.demo.engine.DemoScriptEngineFactory ScriptEngineManager.registerEngine*() ScriptEngineManager mgr = new ScriptEngineManager(); mgr.registerEngineName(engineName, new DemoScriptEngineFactory());
  • 20. Demo 2 • Automatic Registration of „Demo“ Engine – Sample1.java – Call Class from Commandline • Manual Registration of „Demo“ Engine – Sample2.java – Call Class from Commandline
  • 21. Interaction • Variable Bindings – Global Scope – Engine Scope – Runtime Scope • Return Values
  • 22. Demo 3 • Simple Script Executor – Sample4 – Reads and executes <lang>: <script> • Return Value From Script • Global Scope – Shared Bindings • Runtime Scope – Non-shared Bindings
  • 23. Contents Scope • BSF 3.0 • TM • Scripting for the Java Platform • OSGi Framework • Demo
  • 24. OSGi Quick Shot The Framework forms the core of the OSGi Service Platform Specifications. It provides a general-purpose, secure, and managed Java framework that supports the deployment of extensible and downloadable applications known as bundles. OSGi Service Platform Core Specification, Release 4, Version 4.1, The OSGi Alliance, April 2007
  • 25. OSGi Layers • Security Layer – Java 2 Security based • Module Layer – Bundles and Classloaders • Life Cycle Layer – Installation, Start, Stop, Uninstallation, ... • Service Layer – Service Registry • Actual Services
  • 26. Sling and Java Scripting • Provide BSF 3.0 API (Java 5 only) • Manage ScriptEngineFactory – Create ScriptEngineManager – Update ScriptEngineManager • Automatic Registration – META-INF/services/j.s.ScriptEngineFactory – ScriptEngineFactory services
  • 27. ScriptEngine for Sling • Create a Bundle – Export-Package: None required – Import-Package: javax.script plus required – DynamicImport-Package: * • ClassLoader Issues – Create Bridging ClassLoader http://wiki.eclipse.org/BundleProxyClassLoader_recipe – Set Thread's context ClassLoader
  • 28. Sling, Java Scripting: Lifecycle • Problem: – Lifecycle required for Cleanup – META-INF/services required for Interoperability • Solution: – BundleActivator
  • 29. Contents Scope • BSF 3.0 • TM • Scripting for the Java Platform • OSGi Framework • Demo
  • 30. How Sling finds Scripts /content/cars/audi/s4.details.html
  • 31. Demo: Sleep • http://sleep.dashnine.org/ • Perl-like • Provides ScriptEngineFactory with automatic registration • ch.meschberger.demo.sleep – Downloads and Bundles Sleep
  • 32. Demo 3 • Sling Running • Web Console shows known Engines • Show Scripts
  • 33. Links http://jakarta.apache.org/bsf/ • http://www.jcp.org/en/jsr/detail?id=223 • • http://incubator.apache.org/sling/ • http://felix.apache.org/ • http://scripting.dev.java.net/
  • 36. Famous Last Words • Rate this talk at – http://apacheconus2008.crowdvine.com/talks/s how/1348 • Join the Sling Community at – http://incubator.apache.org/sling – mailto:sling-dev@incubator.apache.org