SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
OSGi on Scala
BindForge & ScalaModules: Scala DSLs to ease OSGi development
    Roman Roelofsen (ProSyst), Heiko Seeberger (WeigleWilczek)
Why?

• OSGi is a great module system
• Scala is a great language
  •   Compiles to Java bytecode

  •   Object-functional programming style

  •   Why wait for Java 7 (or 8)? Use Scala now!

• Let’s combine them to ease OSGi development
What?



• BindForge - Module Framework
• ScalaModules - DSL for OSGi development in Scala
BindForge
• Module Framework
  •   Dependency Injection, OSGi service abstraction, etc.

  •   Useful for Java and Scala development

  •   Configuration is written in Scala

• Based on
  •   Scala

  •   Guice

  •   Peaberry
Example Scenario

CustomerRepository        CustomerService


CustomerRep.Impl        CustomerServiceImpl

              Customer Bundle




                                                    LogService

                                              OSGi Log Service Bundle
Example Scenario
// repository
interface CustomerRepository
class CustomerRepositoryImpl implements CustomerRepository

// service
interface CustomerService
class CustomerServiceImpl implements CustomerService {

    public void setCustomerRepository(CustomerRepository cr) {
        ...
    }

    public void setLogService(LogService ls) {
        ...
    }

}
Bundle Conguration

• MANIFEST.MF
   BindForge-Config: com.acme.app.MyConfig




• /OSGI-INF/bindforge/config.scala
   package com.acme.app

   class MyConfig extends org.bindforge.Config {
       ...
   }
Binding Interfaces to
          Implementations

CustomerRepository        CustomerService


CustomerRep.Impl        CustomerServiceImpl

              Customer Bundle
Binding Interfaces to
      Implementations

package com.acme.app

class MyConfig extends org.bindforge.Config {

    bind [CustomerRepository, impl.CustomerRepositoryImpl]

    bind [CustomerService, impl.CustomerServiceImpl]

}
Inject Bindings

CustomerRepository        CustomerService


CustomerRep.Impl        CustomerServiceImpl

              Customer Bundle
Inject Bindings
            (by type)


bind [CustomerRepository, impl.CustomerRepositoryImpl]

bind [CustomerService, impl.CustomerServiceImpl] spec {
    property(“customerRepository”)
}
Inject Bindings
              (by name)


“customerRepository” :: bind [impl.CustomerRepositoryImpl]

bind [CustomerService, impl.CustomerServiceImpl] spec {
    property(“customerRepository”) = ref(“customerRepository”)
}
Export Customer Service

CustomerRepository        CustomerService


CustomerRep.Impl        CustomerServiceImpl

              Customer Bundle
Export Customer Service


  bind [CustomerRepository, impl.CustomerRepositoryImpl]

  bind [CustomerService, impl.CustomerServiceImpl] spec {
      exportService
      property(“customerRepository”)
  }
Export Customer Service
   (with Properties)

 bind [CustomerRepository, impl.CustomerRepositoryImpl]

 bind [CustomerService, impl.CustomerServiceImpl] spec {
     exportService(“vendor” -> “acme”, “security” -> “none”)
     property(“customerRepository”)
 }
Import LogService

CustomerRepository        CustomerService


CustomerRep.Impl        CustomerServiceImpl

              Customer Bundle




                                                    LogService

                                              OSGi Log Service Bundle
Import LogService

bind [LogService] importService

bind [CustomerRepository, impl.CustomerRepositoryImpl]

bind [CustomerService, impl.CustomerServiceImpl] spec {
    exportService
    property(“customerRepository”)
    property(“logService”)
}
Full Conguration
package com.acme.app

class MyConfig extends org.bindforge.Config {

    bind [LogService] importService

    bind [CustomerRepository, impl.CustomerRepositoryImpl]

    bind [CustomerService, impl.CustomerServiceImpl] spec {
        exportService
        property(“customerRepository”)
        property(“logService”)
    }

}
What?



• BindForge - Module Framework
• ScalaModules - DSL for OSGi development in Scala
ScalaModules


• For Scala developers (and Java geeks)
• General OSGi concepts, e.g. service handling
• Compendium services, e.g. Configuration Admin
Register a Service

Greeting hello = new Greeting() {
                                                            afe
                                                          es
    public String welcome() {

                                                     yp
        return quot;Hello!quot;;
                                                  tt
    }
                                               no
    public String goodbye() {
        return quot;See you!quot;;
    }
};
context.registerService(Greeting.class.getName(), hello, null);
Register a Service


context registerAs classOf[Greeting] theService new Greeting {
  override def welcome = quot;Hello!quot;
  override def goodbye = quot;See you!quot;;
}
Register a Service
             with Properties
Greeting welcome = new Greeting() {
                                                                     se
                                                                   o
    public String welcome() {
                                                                 rb
                                                              ve
        return quot;Welcome!quot;;
    }
    public String goodbye() {
        return quot;Good bye!quot;;
    }
};
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(quot;namequot;, quot;welcomequot;);
context.registerService(Greeting.class.getName(), welcome, properties);
Register a Service
   with Properties


context registerAs classOf[Greeting] withProperties
  Map(quot;namequot; -> quot;welcomequot;) theService new Greeting {
    override def welcome = quot;Welcome!quot;
    override def goodbye = quot;Goodbye!quot;
  }
Consume a single Service
ServiceReference reference =
    context.getServiceReference(Greeting.class.getName());
if (reference != null) {
    try {
        Object service = context.getService(reference);
        Greeting greeting = (Greeting) service;
         if (greeting != null) {
             System.out.println(greeting.welcome());
        } else {
             noGreetingService();
        }
    } finally {
        context.ungetService(reference);
                                                      inv
    }
                                                         olv
} else {
                                                            ed
    noGreetingService();
}
Consume a single Service


    context getOne classOf[Greeting] andApply {
      _.welcome
    } match {
      case None          => noGreetingService()
      case Some(welcome) => println(welcome)
    }
Consume many Services
    with their Properties
try {
    ServiceReference[] refs = context.getServiceReferences(
            Greeting.class.getName(), null);
    if (refs != null) {
        for (ServiceReference ref : refs) {
            Object service = context.getService(ref);
            Greeting greeting = (Greeting) service;
             if (greeting != null) {
                 Object name = (ref.getProperty(quot;namequot;) != null)
                         ? ref.getProperty(quot;namequot;)
                         : quot;UNKNOWNquot;;
                 String message = name + quot; says: quot; + greeting.welcome();
                 System.out.println(message);
            }
        }
                                                       ver
    } else {
                                                           y   inv
        noGreetingService();
                                                                  olv
    }
                                                                     ed
} catch (InvalidSyntaxException e) { // Do something meaningful ...
}
Consume many Services
 with their Properties
 context getMany classOf[Greeting] andApply {
   (greeting, properties) => {
     val name = properties.get(quot;namequot;) match {
       case None    => quot;UNKNOWNquot;
       case Some(s) => s
     }
     name + quot; sais: quot; + greeting.welcome
   }
 } match {
   case None           => noGreetingService()
   case Some(welcomes) => welcomes.foreach { println }
 }
Consume Services
           using a Filter
try {
    ServiceReference[] refs = context.getServiceReferences(
            Greeting.class.getName(), quot;(name=*)quot;);
    if (refs != null) {
        for (ServiceReference ref : refs) {
            Object service = context.getService(ref);
            Greeting greeting = (Greeting) service;
             if (greeting != null) {
                 System.out.println(greeting.welcome());
                                           ver
            }
                                               y
        }
                                                   inv
    } else {
                                                      olv
                                                         ed
        noGreetingService();
                                                              aga
    }
                                                                 in
} catch (InvalidSyntaxException e) { // Do something meaningful ...
}
Consume Services
           using a Filter

context getMany classOf[Greeting] withFilter quot;(name=*)quot; andApply {
  _.welcome
} match {
  case None           => noGreetingService()
  case Some(welcomes) => welcomes.foreach { println }
}
Track Services
ServiceTracker tracker = new ServiceTracker(context, Greeting.class.getName(), null) {

   @Override
   public Object addingService(ServiceReference reference) {
       Object service = super.addingService(reference);
       Greeting greeting = (Greeting)service;
       System.out.println(quot;Adding Greeting: quot; + greeting.welcome());
       return service;
   }

   @Override
   public void removedService(ServiceReference reference, Object service) {
       Greeting greeting = (Greeting)service;
       System.out.println(quot;Removed Greeting: quot; + greeting.welcome());
                                                                         and
       super.removedService(reference, service);
                                                                               aga
   }
                                                                                     in
};
tracker.open();
Track Services


greetingTrack = context track classOf[Greeting] on {
  case Adding(greeting, _)   => println(quot;Adding Greeting: quot; + greeting.welcome)
  case Modified(greeting, _) =>
  case Removed(greeting, _) => println(quot;Removed Greeting: quot; + greeting.goodbye)
}
Service Dependencies


context registerAs classOf[Command] dependOn classOf[Greeting] theService {
  greeting => new Command {
    ...
  }
}
And now?

• Forge ahead at www.bindforge.org
• And get fluent at www.scalamodules.org

• Please give feedback:
  •   What do you like?

  •   What do you not like?

  •   What feature would you like to see implemented?

Weitere ähnliche Inhalte

Was ist angesagt?

Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
Morgan Cheng
 
Dart
DartDart
Dart
anandvns
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
Sagie Davidovich
 
"Kotlin и rx в android" Дмитрий Воронин (Avito)
"Kotlin и rx в android" Дмитрий Воронин  (Avito)"Kotlin и rx в android" Дмитрий Воронин  (Avito)
"Kotlin и rx в android" Дмитрий Воронин (Avito)
AvitoTech
 
Scripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScript
Justin Deoliveira
 

Was ist angesagt? (20)

Using Go to build a REST API: yes, it’s a good match! - Vincent BEHAR & Mina ...
Using Go to build a REST API: yes, it’s a good match! - Vincent BEHAR & Mina ...Using Go to build a REST API: yes, it’s a good match! - Vincent BEHAR & Mina ...
Using Go to build a REST API: yes, it’s a good match! - Vincent BEHAR & Mina ...
 
Tdd.eng.ver
Tdd.eng.verTdd.eng.ver
Tdd.eng.ver
 
P1
P1P1
P1
 
Pointers
PointersPointers
Pointers
 
Property Wrappers or how Swift decided to become Java
Property Wrappers or how Swift decided to become JavaProperty Wrappers or how Swift decided to become Java
Property Wrappers or how Swift decided to become Java
 
React table tutorial project setup, use table, and usefilter
React table tutorial project setup, use table, and usefilterReact table tutorial project setup, use table, and usefilter
React table tutorial project setup, use table, and usefilter
 
How to implement g rpc services in nodejs
How to implement g rpc services in nodejsHow to implement g rpc services in nodejs
How to implement g rpc services in nodejs
 
Java9 Beyond Modularity - Java 9 mĂĄs allĂĄ de la modularidad
Java9 Beyond Modularity - Java 9 mĂĄs allĂĄ de la modularidadJava9 Beyond Modularity - Java 9 mĂĄs allĂĄ de la modularidad
Java9 Beyond Modularity - Java 9 mĂĄs allĂĄ de la modularidad
 
AngularJS
AngularJSAngularJS
AngularJS
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results Asynchrhonously
 
No more promises lets RxJS 2 Edit
No more promises lets RxJS 2 EditNo more promises lets RxJS 2 Edit
No more promises lets RxJS 2 Edit
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
 
Dart
DartDart
Dart
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
 
"Kotlin и rx в android" Дмитрий Воронин (Avito)
"Kotlin и rx в android" Дмитрий Воронин  (Avito)"Kotlin и rx в android" Дмитрий Воронин  (Avito)
"Kotlin и rx в android" Дмитрий Воронин (Avito)
 
Grails custom tag lib
Grails custom tag libGrails custom tag lib
Grails custom tag lib
 
Scalaz
ScalazScalaz
Scalaz
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Scripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScript
 
Project Gålbma – Actors vs Types
Project Gålbma – Actors vs TypesProject Gålbma – Actors vs Types
Project Gålbma – Actors vs Types
 

Andere mochten auch

JavaSPEKTRUM - Scala 2
JavaSPEKTRUM - Scala 2JavaSPEKTRUM - Scala 2
JavaSPEKTRUM - Scala 2
Heiko Seeberger
 
JavaSPEKTRUM - Scala 3
JavaSPEKTRUM - Scala 3JavaSPEKTRUM - Scala 3
JavaSPEKTRUM - Scala 3
Heiko Seeberger
 
Java Magazin - Lift
Java Magazin - LiftJava Magazin - Lift
Java Magazin - Lift
Heiko Seeberger
 
Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...
Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...
Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...
Philipp Burgmer
 

Andere mochten auch (9)

JAX 2015 - Continuous Integration mit Java & Javascript
JAX 2015 - Continuous Integration mit Java & JavascriptJAX 2015 - Continuous Integration mit Java & Javascript
JAX 2015 - Continuous Integration mit Java & Javascript
 
JM 08/09 - ScalaModules
JM 08/09 - ScalaModulesJM 08/09 - ScalaModules
JM 08/09 - ScalaModules
 
OSGi DevCon Europe 09 - OSGi on Scala
OSGi DevCon Europe 09 - OSGi on ScalaOSGi DevCon Europe 09 - OSGi on Scala
OSGi DevCon Europe 09 - OSGi on Scala
 
JavaSPEKTRUM - Scala 2
JavaSPEKTRUM - Scala 2JavaSPEKTRUM - Scala 2
JavaSPEKTRUM - Scala 2
 
JavaSPEKTRUM - Scala 3
JavaSPEKTRUM - Scala 3JavaSPEKTRUM - Scala 3
JavaSPEKTRUM - Scala 3
 
JM 04/09 - OSGi in kleinen Dosen 5
JM 04/09 - OSGi in kleinen Dosen 5JM 04/09 - OSGi in kleinen Dosen 5
JM 04/09 - OSGi in kleinen Dosen 5
 
Scaladays 2011 - The Ease of Scalaz
Scaladays 2011 - The Ease of ScalazScaladays 2011 - The Ease of Scalaz
Scaladays 2011 - The Ease of Scalaz
 
Java Magazin - Lift
Java Magazin - LiftJava Magazin - Lift
Java Magazin - Lift
 
Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...
Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...
Grunt, Gulp & fabs: Build Systems and Development-Workflow for Modern Web-App...
 

Ähnlich wie OSGi DevCon 09 - OSGi on Scala

How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 
Corba
CorbaCorba
Corba
_ammar_
 
Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-cas
ellentuck
 
Network
NetworkNetwork
Network
phanleson
 

Ähnlich wie OSGi DevCon 09 - OSGi on Scala (20)

Scala modules
Scala modulesScala modules
Scala modules
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
W-JAX 09 - ScalaModules
W-JAX 09 - ScalaModulesW-JAX 09 - ScalaModules
W-JAX 09 - ScalaModules
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Grails transactions
Grails   transactionsGrails   transactions
Grails transactions
 
Corba
CorbaCorba
Corba
 
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Managing GraphQL servers  with AWS Fargate & Prisma CloudManaging GraphQL servers  with AWS Fargate & Prisma Cloud
Managing GraphQL servers with AWS Fargate & Prisma Cloud
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeGDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
 
Kitura Todolist tutorial
Kitura Todolist tutorialKitura Todolist tutorial
Kitura Todolist tutorial
 
Peaberry - Blending Services And Extensions
Peaberry - Blending Services And ExtensionsPeaberry - Blending Services And Extensions
Peaberry - Blending Services And Extensions
 
Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-cas
 
Connecting to a Webservice.pdf
Connecting to a Webservice.pdfConnecting to a Webservice.pdf
Connecting to a Webservice.pdf
 
iOS Reactive Cocoa Pipeline
iOS Reactive Cocoa PipelineiOS Reactive Cocoa Pipeline
iOS Reactive Cocoa Pipeline
 
Network
NetworkNetwork
Network
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
Implement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyoImplement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyo
 

Mehr von Heiko Seeberger

JavaSPEKTRUM - Scala 1
JavaSPEKTRUM - Scala 1JavaSPEKTRUM - Scala 1
JavaSPEKTRUM - Scala 1
Heiko Seeberger
 
JAX 08 - Agile RCP
JAX 08 - Agile RCPJAX 08 - Agile RCP
JAX 08 - Agile RCP
Heiko Seeberger
 
Eclipse Magazin 12 - Design by Contract
Eclipse Magazin 12 - Design by ContractEclipse Magazin 12 - Design by Contract
Eclipse Magazin 12 - Design by Contract
Heiko Seeberger
 
Eclipse Magazin 16 - Die Stärke der Drei
Eclipse Magazin 16 - Die Stärke der DreiEclipse Magazin 16 - Die Stärke der Drei
Eclipse Magazin 16 - Die Stärke der Drei
Heiko Seeberger
 
Eclipse Magazin15 - Performance Logging
Eclipse Magazin15 - Performance LoggingEclipse Magazin15 - Performance Logging
Eclipse Magazin15 - Performance Logging
Heiko Seeberger
 
Eclipse Magazin 14 - Getting hooked on Equinox
Eclipse Magazin 14 - Getting hooked on EquinoxEclipse Magazin 14 - Getting hooked on Equinox
Eclipse Magazin 14 - Getting hooked on Equinox
Heiko Seeberger
 
Eclipse Magazin 12 - Security does matter
Eclipse Magazin 12 - Security does matterEclipse Magazin 12 - Security does matter
Eclipse Magazin 12 - Security does matter
Heiko Seeberger
 
EclipseCon 08 - Agile RCP
EclipseCon 08 - Agile RCPEclipseCon 08 - Agile RCP
EclipseCon 08 - Agile RCP
Heiko Seeberger
 
W-JAX 07 - AOP im Einsatz mit OSGi und RCP
W-JAX 07 - AOP im Einsatz mit OSGi und RCPW-JAX 07 - AOP im Einsatz mit OSGi und RCP
W-JAX 07 - AOP im Einsatz mit OSGi und RCP
Heiko Seeberger
 
JAX 08 - Experiences using Equinox Aspects in a real-world Project
JAX 08 - Experiences using Equinox Aspects in a real-world ProjectJAX 08 - Experiences using Equinox Aspects in a real-world Project
JAX 08 - Experiences using Equinox Aspects in a real-world Project
Heiko Seeberger
 
Eclipse Summit Europe 08 - Aspect Weaving for OSGi
Eclipse Summit Europe 08 - Aspect Weaving for OSGiEclipse Summit Europe 08 - Aspect Weaving for OSGi
Eclipse Summit Europe 08 - Aspect Weaving for OSGi
Heiko Seeberger
 
W-JAX 08 - Aspect Weaving for OSGii
W-JAX 08 - Aspect Weaving for OSGiiW-JAX 08 - Aspect Weaving for OSGii
W-JAX 08 - Aspect Weaving for OSGii
Heiko Seeberger
 

Mehr von Heiko Seeberger (20)

JavaSPEKTRUM - Scala 1
JavaSPEKTRUM - Scala 1JavaSPEKTRUM - Scala 1
JavaSPEKTRUM - Scala 1
 
RheinJUG 2010 - Sprechen Sie Scala?
RheinJUG 2010 - Sprechen Sie Scala?RheinJUG 2010 - Sprechen Sie Scala?
RheinJUG 2010 - Sprechen Sie Scala?
 
Objektforum 2010 - Sprechen Sie Scala?
Objektforum 2010 - Sprechen Sie Scala?Objektforum 2010 - Sprechen Sie Scala?
Objektforum 2010 - Sprechen Sie Scala?
 
W-JAX 09 - Lift
W-JAX 09 - LiftW-JAX 09 - Lift
W-JAX 09 - Lift
 
JM 08/09 - Beginning Scala Review
JM 08/09 - Beginning Scala ReviewJM 08/09 - Beginning Scala Review
JM 08/09 - Beginning Scala Review
 
JAX 09 - OSGi on Scala
JAX 09 - OSGi on ScalaJAX 09 - OSGi on Scala
JAX 09 - OSGi on Scala
 
JAX 09 - OSGi Service Components Models
JAX 09 - OSGi Service Components ModelsJAX 09 - OSGi Service Components Models
JAX 09 - OSGi Service Components Models
 
JAX 08 - Agile RCP
JAX 08 - Agile RCPJAX 08 - Agile RCP
JAX 08 - Agile RCP
 
Eclipse Magazin 12 - Design by Contract
Eclipse Magazin 12 - Design by ContractEclipse Magazin 12 - Design by Contract
Eclipse Magazin 12 - Design by Contract
 
JUGM 07 - AspectJ
JUGM 07 - AspectJJUGM 07 - AspectJ
JUGM 07 - AspectJ
 
Eclipse Magazin 16 - Die Stärke der Drei
Eclipse Magazin 16 - Die Stärke der DreiEclipse Magazin 16 - Die Stärke der Drei
Eclipse Magazin 16 - Die Stärke der Drei
 
Eclipse Magazin15 - Performance Logging
Eclipse Magazin15 - Performance LoggingEclipse Magazin15 - Performance Logging
Eclipse Magazin15 - Performance Logging
 
Eclipse Magazin 14 - Getting hooked on Equinox
Eclipse Magazin 14 - Getting hooked on EquinoxEclipse Magazin 14 - Getting hooked on Equinox
Eclipse Magazin 14 - Getting hooked on Equinox
 
Eclipse Magazin 12 - Security does matter
Eclipse Magazin 12 - Security does matterEclipse Magazin 12 - Security does matter
Eclipse Magazin 12 - Security does matter
 
EclipseCon 08 - Agile RCP
EclipseCon 08 - Agile RCPEclipseCon 08 - Agile RCP
EclipseCon 08 - Agile RCP
 
W-JAX 07 - AOP im Einsatz mit OSGi und RCP
W-JAX 07 - AOP im Einsatz mit OSGi und RCPW-JAX 07 - AOP im Einsatz mit OSGi und RCP
W-JAX 07 - AOP im Einsatz mit OSGi und RCP
 
W-JAX 08 - Declarative Services versus Spring Dynamic Modules
W-JAX 08 - Declarative Services versus Spring Dynamic ModulesW-JAX 08 - Declarative Services versus Spring Dynamic Modules
W-JAX 08 - Declarative Services versus Spring Dynamic Modules
 
JAX 08 - Experiences using Equinox Aspects in a real-world Project
JAX 08 - Experiences using Equinox Aspects in a real-world ProjectJAX 08 - Experiences using Equinox Aspects in a real-world Project
JAX 08 - Experiences using Equinox Aspects in a real-world Project
 
Eclipse Summit Europe 08 - Aspect Weaving for OSGi
Eclipse Summit Europe 08 - Aspect Weaving for OSGiEclipse Summit Europe 08 - Aspect Weaving for OSGi
Eclipse Summit Europe 08 - Aspect Weaving for OSGi
 
W-JAX 08 - Aspect Weaving for OSGii
W-JAX 08 - Aspect Weaving for OSGiiW-JAX 08 - Aspect Weaving for OSGii
W-JAX 08 - Aspect Weaving for OSGii
 

KĂźrzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
Christopher Logan Kennedy
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

KĂźrzlich hochgeladen (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

OSGi DevCon 09 - OSGi on Scala

  • 1. OSGi on Scala BindForge & ScalaModules: Scala DSLs to ease OSGi development Roman Roelofsen (ProSyst), Heiko Seeberger (WeigleWilczek)
  • 2. Why? • OSGi is a great module system • Scala is a great language • Compiles to Java bytecode • Object-functional programming style • Why wait for Java 7 (or 8)? Use Scala now! • Let’s combine them to ease OSGi development
  • 3. What? • BindForge - Module Framework • ScalaModules - DSL for OSGi development in Scala
  • 4. BindForge • Module Framework • Dependency Injection, OSGi service abstraction, etc. • Useful for Java and Scala development • Conguration is written in Scala • Based on • Scala • Guice • Peaberry
  • 5. Example Scenario CustomerRepository CustomerService CustomerRep.Impl CustomerServiceImpl Customer Bundle LogService OSGi Log Service Bundle
  • 6. Example Scenario // repository interface CustomerRepository class CustomerRepositoryImpl implements CustomerRepository // service interface CustomerService class CustomerServiceImpl implements CustomerService { public void setCustomerRepository(CustomerRepository cr) { ... } public void setLogService(LogService ls) { ... } }
  • 7. Bundle Conguration • MANIFEST.MF BindForge-Config: com.acme.app.MyConfig • /OSGI-INF/bindforge/cong.scala package com.acme.app class MyConfig extends org.bindforge.Config { ... }
  • 8. Binding Interfaces to Implementations CustomerRepository CustomerService CustomerRep.Impl CustomerServiceImpl Customer Bundle
  • 9. Binding Interfaces to Implementations package com.acme.app class MyConfig extends org.bindforge.Config { bind [CustomerRepository, impl.CustomerRepositoryImpl] bind [CustomerService, impl.CustomerServiceImpl] }
  • 10. Inject Bindings CustomerRepository CustomerService CustomerRep.Impl CustomerServiceImpl Customer Bundle
  • 11. Inject Bindings (by type) bind [CustomerRepository, impl.CustomerRepositoryImpl] bind [CustomerService, impl.CustomerServiceImpl] spec { property(“customerRepository”) }
  • 12. Inject Bindings (by name) “customerRepository” :: bind [impl.CustomerRepositoryImpl] bind [CustomerService, impl.CustomerServiceImpl] spec { property(“customerRepository”) = ref(“customerRepository”) }
  • 13. Export Customer Service CustomerRepository CustomerService CustomerRep.Impl CustomerServiceImpl Customer Bundle
  • 14. Export Customer Service bind [CustomerRepository, impl.CustomerRepositoryImpl] bind [CustomerService, impl.CustomerServiceImpl] spec { exportService property(“customerRepository”) }
  • 15. Export Customer Service (with Properties) bind [CustomerRepository, impl.CustomerRepositoryImpl] bind [CustomerService, impl.CustomerServiceImpl] spec { exportService(“vendor” -> “acme”, “security” -> “none”) property(“customerRepository”) }
  • 16. Import LogService CustomerRepository CustomerService CustomerRep.Impl CustomerServiceImpl Customer Bundle LogService OSGi Log Service Bundle
  • 17. Import LogService bind [LogService] importService bind [CustomerRepository, impl.CustomerRepositoryImpl] bind [CustomerService, impl.CustomerServiceImpl] spec { exportService property(“customerRepository”) property(“logService”) }
  • 18. Full Conguration package com.acme.app class MyConfig extends org.bindforge.Config { bind [LogService] importService bind [CustomerRepository, impl.CustomerRepositoryImpl] bind [CustomerService, impl.CustomerServiceImpl] spec { exportService property(“customerRepository”) property(“logService”) } }
  • 19. What? • BindForge - Module Framework • ScalaModules - DSL for OSGi development in Scala
  • 20. ScalaModules • For Scala developers (and Java geeks) • General OSGi concepts, e.g. service handling • Compendium services, e.g. Conguration Admin
  • 21. Register a Service Greeting hello = new Greeting() { afe es public String welcome() { yp return quot;Hello!quot;; tt } no public String goodbye() { return quot;See you!quot;; } }; context.registerService(Greeting.class.getName(), hello, null);
  • 22. Register a Service context registerAs classOf[Greeting] theService new Greeting { override def welcome = quot;Hello!quot; override def goodbye = quot;See you!quot;; }
  • 23. Register a Service with Properties Greeting welcome = new Greeting() { se o public String welcome() { rb ve return quot;Welcome!quot;; } public String goodbye() { return quot;Good bye!quot;; } }; Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(quot;namequot;, quot;welcomequot;); context.registerService(Greeting.class.getName(), welcome, properties);
  • 24. Register a Service with Properties context registerAs classOf[Greeting] withProperties Map(quot;namequot; -> quot;welcomequot;) theService new Greeting { override def welcome = quot;Welcome!quot; override def goodbye = quot;Goodbye!quot; }
  • 25. Consume a single Service ServiceReference reference = context.getServiceReference(Greeting.class.getName()); if (reference != null) { try { Object service = context.getService(reference); Greeting greeting = (Greeting) service; if (greeting != null) { System.out.println(greeting.welcome()); } else { noGreetingService(); } } finally { context.ungetService(reference); inv } olv } else { ed noGreetingService(); }
  • 26. Consume a single Service context getOne classOf[Greeting] andApply { _.welcome } match { case None => noGreetingService() case Some(welcome) => println(welcome) }
  • 27. Consume many Services with their Properties try { ServiceReference[] refs = context.getServiceReferences( Greeting.class.getName(), null); if (refs != null) { for (ServiceReference ref : refs) { Object service = context.getService(ref); Greeting greeting = (Greeting) service; if (greeting != null) { Object name = (ref.getProperty(quot;namequot;) != null) ? ref.getProperty(quot;namequot;) : quot;UNKNOWNquot;; String message = name + quot; says: quot; + greeting.welcome(); System.out.println(message); } } ver } else { y inv noGreetingService(); olv } ed } catch (InvalidSyntaxException e) { // Do something meaningful ... }
  • 28. Consume many Services with their Properties context getMany classOf[Greeting] andApply { (greeting, properties) => { val name = properties.get(quot;namequot;) match { case None => quot;UNKNOWNquot; case Some(s) => s } name + quot; sais: quot; + greeting.welcome } } match { case None => noGreetingService() case Some(welcomes) => welcomes.foreach { println } }
  • 29. Consume Services using a Filter try { ServiceReference[] refs = context.getServiceReferences( Greeting.class.getName(), quot;(name=*)quot;); if (refs != null) { for (ServiceReference ref : refs) { Object service = context.getService(ref); Greeting greeting = (Greeting) service; if (greeting != null) { System.out.println(greeting.welcome()); ver } y } inv } else { olv ed noGreetingService(); aga } in } catch (InvalidSyntaxException e) { // Do something meaningful ... }
  • 30. Consume Services using a Filter context getMany classOf[Greeting] withFilter quot;(name=*)quot; andApply { _.welcome } match { case None => noGreetingService() case Some(welcomes) => welcomes.foreach { println } }
  • 31. Track Services ServiceTracker tracker = new ServiceTracker(context, Greeting.class.getName(), null) { @Override public Object addingService(ServiceReference reference) { Object service = super.addingService(reference); Greeting greeting = (Greeting)service; System.out.println(quot;Adding Greeting: quot; + greeting.welcome()); return service; } @Override public void removedService(ServiceReference reference, Object service) { Greeting greeting = (Greeting)service; System.out.println(quot;Removed Greeting: quot; + greeting.welcome()); and super.removedService(reference, service); aga } in }; tracker.open();
  • 32. Track Services greetingTrack = context track classOf[Greeting] on { case Adding(greeting, _) => println(quot;Adding Greeting: quot; + greeting.welcome) case Modified(greeting, _) => case Removed(greeting, _) => println(quot;Removed Greeting: quot; + greeting.goodbye) }
  • 33. Service Dependencies context registerAs classOf[Command] dependOn classOf[Greeting] theService { greeting => new Command { ... } }
  • 34. And now? • Forge ahead at www.bindforge.org • And get fluent at www.scalamodules.org • Please give feedback: • What do you like? • What do you not like? • What feature would you like to see implemented?