📄 systemtime.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SystemTime.java
package org.gudy.azureus2.core3.util;
import java.io.PrintStream;
import java.util.*;
// Referenced classes of package org.gudy.azureus2.core3.util:
// AEDiagnostics, Debug, Average
public class SystemTime
{
public static interface ChangeListener
{
public abstract void clockChanged(long l, long l1);
}
public static interface HighPrecisionCounter
{
public abstract long nanoTime();
}
protected static class RawProvider
implements SystemTimeProvider
{
private static final int STEPS_PER_SECOND = 40;
private final Thread updater;
private volatile long adjustedTimeOffset;
public long getTime()
{
return System.currentTimeMillis();
}
public long getMonoTime()
{
return getTime() - adjustedTimeOffset;
}
public long getSteppedMonoTime()
{
return getMonoTime();
}
private RawProvider()
{
System.out.println("SystemTime: using raw time provider");
updater = new Thread("SystemTime") {
long last_time;
final RawProvider this$0;
public void run()
{
do
{
long current_time = getTime();
if (last_time != 0L)
{
long offset = current_time - last_time;
if (offset < 0L || offset > 5000L)
{
adjustedTimeOffset+= = offset;
for (Iterator it = SystemTime.clock_change_list.iterator(); it.hasNext(); ((ChangeListener)it.next()).clockChanged(current_time, offset));
}
}
last_time = current_time;
List consumer_list_ref = SystemTime.systemTimeConsumers;
for (int i = 0; i < consumer_list_ref.size(); i++)
{
TickConsumer cons = (TickConsumer)consumer_list_ref.get(i);
try
{
cons.consume(current_time);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
consumer_list_ref = SystemTime.monotoneTimeConsumers;
long adjustedTime = current_time - adjustedTimeOffset;
for (int i = 0; i < consumer_list_ref.size(); i++)
{
TickConsumer cons = (TickConsumer)consumer_list_ref.get(i);
try
{
cons.consume(adjustedTime);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
try
{
Thread.sleep(25L);
}
catch (Exception e)
{
Debug.printStackTrace(e);
}
} while (true);
}
{
this$0 = RawProvider.this;
super(x0);
}
};
updater.setDaemon(true);
updater.setPriority(10);
updater.start();
}
}
protected static class SteppedProvider
implements SystemTimeProvider
{
private static final int STEPS_PER_SECOND = 40;
private final Thread updater;
private volatile long stepped_time;
private volatile long currentTimeOffset;
private volatile long last_approximate_time;
private volatile int access_count;
private volatile int slice_access_count;
private volatile int access_average_per_slice;
private volatile int drift_adjusted_granularity;
private volatile long stepped_mono_time;
public long getTime()
{
return getMonoTime() + currentTimeOffset;
}
public long getMonoTime()
{
long adjusted_time = stepped_time;
long averageSliceStep = access_average_per_slice;
if (averageSliceStep > 0L)
{
long sliceStep = (long)(drift_adjusted_granularity * slice_access_count) / averageSliceStep;
if (sliceStep >= (long)drift_adjusted_granularity)
sliceStep = drift_adjusted_granularity - 1;
adjusted_time += sliceStep;
}
access_count++;
slice_access_count++;
if (adjusted_time < last_approximate_time)
adjusted_time = last_approximate_time;
else
last_approximate_time = adjusted_time;
return adjusted_time;
}
public long getSteppedMonoTime()
{
return stepped_mono_time;
}
private SteppedProvider()
{
currentTimeOffset = System.currentTimeMillis();
stepped_time = 0L;
updater = new Thread("SystemTime") {
final SteppedProvider this$0;
public void run()
{
long adjustedTimeOffset = currentTimeOffset;
Average access_average = Average.getInstance(1000, 10);
Average drift_average = Average.getInstance(1000, 10);
long lastOffset = adjustedTimeOffset;
long lastSecond = -1000L;
int tick_count = 0;
do
{
long rawTime = System.currentTimeMillis();
long newMonotoneTime = rawTime - adjustedTimeOffset;
long delta = newMonotoneTime - stepped_time;
if (delta < 0L || delta > 1000L)
{
stepped_time+= = 25L;
adjustedTimeOffset = rawTime - stepped_time;
} else
{
stepped_time = newMonotoneTime;
}
if (++tick_count == 40)
{
if (lastOffset != adjustedTimeOffset)
{
long change = adjustedTimeOffset - lastOffset;
for (Iterator it = SystemTime.clock_change_list.iterator(); it.hasNext(); ((ChangeListener)it.next()).clockChanged(rawTime, change));
lastOffset = adjustedTimeOffset;
currentTimeOffset = adjustedTimeOffset;
}
long drift = stepped_time - lastSecond - 1000L;
lastSecond = stepped_time;
drift_average.addValue(drift);
drift_adjusted_granularity = (int)(25L + drift_average.getAverage() / 40L);
access_average.addValue(access_count);
access_average_per_slice = (int)(access_average.getAverage() / 40L);
access_count = 0;
tick_count = 0;
}
slice_access_count = 0;
stepped_mono_time = stepped_time;
List consumersRef = SystemTime.monotoneTimeConsumers;
for (int i = 0; i < consumersRef.size(); i++)
{
TickConsumer cons = (TickConsumer)consumersRef.get(i);
try
{
cons.consume(stepped_time);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
consumersRef = SystemTime.systemTimeConsumers;
long adjustedTime = stepped_time + currentTimeOffset;
for (int i = 0; i < consumersRef.size(); i++)
{
TickConsumer cons = (TickConsumer)consumersRef.get(i);
try
{
cons.consume(adjustedTime);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
try
{
Thread.sleep(25L);
}
catch (Exception e)
{
Debug.printStackTrace(e);
}
} while (true);
}
{
this$0 = SteppedProvider.this;
super(x0);
}
};
updater.setDaemon(true);
updater.setPriority(10);
updater.start();
}
}
protected static interface SystemTimeProvider
{
public abstract long getTime();
public abstract long getMonoTime();
public abstract long getSteppedMonoTime();
}
public static interface TickConsumer
{
public abstract void consume(long l);
}
public static final long TIME_GRANULARITY_MILLIS = 25L;
private static SystemTimeProvider instance;
private static volatile List systemTimeConsumers = new ArrayList();
private static volatile List monotoneTimeConsumers = new ArrayList();
private static volatile List clock_change_list = new ArrayList();
private static HighPrecisionCounter high_precision_counter;
private static long hpc_base_time;
private static long hpc_last_time;
public SystemTime()
{
}
public static void useRawProvider()
{
if (!(instance instanceof RawProvider))
instance = new RawProvider();
}
public static long getCurrentTime()
{
return instance.getTime();
}
public static long getMonotonousTime()
{
return instance.getMonoTime();
}
public static long getSteppedMonotonousTime()
{
return instance.getSteppedMonoTime();
}
public static long getOffsetTime(long offsetMS)
{
return instance.getTime() + offsetMS;
}
public static void registerConsumer(TickConsumer c)
{
synchronized (instance)
{
List new_list = new ArrayList(systemTimeConsumers);
new_list.add(c);
systemTimeConsumers = new_list;
}
}
public static void unregisterConsumer(TickConsumer c)
{
synchronized (instance)
{
List new_list = new ArrayList(systemTimeConsumers);
new_list.remove(c);
systemTimeConsumers = new_list;
}
}
public static void registerMonotonousConsumer(TickConsumer c)
{
synchronized (instance)
{
List new_list = new ArrayList(monotoneTimeConsumers);
new_list.add(c);
monotoneTimeConsumers = new_list;
}
}
public static void unregisterMonotonousConsumer(TickConsumer c)
{
synchronized (instance)
{
List new_list = new ArrayList(monotoneTimeConsumers);
new_list.remove(c);
monotoneTimeConsumers = new_list;
}
}
public static void registerClockChangeListener(ChangeListener c)
{
synchronized (instance)
{
List new_list = new ArrayList(clock_change_list);
new_list.add(c);
clock_change_list = new_list;
}
}
public static void unregisterClockChangeListener(ChangeListener c)
{
synchronized (instance)
{
List new_list = new ArrayList(clock_change_list);
new_list.remove(c);
clock_change_list = new_list;
}
}
public static long getHighPrecisionCounter()
{
if (high_precision_counter != null)
break MISSING_BLOCK_LABEL_64;
AEDiagnostics.load15Stuff();
/*<invalid signature>*/java.lang.Object local = org/gudy/azureus2/core3/util/SystemTime;
JVM INSTR monitorenter ;
long now;
now = getCurrentTime();
if (now < hpc_last_time)
{
long gone_back_by_at_least = hpc_last_time - now;
hpc_base_time -= gone_back_by_at_least;
}
hpc_last_time = now;
return (now - hpc_base_time) * 0xf4240L;
Exception exception;
exception;
throw exception;
return high_precision_counter.nanoTime();
}
public static void registerHighPrecisionCounter(HighPrecisionCounter counter)
{
high_precision_counter = counter;
}
public static void main(String args[])
{
for (int i = 0; i < 1; i++)
(new Thread() {
public void run()
{
long cstart = SystemTime.getCurrentTime();
long mstart = SystemTime.getMonotonousTime();
System.out.println("alter system clock to see differences between monotonous and current time");
long cLastRound = cstart;
long mLastRound = mstart;
do
{
long mnow = SystemTime.getMonotonousTime();
long cnow = SystemTime.getCurrentTime();
System.out.println((new StringBuilder()).append("current: ").append(cnow - cstart).append(" monotonous:").append(mnow - mstart).append(" delta current:").append(cnow - cLastRound).append(" delta monotonous:").append(mnow - mLastRound).toString());
cLastRound = cnow;
mLastRound = mnow;
try
{
Thread.sleep(15L);
}
catch (Throwable e) { }
} while (true);
}
}).start();
}
static
{
try
{
if (System.getProperty("azureus.time.use.raw.provider", "0").equals("1"))
{
System.out.println("Warning: Using Raw Provider, monotonous time might be inaccurate");
instance = new RawProvider();
} else
{
instance = new SteppedProvider();
}
}
catch (Throwable e)
{
instance = new SteppedProvider();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -