亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? connection.java

?? 一個p2p仿真軟件
?? JAVA
字號:
/*
 * @(#)Connection.java	ver 1.2  6/20/2005
 *
 * Copyright 2005 Weishuai Yang (wyang@cs.binghamton.edu). 
 * All rights reserved.
 * 
 */
 
package gps.network;

import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.ArrayList;
import java.util.logging.Logger;

import gps.network.graph.Link;
import gps.network.graph.Node;
import gps.protocol.Agent;

/**
 * high level directed connection between nodes
 *
 * @author  Weishuai Yang
 * @version 1.2,  6/20/2005
 */

public class Connection {


	/**
	 * singleton reference to topology
	 */
	protected static Topology mTopology=Topology.getInstance();	
	/**
	 * singleton reference to debug log
	 */
	protected static Logger mDebugLog = Logger.getLogger("Debug");
	
	//public Agent mSource;
	//public Agent mDestination;
	
	/**
	 * source node of the connection, i.e. initiator
	 */
	protected Node mSource;
	/**
	 * destination of the connection
	 */
	protected Node mDestination;
	
	/**
	 * all the links along the connection
	 */
	protected Link[] mLinks=null;
	
	/**
	 * bandwidth consumed by this connection
	 */
	protected double mBandwidth=0;
	/**
	 * bandwidth from source to destination
	 */
	protected double mBandwidthAtoB=0;
	/**
	 * bandwidth from destination to source
	 */
	protected double mBandwidthBtoA=0;
	/**
	 * bandwidth reserved for this connection along links, but not allocated yet
	 */
	protected double mReservedBandwidth=0;
	/**
	 * active connection or not
	 */
	protected boolean mActive=false;
	/**
	 * locked means it is adjusting
	 */
	protected boolean mLocked=false;
	/**
	 * all the connections in the system
	 */
	protected static ArrayList mConnections=new ArrayList();
	
	/**
	 * constructs a connection between agents
	 * @param a source agent
	 * @param b destination agent
	 */
	public Connection(Agent a, Agent b){
		mSource=a.getNode();
		mDestination=b.getNode();
		mLinks=mTopology.getLinksBetween(a.getNode(), b.getNode());
		mConnections.add(this);
		//System.out.println("setting up connection from node "+mSource.getID()+" to node "+mDestination.getID());
	}

	/**
	 * constructs a connection between nodes
	 * @param a source node
	 * @param b destination node
	 */
	public Connection(Node a, Node b){
		mSource=a;
		mDestination=b;
		mLinks=mTopology.getLinksBetween(a, b);
		mConnections.add(this);	
	}
	
	/**
	 * get all the connections in the system, class method
	 * @return connection list
	 */
	public static ArrayList getAllConnections(){
		return mConnections;
	}
	/**
	 * print all connections in system, just for debug purpose
	 */
	public static void printConnections(){
		System.out.println("\n");
		for(int i=0;i<mConnections.size();i++){
			System.out.println((Connection)mConnections.get(i));
		}
		Link[] links=Topology.getInstance().getLinks();
		for(int i=0; i<links.length; i++){
			double d=links[i].getBandwidthManager().getAvailableBandwidth();
			System.out.println(links[i].fromNode()+"->"+links[i].toNode()+":"+d);
		}
	}
	/**
	 * setup this connection along links
	 */
	public void setUp(){
		//always add it to inactive list
		mActive=false;
		mBandwidth=0;
		for(int i=0;i<mLinks.length;i++)
			mLinks[i].getBandwidthManager().addConnection(this);
	}
	/**
	 * reserve bandwidth for this connection along links
	 */
	protected void reserveBandwidth(){
		//after reserve, it's alwasy inactive, even if it is active before reserve
		returnBandwidth();
		negotiateBandwidth();
		for(int i=0;i<mLinks.length;i++)
			mLinks[i].getBandwidthManager().reserveFor(this);
	}
	
	/**
	 * return bandwidth for this connection along links
	 */
	protected void returnBandwidth(){
		for(int i=0;i<mLinks.length;i++)
			mLinks[i].getBandwidthManager().returnBandwidth(this);
		mBandwidth=0;
	}

	protected void negotiateBandwidth(){
		double minimum=mLinks[0].getBandwidthManager().negotiateForConnection(this);
		for(int i=0;i<mLinks.length;i++){
			double tmp=mLinks[i].getBandwidthManager().negotiateForConnection(this);
			if(tmp<minimum){
				minimum=tmp;
			}
		}
		mReservedBandwidth=minimum;
	}
	/**
	 * apply reserved to be real bandwidth
	 */
	protected void applyReservedBandwidth(){
		mBandwidth=mReservedBandwidth;
		mReservedBandwidth=0;
		for(int i=0;i<mLinks.length;i++)
			mLinks[i].getBandwidthManager().activeConnection(this);
	}

	/**
	 * make connection active
	 */
	public void setActive(){
		if(mActive) return;
		reserveBandwidth();
		mActive=true;
		applyReservedBandwidth();
	}
	
	/**
	 * get active status
	 * @return true if active, otherwise false
	 */
	public boolean isActive(){
		return mActive;
	}
	
	/**
	 * maximizes bandwidth for this connection
	 */
	protected void maximize(){
		reserveBandwidth();
		applyReservedBandwidth();
	}

	/**
	 * finds bottle neck along links
	 * @param forward true means search forward, otherwise backward
	 */
	public Link findBottleNeck(boolean forward){
		double minimum=mLinks[0].getBandwidthManager().getAvailableBandwidth();
		Link bottleNeck=mLinks[0];
		if(forward)
			for(int i=0;i<mLinks.length;i++){
				if(mLinks[i].getBandwidthManager().getAvailableBandwidth()<minimum){
					minimum=mLinks[i].getBandwidthManager().negotiateForConnection(this);
					bottleNeck=mLinks[i];
				}
			}
		else
			for(int i=mLinks.length-1;i>=0;i--){
				if(mLinks[i].getBandwidthManager().getAvailableBandwidth()<minimum){
					minimum=mLinks[i].getBandwidthManager().negotiateForConnection(this);
					bottleNeck=mLinks[i];
				}
			}
		return bottleNeck;
	}
	/**
	 * gets bandwidth allocated for this connection
	 * @return allocated bandwidth
	 */
	public double getBandwidth(){
		return mBandwidth;
	}
	
	/**
	 * gets one way bandwidth
	 * @param n source
	 * @return bandwidth from source
	 */
	public double getBandwidthFrom(Node n){
		if(n==mSource)
			return mBandwidthAtoB;
		else if(n==mDestination)
			return mBandwidthBtoA;
		return 0;
	}
	
	/**
	 * sets one way bandwidth
	 * @param n source
	 * @param b new bandwidth value
	 */
	public void setBandwidthFrom(Node n, double b){
		if(n==mSource)
			mBandwidthAtoB=b;
		else if(n==mDestination)
			mBandwidthBtoA=b;
	}
	
	/**
	 * makes connection inactive
	 */
	public void setInActive(){
		if(!mActive) return;
		mActive=false;
		for(int i=0;i<mLinks.length;i++)
			mLinks[i].getBandwidthManager().inActiveConnection(this);
		relaxBandwidthAlongTheWay();
		mBandwidth=0;
	}


	public void relaxBandwidthAlongTheWay(){
		
		//find bottleneck first 
		Link bottleNeck1=findBottleNeck(true);
		Link bottleNeck2=null;

		int count=0;
		while(bottleNeck1!=bottleNeck2){
			count++;
			
			LinkedHashSet connections=bottleNeck1.getBandwidthManager().getActiveConnectionList();
		
			ArrayList connlist=new ArrayList(connections);
	    	Iterator it=connlist.iterator();
	    	while(it.hasNext()){
	    		Connection c=(Connection)it.next();
	    		if(c==this){
	    			mDebugLog.warning("relaxing self!");
	    			return;
	    		}
	    		if(c.mActive){
	    			if(c.getBandwidth()==0) return;
	    			c.maximize();
	    		}
	    		else
	    			mDebugLog.warning("connection get from active connection list is not active!");
	    	}
			bottleNeck2=bottleNeck1;
			bottleNeck1=findBottleNeck(true);
			
			if(count>100){
				mDebugLog.warning("Finding bottleneck forward more than 100 times!");
			}
		}



		//find bottleneck first 
		bottleNeck1=findBottleNeck(false);
		bottleNeck2=null;

		count=0;
		while(bottleNeck1!=bottleNeck2){
			count++;
			
			LinkedHashSet connections=bottleNeck1.getBandwidthManager().getActiveConnectionList();
		
			ArrayList connlist=new ArrayList(connections);
	    	Iterator it=connlist.iterator();
	    	while(it.hasNext()){
	    		Connection c=(Connection)it.next();
	    		if(c==this){
	    			mDebugLog.warning("relaxing self!");
	    			return;
	    		}
	    		if(c.mActive){
	    			if(c.getBandwidth()==0) return;
	    			c.maximize();
	    		}
	    		else
	    			mDebugLog.warning("connection get from active connection list is not active!");
	    	}
			bottleNeck2=bottleNeck1;
			bottleNeck1=findBottleNeck(false);
			
			if(count>100){
				mDebugLog.warning("Finding bottleneck reverse more than 100 times!");
			}
		}
		
	}

	/**
	 * tear down the connection
	 */
	public void tearDown(){
		if(mActive)
			setInActive();
		for(int i=0;i<mLinks.length;i++)
			mLinks[i].getBandwidthManager().removeConnection(this);
		//System.out.println("tearing down connection from node "+mSource.getID()+" to node "+mDestination.getID());
		mConnections.remove(this);
		
	}

	/**
	 * adjust bandwidth for provided amount
	 * @param adj adjust amount
	 */	
	public void adjustBandwidth(double adj){
		//request more or less bandwidth

	    if(!mActive)
			mDebugLog.warning("Trying to adjust bandwidth for inactive connection "+ this);
	    mBandwidth+=adj;
		for(int i=0;i<mLinks.length;i++)
			mLinks[i].getBandwidthManager().adjustBandwidthForConnection(this, adj);

	}
	
	/**
	 * gets string description
	 * 
	 * @return string description
	 */
	public String toString() {
		String ret = "Connection("+mSource.getID()+"->"+mDestination.getID()+")";
		if (mActive) 
			ret += ": Active, Bandwidth: "+mBandwidth;
		else 
			ret += ": InActive";
		if(mReservedBandwidth!=0)
			ret +=" ReservedBandwidth: "+mReservedBandwidth;
		ret+=" ";
		return ret;
	}
	
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一卡二卡三卡四卡无卡久久 | 在线播放/欧美激情| 色婷婷综合久久久中文字幕| 成人午夜短视频| 色综合久久综合网欧美综合网| 成人av在线网站| 99精品黄色片免费大全| 色天使久久综合网天天| 欧美一区二区高清| 中文字幕一区二区在线观看 | 亚洲第一福利一区| 久久91精品久久久久久秒播| 成人av网站在线观看| 欧美精品粉嫩高潮一区二区| 国产欧美日韩精品一区| 亚洲高清免费视频| 91视视频在线观看入口直接观看www | 国产女主播视频一区二区| 亚洲欧美日韩国产中文在线| 国产一区二区三区观看| 在线一区二区观看| 国产精品美女久久久久久久网站| 丝瓜av网站精品一区二区 | 国产精品传媒视频| 免费亚洲电影在线| 欧美一区日本一区韩国一区| 玉足女爽爽91| 欧美伊人久久大香线蕉综合69| 久久久欧美精品sm网站| 美日韩一区二区| 精品播放一区二区| 国产乱码一区二区三区| 欧美精品一区二区三区很污很色的 | 欧美视频中文一区二区三区在线观看| 国产日韩欧美麻豆| 99精品视频一区二区三区| 国产三级精品在线| 色视频欧美一区二区三区| 亚洲激情欧美激情| 日韩欧美国产1| 99国产一区二区三精品乱码| 亚洲欧美日韩一区二区| 欧美日韩一二三| 免费在线看一区| 国产精品传媒在线| 欧美一级高清片| 亚洲国产精品国自产拍av| aaa亚洲精品| 亚洲精品写真福利| 精品动漫一区二区三区在线观看| 国产精品一二三区| 亚洲一区二区av在线| 精品久久久久久久人人人人传媒| 成人白浆超碰人人人人| 日本系列欧美系列| 亚洲国产日日夜夜| 国产精品一区免费在线观看| 欧美日韩中文另类| 欧美激情一区二区三区在线| 亚洲最新在线观看| 成人免费观看视频| 欧美成人video| 亚洲一区免费观看| 9人人澡人人爽人人精品| 26uuu成人网一区二区三区| 日本欧美在线观看| 《视频一区视频二区| 亚洲精品大片www| av不卡在线观看| 日本一区二区免费在线| 国产在线一区二区| 久久理论电影网| 风间由美一区二区三区在线观看 | 亚洲欧洲精品一区二区精品久久久 | 成人高清伦理免费影院在线观看| 久久综合色之久久综合| 亚洲一区av在线| 欧美日韩不卡一区| 人人爽香蕉精品| 成人18精品视频| 国产精品欧美极品| www.日韩av| 亚洲成av人片观看| 精品福利一二区| 91小视频免费观看| 亚洲大片一区二区三区| 日韩一区二区电影在线| 国产成人精品影视| 日本午夜精品一区二区三区电影| 日韩欧美www| 91蜜桃免费观看视频| 日韩va欧美va亚洲va久久| 久久蜜桃香蕉精品一区二区三区| 91丨九色丨尤物| 99久久精品国产一区| 天天色图综合网| 国产精品素人一区二区| 56国语精品自产拍在线观看| 国产精品99久久久久久似苏梦涵 | 久久精品国产澳门| 亚洲日本在线天堂| 国产精品三级久久久久三级| 日韩视频一区二区三区| 精东粉嫩av免费一区二区三区| 欧美一区二区不卡视频| 亚洲成人免费观看| 欧美高清视频在线高清观看mv色露露十八| 久久亚洲精精品中文字幕早川悠里| 人妖欧美一区二区| 久久日一线二线三线suv| 久久精品国产秦先生| 中文字幕欧美日韩一区| 国产99久久久国产精品免费看| 国产亚洲精品超碰| 国产成人av在线影院| 中文字幕日韩精品一区| 91麻豆精东视频| 亚洲.国产.中文慕字在线| 欧美一区二区三区视频在线| 麻豆精品一二三| 亚洲四区在线观看| 91精品国产综合久久久久| 国产毛片精品视频| 一区2区3区在线看| 久久综合九色综合97_久久久| 国产精品中文有码| 亚洲成a人在线观看| 久久久久久久久蜜桃| 欧洲视频一区二区| 国内久久精品视频| 一区二区三区四区精品在线视频| 欧美一级夜夜爽| 91蝌蚪porny九色| 日韩激情视频在线观看| 国产suv一区二区三区88区| 高清在线成人网| 国产精品69毛片高清亚洲| 亚洲国产欧美在线人成| 国产精品另类一区| 久久综合九色欧美综合狠狠 | 国产精品国产三级国产aⅴ中文| 欧美精品粉嫩高潮一区二区| av爱爱亚洲一区| 91在线精品一区二区| eeuss鲁片一区二区三区| 成人黄色电影在线 | 中文在线一区二区| 欧美国产精品v| 亚洲码国产岛国毛片在线| 亚洲免费观看高清| 日本中文字幕不卡| 国产高清亚洲一区| 色综合夜色一区| 欧美电影影音先锋| 亚洲精品在线观看网站| 中文字幕 久热精品 视频在线| 中文字幕巨乱亚洲| 图片区小说区区亚洲影院| 麻豆91免费观看| 91啦中文在线观看| 精品黑人一区二区三区久久| 欧美经典一区二区| 调教+趴+乳夹+国产+精品| 国产在线精品一区二区夜色 | 久久美女高清视频| 亚洲激情校园春色| 成人激情校园春色| 日韩精品一区二区三区中文不卡 | 精品亚洲成a人| 色狠狠一区二区三区香蕉| 精品国产乱码久久久久久图片| 国产精品九色蝌蚪自拍| 日本亚洲电影天堂| 在线观看www91| 亚洲男人的天堂av| 成人精品国产福利| 久久久久久久久久久久久久久99 | 亚洲不卡一区二区三区| 成人精品电影在线观看| 日本一区二区电影| 成人三级在线视频| 国产视频一区在线观看| 久久99国产乱子伦精品免费| 欧美精品日韩一本| 蜜臀99久久精品久久久久久软件| 精品视频一区二区不卡| 亚洲福利一二三区| 6080国产精品一区二区| 久久精品国产第一区二区三区 | 成人成人成人在线视频| 中文字幕日韩av资源站| 欧美中文字幕一区二区三区| 一区二区三区高清不卡| 欧美午夜精品一区二区蜜桃 | 99久久久久免费精品国产| 中文字幕视频一区二区三区久| 99精品热视频| 日本aⅴ精品一区二区三区| 久久色成人在线| 日本精品视频一区二区三区|