package my.domain.test.server.extension;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.wowza.wms.application.WMSProperties;
import com.wowza.wms.logging.WMSLoggerFactory;
import com.wowza.wms.plugin.loadbalancer.utils.Logger;

public class LoadBalancerServerDummyExtension implements ILoadBalancerServerDataExtension
{
	private boolean debug = false;
	private boolean active = false;
	private final String COMPONENT_NAME = "LoadBalancerServerDummyExtension";
	private Logger logger = null;

	public void init(WMSProperties props)
	{
	}

	public void setDebug(boolean debug)
	{
		this.debug = debug;

	}

	public boolean getDebug()
	{
		return this.debug;
	}

	public void setLogger(Logger log)
	{
		this.logger = log;
	}

	public Logger getLogger()
	{
		return this.logger;
	}

	public void updateComponent(HashMap<String, String> data)
	{
	}

	public void setActive(boolean active)
	{
		this.active = active;
	}

	public boolean getActive()
	{
		return this.active;
	}

	public String getComponentName()
	{
		return COMPONENT_NAME;
	}

	public List<ILoadBalancerServerClient> processClientInformation(List <ILoadBalancerServerClient> clientList, Map<String, String> params)
	{
		// The processClientInformation function is run each time a client request is made for
		// load balancing.

		// clientList contains the clients available to be checked

		// params contains any custom parameters added by client requests when a request is
		// received.

		if (!getActive())
			return clientList;

		List<ILoadBalancerServerClient> outputClients = new ArrayList<ILoadBalancerServerClient>();

		Iterator<ILoadBalancerServerClient> clientI = clientList.iterator();
		while (clientI.hasNext())
		{
			ILoadBalancerServerClient thisClient = clientI.next();
			HashMap<String, String> thisClientAtt = thisClient.getAttributes();
			// The attribute list from the client contains ALL attributes passed by ALL the client data collection extensions.
			// Each client extension prefixes the name of the extension

			if (thisClientAtt.containsKey("ClientExtensionDummy-dummyName"))
			{
			// Determine if this client matches criteria you are looking for and add to the
			// return list of clients. This list is passed to the next extension for processing.
			//
			// outputClients.put(thisClient, clientList.get(thisClient));
			}
		}

		return outputClients;
	}
}

