@classmethod
def getActive(cls):
    """
        Return either the currently active StreamingContext (i.e., if there is a context started
        but not stopped) or None.
        """
    activePythonContext = cls._activeContext
    if activePythonContext is not None:
        activePythonContextJavaId = activePythonContext._jssc.ssc().hashCode()
        activeJvmContextOption = (activePythonContext._jvm.StreamingContext
            .getActive())
        if activeJvmContextOption.isEmpty():
            cls._activeContext = None
        elif activeJvmContextOption.get().hashCode(
            ) != activePythonContextJavaId:
            cls._activeContext = None
            raise Exception(
                "JVM's active JavaStreamingContext is not the JavaStreamingContext backing the action Python StreamingContext. This is unexpected."
                )
    return cls._activeContext
