<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>7.0.0</version>
</dependency>
package com.example.clusterinfo;
public interface ClusterInfo {
String getClusterId();
String getLeaderName();
void joinCluster(String nodeId, String nodeName);
void leaveCluster(String nodeId);
void updateLeader(String newLeaderName);
}
package com.example.clusterinfo.impl;
import com.example.clusterinfo.ClusterInfo;
public class ClusterInfoImpl implements ClusterInfo {
private String clusterId;
private String leaderName;
public String getClusterId() {
return clusterId;
}
public String getLeaderName() {
return leaderName;
}
public void joinCluster(String nodeId, String nodeName) {
}
public void leaveCluster(String nodeId) {
}
public void updateLeader(String newLeaderName) {
}
}
package com.example.clusterinfo.impl;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import com.example.clusterinfo.ClusterInfo;
@Component(service = ClusterInfo.class)
public class ClusterInfoImpl implements ClusterInfo {
}
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.4.0" name="com.example.clusterinfo.impl.ClusterInfoImpl">
<implementation class="com.example.clusterinfo.impl.ClusterInfoImpl"/>
<service>
<provide interface="com.example.clusterinfo.ClusterInfo"/>
</service>
</scr:component>
Require-Capability: osgi.service;filter:="(&(objectClass=com.example.clusterinfo.ClusterInfo)(clusterId=myCluster))"