/**
* Copyright (c) 2009 - 2010 - OpenFARM
* Licence: MIT
*
* @Author Filipe Martins
* @Date 11-May-2010
*/
package openfarmmanager.manager.workflow.states;
import java.util.ArrayList;
import java.util.List;
import openfarmmanager.beans.idx.InterpreterDefinitionBean;
import openfarmmanager.manager.workflow.MaterialWorkflow;
public class LoadBalancingState implements IWorkFlow
{
private MaterialWorkflow materialWorkflow;
public LoadBalancingState(MaterialWorkflow materialWorkflow)
{
this.materialWorkflow = materialWorkflow;
}
@Override
public void processMaterial()
{
this.distributeMaterialPerInterpreter();
}
@Override
public void nextState()
{
this.materialWorkflow.setState(null);
}
/**Distribute the list of videos throughout the interpreters that can run them*/
public void distributeMaterialPerInterpreter()
{
for(List<String> materialList : this.materialWorkflow.getVideosInterpretersMap().keySet())
{
List<InterpreterDefinitionBean> interpretersList = this.materialWorkflow.getVideosInterpretersMap().get(materialList);
int index = interpretersList.size()-1;
for(String material : materialList)
{
if(index<0)
index = interpretersList.size()-1;
InterpreterDefinitionBean interpreter = interpretersList.get(index);
if(!this.materialWorkflow.getMaterialPerInterpreterMap().containsKey(interpreter))
{
List<String> interpreterMaterialList = new ArrayList<String>();
interpreterMaterialList.add(material);
this.materialWorkflow.getMaterialPerInterpreterMap().put(interpreter, interpreterMaterialList);
}else
{
this.materialWorkflow.getMaterialPerInterpreterMap().get(interpreter).add(material);
}
index--;
}
}
}
}
|