All Projects → yusufaytas → dlock

yusufaytas / dlock

Licence: Apache-2.0, Unknown licenses found Licenses found Apache-2.0 LICENSE Unknown license-header.txt
Interval Lock

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to dlock

chronoman
Utility class to simplify use of timers created by setTimeout
Stars: ✭ 15 (-21.05%)
Mutual labels:  timeout, interval
create-fastify-app
An utility that help you to generate or add plugin to your Fastify project
Stars: ✭ 53 (+178.95%)
Mutual labels:  postgres
fluent-plugin-http-pull
The input plugin of fluentd to pull log from rest api.
Stars: ✭ 19 (+0%)
Mutual labels:  interval
realtime-flask-experiment
Experimenting with PostgreSQL's Listen/Notify and Flask-SocketIO
Stars: ✭ 22 (+15.79%)
Mutual labels:  postgres
mitoc-trips
The MIT Outing Club's trip management system
Stars: ✭ 30 (+57.89%)
Mutual labels:  postgres
go-pg-crud
Simple Postgres CRUD written in Golang
Stars: ✭ 44 (+131.58%)
Mutual labels:  postgres
cloud-tileserver
Serve mapbox vectortiles via AWS stack
Stars: ✭ 48 (+152.63%)
Mutual labels:  postgres
general-angular
Realtime Angular Admin/CRUD Front End App
Stars: ✭ 24 (+26.32%)
Mutual labels:  postgres
sandboxed-fs
Sandboxed Wrapper for Node.js File System API
Stars: ✭ 41 (+115.79%)
Mutual labels:  lock
candlestick-convert
[NPM] OHLCV Candlestick Batcher/Converter
Stars: ✭ 39 (+105.26%)
Mutual labels:  interval
graphql-to-sql
GraphQL model to SQL
Stars: ✭ 13 (-31.58%)
Mutual labels:  postgres
ChefAPI
API using FastAPI and PostgreSQL for sharing or keeping track of awesome food recipes Based on Oauth2 and JWT 💎
Stars: ✭ 16 (-15.79%)
Mutual labels:  postgres
postgresql-resilient
Automatic re-connection support for PostgreSQL.
Stars: ✭ 16 (-15.79%)
Mutual labels:  postgres
connect4
Connect 4️⃣Game
Stars: ✭ 1 (-94.74%)
Mutual labels:  postgres
erdiagram
Entity-Relationship diagram code generator library
Stars: ✭ 28 (+47.37%)
Mutual labels:  postgres
dynamic-engine
Monitor events in the background on Android.
Stars: ✭ 24 (+26.32%)
Mutual labels:  lock
LockerScreen
Android lock screen,slide to unlock ! 安卓锁屏,上滑解锁,效果酷炫,值得拥有!
Stars: ✭ 81 (+326.32%)
Mutual labels:  lock
shuttletracker
🚐 Shuttle tracking for RPI.
Stars: ✭ 44 (+131.58%)
Mutual labels:  postgres
docker-compose-moodle
This project quickly builds a local workspace for Moodle (Apache2, PHP-FPM with XDEBUG y Postgres) using containers for each of its main components. The local workspace is built and managed by Docker Compose
Stars: ✭ 33 (+73.68%)
Mutual labels:  postgres
api.pokedextracker.com
API for pokedextracker.com
Stars: ✭ 38 (+100%)
Mutual labels:  postgres

DLock

Apache License 2 Build Status

DLock is a library to get an interval lock. An Interval Lock is a lock where the acquirer acquires the lock for a certain amount of time. Once the lock is acquired, it won't be released till the interval ends. Note that, each of the Interval Lock implementations guarantees atomicity over processes and threads. The lock can only be acquired by only one process or thread at a time as expected. The implementations differ based on the technology.

Feedback and pull-requests are welcome!

Usage

Requirements and dependencies

  • Java 8
  • slf4j-api

Note that, there should be only one global lock.

Import project

maven

<dependency>
    <groupId>com.yusufaytas</groupId>
    <artifactId>dlock-spring</artifactId>
    <version>0.2.1</version>
</dependency>
<dependency>
    <groupId>com.yusufaytas</groupId>
    <artifactId>dlock-jdbc</artifactId>
    <version>0.2.1</version>
</dependency>

or you can import all

<dependency>
    <groupId>com.yusufaytas</groupId>
    <artifactId>dlock-all</artifactId>
    <version>0.2.1</version>
</dependency>

gradle

compile 'com.yusufaytas:dlock-spring:0.2.1'
compile 'com.yusufaytas:dlock-jdbc:0.2.1'

or you can import all

compile 'com.yusufaytas:dlock-all:0.2.1'

Add an Interval Lock Support

Spring Bean Config

An example lock support for Postgres can be added as follows

<!-- A bean for the lock implementation. Note that there should be only one global implementation-->
<bean id="postgresLock" class="com.yusufaytas.dlock.jdbc.PostgresIntervalLock">
  <constructor-arg type="javax.sql.DataSource" ref="lockDataSource"/>
</bean>
<!-- The lock gets auto-registered to the registrar -->
<bean id="lockRegistrar" class="com.yusufaytas.dlock.spring.SpringLockRegistrar"/>

Java Code

@Scheduled(cron = "*/1 * * * * *")
@TryLock(name = "example", owner = "dlock", lockFor = ONE_MINUTE)
public void exampleLock() {
  System.out.println("lock works");
}

Lock Implementations

Jdbc

You need to execute the DDL at the target database with appropriate permissions to make the lock work.

Postgres

We insert into postgres if there doesn't exist a lock. Please checkout the Postgres DDL.

MySQL

We get an exclusive lock on the lock table and insert a new lock if a conflicting lock doesn't exit. Please checkout the MySQL DDL.

Contributing

Compiling project

./mvnw clean install -Dgpg.skip

License Header

./mvnw license:format -Dgpg.skip
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].