From d3b11ec5f8d165a66e24951dbc7452d508311c70 Mon Sep 17 00:00:00 2001 From: michael-conway Date: Tue, 20 Jun 2017 08:25:52 -0400 Subject: [PATCH] #1 nio plugin development --- .../plugin/nio/NIOFileIOOperationsImpl.java | 54 ++++++++++---- .../core/pub/io/plugin/nio/AllTests.java | 11 +++ .../nio/NIOFileIOOperationsImplTest.java | 20 ++++++ .../confg/props/CachedJargonProperties.java | 40 ++++++++--- .../common/confg/props/JargonProperties.java | 30 +++++++- .../confg/props/JargonPropertiesLoader.java | 17 +++++ .../PropertiesFileJargonPropertiesLoader.java | 70 +++++++++++++++++++ .../context/monitors/package-info.java | 8 +++ .../JargonConfigurationRuntimeException.java | 59 ++++++++++++++++ .../exception/configuration/package-info.java | 8 +++ .../bundle/ExceptionResourceBundle.java | 2 + .../bundle/ExceptionResourceKeys.java | 2 + .../common/confg/enumz/EnumIoStyleTest.java | 1 + .../props/CachedJargonPropertiesTest.java | 22 ++++++ ...pertiesFileJargonPropertiesLoaderTest.java | 19 +++++ .../jargon2/utils/unittest/AllTests.java | 5 +- .../irods/jargon2/core/context/IOContext.java | 30 ++++++++ .../monitor/IOMonitorStatusReport.java | 41 +++++++++-- .../context/monitor/InstrumentationSink.java | 8 +++ .../ioplugin/AbstractFileIOOperations.java | 51 ++++++++++++++ .../core/ioplugin/FileIOOperations.java | 15 ++-- 21 files changed, 470 insertions(+), 43 deletions(-) create mode 100644 io-plugin-nio/src/test/java/org/irods/jargon2/core/pub/io/plugin/nio/AllTests.java create mode 100644 io-plugin-nio/src/test/java/org/irods/jargon2/core/pub/io/plugin/nio/NIOFileIOOperationsImplTest.java create mode 100644 jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/JargonPropertiesLoader.java create mode 100644 jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/PropertiesFileJargonPropertiesLoader.java create mode 100644 jargon2-core-common/src/main/java/org/irods/jargon2/context/monitors/package-info.java create mode 100644 jargon2-core-common/src/main/java/org/irods/jargon2/exception/configuration/JargonConfigurationRuntimeException.java create mode 100644 jargon2-core-common/src/main/java/org/irods/jargon2/exception/configuration/package-info.java create mode 100644 jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/props/CachedJargonPropertiesTest.java create mode 100644 jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/props/PropertiesFileJargonPropertiesLoaderTest.java create mode 100644 jargon2-core-if/src/main/java/org/irods/jargon2/core/ioplugin/AbstractFileIOOperations.java diff --git a/io-plugin-nio/src/main/java/org/irods/jargon2/core/pub/io/plugin/nio/NIOFileIOOperationsImpl.java b/io-plugin-nio/src/main/java/org/irods/jargon2/core/pub/io/plugin/nio/NIOFileIOOperationsImpl.java index d88ac18..206bb67 100644 --- a/io-plugin-nio/src/main/java/org/irods/jargon2/core/pub/io/plugin/nio/NIOFileIOOperationsImpl.java +++ b/io-plugin-nio/src/main/java/org/irods/jargon2/core/pub/io/plugin/nio/NIOFileIOOperationsImpl.java @@ -4,12 +4,15 @@ package org.irods.jargon2.core.pub.io.plugin.nio; import java.io.IOException; -import java.nio.channels.Channel; import java.nio.channels.FileChannel; +import java.nio.channels.WritableByteChannel; import java.nio.file.Path; import org.irods.jargon2.core.context.IOContext; import org.irods.jargon2.core.context.monitor.IOMonitor; +import org.irods.jargon2.core.context.monitor.IOMonitorStatusReport; +import org.irods.jargon2.core.context.monitor.IOMonitorStatusReport.IOOperType; +import org.irods.jargon2.core.ioplugin.AbstractFileIOOperations; import org.irods.jargon2.core.ioplugin.FileIOOperations; import org.irods.jargon2.exception.io.JargonIOException; import org.irods.jargon2.utils.exception.bundle.ExceptionResourceKeys; @@ -25,38 +28,61 @@ * @author mconway * */ -public class NIOFileIOOperationsImpl implements FileIOOperations { +public class NIOFileIOOperationsImpl extends AbstractFileIOOperations implements FileIOOperations { public static final Logger log = LoggerFactory.getLogger(NIOFileIOOperationsImpl.class); - /* - * (non-Javadoc) + /** + * Constructor taking a context * - * @see org.irods.jargon2.core.ioplugin.FileIOOperations# - * transferLocalFileToIrodsSingleBuffer(java.nio.file.Path, - * java.nio.channels.Channel, org.irods.jargon2.core.ioplugin.IOMonitor, - * org.irods.jargon2.core.ioplugin.IOContext) + * @param ioContext */ + public NIOFileIOOperationsImpl(IOContext ioContext) { + super(ioContext); + } + @Override - public void transferLocalFileToIrodsSingleBuffer(Path path, Channel channel, IOMonitor ioMonitor, - IOContext ioContext) throws JargonIOException { + public void transferLocalFileToIrodsSingleBuffer(Path path, WritableByteChannel channel, IOMonitor ioMonitor) + throws JargonIOException { log.info("transferLocalFileToIrodsSingleBuffer()"); if (path == null) { - throw new IllegalArgumentException("null path"); + throw new IllegalArgumentException( + MessageUtil.formatMessage(ExceptionResourceKeys.NULL_OR_EMPTY_PARAMETER, "path")); } if (channel == null) { - throw new IllegalArgumentException("null channel"); + throw new IllegalArgumentException( + MessageUtil.formatMessage(ExceptionResourceKeys.NULL_OR_EMPTY_PARAMETER, "channel")); } log.info("path:{}", path); log.info("channel:{}", channel); log.info("ioMonitor:{}", ioMonitor); - log.info("ioContext:{}", ioContext); FileChannel fileChannel; try { - FileChannel.open(path); + fileChannel = FileChannel.open(path); + + long startTime = System.currentTimeMillis(); + if (getIoContext().getJargonProperties().isUseFastChannelCopy()) { + log.info("fast channel copy for file"); + fileChannel.transferTo(0, fileChannel.size(), channel); + long endTime = System.currentTimeMillis(); + log.info("successfully transferred"); + if (getIoContext().getJargonProperties().isInstrument()) { + IOMonitorStatusReport statusReport = new IOMonitorStatusReport(); + statusReport.setCompleteTimeInMillisthisOper(endTime); + statusReport.setIoOperType(IOOperType.OUTPUT_WRITE); + statusReport.setSizeThisOperation(fileChannel.size()); + statusReport.setStartInMillisThisOper(startTime); + statusReport.setTotalCompleted(statusReport.getSizeThisOperation()); + statusReport.setTotalSize(statusReport.getSizeThisOperation()); + getIoContext().getInstrumentationSink().reportObservation(statusReport); + } + } else { + log.error("unsupported transfer method"); + throw new UnsupportedOperationException(); + } } catch (IOException e) { log.error("I/O Exception opening path:{}", path, e); throw new JargonIOException(MessageUtil.formatMessage(ExceptionResourceKeys.EXCEPT_lOCAL_IO, path), e); diff --git a/io-plugin-nio/src/test/java/org/irods/jargon2/core/pub/io/plugin/nio/AllTests.java b/io-plugin-nio/src/test/java/org/irods/jargon2/core/pub/io/plugin/nio/AllTests.java new file mode 100644 index 0000000..0924fc7 --- /dev/null +++ b/io-plugin-nio/src/test/java/org/irods/jargon2/core/pub/io/plugin/nio/AllTests.java @@ -0,0 +1,11 @@ +package org.irods.jargon2.core.pub.io.plugin.nio; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ NIOFileIOOperationsImplTest.class }) +public class AllTests { + +} diff --git a/io-plugin-nio/src/test/java/org/irods/jargon2/core/pub/io/plugin/nio/NIOFileIOOperationsImplTest.java b/io-plugin-nio/src/test/java/org/irods/jargon2/core/pub/io/plugin/nio/NIOFileIOOperationsImplTest.java new file mode 100644 index 0000000..bdfefa1 --- /dev/null +++ b/io-plugin-nio/src/test/java/org/irods/jargon2/core/pub/io/plugin/nio/NIOFileIOOperationsImplTest.java @@ -0,0 +1,20 @@ +package org.irods.jargon2.core.pub.io.plugin.nio; + +import static org.junit.Assert.fail; + +import org.junit.Test; + +public class NIOFileIOOperationsImplTest { + + @Test + public void testTransferLocalFileToIrodsSingleBuffer() { + fail("Not yet implemented"); + } + + @Test(expected = IllegalArgumentException.class) + public void testNIOFileIOOperationsImpl() { + // IOContext ioContext = new IOContext(); + new NIOFileIOOperationsImpl(null); + } + +} diff --git a/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/CachedJargonProperties.java b/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/CachedJargonProperties.java index 596680c..f271131 100644 --- a/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/CachedJargonProperties.java +++ b/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/CachedJargonProperties.java @@ -18,7 +18,10 @@ public class CachedJargonProperties implements JargonProperties { public static final String CONNECTION_TIMEOUT_IN_SECONDS = "connection.timeout"; + public static final String INSTRUMENTED = "instrumented"; public static final String IO_STYLE = "io.style"; + public static final String IO_FAST_CHANNEL_COPY = "io.fast.channel.copy"; + public static final String IO_NIO_DIRECT = "io.nio.direct"; private ConcurrentHashMap propertiesCache = new ConcurrentHashMap<>(); @@ -46,37 +49,47 @@ public void setConnectionTimeoutInSeconds(int timeout) { @Override public EnumIoStyle getEnumIoStyle() { - // TODO Auto-generated method stub - return null; + return EnumIoStyle.valueOf(propertiesCache.getOrDefault(IO_STYLE, EnumIoStyle.NIO.toString())); } @Override public void setEnumIoStyle(EnumIoStyle enumIoStyle) { - // TODO Auto-generated method stub + propertiesCache.put(IO_STYLE, enumIoStyle.toString()); } @Override public boolean isUseNioDirect() { - // TODO Auto-generated method stub - return false; + return valAsBooleanOrFalse(IO_NIO_DIRECT); + } @Override public void setUseNioDirect(boolean useNioDirect) { - // TODO Auto-generated method stub + propertiesCache.put(IO_NIO_DIRECT, String.valueOf(useNioDirect)); } @Override public boolean isUseFastChannelCopy() { - // TODO Auto-generated method stub - return false; + return valAsBooleanOrFalse(IO_FAST_CHANNEL_COPY); + } @Override public void setUseFastChannelCopy(boolean useFastChannelCopy) { - // TODO Auto-generated method stub + propertiesCache.put(IO_FAST_CHANNEL_COPY, String.valueOf(useFastChannelCopy)); + + } + + @Override + public boolean isInstrument() { + return valAsBooleanOrFalse(INSTRUMENTED); + } + + @Override + public void setInstrument(boolean instrument) { + propertiesCache.put(INSTRUMENTED, String.valueOf(instrument)); } @@ -89,4 +102,13 @@ private int valAsIntOrZero(final String key) { } } + private boolean valAsBooleanOrFalse(final String key) { + String stringVal = propertiesCache.get(key); + if (stringVal == null) { + return false; + } else { + return Boolean.valueOf(stringVal); + } + } + } diff --git a/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/JargonProperties.java b/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/JargonProperties.java index 7cea73d..da0b50f 100644 --- a/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/JargonProperties.java +++ b/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/JargonProperties.java @@ -11,14 +11,37 @@ public interface JargonProperties { /* - * iRODS connection properties + * ------------------------------------------------------------------------- + * ------------------------- General behavior properties + */ + + /** + * Is performance logging turned on? + * + * @return boolean if logging is turned on + */ + boolean isInstrument(); + + /** + * + * Turn insrumentation logging on or off, true turns on logging + * to the configured {@link IOMonitor} + * + * @param instrument + */ + void setInstrument(boolean instrument); + + /* + * ------------------------------------------------------------------------- + * ------------------------- iRODS connection properties */ int getConnectionTimeoutInSeconds(); void setConnectionTimeoutInSeconds(int connectionTimeoutInSeconds); /* - * General i/o properties + * ------------------------------------------------------------------------- + * ------------------------- General i/o properties */ /** @@ -31,7 +54,8 @@ public interface JargonProperties { void setEnumIoStyle(EnumIoStyle enumIoStyle); /* - * local file system i/o properties + * ------------------------------------------------------------------------- + * ------------------------- local file system i/o properties */ /** diff --git a/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/JargonPropertiesLoader.java b/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/JargonPropertiesLoader.java new file mode 100644 index 0000000..d8688e8 --- /dev/null +++ b/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/JargonPropertiesLoader.java @@ -0,0 +1,17 @@ +/** + * + */ +package org.irods.jargon2.common.confg.props; + +/** + * Describes a source to produce a configured JargonProperties. + * This can load from a properties file, database, etc + * + * @author mcc + * + */ +public interface JargonPropertiesLoader { + + JargonProperties loadJargonProperties(); + +} diff --git a/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/PropertiesFileJargonPropertiesLoader.java b/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/PropertiesFileJargonPropertiesLoader.java new file mode 100644 index 0000000..69ce4ee --- /dev/null +++ b/jargon2-core-common/src/main/java/org/irods/jargon2/common/confg/props/PropertiesFileJargonPropertiesLoader.java @@ -0,0 +1,70 @@ +/** + * + */ +package org.irods.jargon2.common.confg.props; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.irods.jargon2.common.confg.enumz.EnumIoStyle; +import org.irods.jargon2.exception.configuration.JargonConfigurationRuntimeException; +import org.irods.jargon2.utils.exception.bundle.ExceptionResourceKeys; +import org.irods.jargon2.utils.exception.bundle.MessageUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Load JargonProperties via a provided java + * Properties file + * + * @author mcc + * + */ +public class PropertiesFileJargonPropertiesLoader implements JargonPropertiesLoader { + + private final String resourcePath; + public static final Logger log = LoggerFactory.getLogger(PropertiesFileJargonPropertiesLoader.class); + + /** + * + */ + public PropertiesFileJargonPropertiesLoader(final String resourcePath) { + if (resourcePath == null || resourcePath.isEmpty()) { + throw new IllegalArgumentException( + MessageUtil.formatMessage(ExceptionResourceKeys.NULL_OR_EMPTY_PARAMETER, "resourcePath")); + } + this.resourcePath = resourcePath; + } + + /* + * (non-Javadoc) + * + * @see org.irods.jargon2.common.confg.props.JargonPropertiesLoader# + * loadJargonProperties() + */ + @Override + public JargonProperties loadJargonProperties() { + log.info("loadJargonProperties() using:{}", resourcePath); + final Properties properties = new Properties(); + try (final InputStream stream = this.getClass().getResourceAsStream(resourcePath)) { + properties.load(stream); + } catch (IOException e) { + log.error("exception loading properties from:{}", resourcePath, e); + throw new JargonConfigurationRuntimeException( + MessageUtil.formatMessage(ExceptionResourceKeys.CONFIG_EXCEPT_LOAD_CONFIG), e); + } + + JargonProperties jargonProperties = new CachedJargonProperties(); + jargonProperties.setConnectionTimeoutInSeconds( + Integer.parseInt(properties.getProperty(CachedJargonProperties.CONNECTION_TIMEOUT_IN_SECONDS))); + jargonProperties.setEnumIoStyle(EnumIoStyle.valueOf(properties.getProperty(CachedJargonProperties.IO_STYLE))); + jargonProperties.setInstrument(Boolean.valueOf(properties.getProperty(CachedJargonProperties.INSTRUMENTED))); + jargonProperties.setUseFastChannelCopy( + Boolean.valueOf(properties.getProperty(CachedJargonProperties.IO_FAST_CHANNEL_COPY))); + jargonProperties.setUseNioDirect(Boolean.valueOf(properties.getProperty(CachedJargonProperties.IO_NIO_DIRECT))); + return jargonProperties; + + } + +} diff --git a/jargon2-core-common/src/main/java/org/irods/jargon2/context/monitors/package-info.java b/jargon2-core-common/src/main/java/org/irods/jargon2/context/monitors/package-info.java new file mode 100644 index 0000000..7c0eee0 --- /dev/null +++ b/jargon2-core-common/src/main/java/org/irods/jargon2/context/monitors/package-info.java @@ -0,0 +1,8 @@ + +/** + * Various utilities to monitor performance and activity + * + * @author mcc + * + */ +package org.irods.jargon2.context.monitors; \ No newline at end of file diff --git a/jargon2-core-common/src/main/java/org/irods/jargon2/exception/configuration/JargonConfigurationRuntimeException.java b/jargon2-core-common/src/main/java/org/irods/jargon2/exception/configuration/JargonConfigurationRuntimeException.java new file mode 100644 index 0000000..ffe3db9 --- /dev/null +++ b/jargon2-core-common/src/main/java/org/irods/jargon2/exception/configuration/JargonConfigurationRuntimeException.java @@ -0,0 +1,59 @@ +/** + * + */ +package org.irods.jargon2.exception.configuration; + +import org.irods.jargon2.exception.JargonRuntimeException; + +/** + * Exception in the configuration of the Jargon2 api + * + * @author mcc + * + */ +public class JargonConfigurationRuntimeException extends JargonRuntimeException { + + /** + * + */ + private static final long serialVersionUID = 2436589854839525924L; + + /** + * + */ + public JargonConfigurationRuntimeException() { + } + + /** + * @param arg0 + */ + public JargonConfigurationRuntimeException(String arg0) { + super(arg0); + } + + /** + * @param arg0 + */ + public JargonConfigurationRuntimeException(Throwable arg0) { + super(arg0); + } + + /** + * @param arg0 + * @param arg1 + */ + public JargonConfigurationRuntimeException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + /** + * @param arg0 + * @param arg1 + * @param arg2 + * @param arg3 + */ + public JargonConfigurationRuntimeException(String arg0, Throwable arg1, boolean arg2, boolean arg3) { + super(arg0, arg1, arg2, arg3); + } + +} diff --git a/jargon2-core-common/src/main/java/org/irods/jargon2/exception/configuration/package-info.java b/jargon2-core-common/src/main/java/org/irods/jargon2/exception/configuration/package-info.java new file mode 100644 index 0000000..acec9c9 --- /dev/null +++ b/jargon2-core-common/src/main/java/org/irods/jargon2/exception/configuration/package-info.java @@ -0,0 +1,8 @@ + +/** + * Exceptions in the configuration of the Jargon2 layer + * + * @author mcc + * + */ +package org.irods.jargon2.exception.configuration; \ No newline at end of file diff --git a/jargon2-core-common/src/main/java/org/irods/jargon2/utils/exception/bundle/ExceptionResourceBundle.java b/jargon2-core-common/src/main/java/org/irods/jargon2/utils/exception/bundle/ExceptionResourceBundle.java index 1a1fd9b..c3050bb 100644 --- a/jargon2-core-common/src/main/java/org/irods/jargon2/utils/exception/bundle/ExceptionResourceBundle.java +++ b/jargon2-core-common/src/main/java/org/irods/jargon2/utils/exception/bundle/ExceptionResourceBundle.java @@ -18,7 +18,9 @@ public class ExceptionResourceBundle extends ListResourceBundle { { ExceptionResourceKeys.TEST_MSG1, "Test message1" }, { ExceptionResourceKeys.TEST_MSG2, "Test message1 {0}" }, { ExceptionResourceKeys.TEST_MSG3, "Test message1 {0} {1}" }, + { ExceptionResourceKeys.CONFIG_EXCEPT_LOAD_CONFIG, "Exception loading configuration properties" }, { ExceptionResourceKeys.EXCEPT_lOCAL_IO, "Local file IO error at: {0}" }, + { ExceptionResourceKeys.NULL_OR_EMPTY_PARAMETER, "Null or empty parameter {0}" } // Localize to here }; diff --git a/jargon2-core-common/src/main/java/org/irods/jargon2/utils/exception/bundle/ExceptionResourceKeys.java b/jargon2-core-common/src/main/java/org/irods/jargon2/utils/exception/bundle/ExceptionResourceKeys.java index 9b28a68..85b22c0 100644 --- a/jargon2-core-common/src/main/java/org/irods/jargon2/utils/exception/bundle/ExceptionResourceKeys.java +++ b/jargon2-core-common/src/main/java/org/irods/jargon2/utils/exception/bundle/ExceptionResourceKeys.java @@ -14,6 +14,8 @@ public interface ExceptionResourceKeys { public static String TEST_MSG1 = "TEST_MSG1"; public static String TEST_MSG2 = "TEST_MSG2"; public static String TEST_MSG3 = "TEST_MSG3"; + public static String CONFIG_EXCEPT_LOAD_CONFIG = "CONFIG_EXCEPT_LOAD_CONFIG"; public static String EXCEPT_lOCAL_IO = "EXCEPT_lOCAL_IO"; + public static String NULL_OR_EMPTY_PARAMETER = "NULL_OR_EMPTY_PARAMETER"; } diff --git a/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/enumz/EnumIoStyleTest.java b/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/enumz/EnumIoStyleTest.java index 1cc3967..e66d374 100644 --- a/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/enumz/EnumIoStyleTest.java +++ b/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/enumz/EnumIoStyleTest.java @@ -10,6 +10,7 @@ public void testMapIoStyleToEnum() { String test = EnumIoStyle.NIO.toString(); EnumIoStyle actual = EnumIoStyle.mapIoStyleToEnum(test); Assert.assertNotNull("null enumIoStyle", actual); + Assert.assertEquals(EnumIoStyle.NIO, actual); } } diff --git a/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/props/CachedJargonPropertiesTest.java b/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/props/CachedJargonPropertiesTest.java new file mode 100644 index 0000000..a40bcc2 --- /dev/null +++ b/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/props/CachedJargonPropertiesTest.java @@ -0,0 +1,22 @@ +package org.irods.jargon2.common.confg.props; + +import org.junit.Assert; +import org.junit.Test; + +public class CachedJargonPropertiesTest { + + @Test + public void testInstrumented() { + JargonProperties jargonProperties = new CachedJargonProperties(); + jargonProperties.setInstrument(true); + Assert.assertTrue("didn't get instrumented", jargonProperties.isInstrument()); + } + + @Test + public void testFastChannelCopy() { + JargonProperties jargonProperties = new CachedJargonProperties(); + jargonProperties.setUseFastChannelCopy(true); + Assert.assertTrue("didn't get instrumented", jargonProperties.isUseFastChannelCopy()); + } + +} diff --git a/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/props/PropertiesFileJargonPropertiesLoaderTest.java b/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/props/PropertiesFileJargonPropertiesLoaderTest.java new file mode 100644 index 0000000..3cc5653 --- /dev/null +++ b/jargon2-core-common/src/test/java/org/irods/jargon2/common/confg/props/PropertiesFileJargonPropertiesLoaderTest.java @@ -0,0 +1,19 @@ +package org.irods.jargon2.common.confg.props; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class PropertiesFileJargonPropertiesLoaderTest { + + @Test + public void testPropertiesFileJargonPropertiesLoader() { + fail("Not yet implemented"); + } + + @Test + public void testLoadJargonProperties() { + fail("Not yet implemented"); + } + +} diff --git a/jargon2-core-common/src/test/java/org/irods/jargon2/utils/unittest/AllTests.java b/jargon2-core-common/src/test/java/org/irods/jargon2/utils/unittest/AllTests.java index d727ce4..73860d8 100644 --- a/jargon2-core-common/src/test/java/org/irods/jargon2/utils/unittest/AllTests.java +++ b/jargon2-core-common/src/test/java/org/irods/jargon2/utils/unittest/AllTests.java @@ -1,13 +1,16 @@ package org.irods.jargon2.utils.unittest; import org.irods.jargon2.common.confg.enumz.EnumIoStyleTest; +import org.irods.jargon2.common.confg.props.CachedJargonPropertiesTest; +import org.irods.jargon2.common.confg.props.PropertiesFileJargonPropertiesLoaderTest; import org.irods.jargon2.utils.exception.bundle.MessageUtilTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ MessageUtilTest.class, EnumIoStyleTest.class }) +@SuiteClasses({ MessageUtilTest.class, EnumIoStyleTest.class, CachedJargonPropertiesTest.class, + PropertiesFileJargonPropertiesLoaderTest.class }) public class AllTests { } diff --git a/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/IOContext.java b/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/IOContext.java index cccf6c2..6978b6b 100644 --- a/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/IOContext.java +++ b/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/IOContext.java @@ -27,4 +27,34 @@ public class IOContext { */ private InstrumentationSink instrumentationSink; + public JargonProperties getJargonProperties() { + return jargonProperties; + } + + public void setJargonProperties(JargonProperties jargonProperties) { + this.jargonProperties = jargonProperties; + } + + public InstrumentationSink getInstrumentationSink() { + return instrumentationSink; + } + + public void setInstrumentationSink(InstrumentationSink instrumentationSink) { + this.instrumentationSink = instrumentationSink; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("IOContext ["); + if (jargonProperties != null) { + builder.append("jargonProperties=").append(jargonProperties).append(", "); + } + if (instrumentationSink != null) { + builder.append("instrumentationSink=").append(instrumentationSink); + } + builder.append("]"); + return builder.toString(); + } + } diff --git a/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/monitor/IOMonitorStatusReport.java b/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/monitor/IOMonitorStatusReport.java index db49efd..8077765 100644 --- a/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/monitor/IOMonitorStatusReport.java +++ b/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/monitor/IOMonitorStatusReport.java @@ -14,7 +14,7 @@ public class IOMonitorStatusReport { public enum IOOperType { - GET_TRANSFER, PUT_TRANSFER, INPUT, OUTPUT + GET_TRANSFER, PUT_TRANSFER, INPUT_READ, OUTPUT_WRITE } /** @@ -22,30 +22,30 @@ public enum IOOperType { * file size. For io, it's typically the number of bytes to be moved in * total. This could be the entire file, or a file segement. */ - private final long totalSize; + private long totalSize; /** * Amount moved in this operation, which is also reflected in the * totalCompleted */ - private final long sizeThisOperation; + private long sizeThisOperation; /** * Total progress towards the totalSize */ - private final long totalCompleted; + private long totalCompleted; /** * Time when the operation started. This represents the time of the current * invocation, not the total time if multiple invocations make up the whole * operation. */ - private final long startInMillisThisOper; + private long startInMillisThisOper; /** * Time when this operation completed */ - private final long completeTimeInMillisthisOper; + private long completeTimeInMillisthisOper; /** * Metadata describing the type of operation */ - private final IOOperType ioOperType; + private IOOperType ioOperType; /** * @param totalSize @@ -66,6 +66,9 @@ public IOMonitorStatusReport(long totalSize, long sizeThisOperation, long totalC this.ioOperType = ioOperType; } + public IOMonitorStatusReport() { + } + public long getTotalSize() { return totalSize; } @@ -104,4 +107,28 @@ public String toString() { return builder.toString(); } + public void setTotalSize(long totalSize) { + this.totalSize = totalSize; + } + + public void setSizeThisOperation(long sizeThisOperation) { + this.sizeThisOperation = sizeThisOperation; + } + + public void setTotalCompleted(long totalCompleted) { + this.totalCompleted = totalCompleted; + } + + public void setStartInMillisThisOper(long startInMillisThisOper) { + this.startInMillisThisOper = startInMillisThisOper; + } + + public void setCompleteTimeInMillisthisOper(long completeTimeInMillisthisOper) { + this.completeTimeInMillisthisOper = completeTimeInMillisthisOper; + } + + public void setIoOperType(IOOperType ioOperType) { + this.ioOperType = ioOperType; + } + } diff --git a/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/monitor/InstrumentationSink.java b/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/monitor/InstrumentationSink.java index 24e37ed..6f213f6 100644 --- a/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/monitor/InstrumentationSink.java +++ b/jargon2-core-if/src/main/java/org/irods/jargon2/core/context/monitor/InstrumentationSink.java @@ -13,4 +13,12 @@ */ public interface InstrumentationSink { + /** + * Report an IOMonitor instrument observation to be processed by the + * particular sink in a certain way + * + * @param ioMonitorStatusReport + */ + void reportObservation(IOMonitorStatusReport ioMonitorStatusReport); + } diff --git a/jargon2-core-if/src/main/java/org/irods/jargon2/core/ioplugin/AbstractFileIOOperations.java b/jargon2-core-if/src/main/java/org/irods/jargon2/core/ioplugin/AbstractFileIOOperations.java new file mode 100644 index 0000000..75a151c --- /dev/null +++ b/jargon2-core-if/src/main/java/org/irods/jargon2/core/ioplugin/AbstractFileIOOperations.java @@ -0,0 +1,51 @@ +/** + * + */ +package org.irods.jargon2.core.ioplugin; + +import java.nio.channels.WritableByteChannel; +import java.nio.file.Path; + +import org.irods.jargon2.core.context.IOContext; +import org.irods.jargon2.core.context.monitor.IOMonitor; +import org.irods.jargon2.exception.io.JargonIOException; +import org.irods.jargon2.utils.exception.bundle.ExceptionResourceKeys; +import org.irods.jargon2.utils.exception.bundle.MessageUtil; + +/** + * Abstract superclass for FileIOOperations implmementors + * + * @author mcc + * + */ +public abstract class AbstractFileIOOperations implements FileIOOperations { + + private final IOContext ioContext; + + @Override + abstract public void transferLocalFileToIrodsSingleBuffer(Path path, WritableByteChannel channel, + IOMonitor ioMonitor) throws JargonIOException; + + /** + * @param ioContext + * {@link IOContext} with config and other context + */ + public AbstractFileIOOperations(IOContext ioContext) { + super(); + if (ioContext == null) { + throw new IllegalArgumentException( + MessageUtil.formatMessage(ExceptionResourceKeys.NULL_OR_EMPTY_PARAMETER, "ioContext")); + } + this.ioContext = ioContext; + } + + /** + * Get the underlying IOContext + * + * @return {@link IOContext} + */ + public IOContext getIoContext() { + return ioContext; + } + +} diff --git a/jargon2-core-if/src/main/java/org/irods/jargon2/core/ioplugin/FileIOOperations.java b/jargon2-core-if/src/main/java/org/irods/jargon2/core/ioplugin/FileIOOperations.java index 95265f7..4d4ed38 100644 --- a/jargon2-core-if/src/main/java/org/irods/jargon2/core/ioplugin/FileIOOperations.java +++ b/jargon2-core-if/src/main/java/org/irods/jargon2/core/ioplugin/FileIOOperations.java @@ -3,10 +3,9 @@ */ package org.irods.jargon2.core.ioplugin; -import java.nio.channels.Channel; +import java.nio.channels.WritableByteChannel; import java.nio.file.Path; -import org.irods.jargon2.core.context.IOContext; import org.irods.jargon2.core.context.monitor.IOMonitor; import org.irods.jargon2.exception.io.JargonIOException; @@ -29,17 +28,15 @@ public interface FileIOOperations { * @param localSourcePath * {@link Path} representing a local source file * @param irodsChannel - * {@link Channel} representing the iRODS agent in a state - * expecting to receive the local file data + * {@link ritableByteChannel} representing the iRODS agent in a + * state expecting to receive the local file data * @param ioMonitor * {@link IOMonitor}, or null if not needed, that can receive * status updates - * @param ioContext - * {@link IOContext} that can be used to share information and - * signals between threads. * @throws JargonIOException */ - public void transferLocalFileToIrodsSingleBuffer(final Path localSourcePath, final Channel irodsChannel, - final IOMonitor ioMonitor, final IOContext ioContext) throws JargonIOException; + + void transferLocalFileToIrodsSingleBuffer(Path path, WritableByteChannel channel, IOMonitor ioMonitor) + throws JargonIOException; }