A solvable model of hard rods with gravitational interactions