Dynamics of lotic ecosystems