---
name: "Lucy::Store::LockFactory"
section: "3pm"
platform: "linux"
package: "liblucy-perl"
version: "0.3.3-7+b1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/Lucy::Store::LockFactory"
---

# Lucy::Store::LockFactory(3pm)

Create Locks.

## NAME

Lucy::Store::LockFactory - Create Locks.

## SYNOPSIS

```
    use Sys::Hostname qw( hostname );
    my $hostname = hostname() or die "Can't get unique hostname";
    my $folder = Lucy::Store::FSFolder->new(
        path => '/path/to/index',
    );
    my $lock_factory = Lucy::Store::LockFactory->new(
        folder => $folder,
        host   => $hostname,
    );
    my $write_lock = $lock_factory->make_lock(
        name     => 'write',
        timeout  => 5000,
        interval => 100,
    );
```

## DESCRIPTION

LockFactory is used to spin off interprocess mutex locks used by various index reading and writing components.  The default implementation uses lockfiles, but LockFactory subclasses which are implemented using alternatives such as *flock()* are possible.

## CONSTRUCTORS

### new( *\[labeled params\]* )

```
    my $lock_factory = Lucy::Store::LockFactory->new(
        folder => $folder,      # required
        host   => $hostname,    # required
    );
```

- •

  **folder** - A Lucy::Store::Folder.

- •

  **host** - An identifier which should be unique per-machine.

## METHODS

### make\_lock( *\[labeled params\]* )

Return a Lock object, which, once *obtain()* returns successfully, maintains an exclusive lock on a resource.

- •

  **name** - A file-system-friendly id which identifies the resource to be locked.

- •

  **timeout** - Time in milliseconds to keep retrying before abandoning the attempt to *obtain()* a lock.

- •

  **interval** - Time in milliseconds between retries.

### make\_shared\_lock( *\[labeled params\]* )

Return a Lock object for which *shared()* returns true, and which maintains a non-exclusive lock on a resource once *obtain()* returns success.

- •

  **name** - A file-system-friendly id which identifies the resource to be locked.

- •

  **timeout** - Time in milliseconds to keep retrying before abandoning the attempt to *obtain()* a lock.

- •

  **interval** - Time in milliseconds between retries.

## INHERITANCE

Lucy::Store::LockFactory isa Lucy::Object::Obj.
