Created
August 1, 2017 18:11
-
-
Save Rogach/e401f0c6111cd15fcf3c907813dcd7b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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