📄 btconnection.java
字号:
/*
* @(#)BTConnection.java ver 1.2 6/20/2005
*
* Copyright 2005 Weishuai Yang (wyang@cs.binghamton.edu).
* All rights reserved.
*
*/
package gps.protocol.BT;
import gps.network.Connection;
/**
* two way connection between two BTSockets.
*
*
* @author Weishuai Yang
* @version 1.2, 6/20/2005
*/
public class BTConnection extends Connection {
/**
* source bt socket
*/
private BTSocket mSource;
/**
* destination bt socket
*/
private BTSocket mDestination;
/**
* constructs BTConnection object
* @param a source BTSocket
* @param b destination BTSocket
*/
public BTConnection(BTSocket a, BTSocket b){
super(a.mSession.getAgent(),b.mSession.getAgent());
mSource=a;
mDestination=b;
}
/**
* get bandwidth for the flow origniated from a BTSocket
* @param s source BTSocket
* @return one way bandwidth
*/
public double getBandwidthFrom(BTSocket s){
return super.getBandwidthFrom(s.mSession.getAgent().getNode());
}
/**
* set bandwidth for the flow origniated from a BTSocket
* @param s source BTSocket
* @param b new bandwidth
*/
public void setBandwidthFrom(BTSocket s, double b){
super.setBandwidthFrom(s.mSession.getAgent().getNode(), b);
}
/**
* request more or less bandwidth for a connection
* @param adj adjustment
*/
public void adjustBandwidth(double adj){
super.adjustBandwidth(adj);
//bandwidth is already changed here.
if(mSource.mDownloading&&mDestination.mDownloading){
mBandwidthAtoB=mBandwidth/2;
mBandwidthBtoA=mBandwidth/2;
mSource.adjustInBandwidth(adj/2);
mDestination.adjustOutBandwidth(adj/2);
mSource.adjustInBandwidth(adj/2);
mDestination.adjustOutBandwidth(adj/2);
}
else if(mSource.mDownloading&&!mDestination.mDownloading){
mBandwidthAtoB=0;
mBandwidthBtoA=mBandwidth;
mSource.adjustInBandwidth(adj);
mDestination.adjustOutBandwidth(adj);
}
else if(!mSource.mDownloading&&mDestination.mDownloading){
mBandwidthAtoB=mBandwidth;
mBandwidthBtoA=0;
mSource.adjustOutBandwidth(adj);
mDestination.adjustInBandwidth(adj);
}
}
/**
* gets string description
* @return string description
*/
public String toString() {
String ret = "Connection("+mSource+"->"+mDestination+")";
if (mActive)
ret += ": Active, Bandwidth: "+mBandwidth;
else
ret += ": InActive";
ret+=" ";
return ret;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -