All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.anysoft.loadbalance.AbstractLoadBalance Maven / Gradle / Ivy

There is a newer version: 1.6.17
Show newest version
package com.anysoft.loadbalance;

import java.util.ArrayList;
import java.util.List;

import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;

/**
 * LoadBalance虚基类
 * 
 * @author duanyy
 *
 * @param 
 */
abstract public class AbstractLoadBalance implements LoadBalance {

	public AbstractLoadBalance(Properties props){
		onlyValid = PropertiesConstants.getBoolean(props, "loadbalance.onlyvalid", onlyValid);
	}	
	
	
	public load select(String key, Properties props, List loads) {
		List _loads = loads;
		
		if (onlyValid){
			_loads = new ArrayList(loads.size());
			
			for (load l:loads){
				if (l.isValid()){
					_loads.add(l);
				}
			}
			
			if (_loads.size() <= 0){
				_loads = loads;
			}
		}
		return onSelect(key,props,_loads);
	}

	
	/**
	 * Select事件处理
	 * 
	 * @param key
	 * @param props
	 * @param loads
	 * @return load
	 */
	protected abstract load onSelect(String key, Properties props, List loads);

	protected boolean onlyValid = true;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy