public virtual void put(K key, V value) { if (key == default(K) || value == default(V)) { throw new System.NullReferenceException(); } V previousValue = cache.put(key, value); if (previousValue != default(V)) { keys.remove(key); } keys.add(key); if (cache.size() > capacity) { K lruKey = keys.poll(); if (lruKey != default(K)) { cache.remove(lruKey); // remove duplicated keys this.removeAll(lruKey); // queue may not contain any key of a possibly concurrently added entry of the same key in the cache if (cache.containsKey(lruKey)) { keys.add(lruKey); } } } }
public override void ReleaseExclusive(ResourceType resourceType, params long[] resourceIds) { _stateHolder.incrementActiveClients(this); try { ConcurrentMap <long, ForsetiLockManager.Lock> resourceTypeLocks = _lockMaps[resourceType.TypeId()]; MutableLongIntMap exclusiveLocks = _exclusiveLockCounts[resourceType.TypeId()]; MutableLongIntMap sharedLocks = _sharedLockCounts[resourceType.TypeId()]; foreach (long resourceId in resourceIds) { if (ReleaseLocalLock(resourceType, resourceId, exclusiveLocks)) { continue; } if (sharedLocks.containsKey(resourceId)) { // We are still holding a shared lock, so we will release it to be reused ForsetiLockManager.Lock @lock = resourceTypeLocks.get(resourceId); if (@lock is SharedLock) { SharedLock sharedLock = ( SharedLock )@lock; if (sharedLock.UpdateLock) { sharedLock.ReleaseUpdateLock(); } else { throw new System.InvalidOperationException("Incorrect state of exclusive lock. Lock should be updated " + "to exclusive before attempt to release it. Lock: " + this); } } else { // in case if current lock is exclusive we swap it to new shared lock SharedLock sharedLock = new SharedLock(this); resourceTypeLocks.put(resourceId, sharedLock); } } else { // we do not hold shared lock so we just releasing it ReleaseGlobalLock(resourceTypeLocks, resourceId); } } } finally { _stateHolder.decrementActiveClients(); } }
protected internal override ForsetiClient Create() { int?id = UnusedIds.RemoveFirst(); if (id == null) { id = ClientIds.AndIncrement; } long lockAcquisitionTimeoutMillis = Config.get(GraphDatabaseSettings.lock_acquisition_timeout).toMillis(); ForsetiClient client = new ForsetiClient(id.Value, LockMaps, WaitStrategies, this, DeadlockResolutionStrategy, ClientsById.get, lockAcquisitionTimeoutMillis, Clock); ClientsById.put(id, client); return(client); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception public override void UserEventTriggered(ChannelHandlerContext ctx, object evt) { if (evt is Org.Neo4j.causalclustering.protocol.handshake.ServerHandshakeFinishedEvent_Created) { Org.Neo4j.causalclustering.protocol.handshake.ServerHandshakeFinishedEvent_Created created = (Org.Neo4j.causalclustering.protocol.handshake.ServerHandshakeFinishedEvent_Created)evt; _installedProtocols.put(created.AdvertisedSocketAddress, created.ProtocolStack); } else if (evt is Org.Neo4j.causalclustering.protocol.handshake.ServerHandshakeFinishedEvent_Closed) { Org.Neo4j.causalclustering.protocol.handshake.ServerHandshakeFinishedEvent_Closed closed = (Org.Neo4j.causalclustering.protocol.handshake.ServerHandshakeFinishedEvent_Closed)evt; _installedProtocols.remove(closed.AdvertisedSocketAddress); } else { base.UserEventTriggered(ctx, evt); } }
internal void CasLeaders(LeaderInfo leaderInfo, string dbName) { lock ( _leaderMap ) { Optional <LeaderInfo> current = Optional.ofNullable(_leaderMap.get(dbName)); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: bool sameLeader = current.map(LeaderInfo::memberId).Equals(Optional.ofNullable(leaderInfo.MemberId())); int termComparison = current.map(l => Long.compare(l.term(), leaderInfo.Term())).orElse(-1); bool greaterTermExists = termComparison > 0; bool sameTermButNoStepDown = termComparison == 0 && !leaderInfo.SteppingDown; if (!(greaterTermExists || sameTermButNoStepDown || sameLeader)) { _leaderMap.put(dbName, leaderInfo); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public org.neo4j.kernel.api.index.IndexAccessor getOnlineAccessor(org.neo4j.storageengine.api.schema.StoreIndexDescriptor descriptor, org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig samplingConfig) throws java.io.IOException public override IndexAccessor GetOnlineAccessor(StoreIndexDescriptor descriptor, IndexSamplingConfig samplingConfig) { PartitionedIndexStorage indexStorage = GetIndexStorage(descriptor.Id); FulltextIndexDescriptor fulltextIndexDescriptor = readOrInitialiseDescriptor(descriptor, _defaultAnalyzerName, _tokenHolders.propertyKeyTokens(), indexStorage.IndexFolder, _fileSystem); FulltextIndexBuilder fulltextIndexBuilder = FulltextIndexBuilder.Create(fulltextIndexDescriptor, _config, _tokenHolders.propertyKeyTokens()).withFileSystem(_fileSystem).withOperationalMode(_operationalMode).withIndexStorage(indexStorage).withPopulatingMode(false); if (fulltextIndexDescriptor.EventuallyConsistent) { fulltextIndexBuilder = fulltextIndexBuilder.WithIndexUpdateSink(_indexUpdateSink); } DatabaseFulltextIndex fulltextIndex = fulltextIndexBuilder.Build(); fulltextIndex.open(); ThreadStart onClose = () => _openOnlineAccessors.remove(descriptor); FulltextIndexAccessor accessor = new FulltextIndexAccessor(_indexUpdateSink, fulltextIndex, fulltextIndexDescriptor, onClose); _openOnlineAccessors.put(descriptor, accessor); _log.debug("Created online accessor for fulltext schema index %s: %s", descriptor, accessor); return(accessor); }