A period is attached to the present moment:
The Present Perfect Continuous Inclusive.
He has been sleepping for three hours.
Он спит уже три часа.The Present Perfect Inclusive.
I've known him for ten years.
Я знаю его десять лет.
A period of time is attached to a definite moment in the past:
The Past Perfect Continuous Inclusive.
She said that he had been sleeping for three hours.
Она сказала, что спит уже три часа.The Past Perfect Inclusive.
She said that she had known him.
Она сказала, что она его знает.
A period is not attached to any definite moment.
When I was a child, I lived in this town for several years, that's why I know it well.
Когда я был ребенком, я жил в этом городе несколько лет, поэтому я хорошо его знаю.When a period is not attached to any definite moment, the action is regarded as a simple action in the past and it is usually expressed by the Past Indefinite.
Yesterday I played the piano for two hours.
Вчера я играл на пианино два часа.Note: The Past Continuous can be used emphatically to emphasize the duration of an action.
I was waiting for you at the entrance to the metro station for a whole hour yesterday.
Я вчера ждал тебя у входа в метро целый час.