Skip to content

Latest commit

 

History

History

declarative-services-demo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Declarative Services demo

This sample project shows how to configure declarative services components using the different methods available:

To apply the Declarative Services Plugin, add this line to your build file:

apply plugin: 'com.athaydes.osgi-ds'

Config embedded in the Gradle build

Example:

build.gradle

declarativeServices {
    declarations {
        component( name: 'classTrieMessageBus' ) {
            implementation( 'class': 'com.athaydes.osgi.ds.ClassTrieMessageBus' )
            service {
                provide( 'interface': 'com.athaydes.osgi.messaging.MessageBus' )
            }
        }
    }
    show()
}

Config in a separate Groovy script

Example:

build.gradle

declarativeServices {
    declarations = project.file( 'src/main/osgi/declarativeServices.groovy' )
}

declarativeServices.groovy

component( name: 'consumer' ) {
    implementation( 'class': 'com.athaydes.osgi.consumer.MessageConsumer' )
    reference( name: 'message-bus',
            'interface': 'com.athaydes.osgi.messaging.MessageBus',
            'cardinality': '1..1',
            'policy': 'static',
            'bind': 'addMessageBus',
            'unbind': 'removeMessageBus' )
}

Config in a standard Declarative Services XML file

Example:

build.gradle

declarativeServices {
    declarations = project.file( 'src/main/osgi/components.xml' )
}

components.xml

<?xml version="1.0" encoding="UTF-8"?>

<component name='producer' immediate="true">
    <implementation class='com.athaydes.osgi.producer.MessageProducer'/>
    <reference name="message-bus" interface="com.athaydes.osgi.messaging.MessageBus"
               cardinality="0..1" policy="dynamic"
               bind="setMessageBus" unbind="removeMessageBus"/>
</component>