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

es.tid.pce.computingEngine.algorithms.LocalChildRequestManager Maven / Gradle / Ivy

The newest version!
package es.tid.pce.computingEngine.algorithms;

import java.io.DataOutputStream;
import java.net.Inet4Address;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.concurrent.FutureTask;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import es.tid.pce.computingEngine.ComputingRequest;
import es.tid.pce.computingEngine.ComputingResponse;
import es.tid.pce.pcep.constructs.Request;
import es.tid.pce.pcep.messages.PCEPInitiate;
import es.tid.pce.pcep.messages.PCEPRequest;
import es.tid.tedb.TEDB;

/**
 * Manages the requests to the Child PCEs
 * Child PCE Session must register using the registerDomainSession method
 * The Parent PCE when asking a PCE must call the method newRequest
 * @author ogondio
 *
 */
public class LocalChildRequestManager {
	
	/**
	 * Relates Child PCEs with its domain with 
	 */
	//private Hashtable domain_pce;
	/**
	 * Relates domain_id with the output stream of the Child PCEs  
	 */
	private Hashtable domainIdOutputStream;
	private Hashtable domainIdpceId;
	
	public Hashtable locks;
	private Hashtable responses;
	
	
	private ThreadPoolExecutor executor;
	
	private  LinkedBlockingQueue workQueue;
	//private  BlockingQueue workQueue;
	
	private Logger log;
	private Logger logGUI;
	
	
	public LocalChildRequestManager(){
		locks = new Hashtable();	
		responses=new Hashtable();
		domainIdOutputStream=new Hashtable();
		domainIdpceId=new Hashtable();
		int corePoolSize=5;
		int maximumPoolSize=10;
		long keepAliveTime=120;
		workQueue=new LinkedBlockingQueue();
		executor= new ThreadPoolExecutor(corePoolSize, maximumPoolSize,keepAliveTime, TimeUnit.SECONDS,workQueue);
		
		log = LoggerFactory.getLogger("PCEServer");
		logGUI=LoggerFactory.getLogger("GUILogger");
		
	}
	
	public LinkedList executeRequests(LinkedList requestList, LinkedList domainList, ComputingAlgorithmManagerSSON cam_sson, TEDB ted){
		LinkedList response= new  LinkedList();
		int mf=0;
		LinkedList> ftList=new LinkedList>();
		FutureTask ft;
		for (int i=0;i requestList2=new LinkedList();
			compRquest.setRequestList(requestList2);
			compRquest.getRequestList().add(requestList.get(i).getRequestList().get(0));
			ComputingAlgorithm cpr=cam_sson.getComputingAlgorithm(compRquest,ted,mf);
			 ft=new FutureTask(cpr);
			 ftList.add(ft);
			 executor.execute(ft);
		}
		long time=120000;
		System.out.println("The time is "+time+" miliseconds");
		long timeIni=System.currentTimeMillis();
		long time2;
		ComputingResponse resp;
		for (int i=0;i=120000){
					time=0;
				}
				else {
					time=time-timePassed;	
				}
				 response.add(resp);
//			} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			} catch (ExecutionException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
			} catch (TimeoutException e) {
				//System.out.
				resp=null;
				time2=System.currentTimeMillis();
				time=time-time2-timeIni;
				// TODO Auto-generated catch block
				e.printStackTrace();
//			}
			} catch (Exception e){
				return null; //FIXME: REPARAR PARA MANDAR MAS!!!!
				
			}
			
		}
		
		return response;
	}
	
//	public LinkedList executeInitiates(LinkedList iniList, LinkedList domainList, ComputingAlgorithmManagerSSON cam_sson, TEDB ted){
//		LinkedList response= new  LinkedList();
//		int mf=0;
//		LinkedList> ftList=new LinkedList>();
//		FutureTask ft;
//		for (int i=0;i requestList2=new LinkedList();
//			compRquest.setRequestList(requestList2);
//			compRquest.getRequestList().add(iniList.get(i).getRequestList().get(0));
//			ComputingAlgorithm cpr=cam_sson.getComputingAlgorithm(compRquest,ted,mf);
//			 ft=new FutureTask(cpr);
//			 ftList.add(ft);
//			 executor.execute(ft);
//		}
//		long time=120000;
//		System.out.println("The time is "+time+" miliseconds");
//		long timeIni=System.currentTimeMillis();
//		long time2;
//		ComputingResponse resp;
//		for (int i=0;i=120000){
//					time=0;
//				}
//				else {
//					time=time-timePassed;	
//				}
//				 response.add(resp);
////			} catch (InterruptedException e) {
////				// TODO Auto-generated catch block
////				e.printStackTrace();
////			} catch (ExecutionException e) {
////				// TODO Auto-generated catch block
////				e.printStackTrace();
//			} catch (TimeoutException e) {
//				//System.out.
//				resp=null;
//				time2=System.currentTimeMillis();
//				time=time-time2-timeIni;
//				// TODO Auto-generated catch block
//				e.printStackTrace();
////			}
//			} catch (Exception e){
//				return null; //FIXME: REPARAR PARA MANDAR MAS!!!!
//				
//			}
//			
//		}
//		
//		return response;
//	}
	

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy