From 62c27e3c2275ecee87b38cc044248e10674968a6 Mon Sep 17 00:00:00 2001 From: RagnarW Date: Tue, 20 Mar 2018 15:21:16 +0100 Subject: [PATCH] Use static methods to construct stream to disk --- .../catchup/storecopy/StreamToDisk.java | 17 ++++++++++++++++- .../catchup/storecopy/StreamToDiskProvider.java | 5 ++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StreamToDisk.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StreamToDisk.java index d4e34c276089..a9a7d2feee96 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StreamToDisk.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StreamToDisk.java @@ -19,6 +19,7 @@ */ package org.neo4j.causalclustering.catchup.storecopy; +import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; @@ -26,6 +27,10 @@ import java.util.Arrays; import java.util.List; +import org.neo4j.io.fs.FileSystemAbstraction; +import org.neo4j.io.fs.OpenMode; +import org.neo4j.io.pagecache.PagedFile; + import static org.neo4j.io.IOUtils.closeAll; public class StreamToDisk implements StoreFileStream @@ -33,7 +38,17 @@ public class StreamToDisk implements StoreFileStream private WritableByteChannel writableByteChannel; private List closeables; - public StreamToDisk( WritableByteChannel writableByteChannel, AutoCloseable... closeables ) + static StreamToDisk fromPagedFile( PagedFile pagedFile ) throws IOException + { + return new StreamToDisk( pagedFile.openWritableByteChannel(), pagedFile ); + } + + static StreamToDisk fromFile( FileSystemAbstraction fsa, File file ) throws IOException + { + return new StreamToDisk( fsa.open( file, OpenMode.READ_WRITE ) ); + } + + private StreamToDisk( WritableByteChannel writableByteChannel, AutoCloseable... closeables ) { this.writableByteChannel = writableByteChannel; this.closeables = new ArrayList<>(); diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StreamToDiskProvider.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StreamToDiskProvider.java index c9c2675bd705..56afbb81b3ca 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StreamToDiskProvider.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StreamToDiskProvider.java @@ -25,7 +25,6 @@ import org.neo4j.causalclustering.catchup.tx.FileCopyMonitor; import org.neo4j.io.fs.FileSystemAbstraction; -import org.neo4j.io.fs.OpenMode; import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PagedFile; import org.neo4j.kernel.impl.store.StoreType; @@ -56,11 +55,11 @@ public StoreFileStream acquire( String destination, int requiredAlignment ) thro { int filePageSize = pageCache.pageSize() - pageCache.pageSize() % requiredAlignment; PagedFile pagedFile = pageCache.map( fileName, filePageSize, StandardOpenOption.CREATE ); - return new StreamToDisk( pagedFile.openWritableByteChannel(), pagedFile ); + return StreamToDisk.fromPagedFile( pagedFile ); } else { - return new StreamToDisk( fs.open( fileName, OpenMode.READ_WRITE ) ); + return StreamToDisk.fromFile( fs, fileName ); } } }