com.sap.cloud.mt.subscription.TenantMutexFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multi-tenant-subscription Show documentation
Show all versions of multi-tenant-subscription Show documentation
Spring Boot Enablement Parent
/******************************************************************************
* © 2020 SAP SE or an SAP affiliate company. All rights reserved. *
******************************************************************************/
package com.sap.cloud.mt.subscription;
import java.util.concurrent.ConcurrentHashMap;
public class TenantMutexFactory {
private static final ConcurrentHashMap tenantToMutex = new ConcurrentHashMap<>();
private TenantMutexFactory() {
}
public static TenantMutex get(String tenantId) {
TenantMutex mutex = tenantToMutex.get(tenantId);
if (mutex != null) {
return mutex;
}
TenantMutex newMutex = new TenantMutex();
TenantMutex storedMutex = tenantToMutex.putIfAbsent(tenantId, newMutex);
if (storedMutex != null) {
return storedMutex;
} else {
return newMutex;
}
}
}