Permalink
Browse files

Merge branch 'clock-sync' into 'master'

Clock sync

See merge request open-platform/chain!249
  • Loading branch information...
evgeny-krylov committed Oct 22, 2018
2 parents f4dc5bf + 14e2a56 commit 5404c4feeaebca0e8b25fcbe1ae28ba4cf63135b
Showing with 4 additions and 3 deletions.
  1. +4 −3 src/main/kotlin/io/openfuture/chain/network/component/time/Clock.kt
@@ -1,21 +1,22 @@
package io.openfuture.chain.network.component.time

import org.springframework.stereotype.Component
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.locks.ReadWriteLock
import java.util.concurrent.locks.ReentrantReadWriteLock

@Component
class Clock {

@Volatile private var offset: Long = 0
@Volatile private var offset: AtomicLong = AtomicLong()

private val lock: ReadWriteLock = ReentrantReadWriteLock()


fun currentTimeMillis(): Long {
lock.readLock().lock()
try {
return System.currentTimeMillis().plus(offset)
return System.currentTimeMillis().plus(offset.get())
} finally {
lock.readLock().unlock()
}
@@ -24,7 +25,7 @@ class Clock {
fun adjust(offset: Long) {
lock.writeLock().lock()
try {
this.offset = offset
this.offset.getAndAdd(offset)
} finally {
lock.writeLock().unlock()
}

0 comments on commit 5404c4f

Please sign in to comment.