Esempio n. 1
0
        private ThreadStart Inserter <T1>(AtomicReferenceArray <T1> lastBatches, Generator[] generators, System.Threading.CountdownEvent insertersDone, ReadWriteLock updateLock, int slot) where T1 : Org.Neo4j.Kernel.Api.Index.IndexEntryUpdate <T1>
        {
            int worstCaseEntriesPerThread = BATCHES_PER_THREAD * MAX_BATCH_SIZE;

            return(throwing(() =>
            {
                try
                {
                    Generator generator = generators[slot] = new Generator(this, MAX_BATCH_SIZE, Random.seed() + slot, slot * worstCaseEntriesPerThread);
                    for (int j = 0; j < BATCHES_PER_THREAD; j++)
                    {
                        IList <IndexEntryUpdate <object> > batch = generator.Batch();
                        updateLock.readLock().@lock();
                        try
                        {
                            _populator.add(batch);
                        }
                        finally
                        {
                            updateLock.readLock().unlock();
                        }
                        lastBatches.set(slot, batch);
                    }
                }
                finally
                {
                    // This helps the updater know when to stop updating
                    insertersDone.Signal();
                }
            }));
        }
Esempio n. 2
0
        public override void Send(AdvertisedSocketAddress to, Message message, bool block)
        {
            Future <Void> future;

            _serviceLock.readLock().@lock();
            try
            {
                if (!_senderServiceRunning)
                {
                    return;
                }

                future = Channel(to).writeAndFlush(message);
            }
            finally
            {
                _serviceLock.readLock().unlock();
            }

            if (block)
            {
                try
                {
                    future.get();
                }
                catch (ExecutionException e)
                {
                    _log.error("Exception while sending to: " + to, e);
                }
                catch (InterruptedException e)
                {
                    _log.info("Interrupted while sending", e);
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.graphdb.Resource storeCopy(org.neo4j.function.ThrowingAction<java.io.IOException> beforeFirstConcurrentStoreCopy) throws java.io.IOException
        public virtual Resource StoreCopy(ThrowingAction <IOException> beforeFirstConcurrentStoreCopy)
        {
            Lock readLock            = @lock.readLock();
            bool firstConcurrentRead = IncrementCount() == 0;
            bool success             = false;

            try
            {
                if (firstConcurrentRead)
                {
                    try
                    {
                        beforeFirstConcurrentStoreCopy.Apply();
                    }
                    catch (IOException e)
                    {
                        _storeCopyActionError = e;
                        throw e;
                    }
                    catch (Exception e)
                    {
                        _storeCopyActionError = e;
                        throw new IOException(e);
                    }
                    _storeCopyActionCompleted = true;
                }
                else
                {
                    // Wait for the "before" first store copy to complete
                    WaitForFirstStoreCopyActionToComplete();
                }
                success = true;
            }
            finally
            {
                if (success)
                {
                    readLock.@lock();
                }
                else
                {
                    DecrementCount();
                }
            }

            return(() =>
            {
                // Decrement concurrent store-copy count
                DecrementCount();
                readLock.unlock();
            });
        }