se.laz.casual.jca.CasualResourceManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of casual-jca Show documentation
Show all versions of casual-jca Show documentation
Casual JCA - Resource Adapter for Casual middleware.
/*
* Copyright (c) 2017 - 2018, The casual project. All rights reserved.
*
* This software is licensed under the MIT license, https://opensource.org/licenses/MIT
*/
package se.laz.casual.jca;
import javax.transaction.xa.Xid;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
public final class CasualResourceManager
{
private static final CasualResourceManager INSTANCE = new CasualResourceManager();
private final AtomicInteger currentRMId = new AtomicInteger(1);
private final ConcurrentMap pendingRequests = new ConcurrentHashMap<>();
private CasualResourceManager()
{}
public static final CasualResourceManager getInstance()
{
return INSTANCE;
}
public final Integer getNextId()
{
return currentRMId.getAndIncrement();
}
public void put(final Xid xid)
{
if(pendingRequests.containsKey(xid))
{
throw new CasualResourceAdapterException("xid: " + xid + " already stored");
}
pendingRequests.put(xid, true);
}
public void remove(final Xid xid)
{
pendingRequests.remove(xid);
}
public boolean isPending(final Xid xid)
{
return pendingRequests.containsKey(xid);
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder("CasualResourceManager{");
sb.append("currentRMId=").append(currentRMId);
sb.append('}');
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy