Skip to content

Instantly share code, notes, and snippets.

@Rogach
Created August 1, 2017 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rogach/e401f0c6111cd15fcf3c907813dcd7b8 to your computer and use it in GitHub Desktop.
Save Rogach/e401f0c6111cd15fcf3c907813dcd7b8 to your computer and use it in GitHub Desktop.
import org.rogach.scallop._
import java.io.{Serializable, ByteArrayOutputStream, ByteArrayInputStream, ObjectOutputStream, ObjectInputStream}
val args = Array("--apples", "33")
private class ConfSerializationProxy(@transient private var orig: Conf) extends Serializable {
private def writeObject(out: ObjectOutputStream) {
out.defaultWriteObject()
out.writeObject(orig.args.toArray)
}
private def readObject(in: ObjectInputStream) {
in.defaultReadObject()
orig = new Conf(in.readObject().asInstanceOf[Array[String]].toList)
}
private def readResolve(): AnyRef = orig
}
class Conf(arguments: Seq[String]) extends org.rogach.scallop.ScallopConf(arguments) with Serializable {
val apples = opt[Int](required = true)
verify()
protected final def writeReplace(): AnyRef = new ConfSerializationProxy(this)
}
val conf = new Conf(args)
sc.parallelize(Seq(1,2,3)).map { i =>
println(s"$i: " + conf.apples() + " apples")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment