Methods Summary |
---|
public void | deregisterHelper(UploadHelper helper)
if( AUTO_SLOT_ENABLE ) {
picker.deregisterHelper( helper );
}
|
private UploadSession | getNextBestSession(java.util.LinkedList best)
count++;
System.out.print( "getNextBestSession [" +count+"] best.size=" +best.size()+ " " );
if( !best.isEmpty() ) {
UploadSession session = (UploadSession)best.removeFirst(); //get next
if( !isAlreadySlotted( session ) ) { //found an unslotted session
System.out.println( "OK found session [" +session.getStatsTrace()+ "]" );
return session;
}
System.out.println( "FAIL already-slotted session [" +session.getStatsTrace()+ "]" );
return getNextBestSession( best ); //oops, already been slotted, try again
}
return null;
|
public static com.aelitis.azureus.core.peermanager.uploadslots.UploadSlotManager | getSingleton()
return instance;
|
private boolean | isAlreadySlotted(UploadSession session)
for( int i=0; i < slots.length; i++ ) {
UploadSession s = slots[i].getSession();
if( s != null && s.isSameSession( session ) ) return true;
}
return false;
|
private UploadSession | pickOptSession()
int max = picker.getHelperCount(); //max number of sessions the picker will return before it loops back 'round
for( int i=0; i < max; i++ ) { //make sure we don't loop
UploadSession session = picker.pickNextOptimisticSession();
if( session != null && !isAlreadySlotted( session ) ) {
return session; //found!
}
}
return null; //no optimistic sessions
|
private void | printSlotStats()
System.out.println( "\nUPLOAD SLOTS [" +current_round+ "x]:" );
for( int i=0; i < slots.length; i++ ) {
UploadSlot slot = slots[i];
System.out.print( "[" +i+ "]: " );
String slot_type = slot.getSlotType() == UploadSlot.TYPE_NORMAL ? "NORM" : "OPTI";
long rem = slot.getExpireRound() - current_round;
String remaining = rem < 0 ? "" : " [" +rem+ "]rr";
String ses_trace = slot.getSession() == null ? "EMPTY" : slot.getSession().getStatsTrace();
System.out.println( slot_type + remaining+ " : " +ses_trace );
}
|
private void | process()
if( !AUTO_SLOT_ENABLE ) return;
current_round++;
ArrayList to_stop = new ArrayList();
//get a list of the best sessions, peers who are uploading to us in download mode
LinkedList best_sessions = picker.pickBestDownloadSessions( slots.length );
int best_size = best_sessions.size();
//go through all currently expired slots and pick sessions for next round
for( int i=0; i < slots.length; i++ ) {
UploadSlot slot = slots[i];
if( slot.getExpireRound() <= current_round ) { //expired
UploadSession session = slot.getSession();
if( session != null ) {
to_stop.add( session ); //make sure it gets stopped
slot.setSession( null ); //clear slot
}
if( slot.getSlotType() == UploadSlot.TYPE_OPTIMISTIC ) { //optimistic
//pick new session for optimistic upload
session = pickOptSession();
if( session == null ) {
continue;
}
if( session.getSessionType() == UploadSession.TYPE_SEED ) { //place first seed session in a normal slot
best_sessions.addFirst( session ); //put at front of good list to ensure it gets picked
//pick a new optimistic session, whatever type
session = pickOptSession();
if( session == null ) continue;
}
slot.setSession( session ); //place the new session in the slot
slot.setExpireRound( current_round + EXPIRE_OPTIMISTIC ); //set the new expire time
}
else { //normal
session = getNextBestSession( best_sessions ); //get the next "best" session
if( session == null && best_size == slots.length ) {
Debug.out( "session == null && best_size == slots.length" );
}
if( session == null ) { //no download mode peers, must be only seeding; or all best are already slotted
session = pickOptSession(); //just pick the next optimistic
if( session == null ) continue; //no optimistic either
}
slot.setSession( session ); //place the session in the slot
slot.setExpireRound( current_round + ( session.getSessionType() == UploadSession.TYPE_SEED ? EXPIRE_SEED : EXPIRE_NORMAL ) ); //set the new expire time
}
}
}
//start and stop sessions for the round
//filter out sessions allowed to continue another round, so we don't stop-start them
for( Iterator it = to_stop.iterator(); it.hasNext(); ) {
UploadSession stop_s = (UploadSession)it.next();
for( int i=0; i < slots.length; i++ ) {
if( stop_s.isSameSession( slots[i].getSession() ) ) { //need to do this because two session objects can represent the same peer
it.remove();
break;
}
}
}
//stop discontinued sessions
for( Iterator it = to_stop.iterator(); it.hasNext(); ) {
UploadSession session = (UploadSession)it.next();
session.stop();
}
//ensure sessions are started
for( int i=0; i < slots.length; i++ ) {
UploadSession s = slots[i].getSession();
if( s != null ) s.start();
}
printSlotStats();
|
public void | registerHelper(UploadHelper helper)
if( AUTO_SLOT_ENABLE ) {
picker.registerHelper( helper );
}
|
public void | updateHelper(UploadHelper helper)Notify of helper state change (i.e. priority changed)
if( AUTO_SLOT_ENABLE ) {
picker.updateHelper( helper );
}
|