All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sirius.biz.locks.JavaLockManager Maven / Gradle / Ivy

There is a newer version: 9.6
Show newest version
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.biz.locks;

import sirius.kernel.di.std.Register;

import javax.annotation.Nonnull;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Provides a fast implementation which is based on internal JVM locks.
 * 

* Note that this managed is not suitable for clusters, as locks are only held locally. */ @Register(classes = LockManager.class) public class JavaLockManager extends BasicLockManager { /** * Contains the name of this lock manager */ public static final String NAME = "java"; private Map locks = new HashMap<>(); @Nonnull @Override public String getName() { return NAME; } @Override protected int getMaxWait() { return 100; } @Override protected int getWaitIncrement() { return 10; } @Override protected int getInitialWait() { return 10; } @Override protected synchronized boolean acquireLock(String lockName) { if (locks.containsKey(lockName)) { return false; } locks.put(lockName, new LockInfo(lockName, "(local)", Thread.currentThread().getName(), LocalDateTime.now())); return true; } @Override public synchronized boolean isLocked(@Nonnull String lock) { return locks.containsKey(lock); } @Override public synchronized void unlock(String lock, boolean force) { locks.remove(lock); } @Override public synchronized List getLocks() { return new ArrayList<>(locks.values()); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy