Let me explain the context of my work. For the OSGi Remote Services Admin Service (an OSGi specification based on the Distributed OSGi RFC 119 work) we are working on the Reference Implementation in CXF (http://cxf.apache.org/distributed-osgi.html). The Reference Implementation supports the Discovery concepts of the Remote Service specification and for the implementation we make use of ZooKeeper.
In our code, we use zookeeper in two ways:
- In zookeeper client code. This code resides in bundles that import the org.apache.zookeeper and org.apache.zookeeper.data
- We also need to be able to run the zookeeper server from inside an OSGi bundle
So this is really cases 1 & 3 above.
I think we all agree on 1, and I can certainly put that in a separate patch.
On part 2 - this is the one that Alan filed ZOOKEEPER-584 for, right? This is a case that I don't need at this point, and therefore I probably don't understand what the best way to realize it is. I understand that this can be quite useful and registering a 'trivial' zookeeper object in the service registry is easy, but I guess what Alan is really looking for is an object from which he can get some management information. I really see this as a separate issue and one possibly best solved by someone who actually has a need for this.
The code that I attached does address part 3 somewhat, although I agree that it could be better. However it's a start. The zookeeper server starts and can be configured. I can try to make the shutdown/restart on reconfiguration work as well. I haven't been troubled by the System.exits() yet. It works well enough for me at the moment, although it could be improved. Could we not do the improvement over time in the future, starting off with something that works a bit like in my patch and then making it better over time?
Patrick, on your comment re a contrib package. First of all the code is not specific to an osgi container and should work equally in all osgi frameworks. Do you mean just putting the source code in a separate location or are you also thinking of putting it in a separate jar file? I would suggest putting the Activator and ManagedService in the ordinary zookeeper.jar. Outside of an OSGi framework these classes are simply ignored, but when the jar is used as an OSGi bundle they are automatically found and used. If you put it in a separate jar you will have to deploy 2 bundles before you can run the zookeeper server in an OSGi framework, which is possible but you'd have to export org.apache.zookeeper.server which is currently internal to make it work. Besides these two classes are currently only about 5kb in total.