use of com.biglybt.core.networkmanager.LimitedRateGroup in project BiglyBT by BiglySoftware.
the class TransferProcessor method registerPeerConnection.
/**
* Register peer connection for upload handling.
* NOTE: The given max rate limit is ignored until the connection is upgraded.
* @param connection to register
* @param group rate limit group
*/
public void registerPeerConnection(NetworkConnectionBase connection, boolean upload) {
final ConnectionData conn_data = new ConnectionData();
try {
connections_mon.enter();
LimitedRateGroup[] groups = connection.getRateLimiters(upload);
// do group registration
GroupData[] group_datas = new GroupData[groups.length];
for (int i = 0; i < groups.length; i++) {
LimitedRateGroup group = groups[i];
// boolean log = group.getName().contains("parg");
GroupData group_data = (GroupData) group_buckets.get(group);
if (group_data == null) {
int limit = NetworkManagerUtilities.getGroupRateLimit(group);
group_data = new GroupData(createBucket(limit));
group_buckets.put(group, group_data);
/*
if ( log ){
System.out.println( "Creating RL1: " + group.getName() + " -> " + group_data );
}
*/
}
group_data.group_size++;
group_datas[i] = group_data;
/*
if ( log ){
System.out.println( "Applying RL1: " + group.getName() + " -> " + connection );
}
*/
}
conn_data.groups = groups;
conn_data.group_datas = group_datas;
conn_data.state = ConnectionData.STATE_NORMAL;
connections.put(connection, conn_data);
} finally {
connections_mon.exit();
}
main_controller.registerPeerConnection(connection);
}
use of com.biglybt.core.networkmanager.LimitedRateGroup in project BiglyBT by BiglySoftware.
the class PeerImpl method closed.
protected void closed() {
synchronized (this) {
closed = true;
if (up_rg_listener != null) {
// tidy up
LimitedRateGroup[] limiters = delegate.getRateLimiters(true);
for (LimitedRateGroup l : limiters) {
if (l instanceof PluginLimitedRateGroup) {
((PluginLimitedRateGroup) l).removeListener(up_rg_listener);
}
delegate.removeRateLimiter(l, true);
}
limiters = delegate.getRateLimiters(false);
for (LimitedRateGroup l : limiters) {
if (l instanceof PluginLimitedRateGroup) {
((PluginLimitedRateGroup) l).removeListener(down_rg_listener);
}
delegate.removeRateLimiter(l, false);
}
}
}
if (delegate instanceof PeerForeignDelegate) {
((PeerForeignDelegate) delegate).stop();
}
}
use of com.biglybt.core.networkmanager.LimitedRateGroup in project BiglyBT by BiglySoftware.
the class PeerImpl method getRateLimiters.
@Override
public RateLimiter[] getRateLimiters(boolean is_upload) {
LimitedRateGroup[] limiters = delegate.getRateLimiters(is_upload);
RateLimiter[] result = new RateLimiter[limiters.length];
int pos = 0;
for (LimitedRateGroup l : limiters) {
if (l instanceof PluginLimitedRateGroup) {
result[pos++] = UtilitiesImpl.unwrapLmiter((PluginLimitedRateGroup) l);
}
}
if (pos == result.length) {
return (result);
}
RateLimiter[] result_mod = new RateLimiter[pos];
System.arraycopy(result, 0, result_mod, 0, pos);
return (result_mod);
}
Aggregations