Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2013-2014 by Cisco Systems, Inc. All rights reserved.
 
 package com.cisco.oss.foundation.directory.lb;
 
 import java.util.List;
 
A RoundRobin LoadBalancer abstract template based on DirectoryLookupService.

Author(s):
zuxiang
public abstract class RoundRobinLoadBalancer implements ServiceInstanceLoadBalancer{

The DirectoryLookupService to get the ServiceInstance List.
The Round Robin position index.
	private AtomicInteger index;

Constructor.
		this. = lookupService;
		this. = new AtomicInteger(0);
	}

Vote a ServiceInstance based on the LoadBalancer algorithm.

Returns:
the voted ServiceInstance.
	public ServiceInstance vote() {
		if(instances == null || instances.isEmpty()){
			return null;
		}
		int i = .getAndIncrement();
		int pos = i % instances.size();
		ModelServiceInstance instance = instances.get(pos);
		return ServiceInstanceUtils.transferFromModelServiceInstance(instance);
	}

Get the LookupService.

Returns:
the LookupService.
		return ;
	}

Get the ServiceInstance list for the Round Robin.

Returns:
the ServiceInstance list.
New to GrepCode? Check out our FAQ X