Access Spark broadcast variable in different classes
<p>I am broadcasting a value in Spark Streaming application . But I am not sure how to access that variable in a different class than the class where it was broadcasted. </p>

<p>My code looks as follows:</p>

<pre><code>object AppMain{
  def main(args: Array[String]){
    //...
    val broadcastA = sc.broadcast(a)
    //..
    lines.foreachRDD(rdd =&gt; {
    val obj = AppObject1
    rdd.filter(p =&gt; obj.apply(p))
    rdd.count
  }
}

object AppObject1: Boolean{
  def apply(str: String){
    AnotherObject.process(str)
  }
}
object AnotherObject{
  // I want to use broadcast variable in this object
  val B = broadcastA.Value // compilation error here
  def process(): Boolean{
   //need to use B inside this method
  }
}
</code></pre>

<p>Can anyone suggest how to access broadcast variable in this case?</p>