首页 > 代码库 > Server.java
Server.java
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。