Methods Summary |
---|
protected long | getBlockCount()
return( max_mb_sem.getBlockCount());
|
public long | getIOTime()
return( io_time );
|
protected long | getQueueSize()
return( requests_queued );
|
protected long | getQueuedBytes()
return( request_bytes_queued );
|
protected void | getSpaceAllowance(DiskAccessRequestImpl request)
int mb_diff;
synchronized( torrent_dispatcher_map ){
int old_mb = (int)(request_bytes_queued/(1024*1024));
request_bytes_queued += request.getSize();
int new_mb = (int)(request_bytes_queued/(1024*1024));
mb_diff = new_mb - old_mb;
if ( mb_diff > max_mb_queued ){
// if this request is bigger than the max allowed queueable then easiest
// approach is to bump up the limit
max_mb_sem.releaseGroup( mb_diff - max_mb_queued );
max_mb_queued = mb_diff;
}
requests_queued++;
if ( requests_queued >= next_request_num_log ){
//System.out.println( "DAC:" + name + ": requests = " + requests_queued );
next_request_num_log += REQUEST_NUM_LOG_CHUNK;
}
if ( request_bytes_queued >= next_request_byte_log ){
//System.out.println( "DAC:" + name + ": bytes = " + request_bytes_queued );
next_request_byte_log += REQUEST_BYTE_LOG_CHUNK;
}
}
if ( mb_diff > 0 ){
max_mb_sem.reserveGroup( mb_diff );
}
|
public long | getTotalAggregatedBytes()
return( total_aggregated_bytes );
|
protected long | getTotalAggregatedRequests()
return( total_aggregated_requests_made );
|
public long | getTotalBytes()
return( total_bytes );
|
protected long | getTotalRequests()
return( total_requests );
|
public long | getTotalSingleBytes()
return( total_single_bytes );
|
protected long | getTotalSingleRequests()
return( total_single_requests_made );
|
public static void | main(java.lang.String[] args)
final groupSemaphore sem = new groupSemaphore( 9 );
for (int i=0;i<10;i++){
new Thread()
{
public void
run()
{
int count = 0;
while( true ){
int group =RandomUtils.generateRandomIntUpto( 10 );
System.out.println( Thread.currentThread().getName() + " reserving " + group );
sem.reserveGroup( group );
try{
Thread.sleep(5 + RandomUtils.generateRandomIntUpto(5));
}catch( Throwable e ){
}
sem.releaseGroup( group );
count++;
if ( count %100 == 0 ){
System.out.println( Thread.currentThread().getName() + ": " + count + " ops" );
}
}
}
}.start();
}
|
protected void | queueRequest(DiskAccessRequestImpl request)
requestDispatcher dispatcher;
if ( dispatchers.length == 1 ){
dispatcher = dispatchers[0];
}else{
synchronized( torrent_dispatcher_map ){
long now = System.currentTimeMillis();
boolean check = false;
if ( now - last_check > 60000 || now < last_check ){
check = true;
last_check = now;
}
if ( check ){
Iterator it = torrent_dispatcher_map.values().iterator();
while( it.hasNext()){
requestDispatcher d = (requestDispatcher)it.next();
long last_active = d.getLastRequestTime();
if ( now - last_active > 60000 ){
it.remove();
}else if ( now < last_active ){
d.setLastRequestTime( now );
}
}
}
TOTorrent torrent = request.getFile().getTorrentFile().getTorrent();
dispatcher = (requestDispatcher)torrent_dispatcher_map.get(torrent);
if ( dispatcher == null ){
int min_index = 0;
int min_size = Integer.MAX_VALUE;
for (int i=0;i<dispatchers.length;i++){
int size = dispatchers[i].size();
if ( size == 0 ){
min_index = i;
break;
}
if ( size < min_size ){
min_size = size;
min_index = i;
}
}
dispatcher = dispatchers[min_index];
torrent_dispatcher_map.put( torrent, dispatcher );
}
dispatcher.setLastRequestTime( now );
}
}
dispatcher.queue( request );
|
protected void | releaseSpaceAllowance(DiskAccessRequestImpl request)
int mb_diff;
synchronized( torrent_dispatcher_map ){
int old_mb = (int)(request_bytes_queued/(1024*1024));
request_bytes_queued -= request.getSize();
int new_mb = (int)(request_bytes_queued/(1024*1024));
mb_diff = old_mb - new_mb;
requests_queued--;
}
if ( mb_diff > 0 ){
max_mb_sem.releaseGroup( mb_diff );
}
|