FileDocCategorySizeDatePackage
SystemTime.javaAPI DocAzureus 3.0.3.410311Thu May 31 16:35:22 BST 2007org.gudy.azureus2.core3.util

SystemTime

public class SystemTime extends Object
Utility class to retrieve current system time, and catch clock backward time changes.

Fields Summary
public static final long
TIME_GRANULARITY_MILLIS
private static SystemTimeProvider
instance
private static volatile List
consumer_list
private static volatile List
clock_change_list
private static highPrecisionCounter
high_precision_counter
private static long
hpc_base_time
private static long
hpc_last_time
Constructors Summary
Methods Summary
public static longgetCurrentTime()

		return( instance.getTime());
	
public static longgetHighPrecisionCounter()

		if ( high_precision_counter == null ){

			AEDiagnostics.load15Stuff();

			synchronized( SystemTime.class ){

				long now = getCurrentTime();

				if ( now < hpc_last_time ){

					// clock's gone back, by at least

					long	gone_back_by_at_least = hpc_last_time - now;

					// all we can do is move the logical start time back too to ensure that our
					// counter doesn't got backwards

					hpc_base_time -= gone_back_by_at_least;
				}

				hpc_last_time = now;

				return((now - hpc_base_time) * 1000000 );
			}
		}else{

			return( high_precision_counter.nanoTime());
		}
	
public static longgetOffsetTime(long offsetMS)

		return instance.getTime() + offsetMS;
	
public static voidmain(java.lang.String[] args)

		for (int i=0;i<1;i++){

			//final int f_i = i;

			new Thread()
			{
				public void
				run()
				{
					/*
					  Average access_average 	= Average.getInstance( 1000, 10 );

					  long	last = SystemTime.getCurrentTime();

					  int	count = 0;

					  while( true ){

						  long	now = SystemTime.getCurrentTime();

						  long	diff = now - last;

						  System.out.println( "diff=" + diff );

						  last	= now;

						  access_average.addValue( diff );

						  count++;

						  if ( count == 33 ){

							  System.out.println( "AVERAGE " + f_i + " = " + access_average.getAverage());

							  count = 0;
						  }

						  try{
							  Thread.sleep( 3 );

						  }catch( Throwable e ){

						  }
					  }
					 */

					long start = SystemTime.getCurrentTime();

					while( true ){

						long now = SystemTime.getCurrentTime();

						System.out.println( now - start );

						try{
							Thread.sleep(1000);
						}catch( Throwable e ){

						}
					}
				}
			}.start();
		}
	
public static voidregisterClockChangeListener(org.gudy.azureus2.core3.util.SystemTime$consumer c)

		synchronized( instance ){

			List	new_list = new ArrayList( clock_change_list );

			new_list.add( c );

			clock_change_list	= new_list;
		}
	
public static voidregisterConsumer(org.gudy.azureus2.core3.util.SystemTime$consumer c)

		synchronized( instance ){

			List	new_list = new ArrayList( consumer_list );

			new_list.add( c );

			consumer_list	= new_list;
		}
	
public static voidregisterHighPrecisionCounter(org.gudy.azureus2.core3.util.SystemTime$highPrecisionCounter counter)

		high_precision_counter = counter;
	
public static voidunregisterClockChangeListener(org.gudy.azureus2.core3.util.SystemTime$consumer c)

		synchronized( instance ){

			List	new_list = new ArrayList( clock_change_list );

			new_list.remove( c );

			clock_change_list	= new_list;
		}  
	
public static voidunregisterConsumer(org.gudy.azureus2.core3.util.SystemTime$consumer c)

		synchronized( instance ){

			List	new_list = new ArrayList( consumer_list );

			new_list.remove( c );

			consumer_list	= new_list;
		}  
	
public static voiduseRawProvider()

	
	
		
		try{
			if ( System.getProperty( "azureus.time.use.raw.provider", "0" ).equals("1")){
							
				instance = new RawProvider();
				
			}else{
				
				instance = new SteppedProvider();
			}
		}catch( Throwable e ){
			
				// might be in applet...
			
			instance = new SteppedProvider();
		}
	
		if ( !( instance instanceof RawProvider )){
			
			instance = new RawProvider();
		}