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;
    }
}
时间: 2024-10-17 07:07:27

Server.java的相关文章

but could not connect over HTTP to server: &#39;java.sun.com&#39;, port: &#39;80&#39;

在setDomainEnv.sh/setDomainEnv.cmd上添加 export JAVA_OPTIONS="${JAVA_OPTIONS} -Djavax.xml.stream.XMLInputFactoryexport JAVA_OPTIONS="${JAVA_OPTIONS} but could not connect over HTTP to server: 'java.sun.com', port: '80'

Kryonet client disconnects after send a packet to server (java)

http://stackoverflow.com/questions/25934876/kryonet-client-disconnects-after-send-a-packet-to-server-java —————————————————————————————————————————————————————————————————— I'm doing a little MMO project and right now I'm working on the login/registe

Could not publish to the server. java.lang.NullPointerException

错误信息: publishing to tomcat v8.0 server at localhost has encontered a problem 产生错误的操作: 解决方法: 1.找到Tomcat的配置文件"context.xml",在Context标签中添加两个属性( reloadable=true" privileged=true"),如下图: 2.加完保存之后,重新启动Eclipse,否则不生效.重新启动Eclipse之后,问题就解决了:但再查看Con

【异常】Zipkin server java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter containing tag keys [meth

解决办法: 添加下面配置就OK #zipkin启动报错无法访问的解决方法 management.metrics.web.server.auto-time-requests: false 原文地址:https://www.cnblogs.com/756623607-zhang/p/11520287.html

[Java聊天室server]实战之二 监听类

前言 学习不论什么一个稍有难度的技术,要对其有充分理性的分析,之后果断做出决定---->也就是人们常说的"多谋善断":本系列尽管涉及的是socket相关的知识,但学习之前,更想和广大程序猿分享的是一种心境:学习是一个循序渐进的过程,心态应该随时调节,保持戒骄戒躁的状态.比方近期在看网易公开课MIT<算法导论>,老师提到,学习算法之前要计算机数学+离散数学+概率论等课程的知识,所以一直学不好算法的程序猿最好还是从基础入手,这都是中国式教育惹的祸啊!(此处省略一万字...

应用java多线程实现server端与多client之间的通信

应用多线程来实现server与多线程之间的通信的基本步骤 1.server端创建ServerSocket,循环调用accept()等待client链接 2.client创建一个Socket并请求和server端链接 3.server端接受client请求,创建socekt与该client建立专线链接 4.建立链接的socket在一个单独的线程上对话 5.server继续等待新的链接 server端Server.java package test.concurrent.socket; import

java -server 和 -client 的不同,及 java -server 时抛错原因

在dos窗口运行:java -server Error: missing `server' JVM at `C:\Program Files\Java\jre7\bin\server\jvm.dll'. Please install or use the JRE or JDK that contains these missing components. 网上的意思: 找到jdk安装目录下面 jre\bin 里面有 client 和 server 文件夹. 把 server 文件夹复制到 C:\

Chart FX for Java Server 图表解决方案控件下载及介绍

Chart FX for Java Server为有多种数据展示需求的开发者提供一个现成的图表解决方案.Chart FX 7 for Java Server建立在以Chart FX for Java 6.5 Developer为基础的企业质量技术上, 通过增加一个框架独立,基于Ajax的运行时用户界面来使您的图表,地图和统计图提供丰富的用户接口元素,这些元素具有零空间占用或者插件的需求 具体功能: 易于编码和整合 Chart FX通过最小的整合就可以提供开发者高级图表特性.拥有很有用的工具,比如

使用java实现Server和Client(TCP)

Server.java import java.io.*; import java.net.*; public class Server { public static final int PORT=8888; public void Server() throws IOException { ServerSocket ss = new ServerSocket(PORT); InetAddress ia = InetAddress.getByName(null); System.out.pri