Ok thanks. According to the ZK documentation, getChildren() says its not sorted and no guarantee is made about its order.
On Tue, Aug 20, 2013 at 2:54 PM, Jordan Zimmerman < [email protected]> wrote: > What is the order of the ServiceInstances returned by > ServiceDiscovery#queryForInstances(String name)? > > Whatever order ZooKeeper's getChildren() returns it. Which, AFAIK, is > undefined. > > Also what's the order returned by ServiceCache#getInstances()? > > Because it uses PatchChildrenCache internally, this returns instances > sorted by path. > > P.S. Curator has made my work with ZooKeeper much easier :) thanks! > > :) > > > On Aug 20, 2013, at 2:44 PM, Robert Kanter <[email protected]> wrote: > > Hi, > > What is the order of the ServiceInstances returned by > ServiceDiscovery#queryForInstances(String name)? Also what's the order > returned by ServiceCache#getInstances()? > > The context is I have some IDs and I want to assign them to different > instances on the service discovery based on modding the ID by the number of > ServiceInstances (in other words, each ID will be assigned to exactly one > ServiceInstance). I'd like to use the order in which the services > registered with ZooKeeper as their index (that is, the first service that > registers is 0, the second is 1, etc). I can accomplish this by checking > the ServiceInstance#getRegistrationTimeUTC() for each ServiceInstance to > determine the ordering, but it would be easier and faster if the returned > Collection was already in that order (which is what I'm hoping). > > thanks > - Robert > > > P.S. Curator has made my work with ZooKeeper much easier :) thanks! > > >
