SlideShare a Scribd company logo
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 Configuration

• 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)


val customerRepo = bind [impl.CustomerRepositoryImpl]

bind [CustomerService, impl.CustomerServiceImpl] spec {
    property(“customerRepository”) = customerRepo
}
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 Configuration
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?

More Related Content

What's hot

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 ...
Dailymotion
 
Tdd.eng.ver
Tdd.eng.verTdd.eng.ver
Tdd.eng.ver
혜승 이
 
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
Katy Slemon
 
Pointers
PointersPointers
Pointers
Hitesh Wagle
 
P1
P1P1
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
Vincent Pradeilles
 
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
Katy Slemon
 
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
David Gómez García
 
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
Ilia Idakiev
 
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
David Gómez García
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
Morgan Cheng
 
AngularJS
AngularJSAngularJS
AngularJS
LearningTech
 
Scripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScript
Justin Deoliveira
 
The State of GeoServer
The State of GeoServerThe State of GeoServer
The State of GeoServer
Justin Deoliveira
 
"Kotlin и rx в android" Дмитрий Воронин (Avito)
"Kotlin и rx в android" Дмитрий Воронин  (Avito)"Kotlin и rx в android" Дмитрий Воронин  (Avito)
"Kotlin и rx в android" Дмитрий Воронин (Avito)
AvitoTech
 
Grails custom tag lib
Grails custom tag libGrails custom tag lib
Grails custom tag lib
NexThoughts Technologies
 
​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир Миронов​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир Миронов
AvitoTech
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
Christoffer Noring
 
GeoScript - Spatial Capabilities for Scripting Languages
GeoScript - Spatial Capabilities for Scripting LanguagesGeoScript - Spatial Capabilities for Scripting Languages
GeoScript - Spatial Capabilities for Scripting Languages
Justin Deoliveira
 
The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196
Mahmoud Samir Fayed
 

What's hot (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
 
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
 
Pointers
PointersPointers
Pointers
 
P1
P1P1
P1
 
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
 
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
 
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
 
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
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
 
AngularJS
AngularJSAngularJS
AngularJS
 
Scripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScript
 
The State of GeoServer
The State of GeoServerThe State of GeoServer
The State of GeoServer
 
"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
 
​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир Миронов​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир Миронов
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
GeoScript - Spatial Capabilities for Scripting Languages
GeoScript - Spatial Capabilities for Scripting LanguagesGeoScript - Spatial Capabilities for Scripting Languages
GeoScript - Spatial Capabilities for Scripting Languages
 
The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196
 

Similar to JAX 09 - OSGi on Scala

Scala modules
Scala modulesScala modules
Scala modules
Skills Matter
 
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
Loiane Groner
 
W-JAX 09 - ScalaModules
W-JAX 09 - ScalaModulesW-JAX 09 - ScalaModules
W-JAX 09 - ScalaModules
Heiko Seeberger
 
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
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
Adam Stephensen
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
Dzmitry Ivashutsin
 
Grails transactions
Grails   transactionsGrails   transactions
Grails transactions
Husain Dalal
 
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
Nikolas Burk
 
Kitura Todolist tutorial
Kitura Todolist tutorialKitura Todolist tutorial
Kitura Todolist tutorial
Robert F. Dickerson
 
Peaberry - Blending Services And Extensions
Peaberry - Blending Services And ExtensionsPeaberry - Blending Services And Extensions
Peaberry - Blending Services And Extensions
Stuart McCulloch
 
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
KAI CHU CHUNG
 
Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-cas
ellentuck
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
Stefano Fago
 
Connecting to a Webservice.pdf
Connecting to a Webservice.pdfConnecting to a Webservice.pdf
Connecting to a Webservice.pdf
ShaiAlmog1
 
Corba
CorbaCorba
Corba
_ammar_
 
iOS Reactive Cocoa Pipeline
iOS Reactive Cocoa PipelineiOS Reactive Cocoa Pipeline
iOS Reactive Cocoa Pipeline
Ivan Trifonov
 
Network
NetworkNetwork
Network
phanleson
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
Paco de la Cruz
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Sapphire Gimlets
Sapphire GimletsSapphire Gimlets
Sapphire Gimlets
Robert Cooper
 

Similar to JAX 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
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
 
Grails transactions
Grails   transactionsGrails   transactions
Grails transactions
 
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
 
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
 
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
 
Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-cas
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Connecting to a Webservice.pdf
Connecting to a Webservice.pdfConnecting to a Webservice.pdf
Connecting to a Webservice.pdf
 
Corba
CorbaCorba
Corba
 
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++
 
Sapphire Gimlets
Sapphire GimletsSapphire Gimlets
Sapphire Gimlets
 

More from Heiko Seeberger

Scaladays 2011 - The Ease of Scalaz
Scaladays 2011 - The Ease of ScalazScaladays 2011 - The Ease of Scalaz
Scaladays 2011 - The Ease of Scalaz
Heiko Seeberger
 
RheinJUG 2010 - Sprechen Sie Scala?
RheinJUG 2010 - Sprechen Sie Scala?RheinJUG 2010 - Sprechen Sie Scala?
RheinJUG 2010 - Sprechen Sie Scala?
Heiko Seeberger
 
Objektforum 2010 - Sprechen Sie Scala?
Objektforum 2010 - Sprechen Sie Scala?Objektforum 2010 - Sprechen Sie Scala?
Objektforum 2010 - Sprechen Sie Scala?
Heiko Seeberger
 
W-JAX 09 - Lift
W-JAX 09 - LiftW-JAX 09 - Lift
W-JAX 09 - Lift
Heiko Seeberger
 
JM 08/09 - Beginning Scala Review
JM 08/09 - Beginning Scala ReviewJM 08/09 - Beginning Scala Review
JM 08/09 - Beginning Scala Review
Heiko Seeberger
 
JM 08/09 - ScalaModules
JM 08/09 - ScalaModulesJM 08/09 - ScalaModules
JM 08/09 - ScalaModules
Heiko Seeberger
 
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
Heiko Seeberger
 
JAX 09 - OSGi Service Components Models
JAX 09 - OSGi Service Components ModelsJAX 09 - OSGi Service Components Models
JAX 09 - OSGi Service Components Models
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 ContractHeiko 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 DreiHeiko Seeberger
 
Eclipse Magazin15 - Performance Logging
Eclipse Magazin15 - Performance LoggingEclipse Magazin15 - Performance Logging
Eclipse Magazin15 - Performance LoggingHeiko 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 EquinoxHeiko Seeberger
 
Eclipse Magazin 12 - Security does matter
Eclipse Magazin 12 - Security does matterEclipse Magazin 12 - Security does matter
Eclipse Magazin 12 - Security does matterHeiko Seeberger
 
EclipseCon 08 - Agile RCP
EclipseCon 08 - Agile RCPEclipseCon 08 - Agile RCP
EclipseCon 08 - Agile RCP
Heiko Seeberger
 

More from Heiko Seeberger (20)

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
 
JavaSPEKTRUM - Scala 3
JavaSPEKTRUM - Scala 3JavaSPEKTRUM - Scala 3
JavaSPEKTRUM - Scala 3
 
JavaSPEKTRUM - Scala 2
JavaSPEKTRUM - Scala 2JavaSPEKTRUM - Scala 2
JavaSPEKTRUM - Scala 2
 
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
 
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
 
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
 

Recently uploaded

AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 

Recently uploaded (20)

AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 

JAX 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 • Configuration 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 Configuration • MANIFEST.MF BindForge-Config: com.acme.app.MyConfig • /OSGI-INF/bindforge/config.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) val customerRepo = bind [impl.CustomerRepositoryImpl] bind [CustomerService, impl.CustomerServiceImpl] spec { property(“customerRepository”) = customerRepo }
  • 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 Configuration 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. Configuration 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?