Ergodic theorems for convex sets and operator algebras