Methods Summary |
---|
public void | addReadEntity(RateControlledEntity entity)Add the given entity to the controller for read processing.
try { entities_mon.enter();
if( entity.getPriority() == RateControlledEntity.PRIORITY_HIGH ) {
//copy-on-write
ArrayList high_new = new ArrayList( high_priority_entities.size() + 1 );
high_new.addAll( high_priority_entities );
high_new.add( entity );
high_priority_entities = high_new;
}
else {
//copy-on-write
ArrayList norm_new = new ArrayList( normal_priority_entities.size() + 1 );
norm_new.addAll( normal_priority_entities );
norm_new.add( entity );
normal_priority_entities = norm_new;
}
}
finally { entities_mon.exit(); }
|
private boolean | doHighPriorityRead()
return( doRead( getNextReadyHighPriorityEntity()));
|
private boolean | doNormalPriorityRead()
return( doRead( getNextReadyNormalPriorityEntity()));
|
private boolean | doRead(RateControlledEntity ready_entity)
if ( ready_entity != null ){
if ( AGGRESIVE_READ ){
// skip over failed readers to find a good one
if ( ready_entity.doProcessing( read_waiter ) ) {
progress_count++;
return( true );
}else{
non_progress_count++;
if ( entity_check_count - last_entity_check_count >= normal_priority_entities.size() + high_priority_entities.size() ){
last_entity_check_count = entity_check_count;
// force a wait
if ( read_waiter.waitForEvent( IDLE_SLEEP_TIME )){
wait_count++;
}
return( false);
}
return( true );
}
}else{
return( ready_entity.doProcessing( read_waiter ));
}
}
return false;
|
private RateControlledEntity | getNextReadyHighPriorityEntity()
ArrayList ref = high_priority_entities;
int size = ref.size();
int num_checked = 0;
while( num_checked < size ) {
entity_check_count++;
next_high_position = next_high_position >= size ? 0 : next_high_position; //make circular
RateControlledEntity entity = (RateControlledEntity)ref.get( next_high_position );
next_high_position++;
num_checked++;
if( entity.canProcess( read_waiter ) ) { //is ready
return entity;
}
}
return null; //none found ready
|
private RateControlledEntity | getNextReadyNormalPriorityEntity()
ArrayList ref = normal_priority_entities;
int size = ref.size();
int num_checked = 0;
while( num_checked < size ) {
entity_check_count++;
next_normal_position = next_normal_position >= size ? 0 : next_normal_position; //make circular
RateControlledEntity entity = (RateControlledEntity)ref.get( next_normal_position );
next_normal_position++;
num_checked++;
if( entity.canProcess( read_waiter ) ) { //is ready
return entity;
}
}
return null; //none found ready
|
private void | readProcessorLoop()
boolean check_high_first = true;
while( true ) {
loop_count++;
try {
if( check_high_first ) {
check_high_first = false;
if( !doHighPriorityRead() ) {
if( !doNormalPriorityRead() ) {
if ( read_waiter.waitForEvent( IDLE_SLEEP_TIME )){
wait_count++;
}
}
}
}
else {
check_high_first = true;
if( !doNormalPriorityRead() ) {
if( !doHighPriorityRead() ) {
if ( read_waiter.waitForEvent( IDLE_SLEEP_TIME )){
wait_count++;
}
}
}
}
}
catch( Throwable t ) {
Debug.out( "readProcessorLoop() EXCEPTION: ", t );
}
}
|
public void | removeReadEntity(RateControlledEntity entity)Remove the given entity from the controller.
try { entities_mon.enter();
if( entity.getPriority() == RateControlledEntity.PRIORITY_HIGH ) {
//copy-on-write
ArrayList high_new = new ArrayList( high_priority_entities );
high_new.remove( entity );
high_priority_entities = high_new;
}
else {
//copy-on-write
ArrayList norm_new = new ArrayList( normal_priority_entities );
norm_new.remove( entity );
normal_priority_entities = norm_new;
}
}
finally { entities_mon.exit(); }
|
public void | updateStats(java.util.Set types, java.util.Map values)
if ( types.contains( AzureusCoreStats.ST_NET_READ_CONTROL_LOOP_COUNT )){
values.put( AzureusCoreStats.ST_NET_READ_CONTROL_LOOP_COUNT, new Long( loop_count ));
}
if ( types.contains( AzureusCoreStats.ST_NET_READ_CONTROL_NP_COUNT )){
values.put( AzureusCoreStats.ST_NET_READ_CONTROL_NP_COUNT, new Long( non_progress_count ));
}
if ( types.contains( AzureusCoreStats.ST_NET_READ_CONTROL_P_COUNT )){
values.put( AzureusCoreStats.ST_NET_READ_CONTROL_P_COUNT, new Long( progress_count ));
}
if ( types.contains( AzureusCoreStats.ST_NET_READ_CONTROL_WAIT_COUNT )){
values.put( AzureusCoreStats.ST_NET_READ_CONTROL_WAIT_COUNT, new Long( wait_count ));
}
if ( types.contains( AzureusCoreStats.ST_NET_READ_CONTROL_ENTITY_COUNT )){
values.put( AzureusCoreStats.ST_NET_READ_CONTROL_ENTITY_COUNT, new Long( high_priority_entities.size() + normal_priority_entities.size()));
}
if ( types.contains( AzureusCoreStats.ST_NET_READ_CONTROL_CON_COUNT ) ||
types.contains( AzureusCoreStats.ST_NET_READ_CONTROL_READY_CON_COUNT )){
int ready_connections = 0;
int connections = 0;
ArrayList[] refs = { normal_priority_entities, high_priority_entities };
for (int i=0;i<refs.length;i++){
ArrayList ref = refs[i];
for (int j=0;j<ref.size();j++){
RateControlledEntity entity = (RateControlledEntity)ref.get( j );
connections += entity.getConnectionCount();
ready_connections += entity.getReadyConnectionCount( read_waiter );
}
}
values.put( AzureusCoreStats.ST_NET_READ_CONTROL_CON_COUNT, new Long( connections ));
values.put( AzureusCoreStats.ST_NET_READ_CONTROL_READY_CON_COUNT, new Long( ready_connections ));
}
|