Methods Summary |
---|
public void | configurationSaved()
// only pick up configuration changes when saved
readConfigValues();
writeStats();
|
public static StatsWriterPeriodic | create(com.aelitis.azureus.core.AzureusCore _core)
try{
class_mon.enter();
if ( singleton == null ){
singleton = new StatsWriterPeriodicImpl(_core);
}
return( singleton );
}finally{
class_mon.exit();
}
|
protected void | readConfigValues()
config_enabled = COConfigurationManager.getBooleanParameter( "Stats Enable" );
config_period = COConfigurationManager.getIntParameter( "Stats Period" );
config_dir = COConfigurationManager.getStringParameter( "Stats Dir" );
config_file = COConfigurationManager.getStringParameter( "Stats File" );
|
public void | start()
try{
class_mon.enter();
start_count++;
if ( start_count == 1 ){
current_thread =
new AEThread("StatsWriter"){
public void
runSupport()
{
update();
}
};
current_thread.setDaemon( true );
current_thread.start();
}
}finally{
class_mon.exit();
}
|
public void | stop()
try{
class_mon.enter();
start_count--;
if ( start_count == 0 ){
current_thread = null;
}
}finally{
class_mon.exit();
}
|
protected void | update()
readConfigValues();
while( true ){
try{
class_mon.enter();
if ( Thread.currentThread() != current_thread ){
break;
}
writeStats();
}catch( Throwable e ){
Debug.printStackTrace(e );
}finally{
class_mon.exit();
}
try{
int period;
if ( !config_enabled ){
period = DEFAULT_SLEEP_PERIOD;
}else{
period = config_period*1000;
}
if ( period > DEFAULT_SLEEP_PERIOD ){
period = DEFAULT_SLEEP_PERIOD;
}
Thread.sleep( period );
}catch( InterruptedException e ){
Debug.printStackTrace( e );
}
}
|
protected void | writeStats()
if ( !config_enabled ){
return;
}
int period = config_period;
long now = SystemTime.getCurrentTime() /1000;
if( now < last_write_time ) { //time went backwards
last_write_time = now;
}
// if we have a 1 second period then now-last-write_time will often be 0 (due to the
// rounding of SystemTime) and the stats won't be written - hence the check against
// (period-1). Its only
if ( now - last_write_time < ( period - 1 ) ){
return;
}
last_write_time = now;
try{
String dir = config_dir;
dir = dir.trim();
if ( dir.length() == 0 ){
dir = File.separator;
}
String file_name = dir;
if ( !file_name.endsWith( File.separator )){
file_name = file_name + File.separator;
}
String file = config_file;
if ( file.trim().length() == 0 ){
file = DEFAULT_STATS_FILE_NAME;
}
file_name += file;
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "Stats Logged to '" + file_name + "'"));
new StatsWriterImpl( core ).write( file_name );
}catch( Throwable e ){
Logger.log(new LogEvent(LOGID, "Stats Logging fails", e));
}
|