Open main menu

CDOT Wiki β

Changes

OSGi Concepts Services

1,047 bytes added, 15:43, 21 January 2011
no edit summary
</service>
</component>
</source>
 
Thus, the bundle that provides the service could register its services to an OSGi registry, while the bundle that needs the service could query the registry. The model is Service Oriented Architecture (SOA).
[[Image:filename|thumb|widthpx| ]]
 
The bundle consumer must
<source lang="java">
 
package cs.ecl.osgi.simple.declarativeservice.consumer;
 
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
 
import cs.ecl.osgi.simple.declarativeservice.say.Sayable;
 
public class SaySingleConsumer implements CommandProvider {
 
private Sayable s;
 
public synchronized void bindSayable(Sayable s) {
this.s = s;
}
 
public synchronized void unbindSayable(Sayable s) {
this.s = null;
}
 
public synchronized void _run(CommandInterpreter ci) {
if (s != null) {
System.out.println(s.say());
} else {
ci.println("Error, No Service of type Sayable available");
}
}
 
@Override
public String getHelp() {
return "\n\t run - EXECUTE the Sayable service";
}
}
</source>