FileDocCategorySizeDatePackage
DiskManagerReadRequestImpl.javaAPI DocAzureus 3.0.3.44269Wed Jul 19 13:36:20 BST 2006org.gudy.azureus2.core3.disk.impl.access.impl

DiskManagerReadRequestImpl

public class DiskManagerReadRequestImpl extends DiskManagerRequestImpl implements org.gudy.azureus2.core3.disk.DiskManagerReadRequest
This class represents a Bittorrent Request. and a time stamp to know when it was created. Request may expire after some time, which is used to determine who is snubbed.
author
Olivier

Fields Summary
private static final int
EXPIRATION_TIME
private final int
pieceNumber
private final int
offset
private final int
length
private final int
hashcode
private long
timeCreated
private boolean
flush
private boolean
cancelled
private boolean
use_cache
Constructors Summary
public DiskManagerReadRequestImpl(int _pieceNumber, int _offset, int _length)
Parameters correspond to bittorrent parameters

param
pieceNumber
param
offset
param
length

  
  
  
                
           
  
    pieceNumber = _pieceNumber;
    offset = _offset;
    length = _length;
    
    timeCreated = SystemTime.getCurrentTime();
    
    hashcode = pieceNumber + offset + length;
  
Methods Summary
public voidcancel()

		cancelled	= true;
	
public booleanequals(java.lang.Object o)
We override the equals method 2 requests are equals if all their bt fields (piece number, offset, length) are equal

    if(! (o instanceof DiskManagerReadRequestImpl))
      return false;
	DiskManagerReadRequestImpl otherRequest = (DiskManagerReadRequestImpl) o;
    if(otherRequest.pieceNumber != this.pieceNumber)
      return false;
    if(otherRequest.offset != this.offset)
      return false;
    if(otherRequest.length != this.length)
      return false;
      
    return true;
  
public booleangetFlush()

		return( flush );
	
public intgetLength()

    return this.length;
  
protected java.lang.StringgetName()

		return( "Read: " + pieceNumber + ",off=" + offset +",len=" + length + ",fl=" + flush + ",uc=" + use_cache );
	
public intgetOffset()

    return this.offset;
  
public intgetPieceNumber()

    return this.pieceNumber;
  
public longgetTimeCreated(long now)

      if (this.timeCreated >now)
          this.timeCreated =now;
    return this.timeCreated;
  
public booleangetUseCache()

		return( use_cache );
	
public inthashCode()

    return hashcode;
  
public booleanisCancelled()

		return( cancelled );
	
public booleanisExpired()
Method to determine if a Request has expired

return
true if the request is expired

      final long now =SystemTime.getCurrentTime();
      if (now >=this.timeCreated)
          return (now -this.timeCreated) >EXPIRATION_TIME;
      //time error
      this.timeCreated =now;
      return false;
  
public voidreSetTime(long now)
Allow some more time to the request. Typically used on peers that have just sent some data, we reset all other requests to give them extra time.

      timeCreated =now;
  
public voidresetTime(long now)

	  reSetTime(now);
  
public voidsetFlush(boolean _flush)

		flush	= _flush;
	
public voidsetUseCache(boolean cache)

		use_cache	= cache;