Skip to content

Commit

Permalink
#1 passing context to local io
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-conway committed Jun 14, 2017
1 parent 23fc1f1 commit a2f8b7e
Show file tree
Hide file tree
Showing 33 changed files with 206 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
*/
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.file.Path;

import org.irods.jargon2.core.context.IOContext;
import org.irods.jargon2.core.context.monitor.IOMonitor;
import org.irods.jargon2.core.ioplugin.FileIOOperations;
import org.irods.jargon2.core.ioplugin.IOContext;
import org.irods.jargon2.core.ioplugin.IOMonitor;
import org.irods.jargon2.exception.io.JargonIOException;
import org.irods.jargon2.utils.exception.bundle.ExceptionResourceKeys;
import org.irods.jargon2.utils.exception.bundle.MessageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,7 +39,7 @@ public class NIOFileIOOperationsImpl implements FileIOOperations {
*/
@Override
public void transferLocalFileToIrodsSingleBuffer(Path path, Channel channel, IOMonitor ioMonitor,
IOContext ioContext) {
IOContext ioContext) throws JargonIOException {
log.info("transferLocalFileToIrodsSingleBuffer()");
if (path == null) {
throw new IllegalArgumentException("null path");
Expand All @@ -50,7 +54,13 @@ public void transferLocalFileToIrodsSingleBuffer(Path path, Channel channel, IOM
log.info("ioMonitor:{}", ioMonitor);
log.info("ioContext:{}", ioContext);

FileChannel.open(path);
FileChannel fileChannel;
try {
FileChannel.open(path);
} catch (IOException e) {
log.error("I/O Exception opening path:{}", path, e);
throw new JargonIOException(MessageUtil.formatMessage(ExceptionResourceKeys.EXCEPT_lOCAL_IO, path), e);
}

}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion jargon2-core-util/pom.xml → jargon2-core-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>4.3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jargon2-core-util</artifactId>
<artifactId>jargon2-core-common</artifactId>
<packaging>jar</packaging>
<description>Utilities and common code</description>
<dependencies />
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
*
*/
package org.irods.jargon2.common.confg.props;

import java.util.concurrent.ConcurrentHashMap;

/**
* Defines global tuning and behavior properties. Properties are internally
* stored as a concurrent hashmap, allowing sharing of this properties class
* among services.
*
* @author mconway
*
*/
public class CachedJargonProperties implements JargonProperties {

public static final String CONNECTION_TIMEOUT_IN_SECONDS = "connection.timeout";

private ConcurrentHashMap<String, String> propertiesCache = new ConcurrentHashMap<>();

/*
* (non-Javadoc)
*
* @see org.irods.jargon2.utils.confg.props.JargonPropertiesIf#
* getConnectionTimeoutInSeconds()
*/
@Override
public int getConnectionTimeoutInSeconds() {
return valAsIntOrZero(CONNECTION_TIMEOUT_IN_SECONDS);
}

/*
* (non-Javadoc)
*
* @see org.irods.jargon2.utils.confg.props.JargonPropertiesIf#
* setConnectionTimeoutInSeconds(int)
*/
@Override
public void setConnectionTimeoutInSeconds(int timeout) {
propertiesCache.put(CONNECTION_TIMEOUT_IN_SECONDS, String.valueOf(timeout));
}

private int valAsIntOrZero(final String key) {
String stringVal = propertiesCache.get(key);
if (stringVal == null) {
return 0;
} else {
return Integer.parseInt(stringVal);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package org.irods.jargon2.utils.confg.props;
package org.irods.jargon2.common.confg.props;

import java.lang.management.ManagementFactory;

Expand All @@ -20,7 +20,7 @@ public static void main(String[] args) throws Exception {

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("org.irods.jargon2.utils.confg.props:type=JargonProperties");
JargonProperties jargonProperties = new JargonProperties();
CachedJargonProperties jargonProperties = new CachedJargonProperties();
mbs.registerMBean(jargonProperties, name);

System.out.println("Waiting forever...");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.irods.jargon2.utils.confg.props;
package org.irods.jargon2.common.confg.props;

/**
* Interface for jargon
* @author mconway
*
*/
public interface JargonPropertiesMBean {
public interface JargonProperties {

int getConnectionTimeoutInSeconds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* @author mconway
*
*/
package org.irods.jargon2.utils.confg.props;
package org.irods.jargon2.common.confg.props;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
*
*/
package org.irods.jargon2.exception.io;

import org.irods.jargon2.exception.JargonException;

/**
* General IO Exception
*
* @author mcc
*
*/
public class JargonIOException extends JargonException {

/**
*
*/
private static final long serialVersionUID = 5668474226177204223L;

/**
*
*/
public JargonIOException() {
super();
}

/**
* @param arg0
* @param arg1
* @param arg2
* @param arg3
*/
public JargonIOException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
super(arg0, arg1, arg2, arg3);
}

/**
* @param arg0
* @param arg1
*/
public JargonIOException(String arg0, Throwable arg1) {
super(arg0, arg1);
}

/**
* @param arg0
*/
public JargonIOException(String arg0) {
super(arg0);
}

/**
* @param arg0
*/
public JargonIOException(Throwable arg0) {
super(arg0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class ExceptionResourceBundle extends ListResourceBundle {
// Localize from here
{ ExceptionResourceKeys.TEST_MSG1, "Test message1" },
{ ExceptionResourceKeys.TEST_MSG2, "Test message1 {0}" },
{ ExceptionResourceKeys.TEST_MSG3, "Test message1 {0} {1}" }
{ ExceptionResourceKeys.TEST_MSG3, "Test message1 {0} {1}" },
{ ExceptionResourceKeys.EXCEPT_lOCAL_IO, "Local file IO error at: {0}" },

// Localize to here
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ 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 EXCEPT_lOCAL_IO = "EXCEPT_lOCAL_IO";

}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
*
*/
package org.irods.jargon2.core.context;

import org.irods.jargon2.common.confg.props.JargonProperties;
import org.irods.jargon2.core.context.monitor.InstrumentationSink;

/**
* Represents a shared, thread safe object between IO operations and the process
* calling those operations. This allows cancellation, pause, and other types of
* information to be passed to the i/o process.
*
* @author mconway
*
*/
public class IOContext {

private JargonProperties jargonProperties;

/**
* {@link InstrumentationSink} that can receive reports of performance
* characteristics, timing, etc, per the message hierarcy
*/
private InstrumentationSink instrumentationSink;

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package org.irods.jargon2.core.ioplugin;
package org.irods.jargon2.core.context.monitor;

/**
* Monitor of an i/o process. This represents the movement of file or stream
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package org.irods.jargon2.core.ioplugin;
package org.irods.jargon2.core.context.monitor;

/**
* Represents an instantaneous representation of the status of an i/o operation.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
*
*/
package org.irods.jargon2.core.context.monitor;

/**
* Receiver of instrumentation, these are messages that indicate the performance
* of various operations. How reports are handled and analyzed is implementation
* dependent, but each implementation should minimize latency and overhead.
*
* @author mcc
*
*/
public interface InstrumentationSink {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/**
* Support for callacks and monitoring/instrumentation
*
* @author mcc
*
*/
package org.irods.jargon2.core.context.monitor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

/**
* Main interfaces providing context, property management, and shared references
* between parts of the API
*
* @author mcc
*
*/
package org.irods.jargon2.core.context;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import java.nio.channels.Channel;
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;

/**
* Interface for a file operations plugin that will handle the primary i/o
* between the local file system and the iRODS agent. These operations sit below
Expand Down Expand Up @@ -33,8 +37,9 @@ public interface FileIOOperations {
* @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);
final IOMonitor ioMonitor, final IOContext ioContext) throws JargonIOException;

}

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
</build>
<modules>
<module>jargon2-core-if</module>
<module>jargon2-core-util</module>
<module>jargon2-core-common</module>
<module>io-plugin-nio</module>
</modules>
</project>

0 comments on commit a2f8b7e

Please sign in to comment.