Skip to content

Commit

Permalink
Cleanup, javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 25, 2016
1 parent 4db425d commit bdb2b42
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
37 changes: 32 additions & 5 deletions community/common/src/main/java/org/neo4j/time/Clocks.java
Expand Up @@ -22,27 +22,54 @@
import java.time.Clock;
import java.util.concurrent.TimeUnit;

/**
* This class consists of {@code static} utility methods for operating
* on clocks. These utilities include factory methods for different type of clocks.
*/
public class Clocks
{
private static final Clock SYSTEM_CLOCK = Clock.systemUTC();

private Clocks()
{
// non-instantiable
}

/**
* Returns system clock.
* @return system clock
*/
public static Clock systemClock()
{
return SYSTEM_CLOCK;
}

public static Clock nanoClock()
/**
* Returns clock that allow to get current nanos.
* @return clock with nano time support
*/
public static SystemNanoClock nanoClock()
{
return new SystemNanoClock();
return SystemNanoClock.INSTANCE;
}

/**
* Return new fake clock instance.
* @return fake clock
*/
public static FakeClock fakeClock()
{
return fakeClock();
return new FakeClock();
}

public static FakeClock fakeClock( long delta, TimeUnit unit )
/**
* Return new fake clock instance.
* @param initialTime initial fake clock time
* @param unit initialTime fake clock time unit
* @return fake clock
*/
public static FakeClock fakeClock( long initialTime, TimeUnit unit )
{
return new FakeClock( delta, unit );
return new FakeClock( initialTime, unit );
}
}
12 changes: 6 additions & 6 deletions community/common/src/main/java/org/neo4j/time/FakeClock.java
Expand Up @@ -30,15 +30,15 @@
*/
public class FakeClock extends SystemNanoClock
{
private long nanos = 0;
private long nanoTime = 0;

FakeClock()
{
}

FakeClock( long delta, TimeUnit unit )
FakeClock( long initialTime, TimeUnit unit )
{
forward( delta, unit );
forward( initialTime, unit );
}

@Override
Expand All @@ -56,18 +56,18 @@ public Clock withZone( ZoneId zone )
@Override
public Instant instant()
{
return Instant.ofEpochMilli( TimeUnit.NANOSECONDS.toMillis( nanos ) );
return Instant.ofEpochMilli( TimeUnit.NANOSECONDS.toMillis( nanoTime ) );
}

@Override
public long nanos()
{
return nanos;
return nanoTime;
}

public FakeClock forward( long delta, TimeUnit unit )
{
nanos += unit.toNanos( delta );
nanoTime += unit.toNanos( delta );
return this;
}
}
Expand Up @@ -24,9 +24,13 @@
import java.time.ZoneId;
import java.time.ZoneOffset;

/**
* {@link Clock} that support nano time resolution.
* @see Clocks
*/
public class SystemNanoClock extends Clock
{
public static final SystemNanoClock INSTANCE = new SystemNanoClock();
static final SystemNanoClock INSTANCE = new SystemNanoClock();

protected SystemNanoClock()
{
Expand Down
Expand Up @@ -21,6 +21,7 @@

/**
* @deprecated please use {@link java.time.Clock} instead
* @see org.neo4j.time.Clocks
*/
@Deprecated
public interface Clock
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.neo4j.kernel.impl.transaction.tracing.TransactionEvent;
import org.neo4j.kernel.impl.transaction.tracing.TransactionTracer;
import org.neo4j.kernel.impl.util.JobScheduler;
import org.neo4j.time.Clocks;
import org.neo4j.time.SystemNanoClock;

public class DefaultTransactionTracer implements TransactionTracer, LogRotationMonitor
Expand Down Expand Up @@ -155,7 +156,7 @@ public void setReadOnly( boolean wasReadOnly )

public DefaultTransactionTracer( Monitor monitor, JobScheduler jobScheduler )
{
this( SystemNanoClock.INSTANCE, monitor, jobScheduler );
this( Clocks.nanoClock(), monitor, jobScheduler );
}

public DefaultTransactionTracer( SystemNanoClock clock, Monitor monitor, JobScheduler jobScheduler )
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.neo4j.kernel.impl.transaction.tracing.LogForceEvent;
import org.neo4j.kernel.impl.transaction.tracing.LogForceWaitEvent;
import org.neo4j.kernel.impl.util.JobScheduler;
import org.neo4j.time.Clocks;
import org.neo4j.time.SystemNanoClock;

public class DefaultCheckPointerTracer implements CheckPointTracer, CheckPointerMonitor
Expand Down Expand Up @@ -68,7 +69,7 @@ public LogForceEvent beginLogForce()

public DefaultCheckPointerTracer( Monitor monitor, JobScheduler jobScheduler )
{
this( SystemNanoClock.INSTANCE, monitor, jobScheduler );
this( Clocks.nanoClock(), monitor, jobScheduler );
}

public DefaultCheckPointerTracer( SystemNanoClock clock, Monitor monitor, JobScheduler jobScheduler )
Expand Down

0 comments on commit bdb2b42

Please sign in to comment.