Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get command line arguments when running an Akka Microkernel?

I have the Akka microkernel below:

class ServiceKernel extends Bootable {

  val system = ActorSystem("service-kernel")

  def startup = {
    system.actorOf(Props(new Boot(false))) ! Start
  }

  def shutdown = {
    system.shutdown()
  }
}

Because the kernel extends Bootable and not App, how would I access command line arguments used when starting the kernel? For instance if I run the kernel using start namespace.ServiceKernel -d rundevmode or similar. Thanks!

Additional Info

I thought it would be worth adding this information about the start up script in the microkernel. In /bin/start you notice the following:

#!/bin/sh

AKKA_HOME="$(cd "$(cd "$(dirname "$0")"; pwd -P)"/..; pwd)"
AKKA_CLASSPATH="$AKKA_HOME/config:$AKKA_HOME/lib/*"
JAVA_OPTS="-Xms256M -Xmx512M -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2"

java $JAVA_OPTS -cp "$AKKA_CLASSPATH" -Dakka.home="$AKKA_HOME" akka.kernel.Main "$@"

Although om-nom-nom originally suggested -D options, it looks like it's in use and the main start up parameter is being passed to the akka.kernel.Main class (which in this case would be the ServiceKernel class above).

like image 619
crockpotveggies Avatar asked Oct 21 '22 13:10

crockpotveggies


1 Answers

Here is the minimal example:

object Foo extends App {
    val debugModeOn = System.getProperty("debugmode") != null
    val msg = if (debugModeOn) "in debug mode" else "not in debug mode"
    println(msg)
}

» scala Foo -Ddebugmode
in debug mode
» scala Foo            
not in debug mode

You can do extra check to overcome this issue:

» scala Foo -Ddebugmode=false
in debug mode

P.S. you might also want to use Properties helper, that contains bunch of methods like propOrNone, propOrElse, etc

like image 63
om-nom-nom Avatar answered Oct 24 '22 11:10

om-nom-nom