java.util.concurrent.locks.ReadWriteLock Java Examples

The following examples show how to use java.util.concurrent.locks.ReadWriteLock. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CtrlDrbdProxyEnableApiCallHandler.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public CtrlDrbdProxyEnableApiCallHandler(
    @ApiContext AccessContext apiCtxRef,
    ScopeRunner scopeRunnerRef,
    CtrlTransactionHelper ctrlTransactionHelperRef,
    CtrlSatelliteUpdateCaller ctrlSatelliteUpdateCallerRef,
    CtrlApiDataLoader ctrlApiDataLoaderRef,
    ResponseConverter responseConverterRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    @Named(CoreModule.RSC_DFN_MAP_LOCK) ReadWriteLock rscDfnMapLockRef,
    CtrlDrbdProxyHelper drbdProxyHelperRef
)
{
    apiCtx = apiCtxRef;
    scopeRunner = scopeRunnerRef;
    ctrlTransactionHelper = ctrlTransactionHelperRef;
    ctrlSatelliteUpdateCaller = ctrlSatelliteUpdateCallerRef;
    ctrlApiDataLoader = ctrlApiDataLoaderRef;
    responseConverter = responseConverterRef;
    nodesMapLock = nodesMapLockRef;
    rscDfnMapLock = rscDfnMapLockRef;
    drbdProxyHelper = drbdProxyHelperRef;
}
 
Example #2
Source File: UpdateMonitorImpl.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public UpdateMonitorImpl(
    @Named(CoreModule.RECONFIGURATION_LOCK)  ReadWriteLock reconfigurationLockRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    @Named(CoreModule.RSC_DFN_MAP_LOCK) ReadWriteLock rscDfnMapLockRef,
    @Named(CoreModule.STOR_POOL_DFN_MAP_LOCK) ReadWriteLock storPoolDfnMapLockRef
)
{
    reconfigurationLock = reconfigurationLockRef;
    nodesMapLock = nodesMapLockRef;
    rscDfnMapLock = rscDfnMapLockRef;
    storPoolDfnMapLock = storPoolDfnMapLockRef;

    // Don't start with 0 to ensure the controller mirrors our fullSyncId
    fullSyncId = new AtomicLong(2);

    awaitedUpdateId = new AtomicLong(0);
}
 
Example #3
Source File: CoreDocumentSynchronizationConfig.java    From stitch-android-sdk with Apache License 2.0 6 votes vote down vote up
private CoreDocumentSynchronizationConfig(
    final MongoCollection<CoreDocumentSynchronizationConfig> docsColl,
    final MongoNamespace namespace,
    final BsonValue documentId,
    final ChangeEvent<BsonDocument> lastUncommittedChangeEvent,
    final long lastResolution,
    final BsonDocument lastVersion,
    final ReadWriteLock docsLock,
    final boolean isStale,
    final boolean isPaused,
    final long lastKnownHash
) {
  this.docsColl = docsColl;
  this.namespace = namespace;
  this.documentId = documentId;
  this.lastResolution = lastResolution;
  this.lastKnownRemoteVersion = lastVersion;
  this.lastUncommittedChangeEvent = lastUncommittedChangeEvent;
  this.docLock = docsLock;
  this.isStale = isStale;
  this.isPaused = isPaused;
  this.lastKnownHash = lastKnownHash;
}
 
Example #4
Source File: LuceneEngine.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
public LuceneEngine(IndexWriterConfig config, Path path) {
    try {
        this.config = config;
        Directory transienceDirectory = new ByteBuffersDirectory();
        this.transienceManager = new TransienceManager((IndexWriterConfig) BeanUtils.cloneBean(config), transienceDirectory);
        Directory persistenceDirectory = FSDirectory.open(path);
        this.persistenceManager = new PersistenceManager((IndexWriterConfig) BeanUtils.cloneBean(config), persistenceDirectory);
        this.searcher = new LuceneSearcher(this.transienceManager, this.persistenceManager);

        this.semaphore = new AtomicInteger();
        ReadWriteLock lock = new ReentrantReadWriteLock();
        this.readLock = lock.readLock();
        this.writeLock = lock.writeLock();
    } catch (Exception exception) {
        throw new StorageException(exception);
    }
}
 
Example #5
Source File: CmdDisplayLockStatus.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
private void reportRwLock(PrintStream output, String label, ReadWriteLock readWriteLock)
{
    ReentrantReadWriteLock reentrantReadWriteLock = (ReentrantReadWriteLock) readWriteLock;

    boolean writeLocked = reentrantReadWriteLock.isWriteLocked();
    boolean fair = reentrantReadWriteLock.isFair();
    boolean queued = reentrantReadWriteLock.hasQueuedThreads();
    int readerCount = reentrantReadWriteLock.getReadLockCount();

    output.printf(
        RWLOCK_FORMAT,
        label,
        writeLocked ? "Y" : "N",
        fair ? "Y" : "N",
        queued ? "Y" : "N",
        readerCount
    );
}
 
Example #6
Source File: ContainerImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public ContainerImpl(Configuration conf, Dispatcher dispatcher,
    NMStateStoreService stateStore, ContainerLaunchContext launchContext,
    Credentials creds, NodeManagerMetrics metrics,
    ContainerTokenIdentifier containerTokenIdentifier) {
  this.daemonConf = conf;
  this.dispatcher = dispatcher;
  this.stateStore = stateStore;
  this.launchContext = launchContext;
  this.containerTokenIdentifier = containerTokenIdentifier;
  this.containerId = containerTokenIdentifier.getContainerID();
  this.resource = containerTokenIdentifier.getResource();
  this.diagnostics = new StringBuilder();
  this.credentials = creds;
  this.metrics = metrics;
  user = containerTokenIdentifier.getApplicationSubmitter();
  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  this.readLock = readWriteLock.readLock();
  this.writeLock = readWriteLock.writeLock();

  stateMachine = stateMachineFactory.make(this);
}
 
Example #7
Source File: LockGuardFactory.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public LockGuardFactory(
    @Named(CoreModule.RECONFIGURATION_LOCK) ReadWriteLock reconfigurationLockRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    @Named(CoreModule.RSC_DFN_MAP_LOCK) ReadWriteLock rscDfnMapLockRef,
    @Named(CoreModule.STOR_POOL_DFN_MAP_LOCK) ReadWriteLock storPoolDfnMapLockRef,
    @Named(CoreModule.CTRL_CONF_LOCK) ReadWriteLock ctrlConfigLockRef,
    @Named(CoreModule.KVS_MAP_LOCK) ReadWriteLock kvsMapLockRef,
    @Named(CoreModule.RSC_GROUP_MAP_LOCK) ReadWriteLock rscGrpMapLockRef
)
{
    reconfigurationLock = reconfigurationLockRef;
    nodesMapLock = nodesMapLockRef;
    rscDfnMapLock = rscDfnMapLockRef;
    storPoolDfnMapLock = storPoolDfnMapLockRef;
    ctrlConfigLock = ctrlConfigLockRef;
    kvsMapLock = kvsMapLockRef;
    rscGrpMapLock = rscGrpMapLockRef;
}
 
Example #8
Source File: RocksDBStore.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public RocksDBStore(String name, ColumnFamilyDescriptor family, ColumnFamilyHandle handle, RocksDB db, int stripes,
                    MetaManager metaManager) {
  super();
  this.family = family;
  this.name = name;
  this.db = db;
  this.parallel = stripes;
  this.handle = handle;
  this.sharedLocks = new AutoCloseableLock[stripes];
  this.exclusiveLocks = new AutoCloseableLock[stripes];
  this.metaManager = metaManager;

  for (int i = 0; i < stripes; i++) {
    ReadWriteLock core = new ReentrantReadWriteLock();
    sharedLocks[i] = new AutoCloseableLock(core.readLock());
    exclusiveLocks[i] = new AutoCloseableLock(core.writeLock());
  }

  registerMetrics();
}
 
Example #9
Source File: StorPoolInternalCallHandler.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public StorPoolInternalCallHandler(
    ErrorReporter errorReporterRef,
    @ApiContext AccessContext apiCtxRef,
    CtrlTransactionHelper ctrlTransactionHelperRef,
    CtrlApiDataLoader ctrlApiDataLoaderRef,
    ResponseConverter responseConverterRef,
    CtrlStltSerializer ctrlStltSerializerRef,
    Provider<Peer> peerRef,
    @PeerContext Provider<AccessContext> peerAccCtxRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    @Named(CoreModule.STOR_POOL_DFN_MAP_LOCK) ReadWriteLock storPoolDfnMapLockRef
)
{
    errorReporter = errorReporterRef;
    apiCtx = apiCtxRef;
    ctrlTransactionHelper = ctrlTransactionHelperRef;
    ctrlApiDataLoader = ctrlApiDataLoaderRef;
    responseConverter = responseConverterRef;
    ctrlStltSerializer = ctrlStltSerializerRef;
    peer = peerRef;
    peerAccCtx = peerAccCtxRef;
    nodesMapLock = nodesMapLockRef;
    storPoolDfnMapLock = storPoolDfnMapLockRef;
}
 
Example #10
Source File: CtrlFullSyncResponseApiCallHandler.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public CtrlFullSyncResponseApiCallHandler(
    @ApiContext AccessContext apiCtxRef,
    ScopeRunner scopeRunnerRef,
    CtrlSatelliteConnectionNotifier ctrlSatelliteConnectionNotifierRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    @Named(CoreModule.RSC_DFN_MAP_LOCK) ReadWriteLock rscDfnMapLockRef,
    Provider<Peer> satelliteProviderRef
)
{
    apiCtx = apiCtxRef;
    scopeRunner = scopeRunnerRef;
    ctrlSatelliteConnectionNotifier = ctrlSatelliteConnectionNotifierRef;
    nodesMapLock = nodesMapLockRef;
    rscDfnMapLock = rscDfnMapLockRef;
    satelliteProvider = satelliteProviderRef;
}
 
Example #11
Source File: NodeInternalCallHandler.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public NodeInternalCallHandler(
    ErrorReporter errorReporterRef,
    @ApiContext AccessContext apiCtxRef,
    CtrlStltSerializer ctrlStltSerializerRef,
    Provider<Peer> peerRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    CtrlApiDataLoader ctrlApiDataLoaderRef
)
{
    errorReporter = errorReporterRef;
    apiCtx = apiCtxRef;
    ctrlStltSerializer = ctrlStltSerializerRef;
    peer = peerRef;
    nodesMapLock = nodesMapLockRef;
    ctrlApiDataLoader = ctrlApiDataLoaderRef;
}
 
Example #12
Source File: LockInstance.java    From summerframework with Apache License 2.0 6 votes vote down vote up
public LockInstance createLockIfNotExist() {
    if (getLock() != null) {
        return this;
    }
    Assert.notNull(getName(), "Lock name can not be null");
    switch (getType()) {
        case DEFAULT:
            Lock lock = lockFactory.getLock(this);
            this.setLock(lock);
            break;
        case READ:
            ReadWriteLock read = lockFactory.getReadWriteLock(this);
            this.setReadWriteLock(read);
            this.setLock(read.readLock());
            break;
        case WRITE:
            ReadWriteLock write = lockFactory.getReadWriteLock(this);
            this.setReadWriteLock(write);
            this.setLock(write.writeLock());
            break;
        default:
            Assert.notNull(this.getType(), "LockType cant not be null");
            break;
    }
    return this;
}
 
Example #13
Source File: StltApiCallHandlerUtils.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public StltApiCallHandlerUtils(
    ErrorReporter errorReporterRef,
    @ApiContext AccessContext apiCtxRef,
    ControllerPeerConnector controllerPeerConnectorRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    @Named(CoreModule.STOR_POOL_DFN_MAP_LOCK) ReadWriteLock storPoolDfnMapLockRef,
    @Named(CoreModule.RSC_DFN_MAP_LOCK) ReadWriteLock rscDfnMapLockRef,
    StorageLayer storageLayerRef,
    DeviceProviderMapper deviceProviderMapperRef,
    LockGuardFactory lockGuardFactoryRef,
    Provider<DeviceManager> devMgrProviderRef
)
{
    errorReporter = errorReporterRef;
    apiCtx = apiCtxRef;
    controllerPeerConnector = controllerPeerConnectorRef;
    nodesMapLock = nodesMapLockRef;
    storPoolDfnMapLock = storPoolDfnMapLockRef;
    rscDfnMapLock = rscDfnMapLockRef;
    storageLayer = storageLayerRef;
    deviceProviderMapper = deviceProviderMapperRef;
    lockGuardFactory = lockGuardFactoryRef;
    devMgr = devMgrProviderRef;
}
 
Example #14
Source File: ReadWriteLockDemo1.java    From LearningOfThinkInJava with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    //创建并发访问的账户
    MyCount myCount = new MyCount("95599200901215522", 10000);
    //创建一个锁对象
    ReadWriteLock lock = new ReentrantReadWriteLock(false);
    //创建一个线程池
    ExecutorService pool = Executors.newFixedThreadPool(2);
    //创建一些并发访问用户,一个信用卡,存的存,取的取,好热闹啊
    User u1 = new User("张三", myCount, -4000, lock, true);
    User u2 = new User("张三他爹", myCount, 6000, lock, false);
    User u3 = new User("张三他弟", myCount, -8000, lock, false);
    User u4 = new User("张三", myCount, 800, lock, false);
    User u5 = new User("张三他爹", myCount, 0, lock, true);
    //在线程池中执行各个用户的操作
    pool.execute(u1);
    pool.execute(u2);
    pool.execute(u3);
    pool.execute(u4);
    pool.execute(u5);
    //关闭线程池
    pool.shutdown();
}
 
Example #15
Source File: VlmAllocatedFetcherProto.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Inject
public VlmAllocatedFetcherProto(
    ScopeRunner scopeRunnerRef,
    CtrlStltSerializer ctrlStltSerializerRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    @Named(CoreModule.RSC_DFN_MAP_LOCK) ReadWriteLock rscDfnMapLockRef,
    @Named(CoreModule.STOR_POOL_DFN_MAP_LOCK) ReadWriteLock storPoolDfnMapLockRef,
    CtrlApiDataLoader ctrlApiDataLoaderRef,
    NodeRepository nodeRepositoryRef,
    @PeerContext Provider<AccessContext> peerAccCtxRef
)
{
    scopeRunner = scopeRunnerRef;
    ctrlStltSerializer = ctrlStltSerializerRef;
    nodesMapLock = nodesMapLockRef;
    rscDfnMapLock = rscDfnMapLockRef;
    storPoolDfnMapLock = storPoolDfnMapLockRef;
    ctrlApiDataLoader = ctrlApiDataLoaderRef;
    nodeRepository = nodeRepositoryRef;
    peerAccCtx = peerAccCtxRef;
}
 
Example #16
Source File: EventFileManager.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public void releaseWriteLock(final File file) {
    final String key = getMapKey(file);

    boolean updated = false;
    while (!updated) {
        final Tuple<ReadWriteLock, Integer> tuple = lockMap.get(key);
        if (tuple == null) {
            throw new IllegalMonitorStateException("Lock is not owned");
        }

        // If this is the only reference to the lock, remove it from the map and then unlock.
        if (tuple.getValue() <= 1) {
            updated = lockMap.remove(key, tuple);
            if (updated) {
                tuple.getKey().writeLock().unlock();
            }
        } else {
            final Tuple<ReadWriteLock, Integer> updatedTuple = new Tuple<>(tuple.getKey(), tuple.getValue() - 1);
            updated = lockMap.replace(key, tuple, updatedTuple);
            if (updated) {
                tuple.getKey().writeLock().unlock();
            }
        }
    }
}
 
Example #17
Source File: SatelliteCoreModule.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void configure()
{
    bind(String.class).annotatedWith(Names.named(CoreModule.MODULE_NAME))
        .toInstance(LinStor.SATELLITE_MODULE);

    bind(ReadWriteLock.class).annotatedWith(Names.named(STLT_CONF_LOCK))
        .toInstance(new ReentrantReadWriteLock(true));

    bind(ControllerPeerConnector.class).to(ControllerPeerConnectorImpl.class);
    // bind(UpdateMonitor.class).to(UpdateMonitorImpl.class);
    // bind(DeviceManager.class).to(DeviceManagerImpl.class);
    // install(new FactoryModuleBuilder()
    //    .implement(DeviceManagerImpl.DeviceHandlerInvocation.class,
    //       DeviceManagerImpl.DeviceHandlerInvocation.class)
    //    .build(DeviceManagerImpl.DeviceHandlerInvocationFactory.class));

    bind(Path.class).annotatedWith(Names.named(DRBD_CONFIG_PATH)).toInstance(
        FileSystems.getDefault().getPath(CoreModule.CONFIG_PATH)
    );
}
 
Example #18
Source File: ControllerDebugModule.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Provides
CmdDisplayNodes cmdDisplayNodes(
    @Named(CoreModule.RECONFIGURATION_LOCK) ReadWriteLock reconfigurationLockRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    NodeRepository nodeRepository,
    CoreModule.NodesMap nodesMap
)
    throws AccessDeniedException
{
    return new CmdDisplayNodes(
        reconfigurationLockRef,
        nodesMapLockRef,
        nodeRepository::getObjProt,
        nodesMap
    );
}
 
Example #19
Source File: ControllerDebugModule.java    From linstor-server with GNU General Public License v3.0 6 votes vote down vote up
@Provides
CmdDisplayResourceDfn cmdDisplayResourceDfn(
    @Named(CoreModule.RECONFIGURATION_LOCK) ReadWriteLock reconfigurationLockRef,
    @Named(CoreModule.RSC_DFN_MAP_LOCK) ReadWriteLock rscDfnMapLockRef,
    ResourceDefinitionRepository resourceDefinitionRepository,
    CoreModule.ResourceDefinitionMap resourceDefinitionMap
)
    throws AccessDeniedException
{
    return new CmdDisplayResourceDfn(
        reconfigurationLockRef,
        rscDfnMapLockRef,
        resourceDefinitionRepository::getObjProt,
        resourceDefinitionMap
    );
}
 
Example #20
Source File: LocalMessageCache.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private ReadWriteLock getLockInProcessQueue(ProcessQueue pq) {
    try {
        return (ReadWriteLock) FieldUtils.readDeclaredField(pq, "lockTreeMap", true);
    } catch (IllegalAccessException e) {
        return null;
    }
}
 
Example #21
Source File: DefaultConnectionManager.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ProhibitedExceptionCaught")
private <T> T withReadLock(ReadWriteLock lock, CheckedSupplier<T> supplier) {
    try {
        lock.readLock().lock();
        return supplier.get();
    } catch (Throwable t) {
        return ExceptionUtils.rethrow(t);
    } finally {
        lock.readLock().unlock();
    }
}
 
Example #22
Source File: StltNodeApiCallHandler.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
@Inject
StltNodeApiCallHandler(
    ErrorReporter errorReporterRef,
    @ApiContext AccessContext apiCtxRef,
    DeviceManager deviceManagerRef,
    @Named(CoreModule.RECONFIGURATION_LOCK) ReadWriteLock reconfigurationLockRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    CoreModule.NodesMap nodesMapRef,
    NodeSatelliteFactory nodeFactoryRef,
    NodeConnectionFactory nodeConnectionFactoryRef,
    NetInterfaceFactory netInterfaceFactoryRef,
    ControllerPeerConnector controllerPeerConnectorRef,
    Provider<TransactionMgr> transMgrProviderRef
)
{
    errorReporter = errorReporterRef;
    apiCtx = apiCtxRef;
    deviceManager = deviceManagerRef;
    reconfigurationLock = reconfigurationLockRef;
    nodesMapLock = nodesMapLockRef;
    nodesMap = nodesMapRef;
    nodeFactory = nodeFactoryRef;
    nodeConnectionFactory = nodeConnectionFactoryRef;
    netInterfaceFactory = netInterfaceFactoryRef;
    controllerPeerConnector = controllerPeerConnectorRef;
    transMgrProvider = transMgrProviderRef;
}
 
Example #23
Source File: LocalizedResource.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public LocalizedResource(LocalResourceRequest rsrc, Dispatcher dispatcher) {
  this.rsrc = rsrc;
  this.dispatcher = dispatcher;
  this.ref = new LinkedList<ContainerId>();

  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  this.readLock = readWriteLock.readLock();
  this.writeLock = readWriteLock.writeLock();

  this.stateMachine = stateMachineFactory.make(this);
}
 
Example #24
Source File: SatelliteDebugModule.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
@Provides
CmdDisplayResourceDfn cmdDisplayResourceDfn(
    @Named(CoreModule.RECONFIGURATION_LOCK) ReadWriteLock reconfigurationLockRef,
    @Named(CoreModule.RSC_DFN_MAP_LOCK) ReadWriteLock rscDfnMapLockRef,
    CoreModule.ResourceDefinitionMap rscDfnMapRef
)
{
    return new CmdDisplayResourceDfn(reconfigurationLockRef, rscDfnMapLockRef, null, rscDfnMapRef);
}
 
Example #25
Source File: CmdDisplayResourceDfn.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
public CmdDisplayResourceDfn(
    ReadWriteLock reconfigurationLockRef,
    ReadWriteLock rscDfnMapLockRef,
    Supplier<ObjectProtection> rscDfnMapProtRef,
    CoreModule.ResourceDefinitionMap rscDfnMapRef
)
{
    super(
        new String[]
        {
            "DspRscDfn"
        },
        "Display resource definition(s)",
        "Displays information about one or multiple resource definition(s)",
        PARAMETER_DESCRIPTIONS,
        null
    );

    reconfigurationLock = reconfigurationLockRef;
    rscDfnMapLock = rscDfnMapLockRef;
    rscDfnMapProt = rscDfnMapProtRef;
    rscDfnMap = rscDfnMapRef;

    lister = new FilteredObjectLister<>(
        "resource definition",
        "resource definition",
        new ResourceDefinitionHandler()
    );
}
 
Example #26
Source File: EventFileManager.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private ReadWriteLock updateCount(final File file, final Function<Integer, Integer> update) {
    final String key = getMapKey(file);
    boolean updated = false;

    Tuple<ReadWriteLock, Integer> updatedTuple = null;
    while (!updated) {
        final Tuple<ReadWriteLock, Integer> tuple = lockMap.computeIfAbsent(key, k -> new Tuple<>(new ReentrantReadWriteLock(), 0));
        final Integer updatedCount = update.apply(tuple.getValue());
        updatedTuple = new Tuple<>(tuple.getKey(), updatedCount);
        updated = lockMap.replace(key, tuple, updatedTuple);
    }

    return updatedTuple.getKey();
}
 
Example #27
Source File: ControllerPeerConnectorImpl.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
@Inject
public ControllerPeerConnectorImpl(
    CoreModule.NodesMap nodesMapRef,
    CoreModule.ResourceDefinitionMap rscDfnMapRef,
    CoreModule.StorPoolDefinitionMap storPoolDfnMapRef,
    @Named(CoreModule.RECONFIGURATION_LOCK) ReadWriteLock reconfigurationLockRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef,
    @Named(CoreModule.RSC_DFN_MAP_LOCK) ReadWriteLock rscDfnMapLockRef,
    @Named(CoreModule.STOR_POOL_DFN_MAP_LOCK) ReadWriteLock storPoolDfnMapLockRef,
    ErrorReporter errorReporterRef,
    @SystemContext AccessContext sysCtxRef,
    StorPoolDefinitionSatelliteFactory storPoolDefinitionFactoryRef,
    NodeSatelliteFactory nodeFactoryRef,
    Provider<TransactionMgr> transMgrProviderRef,
    CommonSerializer commonSerializerRef
)
{
    nodesMap = nodesMapRef;
    rscDfnMap = rscDfnMapRef;
    storPoolDfnMap = storPoolDfnMapRef;
    reconfigurationLock = reconfigurationLockRef;
    nodesMapLock = nodesMapLockRef;
    rscDfnMapLock = rscDfnMapLockRef;
    storPoolDfnMapLock = storPoolDfnMapLockRef;
    errorReporter = errorReporterRef;
    sysCtx = sysCtxRef;
    nodeFactory = nodeFactoryRef;
    transMgrProvider = transMgrProviderRef;
    commonSerializer = commonSerializerRef;
}
 
Example #28
Source File: DynamoDB.java    From strongbox with Apache License 2.0 5 votes vote down vote up
public static DynamoDB fromCredentials(AWSCredentialsProvider awsCredentials,
                                       ClientConfiguration clientConfiguration,
                                       SecretsGroupIdentifier groupIdentifier,
                                       ReadWriteLock readWriteLock) {
    AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
        .withCredentials(awsCredentials)
        .withClientConfiguration(verifyOrThrow(transformAndVerifyOrThrow(clientConfiguration)))
        .withRegion(groupIdentifier.region.getName())
        .build();
    return new DynamoDB(client, awsCredentials, clientConfiguration, groupIdentifier, readWriteLock);
}
 
Example #29
Source File: SimpleLRUCache.java    From dorado with Apache License 2.0 5 votes vote down vote up
private SimpleLRUCache(int capacity) {
	this.cache = new LRUMap<K, V>(capacity);
	ReadWriteLock lock = new ReentrantReadWriteLock();

	this.r = lock.readLock();
	this.w = lock.writeLock();
}
 
Example #30
Source File: SatelliteStateHelper.java    From linstor-server with GNU General Public License v3.0 5 votes vote down vote up
@Inject
public SatelliteStateHelper(
    @ApiContext AccessContext accCtxRef,
    CoreModule.NodesMap nodesMapRef,
    @Named(CoreModule.NODES_MAP_LOCK) ReadWriteLock nodesMapLockRef
)
{
    accCtx = accCtxRef;
    nodesMap = nodesMapRef;
    nodesMapLock = nodesMapLockRef;
}