flex-lock

Simple generic lock interface, designed for remote locking accross network nodes.

License

License

GroupId

GroupId

com.nofacepress
ArtifactId

ArtifactId

flex-lock
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

flex-lock
Simple generic lock interface, designed for remote locking accross network nodes.
Project URL

Project URL

https://github.com/nofacepress/flex-lock
Project Organization

Project Organization

No Face Press, LLC
Source Code Management

Source Code Management

https://github.com/nofacepress/flex-lock

Download flex-lock

How to add to project

<!-- https://jarcasting.com/artifacts/com.nofacepress/flex-lock/ -->
<dependency>
    <groupId>com.nofacepress</groupId>
    <artifactId>flex-lock</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.nofacepress/flex-lock/
implementation 'com.nofacepress:flex-lock:1.0.1'
// https://jarcasting.com/artifacts/com.nofacepress/flex-lock/
implementation ("com.nofacepress:flex-lock:1.0.1")
'com.nofacepress:flex-lock:jar:1.0.1'
<dependency org="com.nofacepress" name="flex-lock" rev="1.0.1">
  <artifact name="flex-lock" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.nofacepress', module='flex-lock', version='1.0.1')
)
libraryDependencies += "com.nofacepress" % "flex-lock" % "1.0.1"
[com.nofacepress/flex-lock "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.apache.commons : commons-dbcp2 jar 2.7.0

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok Optional jar 1.18.10

test (2)

Group / Artifact Type Version
com.h2database : h2 jar 1.4.200
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

Flex Lock

Flexible lock interface for locking shared network resources using a database or for simple locking with-in an application.

Build status: build_status

Maven Setup

<dependency>
  <groupId>com.nofacepress</groupId>
  <artifactId>flex-lock</artifactId>
  <version>1.0.1</version>
</dependency>

Usage Example

		FlexLockRegistry<String> registry = new DatabaseFlexLockRegistry<String>(DB_DRIVER, DB_URL, DB_USER, DB_PASSWORD, DB_TABLE_NAME);
		FlexLockHandle<String> handle = registry.lock("key", 1000);
		registry.unlock(handle);

Database Setup

Default Setup

CREATE TABLE IF NOT EXISTS `AnyTableName` (
	`mutex_id` VARCHAR(128) NOT NULL,
	`expire_time` LONG DEFAULT 0 NOT NULL,
	`owner` VARCHAR(36),
	PRIMARY KEY (`mutex_id`)
);

Integration with an existing table

In this case, the lock table is a part of an existing table.

CREATE TABLE IF NOT EXISTS `AnotherTableName` (
	`another_id` LONG NOT NULL,
	-- Other fields
	`expires` LONG DEFAULT 0 NOT NULL,
	`owner` VARCHAR(36),
	PRIMARY KEY (`another_id`)
);

To work with this table, specify the primary key

		FlexLockRegistry<Long> registry = new DatabaseFlexLockRegistry<Long>(DB_DRIVER, DB_URL, DB_USER, DB_PASSWORD, "AnotherTableName", "another_id", "expires", "owner");
		FlexLockHandle<Long> handle = registry.lock(101L, 1000);
		registry.unlock(handle);

The registry keeps locks in memory. If there is going to be a very large number of keys, it is best to use the adapter directly.

    final FlexLockAdapter<Long> adapter = new DatabaseFlexLockAdapter<Long>(DB_DRIVER, DB_URL, DB_USER, DB_PASSWORD, "AnotherTableName", "another_id", "expires", "owner");
		
	final FlexLockHandle handle = new FlexLockHandle();  // used to uniquely identify the owner
	
    final long now = System.currentTimeMillis();
    final boolean success = adapter.tryLock(101L, handle, now, now + 10000);
    adapter.unlock(101L, handle);
com.nofacepress

noface.press LLC

Versions

Version
1.0.1
0.0.3
0.0.2