码迷,mamicode.com
首页 > 编程语言 > 详细

Server.java

时间:2016-09-29 01:08:08      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

package EPON;
public class Server implements Runnable {
    
    private int ONUNUMBER;
    private int CYCLENUMBER;
    private int counter = 0;
    public static double systime = 0;
    private double[] idle_time;
    private double tmp;

    public Server(int ONUNUMBER, int CYCLENUMBER){
        this.ONUNUMBER = ONUNUMBER;
        this.CYCLENUMBER = CYCLENUMBER;
        idle_time = new double[ONUNUMBER];
    }

    public void run(){
        while(counter < CYCLENUMBER){
            for(int i = 0; i < ONUNUMBER; i++) {
                try {
                    Simulation.server_lock.acquire();
                    if(counter!=0) Simulation.set_grant((i-1+ONUNUMBER)%ONUNUMBER, tmp);
                    systime = Simulation.grant[i];
                    tmp = calculate_next_grant(Simulation.report, i);
                    Simulation.customer_lock[i].release();
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
            counter++;
        }
        for(int i = 0; i < ONUNUMBER; i++) {
            Simulation.set_grant(i, -1);
            Simulation.customer_lock[i].release();
        }
    }

    public double calculate_next_grant(int [] report, int i){
        double grant;
        double factor = Simulation.PACKETBIT/Simulation.RATE;

        if((systime + report[i]*factor + Simulation.RTT)>(Simulation.grant[(i-1+ONUNUMBER)%ONUNUMBER]+report[(i-1+ONUNUMBER)%ONUNUMBER]*factor+Simulation.GUARDTIME)){
            grant = systime + report[i]*factor + Simulation.RTT;
            //idle_time[i] += (systime + report[i]*factor + Simulation.RTT - (Simulation.grant[(i-1+ONUNUMBER)%ONUNUMBER]+report[(i-1+ONUNUMBER)%ONUNUMBER]*factor+Simulation.guard_time));
        }
        else {
            grant = Simulation.grant[(i-1+ONUNUMBER)%ONUNUMBER]+report[(i-1+ONUNUMBER)%ONUNUMBER]*factor+Simulation.GUARDTIME;
        }
        return grant;
    }
}

 

Server.java

标签:

原文地址:http://www.cnblogs.com/yanyuqi/p/5918260.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!