Skip to content

Instantly share code, notes, and snippets.

@dileeph
Last active June 22, 2017 23:30
Show Gist options
  • Save dileeph/ac95bde2f095627028277bdb504c81ad to your computer and use it in GitHub Desktop.
Save dileeph/ac95bde2f095627028277bdb504c81ad to your computer and use it in GitHub Desktop.
services in osgi using bundle activator
Bundle-Name: 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
Export-Package: com.x.policy.service
========================================
package com.x.policy.service;
public interface PolicyService {
public boolean verifyPolicy(String policyNumber);
}
======================================================
package com.x.policy.service.impl;
import java.util.Arrays;
import com.x.policy.service.PolicyService;
public class PolicyServiceImpl implements PolicyService {
public String[] policies = {"1234", "1212", "3434"};
public boolean verifyPolicy(String policyNumber) {
return Arrays.asList(policies).contains(policyNumber);
}
}
============================================================
package com.x.policy;
import java.util.Dictionary;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import com.x.policy.service.PolicyService;
import com.x.policy.service.impl.PolicyServiceImpl;
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
System.out.println("Policy service A start");
Dictionary<String, String> props = new Hashtable<String, String>();
props.put("Insurer", "A");
context.registerService(PolicyService.class.getName(), new PolicyServiceImpl(), props);
}
public void stop(BundleContext context) throws Exception {
System.out.println("Policy service A stop");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment