Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized org.neo4j.io.pagecache.PagedFile map(java.io.File file, int filePageSize, java.nio.file.OpenOption... openOptions) throws java.io.IOException
        public override PagedFile Map(File file, int filePageSize, params OpenOption[] openOptions)
        {
            lock (this)
            {
                AssertHealthy();
                EnsureThreadsInitialised();
                if (filePageSize > _cachePageSize)
                {
                    throw new System.ArgumentException("Cannot map files with a filePageSize (" + filePageSize + ") that is greater than the " + "cachePageSize (" + _cachePageSize + ")");
                }
                file = file.CanonicalFile;
                bool createIfNotExists = false;
                bool truncateExisting  = false;
                bool deleteOnClose     = false;
                bool anyPageSize       = false;
                bool noChannelStriping = false;
                foreach (OpenOption option in openOptions)
                {
                    if (option.Equals(StandardOpenOption.CREATE))
                    {
                        createIfNotExists = true;
                    }
                    else if (option.Equals(StandardOpenOption.TRUNCATE_EXISTING))
                    {
                        truncateExisting = true;
                    }
                    else if (option.Equals(StandardOpenOption.DELETE_ON_CLOSE))
                    {
                        deleteOnClose = true;
                    }
                    else if (option.Equals(PageCacheOpenOptions.ANY_PAGE_SIZE))
                    {
                        anyPageSize = true;
                    }
                    else if (option.Equals(PageCacheOpenOptions.NO_CHANNEL_STRIPING))
                    {
                        noChannelStriping = true;
                    }
                    else if (!_ignoredOpenOptions.Contains(option))
                    {
                        throw new System.NotSupportedException("Unsupported OpenOption: " + option);
                    }
                }

                FileMapping current = _mappedFiles;

                // find an existing mapping
                while (current != null)
                {
                    if (current.File.Equals(file))
                    {
                        MuninnPagedFile pagedFile = current.PagedFile;
                        if (pagedFile.PageSize() != filePageSize && !anyPageSize)
                        {
                            string msg = "Cannot map file " + file + " with " +
                                         "filePageSize " + filePageSize + " bytes, " +
                                         "because it has already been mapped with a " +
                                         "filePageSize of " + pagedFile.PageSize() +
                                         " bytes.";
                            throw new System.ArgumentException(msg);
                        }
                        if (truncateExisting)
                        {
                            throw new System.NotSupportedException("Cannot truncate a file that is already mapped");
                        }
                        pagedFile.IncrementRefCount();
                        pagedFile.MarkDeleteOnClose(deleteOnClose);
                        return(pagedFile);
                    }
                    current = current.Next;
                }

                if (filePageSize < Long.BYTES)
                {
                    throw new System.ArgumentException("Cannot map files with a filePageSize (" + filePageSize + ") that is less than " + Long.BYTES + " bytes");
                }

                // there was no existing mapping
                MuninnPagedFile pagedFile = new MuninnPagedFile(file, this, filePageSize, _swapperFactory, _pageCacheTracer, _pageCursorTracerSupplier, _versionContextSupplier, createIfNotExists, truncateExisting, noChannelStriping);
                pagedFile.IncrementRefCount();
                pagedFile.MarkDeleteOnClose(deleteOnClose);
                current      = new FileMapping(file, pagedFile);
                current.Next = _mappedFiles;
                _mappedFiles = current;
                _pageCacheTracer.mappedFile(file);
                return(pagedFile);
            }
        }