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 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?

Weitere ähnliche Inhalte

Was ist angesagt?

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
 
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 usefilterKaty Slemon
 
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 JavaVincent 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 nodejsKaty 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 modularidadDavid 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 EditIlia 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 AsynchrhonouslyDavid Gómez García
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web ModuleMorgan Cheng
 
Scripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptScripting GeoServer with GeoScript
Scripting GeoServer with GeoScriptJustin Deoliveira
 
"Kotlin и rx в android" Дмитрий Воронин (Avito)
"Kotlin и rx в android" Дмитрий Воронин  (Avito)"Kotlin и rx в android" Дмитрий Воронин  (Avito)
"Kotlin и rx в android" Дмитрий Воронин (Avito)AvitoTech
 
​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир Миронов​"Delegates, Delegates everywhere" Владимир Миронов
​"Delegates, Delegates everywhere" Владимир МироновAvitoTech
 
GeoScript - Spatial Capabilities for Scripting Languages
GeoScript - Spatial Capabilities for Scripting LanguagesGeoScript - Spatial Capabilities for Scripting Languages
GeoScript - Spatial Capabilities for Scripting LanguagesJustin 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 196Mahmoud Samir Fayed
 

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

Ähnlich wie JAX 09 - OSGi on Scala

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 2018Loiane Groner
 
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 frameworkBen Lin
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionDzmitry Ivashutsin
 
Grails transactions
Grails   transactionsGrails   transactions
Grails transactionsHusain 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 CloudNikolas Burk
 
Peaberry - Blending Services And Extensions
Peaberry - Blending Services And ExtensionsPeaberry - Blending Services And Extensions
Peaberry - Blending Services And ExtensionsStuart 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 easeKAI CHU CHUNG
 
Jasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casJasigsakai12 columbia-customizes-cas
Jasigsakai12 columbia-customizes-casellentuck
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
Connecting to a Webservice.pdf
Connecting to a Webservice.pdfConnecting to a Webservice.pdf
Connecting to a Webservice.pdfShaiAlmog1
 
iOS Reactive Cocoa Pipeline
iOS Reactive Cocoa PipelineiOS Reactive Cocoa Pipeline
iOS Reactive Cocoa PipelineIvan Trifonov
 
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
 

Ähnlich wie 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
 

Mehr von Heiko Seeberger

Scaladays 2011 - The Ease of Scalaz
Scaladays 2011 - The Ease of ScalazScaladays 2011 - The Ease of Scalaz
Scaladays 2011 - The Ease of ScalazHeiko 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
 
JM 08/09 - Beginning Scala Review
JM 08/09 - Beginning Scala ReviewJM 08/09 - Beginning Scala Review
JM 08/09 - Beginning Scala ReviewHeiko 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 ScalaHeiko Seeberger
 
JAX 09 - OSGi Service Components Models
JAX 09 - OSGi Service Components ModelsJAX 09 - OSGi Service Components Models
JAX 09 - OSGi Service Components ModelsHeiko 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 RCPHeiko Seeberger
 

Mehr von 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
 

Kürzlich hochgeladen

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Kürzlich hochgeladen (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

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?