import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;



public class SeverList {
	 /**
     * 创建虚拟的服务器的链表
     * **/
	 private String host_name;
	 private int all_Memory;
	 
	 //剩余的内存
	 public  int rest_Memory;
	 public  int runing_num;
	 //分配的任务还需要多长时间运行
	 public  int rest_time_ms;
	 public int exec_task;
	 
	 public  int rate_memory;
	 //标志位
	 public boolean isDispose = true;
	 //服务器自己的处理特殊任务队列
	 TaskList importTask = new TaskList(null,0,0);
	 
	 private SeverList next;
	 
	 //每个服务器自带一把锁的对象，用于lock和unlock
	 public static Lock lock = new ReentrantLock();
	 public static SynchronizedTask syntask = new SynchronizedTask();
	 public AllocatetaskThread allcatethread= new AllocatetaskThread(this);
	 
	 public SeverList(String host_name,int all_Memory)
	 { 
		 this.host_name = host_name;
		 this.all_Memory = all_Memory;
		 this.rest_Memory = this.all_Memory;
		 this.runing_num = 0;
		 this.next =null;
		 this.exec_task=0;
		 this.rate_memory = 0;
	 }
	 
	 public void  setNext(SeverList next)
	 {
		 this.next = next;
	 }
	 
	 public SeverList getNext()
	 {
		 return this.next;
	 }
	 
	 public String get_host_name()
	 {
		 return this.host_name;
	 }
	 
	 public int get_all_Memory()
	 {
		 return this.all_Memory;
	 }
	 //增加节点
	 public void add_SeverList(SeverList new_SeverList)
	 {
		 if(this.next == null)
		 {
			 this.next = new_SeverList;
		 }
		 else
		 {
			 this.next.add_SeverList(new_SeverList);
		 }
	 }
	 //打印节点
	 public void print_SeverList() {
		 
			System.out.println("hostname:"+this.host_name+",allmemory:"+this.all_Memory+",rest_memory:"+this.rest_Memory) ;
			
			if(this.next != null) {
				this.next.print_SeverList();
			}
		}
	 //打印单个节点
	 public void print_server()
	 {
		 System.out.println("hostname:"+this.host_name+",allmemory:"+this.all_Memory+",rest_memory:"+this.rest_Memory+"memory rate:" + (int)(((float)(this.rest_Memory)/this.all_Memory)*100) + "%") ; 
	 }
	 
	 public int print_rate()
	 {
		 return this.rate_memory;
	 }
	 //打印任务个数
	 public void print_task()
	 {
		 System.out.println("hostname:"+this.host_name+",task_num:"+this.exec_task) ;
			
			if(this.next != null) {
				this.next.print_task();
			}
	 }
	 

}
