SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

快快樂樂用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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Último (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

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