acsgh / scala-common   1.3.0

Apache License 2.0 GitHub

Common utils used in several projects

Scala versions: 3.x

scala-common

Common utils used in several projects

Build Status Maven Central

Log support

Forget about initiate your log just extends your class / object with

import com.acsgh.common.scala.log.LogSupport

object Foo extends LogSupport {
  log.info("Hello world")
}

Stop Watch

Utility to measure time in your code

import com.acsgh.common.scala.time.StopWatch
import com.acsgh.common.scala.log.LogLevel

val stopWatch = StopWatch.createStarted()
try{
// YOUR CODE HERE
} finally {
  stopWatch.printElapseTime("Important stuff", log, LogLevel.INFO)
}

It will print: 'Important stuff in 234 milliseconds'

Reentrant locks

Utility to run safe locking in scala

Simple

import com.acsgh.common.scala.lock.ReentrantLock

val simpleLock = ReentrantLock()

simpleLock.run{
 1 + 1
}

val result = simpleLock.get {
 1 + 1
}

Read/Write

import com.acsgh.common.scala.lock.ReentrantReadWriteLock

val simpleLock = ReentrantLock()

simpleLock.write{
 1 + 1
}

val writeResult = simpleLock.write {
 1 + 1
}

val readResult = simpleLock.read {
 1 + 1
}