Skip to content

Instantly share code, notes, and snippets.

View dileeph's full-sized avatar

Dileep Hareendran dileeph

View GitHub Profile
public void start(BundleContext context) throws Exception {
System.out.println("start simple policy client");
ServiceReference[] serviceReferences = context.getServiceReferences(PolicyService.class.getName(), "(Insurer=*)");
if(serviceReferences != null && serviceReferences.length > 0){
for(int i =0; i < serviceReferences.length; i++){
PolicyService policyService = (PolicyService)context.getService(serviceReferences[i]);
System.out.println("Trying to find the services");
Bundle-Name: policy.service.api
Bundle-Description: policy.service.api
Bundle-Version: 1.0.0
Bundle-Activator: com.x.policy.Activator
Import-Package: org.osgi.framework
Export-Package: com.x.policy.service.api
Bundle-Name: policy.service.client
Bundle-SymbolicName: policy.service.client
Bundle-Description: Simple policy.service client
Bundle-Version: 1.0
Bundle-Activator: com.x.policy.Activator
Import-Package: org.osgi.framework, com.x.policy.service.api;version="[1.0,2)"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.x</groupId>
<artifactId>policy.service.api</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>policy.service.api</name>
<groupId>com.x</groupId>
<artifactId>policy.client</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
==================================
<dependency>
<groupId>com.x</groupId>
<artifactId>policy.service.api</artifactId>
Bundle-Name: Policy.Service.A
Bundle-SymbolicName: Policy.Service.A
Bundle-Description: policy service for Insurer A
Bundle-Version: 1.0.0
Bundle-Activator: com.x.policy.Activator
Import-Package: org.osgi.framework, com.x.policy.service.api;version="1.0.0"
<!-- at the top , note packaging is changed from jar to bundle-->
<groupId>com.x</groupId>
<artifactId>policy.client</artifactId>
<version>3.0.0</version>
<packaging>bundle</packaging>
===================================
<!-- inside dependencies -->
<!-- at top, note packaging type changed -->
<groupId>com.x</groupId>
<artifactId>policy.service.api</artifactId>
<version>3.0.0</version>
<packaging>bundle</packaging>
==================================
<!-- inside build tag, replace maven jar plugin with this -->
<plugin>
<!-- at top -->
<groupId>com.x</groupId>
<artifactId>policy.service.a</artifactId>
<version>3.0.0</version>
<packaging>bundle</packaging>
<!-- in dependencies -->
<dependencies>
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="policy.service.api" immediate="false">
<service>
<provide interface="com.x.policy.service.api.PolicyService"/>
</service>
</scr:component>