Packages

  • package root

    Akka based micro service proving general leaderboard functionality for applications such as back-end game servers.

    Leaderboard Micro Service

    Akka based micro service proving general leaderboard functionality for applications such as back-end game servers.

    Overview

    Definition Classes
    root
  • package net
    Definition Classes
    root
  • package kolotyluk
    Definition Classes
    net
  • package scala
    Definition Classes
    kolotyluk
  • package extras

    Extra utilities for Scala developers.

    Extra Utilities

    Extra utilities for Scala developers.

    Some things it might have been nice to see in the standard Scala libraries, but are offered here instead. For example:

    object Main
      extends App
        with Configuration
        with Environment
        with Logging {
    
      // Safest way to indicate something is happening, don't rely on logging yet
      println(s"Starting ${getClass.getName}...")
    
      println("Reporting environment and configuration for troubleshooting purposes")
      println(environment.getEnvironmentReport())
      println(config.getConfigurationReport())
    
      // If logging is broken, hopefully there is enough output now for a diagnosis
      logger.info("Logging started")
    }

    Base 64 URL Identifiers

    Sometimes it's nice to encode a 128-bit UUID as a 22-character Base 64 URL String, such as "keAoZQECSwm0h7v6yw_3WQ". Normally a UUID is expressed as a 36-character string such as "91e02865-0102-4b09-b487-bbfacb0ff759", so this is a simple way of saving 14 characters in URL encoding. For example

    curl http://localhost/foo/keAoZQECSwm0h7v6yw_3WQ

    Would internally refer to a resource for "foo/91e02865-0102-4b09-b487-bbfacb0ff759"

    Definition Classes
    scala
  • Configuration
  • Environment
  • Identity
  • Internalized
  • InvalidBase64UrlToUuidException
  • Logging

package extras

Extra Utilities

Extra utilities for Scala developers.

Some things it might have been nice to see in the standard Scala libraries, but are offered here instead. For example:

object Main
  extends App
    with Configuration
    with Environment
    with Logging {

  // Safest way to indicate something is happening, don't rely on logging yet
  println(s"Starting ${getClass.getName}...")

  println("Reporting environment and configuration for troubleshooting purposes")
  println(environment.getEnvironmentReport())
  println(config.getConfigurationReport())

  // If logging is broken, hopefully there is enough output now for a diagnosis
  logger.info("Logging started")
}

Base 64 URL Identifiers

Sometimes it's nice to encode a 128-bit UUID as a 22-character Base 64 URL String, such as "keAoZQECSwm0h7v6yw_3WQ". Normally a UUID is expressed as a 36-character string such as "91e02865-0102-4b09-b487-bbfacb0ff759", so this is a simple way of saving 14 characters in URL encoding. For example

curl http://localhost/foo/keAoZQECSwm0h7v6yw_3WQ

Would internally refer to a resource for "foo/91e02865-0102-4b09-b487-bbfacb0ff759"

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. extras
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait Configuration extends Logging

    Extra features for Typesafe Config

    Enhanced Typesafe Config

    Extra features for Typesafe Config

    It is recommended that you extend this trait in your app, in the same style, but for local configuration. For example:

    trait Configuration extends net.kolotyluk.scala.extras.Configuration {
    
      config.setPathBase("net.flybynight.myapp")
    
      implicit class LocalConfiguration(val config: com.typesafe.config.Config) extends Logging  {
        import com.typesafe.config.Config
    
        // net.flybynight.myapp.akka.system.name
        def getAkkaSystemName(default: Some[String] = Some("myapp")): String  = config.getDefaultString("akka.system.name", default)
        def getRestAddress(default: Some[String] = Some("0.0.0.0")) : String = config.getDefaultString("rest.address", default)
        def getRestPort(default: Some[Int] = Some(8080)) : Int = config.getDefaultInt("rest.port", default, 0 to 65535)
      }
    }

    Good Separation of Concerns practice would be to make your configuration code as robust as possible. You main application should not handle any configuration problems, rather all configuration troubleshooting should be in your Configuration trait. In the main body of code you might use:

    val akkaSystemName = config.getAkkaSystemName()
    val restAddress = config.getRestAddress()
    val restPort = config.getRestPort()
  2. trait Environment extends AnyRef

    Some extra utilities for accessing the local system environment variables.

    Scala Environment Extras

    Some extra utilities for accessing the local system environment variables.

  3. class Internalized[T] extends AnyRef

    Because there are no duplicates in this class, obj1 eq obj2 is sufficient

    Class of Internalized Objects

    Because there are no duplicates in this class, obj1 eq obj2 is sufficient

    Behaves similar to java.lang.String#intern

  4. class InvalidBase64UrlToUuidException extends Exception
  5. trait Logging extends AnyRef

    It is recommended that you extend this trait in your app, in the same style, but for local configuration.

    Extra Logging Behavior

    It is recommended that you extend this trait in your app, in the same style, but for local configuration.

Value Members

  1. def base64UrlIdToUuid(base64UrlId: String): UUID

    Parse UUID from Base 64 URL String

    returns

    Unique Universal Identifier

    Exceptions thrown

    InvalidBase64UrlToUuidException when parsing fails

  2. def getFutureResult[I, O](input: Any, output: (I) ⇒ O)(implicit executor: ExecutionContext): Future[O]

    Given a input value which can return either a value or a Future(value), this function always returns a Future output value.

    Return a Future Result

    Given a input value which can return either a value or a Future(value), this function always returns a Future output value.

    Examples

    getFutureResult[Int,LeaderboardStatusResponse](
      leaderboard.getCount,
      count => LeaderboardStatusResponse(leaderboardUrlId, count))
    I

    Input Type

    O

    Output Type

    input

    value

    output

    function

    executor

    ExecutionContext for running Futures

    returns

    Future with Output Result

  3. def uuidToBase64UrlId(uuid: UUID): String

    Generate Base 64 URL String from UUID

    uuid

    Unique Universal Identifier

    returns

    Base 64 URL String

  4. object Identity
  5. object Internalized

    Behaves similar to java.lang.String#intern

    Maintain a Manifest of Objects

    Behaves similar to java.lang.String#intern

    This code is thread-safe

    Examples

    val id1 = UUID.fromString("02b9670c-afd4-4c39-b4d3-3c46ac4f1a9c")
    val id2 = UUID.fromString("02b9670c-afd4-4c39-b4d3-3c46ac4f1a9c")
    val id3 = UUID.fromString("02b9670c-afd4-4c39-b4d3-3c46ac4f1a9c")
    assert(id1 == id2)
    assert(! (id1 eq id2))
    assert(id1 == id3)
    assert(! (id1 eq id3))
    assert(id2 == id3)
    assert(! (id2 eq id3))
    assert(Internalized(id1) eq Internalized(id1))
    assert(Internalized(id2) eq Internalized(id3))

    Uses

    See also

    net.kolotyluk.scala.extras.InternalizedSpec

Inherited from AnyRef

Inherited from Any

Ungrouped