Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Zoodiscovery"
Line 9: | Line 9: | ||
==The concept in some words== | ==The concept in some words== | ||
− | ZooDiscovery implements both ECF discovery interfaces: IDiscoveryAdvertiser and IDiscoveryLocator. That is, ZooDiscovery can publish our services and gets us noticed about discovered services. Perfect! But how? | + | ZooDiscovery implements both ECF discovery interfaces: IDiscoveryAdvertiser and IDiscoveryLocator. That is, ZooDiscovery can publish our services and gets us noticed about |
+ | discovered services. Perfect! But how? | ||
A ZooDiscovery instance running at your machine does its job by exchanging data with other ZooDiscovery instance(s) running elsewhere. So each running ZooDiscovety service must know where that other "elsewhere" exactly is. This is why we should first make our ZooDiscovery happy, giving it an IP address to play with.<br> | A ZooDiscovery instance running at your machine does its job by exchanging data with other ZooDiscovery instance(s) running elsewhere. So each running ZooDiscovety service must know where that other "elsewhere" exactly is. This is why we should first make our ZooDiscovery happy, giving it an IP address to play with.<br> | ||
To keep it smooth, let's take it step by step following these cases: | To keep it smooth, let's take it step by step following these cases: | ||
Line 15: | Line 16: | ||
==Learn by asking== | ==Learn by asking== | ||
===How to tell ZooDiscovery the target I want to connect to?=== | ===How to tell ZooDiscovery the target I want to connect to?=== | ||
− | We use the property "discovery.flavor.standalone" ( | + | /*We use the property "discovery.flavor.standalone" to specify we're going to run as standalone(more about this later) |
+ | and its value is the remote location's IP address we intend to connect to . | ||
+ | Please replace with usable IP address(es) when applicable. A comma separated list of one or more IP address is valid as well. | ||
+ | Something like: "discovery.flavor.standalone=192.1.32.10,192.1.32.11" means our ZooDiscovery instance will connect to both address 192.1.32.10 and 192.1.32.11 | ||
+ | where other ZooDiscovery services are running. | ||
+ | */ | ||
ID target = container.getConnectNamespace().createInstance( | ID target = container.getConnectNamespace().createInstance( | ||
new String[] { "discovery.flavor.standalone=192.1.32.10" }); | new String[] { "discovery.flavor.standalone=192.1.32.10" }); | ||
Line 25: | Line 31: | ||
} catch(ContainerCreateException e1){ // TODO | } catch(ContainerCreateException e1){ // TODO | ||
} | } | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
ID serverId = container.getConnectNamespace().createInstance( | ID serverId = container.getConnectNamespace().createInstance( | ||
new String[] { "discovery.flavor.standalone=192.1.32.10" }); | new String[] { "discovery.flavor.standalone=192.1.32.10" }); | ||
Line 48: | Line 50: | ||
//then we enjoy calling IDiscoveryLocator contract methods | //then we enjoy calling IDiscoveryLocator contract methods | ||
− | ===I want ZooDiscovery publishing my OSGi services | + | ===I want ZooDiscovery publishing my OSGi services automatically=== |
− | OSGi services registered with property "osgi.remote.interface=*" are candidate for auto-publication. By default this option is disabled. | + | OSGi services registered with property '''"osgi.remote.interface=*"''' are candidate for auto-publication. By default this option is disabled. |
To make ZooDiscovery autopublish all services having the above property once connected, you basically use the same way as above (How to get ZooDiscovery service?)<br> | To make ZooDiscovery autopublish all services having the above property once connected, you basically use the same way as above (How to get ZooDiscovery service?)<br> | ||
with the property "discovery.publish.auto=true" added when creating the target id. | with the property "discovery.publish.auto=true" added when creating the target id. |
Revision as of 08:10, 23 March 2010
Contents
- 1 What is ZooDiscovery?
- 2 Download
- 3 The concept in some words
- 4 Learn by asking
- 4.1 How to tell ZooDiscovery the target I want to connect to?
- 4.2 How to get ZooDiscovery service?
- 4.3 I want ZooDiscovery publishing my OSGi services automatically
- 4.4 How to build a ServiceInfo object and publish it
- 4.5 I want to publish an OSGi service directly via its ServiceReference
- 4.6 I want to get notified about discovered services
- 5 Advanced configuration
- 6 Recipes
What is ZooDiscovery?
ZooDiscovery is a discovery mechanism that runs as an OSGi service. It leverage Apache ZooKeeper robustness and implements Eclipse ECF Discovery API.(Hence the name!). ZooDiscovery is flexible and easy to configure.
Download
being edited...
The concept in some words
ZooDiscovery implements both ECF discovery interfaces: IDiscoveryAdvertiser and IDiscoveryLocator. That is, ZooDiscovery can publish our services and gets us noticed about
discovered services. Perfect! But how?
A ZooDiscovery instance running at your machine does its job by exchanging data with other ZooDiscovery instance(s) running elsewhere. So each running ZooDiscovety service must know where that other "elsewhere" exactly is. This is why we should first make our ZooDiscovery happy, giving it an IP address to play with.
To keep it smooth, let's take it step by step following these cases:
Learn by asking
How to tell ZooDiscovery the target I want to connect to?
/*We use the property "discovery.flavor.standalone" to specify we're going to run as standalone(more about this later) and its value is the remote location's IP address we intend to connect to . Please replace with usable IP address(es) when applicable. A comma separated list of one or more IP address is valid as well. Something like: "discovery.flavor.standalone=192.1.32.10,192.1.32.11" means our ZooDiscovery instance will connect to both address 192.1.32.10 and 192.1.32.11 where other ZooDiscovery services are running. */ ID target = container.getConnectNamespace().createInstance( new String[] { "discovery.flavor.standalone=192.1.32.10" });
How to get ZooDiscovery service?
IContainer container = null; try { //"ecf.discovery.zookeeper" is the container name we want to initiate. container = ContainerFactory.getDefault().createContainer("ecf.discovery.zookeeper"); } catch(ContainerCreateException e1){ // TODO } ID serverId = container.getConnectNamespace().createInstance( new String[] { "discovery.flavor.standalone=192.1.32.10" }); try { //we then try and connect. container.connect(serverId, null); } catch (ContainerConnectException e1) { // TODO } // Connected! Our provider is ready then.
// To advertise services we need adapting our container this way: IDiscoveryAdvertiser discoveryAdvertiser = (IDiscoveryAdvertiser) container.getAdapter(IDiscoveryAdvertiser.class); //then we enjoy calling IDiscoveryAdvertiser contract methods
// To localize/discover services we need adapting it this way: IDiscoveryLocator discoveryLocator = (IDiscoveryLocator) container.getAdapter(IDiscoveryLocator.class); //then we enjoy calling IDiscoveryLocator contract methods
I want ZooDiscovery publishing my OSGi services automatically
OSGi services registered with property "osgi.remote.interface=*" are candidate for auto-publication. By default this option is disabled. To make ZooDiscovery autopublish all services having the above property once connected, you basically use the same way as above (How to get ZooDiscovery service?)
with the property "discovery.publish.auto=true" added when creating the target id. ID serverId = container.getConnectNamespace().createInstance( new String[] { "discovery.flavor.standalone=192.1.32.10" ,"discovery.publish.auto=true"}); //...same as above // Once connected ZooDiscovery will publish all OSGi services registered with "osgi.remote.interface=*". You can still adapt and use as above, though.
How to build a ServiceInfo object and publish it
//Some service location URI uri = URI uri = URI.create("http://www.example.com/discovery"); //Some service priority int priority = 0; //Some service weight int weight = 3; //Service properties ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.setProperty("foobar", new String("foobar")); serviceProperties.setPropertyBytes("foobar1", new byte[] { 1, 2, 3 }); IServiceTypeID serviceTypeID = null; try { serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID( DiscoveryContainer.getSingleton().getConnectNamespace(),new String[] {"service1","service2"}, new String[] {"someProtocol"}); } catch (IDCreateException e) {//TODO } //build a service info instance to be published ServiceInfo serviceInfo = new ServiceInfo(uri, "myServiceName", serviceTypeID, priority, weight, serviceProperties); //advertise the service discoveryAdvertiser.registerService(serviceInfo);
I want to publish an OSGi service directly via its ServiceReference
ServiceReference ref =... //wrap you reference in an AdvertisedService and that is it. IServiceInfo sinfo = new AdvertisedService(ref); discoveryAdvertiser.registerService(sinfo);
I want to get notified about discovered services
being edited...
Advanced configuration
ZooDiscovery Flavors
Standalone mode: discovery.flavor.standalone
being edited...
Centralized mode: discovery.flavor.centralized
being edited...
Replicated mode: discovery.flavor.replicated
being edited...
Fine tuning the underlying ZooKeeper
being edited...
Recipes
Automate proxying discovered services using R-OSGi and ZooDiscovery
being edited...