Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ use AtomicLong instead a local long as a logical timestamp #1

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
+ use AtomicLong instead a local long as a logical timestamp
  • Loading branch information
vkuptcov committed Mar 14, 2015
commit fd0ec6ebabafd72d14de9549cd53f59b4ea0c820
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
*.class
target/
*~
build.sbt
project
stapl-core.iml
11 changes: 5 additions & 6 deletions src/main/scala/stapl/core/pdp/TimestampGenerator.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package stapl.core.pdp

import java.util.concurrent.atomic.AtomicLong

/**
* Class responsible for generating a globally unique timestamp. These timestamps
* are longs that have an ascending order. Notice that these timestamps do not
Expand All @@ -15,22 +17,19 @@ trait TimestampGenerator {
}

/**
* Simple implementation of a timing server: just increment a local variable.
* Simple implementation of a timing server.
* Not a robust implementation for distributed scenarios: it is hard to replace it
* by another timing server because the count is not known externally.
*/
class SimpleTimestampGenerator extends TimestampGenerator {

private var counter: Long = 0
private val counter = new AtomicLong(0)

/**
* Simple implementation using an internal counter. This leads to a possible
* exception in uniqueness in case of long roll-over, but this is assumed to fall
* outside the expected lifespan of any request that might still be executing system-wide.
*/
override def getTimestamp(): String = {
counter = counter + 1
s"$counter"
}
override def getTimestamp(): String = counter.incrementAndGet().toString

}