Refactor lock logic into a common class.
Merge pull request #324 from continuuity/feature/refactor-locks

Refactor lock logic into a common class.