}
long trackerClientInterval = getTrackerClientInterval (serviceProperties.getProperty());
for (URI uri : discoveryProperties.Uris())
{
Map<Integer, PartitionData> partitionDataMap = discoveryProperties.getPartitionDataMap(uri);
TrackerClient client = trackerClients.get(uri);
if (client == null || !client.getParttitionDataMap().equals(partitionDataMap))
{
client = getTrackerClient(serviceName,
uri,
partitionDataMap,
config,
trackerClientInterval);
if (client != null)
{
info(_log,
"adding new tracker client from updated uri properties: ",
client);
// notify listeners of the added client
for (SimpleLoadBalancerStateListener listener : _listeners)
{
listener.onClientAdded(serviceName, client);
}
trackerClients.put(uri, client);
}
}
}
}
}
}
// replace the URI properties
_uriProperties.put(listenTo,
new LoadBalancerStateItem<UriProperties>(discoveryProperties,
_version.incrementAndGet(),
System.currentTimeMillis()));
// now remove URIs that we're tracking, but have been removed from the new uri
// properties
if (discoveryProperties != null)
{
Set<String> serviceNames = _servicesPerCluster.get(discoveryProperties.getClusterName());
if (serviceNames != null)
{
for (String serviceName : serviceNames)
{
Map<URI, TrackerClient> trackerClients = _trackerClients.get(serviceName);
if (trackerClients != null)
{
for (Iterator<URI> it = trackerClients.keySet().iterator(); it.hasNext();)
{
URI uri = it.next();
if (!discoveryProperties.Uris().contains(uri))
{
TrackerClient client = trackerClients.remove(uri);
info(_log, "removing dead tracker client: ", client);
// notify listeners of the removed client
for (SimpleLoadBalancerStateListener listener : _listeners)