[SPARK-3027] TaskContext: tighten the visibility and provide Java friendly callback API