[SPARK-3543] Write TaskContext in Java and expose it through a static accessor.

fyi all these should be primitives rather than boxed Integers/Longs/Booleans. I'm going to fix it in a separate pr.