Skip to content
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
18 changes: 8 additions & 10 deletions samples/scala-fibonacci-action/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@ name := "fibonacci-action"

organization := "com.akkaserverless.samples"
organizationHomepage := Some(url("https://akkaserverless.com"))
licenses := Seq(
("CC0", url("https://creativecommons.org/publicdomain/zero/1.0"))
)
licenses := Seq(("CC0", url("https://creativecommons.org/publicdomain/zero/1.0")))

scalaVersion := "2.13.6"

enablePlugins(AkkaserverlessPlugin)
enablePlugins(AkkaserverlessPlugin, JavaAppPackaging, DockerPlugin)
dockerBaseImage := "docker.io/library/adoptopenjdk:11-jre-hotspot"
dockerUsername := sys.props.get("docker.username")
dockerRepository := sys.props.get("docker.registry")
ThisBuild / dynverSeparator := "-"

Compile / scalacOptions ++= Seq(
"-target:11",
"-deprecation",
"-feature",
"-unchecked",
"-Xlog-reflective-calls",
"-Xlint"
)
Compile / javacOptions ++= Seq(
"-Xlint:unchecked",
"-Xlint:deprecation",
"-parameters" // for Jackson
"-Xlint")
Compile / javacOptions ++= Seq("-Xlint:unchecked", "-Xlint:deprecation", "-parameters" // for Jackson
)

Test / parallelExecution := false
Expand Down
3 changes: 3 additions & 0 deletions samples/scala-fibonacci-action/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
addSbtPlugin("com.akkaserverless" % "sbt-akkaserverless" % System.getProperty("akkaserverless-sdk.version", "0.7.2"))
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.8.1")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* This code was generated by Akka Serverless tooling.
* As long as this file exists it will not be re-generated.
* You are free to make changes to this file.
*/
package com.example.fibonacci

import com.akkaserverless.scalasdk.action.Action
import com.akkaserverless.scalasdk.action.ActionCreationContext

/** An action. */
class FibonacciAction(creationContext: ActionCreationContext) extends AbstractFibonacciAction {

private def isFibonacci(num: Long): Boolean = {
val isPerfectSquare = (n: Long) => {
val square = Math.sqrt(n.toDouble).toLong
square * square == n
}
isPerfectSquare(5 * num * num + 4) || isPerfectSquare(5 * num * num - 4)
}

private def nextFib(num: Long): Long = {
val result = num * (1 + Math.sqrt(5)) / 2.0;
Math.round(result)
}

/** Handler for "NextNumber". */
override def nextNumber(number: Number): Action.Effect[Number] = {
val num = number.value
if (isFibonacci(num))
effects.reply(Number(nextFib(num)))
else
effects.error(s"Input number is not a Fibonacci number, received '$num'")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.fibonacci

import com.akkaserverless.scalasdk.AkkaServerless
import org.slf4j.LoggerFactory

object Main {

private val log = LoggerFactory.getLogger("com.example.fibonacci.Main")

def createAkkaServerless(): AkkaServerless = {
// The AkkaServerlessFactory automatically registers any generated Actions, Views or Entities,
// and is kept up-to-date with any changes in your protobuf definitions.
// If you prefer, you may remove this and manually register these components in a
// `AkkaServerless()` instance.
AkkaServerlessFactory.withComponents(
new FibonacciAction(_))
}

def main(args: Array[String]): Unit = {
log.info("starting the Akka Serverless service")
createAkkaServerless().start()
}
}