class TransactionScopeKeyLocker implements KeyLocker {

    @Override
    public LockMonitor writeLock(final Object key,
                                 final long transactionId,
                                 final long timeout,
                                 final boolean strict) {
        final Map<Object, LockMonitor> locks = writeLocks;
        LockMonitor monitor = null;

        synchronized ( locks ) {
            monitor = locks.get( key );
            if ( monitor == null ) {
                monitor = new LockMonitor( new TransactionModificationLock( strict ), key );
                locks.put( key, monitor );
            }
            monitor.acquires++;
        }

        try {
            boolean locked = timeout == Long.MAX_VALUE ? monitor.lock.lock( transactionId ) : monitor.lock.tryLock(
                    transactionId,
                    timeout,
                    TimeUnit.MILLISECONDS );
            return locked ? monitor : null;
        }
        catch ( InterruptedException e ) {
            Thread.currentThread().interrupt();
            throw new SpaceException( Thread.currentThread().toString() + " has been interrupted", e );
        }
    }

}