diff --git a/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java b/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java index f3ec09a1c0a7b013c6a79c53b7dfcf01209faa31..243533b7c94252f0131ed88a2b70ff17ccf700c4 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java @@ -25,6 +25,7 @@ import com.exlibris.core.infra.common.util.IOUtil; import com.exlibris.core.infra.svc.api.scriptRunner.ExecExternalProcess; import com.exlibris.core.sdk.storage.containers.StoredEntityMetaData; import com.exlibris.core.sdk.storage.handler.AbstractStorageHandler; +import com.exlibris.core.sdk.storage.handler.StorageHandler; import com.exlibris.core.sdk.storage.handler.StorageUtil; import com.exlibris.core.sdk.utils.FileUtil; import com.exlibris.digitool.common.dnx.DnxDocument; @@ -73,26 +74,22 @@ import java.util.Map; */ public class SLUBStoragePlugin extends AbstractStorageHandler { private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class); - private static String DIR_ROOT = "DIR_ROOT"; /** {@inheritDoc} */ - private static String FILES_HANDLING_METHOD = "move"; - private static int BLOCK_SIZE = 32*1024; - public SLUBStoragePlugin() { - log.info("SLUBStoragePlugin instantiated (using DIR_ROOT="+DIR_ROOT+" BLOCK_SIZE="+BLOCK_SIZE); + private String getDirRoot () { + return parameters.get("DIR_ROOT"); } - - @Override - public void init(Map<String, String> params) { - super.init(params); - DIR_ROOT = parameters.get("DIR_ROOT"); + private int getBlockSize () { + int blockSize = 32*1024; try { - BLOCK_SIZE = Integer.parseInt(this.parameters.get("BLOCK_SIZE")); + blockSize = Integer.parseInt(this.parameters.get("BLOCK_SIZE")); } catch (NumberFormatException e) { log.error("Could not convert BLOCK_SIZE string to int, " + e); - BLOCK_SIZE = 32*1024; + blockSize = 32*1024; } - FILES_HANDLING_METHOD = this.parameters.get("FILES_HANDLING_METHOD"); - log.info("SLUBStoragePlugin initialized (using DIR_ROOT="+DIR_ROOT+" BLOCK_SIZE="+BLOCK_SIZE); + return blockSize; + } + private String getFilesHandlingMethod () { + return this.parameters.get("FILES_HANDLING_METHOD"); } private String throughput(long starttime_in_ms, long endtime_in_ms, String filename) { @@ -113,6 +110,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { } public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) throws Exception { log.info("SLUBStoragePlugin.checkFixity()"); + /* todo: only absolute paths */ return checkFixity(fixities, storedEntityIdentifier, true); } @@ -191,7 +189,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { boolean result = fixity.getResult(); is.close(); long endtime = System.currentTimeMillis(); - var pathname = (isRelativePath ? DIR_ROOT : "") + storedEntityIdentifier; + var pathname = (isRelativePath ? getDirRoot() : "") + storedEntityIdentifier; log.info("SLUBStoragePlugin.checkFixity() pathname='"+ pathname + "' result=" + result + " (builtin " + throughput(starttime, endtime, pathname)+ ")"); return result; } @@ -232,7 +230,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { log.info("SLUBStoragePlugin.checkFixityByPlugin() newvalue=" + fixity.getValue()); boolean result = fixity.getResult(); long endtime = System.currentTimeMillis(); - var pathname = (isRelativePath ? DIR_ROOT : "") + storedEntityIdentifier; + var pathname = (isRelativePath ? getDirRoot() : "") + storedEntityIdentifier; log.info("SLUBStoragePlugin.checkFixityByPlugin() pathname='" + pathname + "' result=" + result + " (plugins " + throughput(starttime, endtime, pathname)+ ")"); return result; } @@ -240,7 +238,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { public boolean deleteEntity(String storedEntityIdentifier) { log.info("SLUBStoragePlugin.deleteEntity() storedEntityIdentifier='" + storedEntityIdentifier + "'"); - File file = new File(DIR_ROOT + storedEntityIdentifier); + File file = new File(getDirRoot() + storedEntityIdentifier); try { return file.delete(); @@ -261,7 +259,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { public String getFullFilePath(String storedEntityIdentifier) { log.info("SLUBStoragePlugin.getFullFilePath() with '" + storedEntityIdentifier + "'"); - return DIR_ROOT + storedEntityIdentifier; + return getDirRoot() + storedEntityIdentifier; } public InputStream retrieveEntity(String storedEntityIdentifier) @@ -274,16 +272,16 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { throws IOException { log.info("SLUBStoragePlugin.retrieveEntity() with '" + storedEntityIdentifier + "' isrelative=" + isRelative); - var pathname = (isRelative ? DIR_ROOT : "") + storedEntityIdentifier; + var pathname = (isRelative ? getDirRoot() : "") + storedEntityIdentifier; // TODO: 64k (1MB) buffer set // OLD, without buffering, but working: InputStream foo = java.nio.file.Files.newInputStream( Paths.get( pathname)); - return new BufferedInputStream( java.nio.file.Files.newInputStream(Paths.get( pathname)), BLOCK_SIZE); + return new BufferedInputStream( java.nio.file.Files.newInputStream(Paths.get( pathname)), getBlockSize()); } public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end) throws Exception { log.info("SLUBStoragePlugin.retrieveEntitybyRange() with '" + storedEntityIdentifier + "' start=" + start + " end=" + end); /* try-with-ressource block, no close if failed needed */ - try (RandomAccessFile file = new RandomAccessFile(DIR_ROOT + storedEntityIdentifier, "r")) + try (RandomAccessFile file = new RandomAccessFile(getDirRoot() + storedEntityIdentifier, "r")) { long starttime = System.currentTimeMillis(); file.seek(start); @@ -350,7 +348,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { try (OutputStream output = java.nio.file.Files.newOutputStream( Paths.get( destFilePath))) { long starttime = System.currentTimeMillis(); - IOUtil.copy(is, output, BLOCK_SIZE); + IOUtil.copy(is, output, getBlockSize()); long endtime = System.currentTimeMillis(); log.info("SLUBStoragePlugin.storeEntity() try copy (IOUtil.copy) was successfull (" + throughput(starttime, endtime, destFilePath)+ ")" ); } @@ -368,7 +366,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { throws IOException { log.info("SLUBStoragePlugin.copyStream()"); - String filesHandlingMethod = FILES_HANDLING_METHOD; + String filesHandlingMethod = getFilesHandlingMethod(); String srcPath = storedEntityMetadata.getCurrentFilePath(); log.info("SLUBStoragePlugin.copyStream() destPath='" + destPath + "'"); log.info("SLUBStoragePlugin.copyStream() srcPath='" + srcPath + "'"); @@ -492,7 +490,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { */ File getStreamDirectory(String path, String fileName) { log.info("SLUBStoragePlugin.getStreamDirectory path='" + path + "' fileName='" + fileName + "'"); - File newDir = new File(DIR_ROOT + File.separator + path); + File newDir = new File(getDirRoot() + File.separator + path); log.debug("SLUBStoragePlugin.getStreamDirectory newDir.getAbsolutePath()=" + newDir.getAbsolutePath()); boolean arecreated = newDir.mkdirs(); log.debug("SLUBStoragePlugin.getStreamDirectory newDir.mkdirs(), directories are created:" + arecreated);