You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2015/04/22 05:39:45 UTC
[1/7] incubator-nifi git commit: NIFI-271 checkpoint
Repository: incubator-nifi
Updated Branches:
refs/heads/NIFI-271 afb4fe52b -> b612b6bcd
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java
index 5306ddf..c6ed9fb 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java
@@ -31,73 +31,72 @@ import org.junit.Test;
public class ProcessorDocumentationWriterTest {
- @Test
- public void testFullyDocumentedProcessor() throws IOException {
- FullyDocumentedProcessor processor = new FullyDocumentedProcessor();
- processor.initialize(new MockProcessorInitializationContext());
-
- DocumentationWriter writer = new HtmlProcessorDocumentationWriter();
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- writer.write(processor, baos, false);
-
- String results = new String(baos.toByteArray());
- XmlValidator.assertXmlValid(results);
-
- assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDisplayName());
- assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDescription());
- assertContains(results, FullyDocumentedProcessor.OPTIONAL_PROPERTY.getDisplayName());
- assertContains(results, FullyDocumentedProcessor.OPTIONAL_PROPERTY.getDescription());
- assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDisplayName());
- assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDescription());
- assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDefaultValue());
- assertContains(results, FullyDocumentedProcessor.RECURSE.getDisplayName());
- assertContains(results, FullyDocumentedProcessor.RECURSE.getDescription());
-
- assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getName());
- assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getDescription());
- assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getName());
- assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getDescription());
- assertContains(results, "Controller Service: ");
- assertContains(results, "SampleService");
-
- assertNotContains(results, "iconSecure.png");
- assertContains(results, FullyDocumentedProcessor.class.getAnnotation(CapabilityDescription.class)
- .value());
- assertNotContains(results, "This component has no required or optional properties.");
- assertNotContains(results, "No description provided.");
- assertNotContains(results, "No Tags provided.");
- assertNotContains(results, "Additional Details...");
- }
-
- @Test
- public void testNakedProcessor() throws IOException {
- NakedProcessor processor = new NakedProcessor();
- processor.initialize(new MockProcessorInitializationContext());
-
- DocumentationWriter writer = new HtmlProcessorDocumentationWriter();
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- writer.write(processor, baos, false);
-
- String results = new String(baos.toByteArray());
- XmlValidator.assertXmlValid(results);
-
- // no description
- assertContains(results, "No description provided.");
-
- // no tags
- assertContains(results, "None.");
-
- // properties
- assertContains(results, "This component has no required or optional properties.");
-
- // relationships
- assertContains(results, "This processor has no relationships.");
-
-
- }
+ @Test
+ public void testFullyDocumentedProcessor() throws IOException {
+ FullyDocumentedProcessor processor = new FullyDocumentedProcessor();
+ processor.initialize(new MockProcessorInitializationContext());
+
+ DocumentationWriter writer = new HtmlProcessorDocumentationWriter();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ writer.write(processor, baos, false);
+
+ String results = new String(baos.toByteArray());
+ XmlValidator.assertXmlValid(results);
+
+ assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDisplayName());
+ assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDescription());
+ assertContains(results, FullyDocumentedProcessor.OPTIONAL_PROPERTY.getDisplayName());
+ assertContains(results, FullyDocumentedProcessor.OPTIONAL_PROPERTY.getDescription());
+ assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDisplayName());
+ assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDescription());
+ assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDefaultValue());
+ assertContains(results, FullyDocumentedProcessor.RECURSE.getDisplayName());
+ assertContains(results, FullyDocumentedProcessor.RECURSE.getDescription());
+
+ assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getName());
+ assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getDescription());
+ assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getName());
+ assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getDescription());
+ assertContains(results, "Controller Service: ");
+ assertContains(results, "SampleService");
+
+ assertNotContains(results, "iconSecure.png");
+ assertContains(results, FullyDocumentedProcessor.class.getAnnotation(CapabilityDescription.class)
+ .value());
+ assertNotContains(results, "This component has no required or optional properties.");
+ assertNotContains(results, "No description provided.");
+ assertNotContains(results, "No Tags provided.");
+ assertNotContains(results, "Additional Details...");
+ }
+
+ @Test
+ public void testNakedProcessor() throws IOException {
+ NakedProcessor processor = new NakedProcessor();
+ processor.initialize(new MockProcessorInitializationContext());
+
+ DocumentationWriter writer = new HtmlProcessorDocumentationWriter();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ writer.write(processor, baos, false);
+
+ String results = new String(baos.toByteArray());
+ XmlValidator.assertXmlValid(results);
+
+ // no description
+ assertContains(results, "No description provided.");
+
+ // no tags
+ assertContains(results, "None.");
+
+ // properties
+ assertContains(results, "This component has no required or optional properties.");
+
+ // relationships
+ assertContains(results, "This processor has no relationships.");
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java
index 6cb7499..8bddf98 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java
@@ -28,23 +28,24 @@ import org.xml.sax.SAXException;
/**
* A helper class to validate xml documents.
- *
+ *
*
*/
public class XmlValidator {
- public static void assertXmlValid(String xml) {
- try {
- DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
- } catch (SAXException | IOException | ParserConfigurationException e) {
- Assert.fail(e.getMessage());
- }
- }
- public static void assertContains(String original, String subword) {
- Assert.assertTrue(original + " did not contain: " + subword, original.contains(subword));
- }
+ public static void assertXmlValid(String xml) {
+ try {
+ DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
+ } catch (SAXException | IOException | ParserConfigurationException e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ public static void assertContains(String original, String subword) {
+ Assert.assertTrue(original + " did not contain: " + subword, original.contains(subword));
+ }
- public static void assertNotContains(String original, String subword) {
- Assert.assertFalse(original + " did contain: " + subword, original.contains(subword));
- }
+ public static void assertNotContains(String original, String subword) {
+ Assert.assertFalse(original + " did contain: " + subword, original.contains(subword));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java
index 6950eb8..9b1772b 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java
@@ -85,7 +85,7 @@ public class ExtensionManager {
// consider each nar class loader
for (final ClassLoader ncl : NarClassLoaders.getExtensionClassLoaders()) {
- // Must set the context class loader to the nar classloader itself
+ // Must set the context class loader to the nar classloader itself
// so that static initialization techniques that depend on the context class loader will work properly
Thread.currentThread().setContextClassLoader(ncl);
loadExtensions(ncl);
@@ -100,7 +100,7 @@ public class ExtensionManager {
/**
* Loads extensions from the specified class loader.
*
- * @param classLoader
+ * @param classLoader from which to load extensions
*/
@SuppressWarnings("unchecked")
private static void loadExtensions(final ClassLoader classLoader) {
@@ -117,10 +117,10 @@ public class ExtensionManager {
* Registers extension for the specified type from the specified
* ClassLoader.
*
- * @param type
- * @param classloaderMap
- * @param classLoader
- * @param classes
+ * @param type the extension type
+ * @param classloaderMap mapping of classname to classloader
+ * @param classLoader the classloader being mapped to
+ * @param classes to map to this classloader but which come from its ancestors
*/
private static void registerServiceClass(final Class<?> type, final Map<String, ClassLoader> classloaderMap, final ClassLoader classLoader, final Set<Class> classes) {
final String className = type.getName();
@@ -157,7 +157,7 @@ public class ExtensionManager {
* returns null it indicates the given type is not known or was not
* detected.
*
- * @param classType
+ * @param classType to lookup the classloader of
* @return String of fully qualified class name; null if not a detected type
*/
public static ClassLoader getClassLoader(final String classType) {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java
index 946c26e..3331fd2 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java
@@ -49,10 +49,10 @@ import org.slf4j.LoggerFactory;
* directory structure:
*
* <pre>
- * +META-INF/
- * +-- bundled-dependencies/
- * +-- <JAR files>
- * +-- MANIFEST.MF
+ * +META-INF/
+ * +-- bundled-dependencies/
+ * +-- <JAR files>
+ * +-- MANIFEST.MF
* </pre>
* </p>
*
@@ -134,7 +134,7 @@ public class NarClassLoader extends URLClassLoader {
/**
* Construct a nar class loader.
*
- * @param narWorkingDirectory
+ * @param narWorkingDirectory directory to explode nar contents to
* @throws IllegalArgumentException if the NAR is missing the Java Services
* API file for <tt>FlowFileProcessor</tt> implementations.
* @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt>
@@ -152,8 +152,8 @@ public class NarClassLoader extends URLClassLoader {
/**
* Construct a nar class loader with the specific parent.
*
- * @param narWorkingDirectory
- * @param parentClassLoader
+ * @param narWorkingDirectory directory to explode nar contents to
+ * @param parentClassLoader parent class loader of this nar
* @throws IllegalArgumentException if the NAR is missing the Java Services
* API file for <tt>FlowFileProcessor</tt> implementations.
* @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt>
@@ -204,22 +204,22 @@ public class NarClassLoader extends URLClassLoader {
if (!dependencies.isDirectory()) {
LOGGER.warn(narWorkingDirectory + " does not contain META-INF/bundled-dependencies!");
}
-
+
final File nativeDir = new File(dependencies, "native");
final File soFile = new File(nativeDir, libname + ".so");
- if ( soFile.exists() ) {
+ if (soFile.exists()) {
return soFile.getAbsolutePath();
} else {
final File dllFile = new File(nativeDir, libname + ".dll");
- if ( dllFile.exists() ) {
+ if (dllFile.exists()) {
return dllFile.getAbsolutePath();
}
}
-
+
// not found in the nar. try system native dir
return null;
}
-
+
@Override
public String toString() {
return NarClassLoader.class.getName() + "[" + narWorkingDirectory.getPath() + "]";
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java
index e7e01a8..a8d678d 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java
@@ -56,9 +56,9 @@ public final class NarClassLoaders {
* Subsequent attempts will be ignored.
*
*
- * @param properties
- * @throws java.io.IOException
- * @throws java.lang.ClassNotFoundException
+ * @param properties properties object to initialize with
+ * @throws java.io.IOException ioe
+ * @throws java.lang.ClassNotFoundException cfne
* @throws IllegalStateException if the class loaders have already been
* created
*/
@@ -175,11 +175,11 @@ public final class NarClassLoaders {
/**
* Creates a new NarClassLoader. The parentClassLoader may be null.
*
- * @param narDirectory
- * @param parentClassLoader
- * @return
- * @throws IOException
- * @throws ClassNotFoundException
+ * @param narDirectory root directory of nar
+ * @param parentClassLoader parent classloader of nar
+ * @return the nar classloader
+ * @throws IOException ioe
+ * @throws ClassNotFoundException cfne
*/
private static ClassLoader createNarClassLoader(final File narDirectory, final ClassLoader parentClassLoader) throws IOException, ClassNotFoundException {
logger.debug("Loading NAR file: " + narDirectory.getAbsolutePath());
@@ -192,9 +192,9 @@ public final class NarClassLoaders {
* Loads the details for the specified NAR. The details will be extracted
* from the manifest file.
*
- * @param narDirectory
- * @return
- * @throws IOException
+ * @param narDirectory the nar directory
+ * @return details about the NAR
+ * @throws IOException ioe
*/
private static NarDetails getNarDetails(final File narDirectory) throws IOException {
final NarDetails narDetails = new NarDetails();
@@ -214,9 +214,7 @@ public final class NarClassLoaders {
}
/**
- * Gets the framework class loader.
- *
- * @return
+ * @return the framework class loader
*
* @throws IllegalStateException if the frame class loader has not been
* loaded
@@ -230,12 +228,9 @@ public final class NarClassLoaders {
}
/**
- * Gets the class loader for the specified working directory. Returns null
- * when no class loader exists for the specified working directory.
- *
- * @param extensionWorkingDirectory
- * @return
- *
+ * @param extensionWorkingDirectory the directory
+ * @return the class loader for the specified working directory. Returns
+ * null when no class loader exists for the specified working directory
* @throws IllegalStateException if the class loaders have not been loaded
*/
public static ClassLoader getExtensionClassLoader(final File extensionWorkingDirectory) {
@@ -251,10 +246,7 @@ public final class NarClassLoaders {
}
/**
- * Gets the extension class loaders.
- *
- * @return
- *
+ * @return the extension class loaders
* @throws IllegalStateException if the class loaders have not been loaded
*/
public static Set<ClassLoader> getExtensionClassLoaders() {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java
index 3aaf839..f1fef15 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java
@@ -169,10 +169,10 @@ public final class NarUnpacker {
/**
* Unpacks the specified nar into the specified base working directory.
*
- * @param nar
- * @param baseWorkingDirectory
- * @return
- * @throws IOException
+ * @param nar the nar to unpack
+ * @param baseWorkingDirectory the directory to unpack to
+ * @return the directory to the unpacked NAR
+ * @throws IOException if unable to explode nar
*/
private static File unpackNar(final File nar, final File baseWorkingDirectory) throws IOException {
final File narWorkingDirectory = new File(baseWorkingDirectory, nar.getName() + "-unpacked");
@@ -324,9 +324,9 @@ public final class NarUnpacker {
/**
* Calculates an md5 sum of the specified file.
*
- * @param file
- * @return
- * @throws IOException
+ * @param file to calculate the md5sum of
+ * @return the md5sum bytes
+ * @throws IOException if cannot read file
*/
private static byte[] calculateMd5sum(final File file) throws IOException {
try (final FileInputStream inputStream = new FileInputStream(file)) {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java
index fb95dbf..42bea01 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java
@@ -52,9 +52,9 @@ public class FileUtils {
* Deletes the given file. If the given file exists but could not be deleted
* this will be printed as a warning to the given logger
*
- * @param file
- * @param logger
- * @return
+ * @param file to delete
+ * @param logger to notify
+ * @return true if deleted
*/
public static boolean deleteFile(final File file, final Logger logger) {
return FileUtils.deleteFile(file, logger, 1);
@@ -64,8 +64,8 @@ public class FileUtils {
* Deletes the given file. If the given file exists but could not be deleted
* this will be printed as a warning to the given logger
*
- * @param file
- * @param logger
+ * @param file to delete
+ * @param logger to notify
* @param attempts indicates how many times an attempt to delete should be
* made
* @return true if given file no longer exists
@@ -101,9 +101,9 @@ public class FileUtils {
* recursive) that match the given filename filter. If any file cannot be
* deleted then this is printed at warn to the given logger.
*
- * @param directory
+ * @param directory to delete contents of
* @param filter if null then no filter is used
- * @param logger
+ * @param logger to notify
*/
public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger) {
FileUtils.deleteFilesInDir(directory, filter, logger, false);
@@ -114,10 +114,10 @@ public class FileUtils {
* that match the given filename filter. If any file cannot be deleted then
* this is printed at warn to the given logger.
*
- * @param directory
+ * @param directory to delete contents of
* @param filter if null then no filter is used
- * @param logger
- * @param recurse
+ * @param logger to notify
+ * @param recurse true if should recurse
*/
public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger, final boolean recurse) {
FileUtils.deleteFilesInDir(directory, filter, logger, recurse, false);
@@ -128,9 +128,9 @@ public class FileUtils {
* that match the given filename filter. If any file cannot be deleted then
* this is printed at warn to the given logger.
*
- * @param directory
+ * @param directory to delete contents of
* @param filter if null then no filter is used
- * @param logger
+ * @param logger to notify
* @param recurse will look for contents of sub directories.
* @param deleteEmptyDirectories default is false; if true will delete
* directories found that are empty
@@ -157,9 +157,9 @@ public class FileUtils {
/**
* Deletes given files.
*
- * @param files
+ * @param files to delete
* @param recurse will recurse
- * @throws IOException
+ * @throws IOException if issues deleting files
*/
public static void deleteFiles(final Collection<File> files, final boolean recurse) throws IOException {
for (final File file : files) {
[2/7] incubator-nifi git commit: NIFI-271 checkpoint
Posted by jo...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/TestRunner.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/TestRunner.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/TestRunner.java
index 177c889..c4fec35 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/TestRunner.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/TestRunner.java
@@ -38,29 +38,23 @@ import org.apache.nifi.reporting.InitializationException;
public interface TestRunner {
/**
- * Returns the {@link Processor} for which this <code>TestRunner</code> is
+ * @return the {@link Processor} for which this <code>TestRunner</code> is
* configured
- *
- * @return
*/
Processor getProcessor();
/**
- * Returns the {@link ProcessSessionFactory} that this
+ * @return the {@link ProcessSessionFactory} that this
* <code>TestRunner</code> will use to invoke the
* {@link Processor#onTrigger(ProcessContext, ProcessSessionFactory)} method
- *
- * @return
*/
ProcessSessionFactory getProcessSessionFactory();
/**
- * Returns the {@Link ProcessContext} that this <code>TestRunner</code> will
+ * @return the {@Link ProcessContext} that this <code>TestRunner</code> will
* use to invoke the
* {@link Processor#onTrigger(ProcessContext, ProcessSessionFactory) onTrigger}
* method
- *
- * @return
*/
ProcessContext getProcessContext();
@@ -74,25 +68,26 @@ public interface TestRunner {
* Performs the same operation as calling {@link #run(int, boolean)} with a
* value of <code>true</code>
*
- * @param iterations
+ * @param iterations number of iterations
*/
void run(int iterations);
/**
- * performs the same operation as calling {@link #run(int, boolean, int)} with a value
- * of {@code iterations}, {@code stopOnFinish}, {@code true}
- *
- * @param iterations
- * @param stopOnFinish
+ * performs the same operation as calling {@link #run(int, boolean, int)}
+ * with a value of {@code iterations}, {@code stopOnFinish}, {@code true}
+ *
+ * @param iterations number of iterations
+ * @param stopOnFinish flag to stop when finished
*/
void run(int iterations, boolean stopOnFinish);
-
+
/**
* This method runs the {@link Processor} <code>iterations</code> times,
* using the sequence of steps below:
* <ul>
* <li>
- * If {@code initialize} is true, run all methods on the Processor that are annotated with the
+ * If {@code initialize} is true, run all methods on the Processor that are
+ * annotated with the
* {@link nifi.processor.annotation.OnScheduled @OnScheduled} annotation. If
* any of these methods throws an Exception, the Unit Test will fail.
* </li>
@@ -122,14 +117,13 @@ public interface TestRunner {
* </li>
* </ul>
*
- * @param iterations
+ * @param iterations number of iterations
* @param stopOnFinish whether or not to run the Processor methods that are
* annotated with {@link nifi.processor.annotation.OnStopped @OnStopped}
+ * @param initialize true if must initialize
*/
void run(int iterations, boolean stopOnFinish, final boolean initialize);
-
-
/**
* Invokes all methods on the Processor that are annotated with the
* {@link nifi.processor.annotation.OnShutdown @OnShutdown} annotation. If
@@ -141,16 +135,14 @@ public interface TestRunner {
* Updates the number of threads that will be used to run the Processor when
* calling the {@link #run()} or {@link #run(int)} methods.
*
- * @param threadCount
+ * @param threadCount num threads
*/
void setThreadCount(int threadCount);
/**
- * Returns the currently configured number of threads that will be used to
+ * @return the currently configured number of threads that will be used to
* runt he Processor when calling the {@link #run()} or {@link #run(int)}
- * methods.
- *
- * @return
+ * methods
*/
int getThreadCount();
@@ -160,9 +152,9 @@ public interface TestRunner {
* descriptor's validator. Otherwise, Assert.fail() is called, causing the
* unit test to fail
*
- * @param propertyName
- * @param propertyValue
- * @return
+ * @param propertyName name
+ * @param propertyValue value
+ * @return result
*/
ValidationResult setProperty(String propertyName, String propertyValue);
@@ -172,9 +164,9 @@ public interface TestRunner {
* descriptor's validator. Otherwise, Assert.fail() is called, causing the
* unit test to fail
*
- * @param descriptor
- * @param value
- * @return
+ * @param descriptor descriptor
+ * @param value value
+ * @return result
*/
ValidationResult setProperty(PropertyDescriptor descriptor, String value);
@@ -184,16 +176,16 @@ public interface TestRunner {
* descriptor's validator. Otherwise, Assert.fail() is called, causing the
* unit test to fail
*
- * @param descriptor
- * @param value
- * @return
+ * @param descriptor descriptor
+ * @param value allowable valu
+ * @return result
*/
ValidationResult setProperty(PropertyDescriptor descriptor, AllowableValue value);
/**
- * Sets the annontation data.
+ * Sets the annotation data.
*
- * @param annotationData
+ * @param annotationData data
*/
void setAnnotationData(String annotationData);
@@ -201,7 +193,7 @@ public interface TestRunner {
* Asserts that all FlowFiles that were transferred were transferred to the
* given relationship
*
- * @param relationship
+ * @param relationship to verify
*/
void assertAllFlowFilesTransferred(String relationship);
@@ -209,7 +201,7 @@ public interface TestRunner {
* Asserts that all FlowFiles that were transferred were transferred to the
* given relationship
*
- * @param relationship
+ * @param relationship to verify
*/
void assertAllFlowFilesTransferred(Relationship relationship);
@@ -218,8 +210,8 @@ public interface TestRunner {
* given relationship and that the number of FlowFiles transferred is equal
* to <code>count</code>
*
- * @param relationship
- * @param count
+ * @param relationship to verify
+ * @param count number of expected transfers
*/
void assertAllFlowFilesTransferred(String relationship, int count);
@@ -228,8 +220,8 @@ public interface TestRunner {
* given relationship and that the number of FlowFiles transferred is equal
* to <code>count</code>
*
- * @param relationship
- * @param count
+ * @param relationship to verify
+ * @param count number of expected transfers
*/
void assertAllFlowFilesTransferred(Relationship relationship, int count);
@@ -237,8 +229,8 @@ public interface TestRunner {
* Assert that the number of FlowFiles transferred to the given relationship
* is equal to the given count
*
- * @param relationship
- * @param count
+ * @param relationship to verify
+ * @param count number of expected transfers
*/
void assertTransferCount(Relationship relationship, int count);
@@ -246,8 +238,8 @@ public interface TestRunner {
* Assert that the number of FlowFiles transferred to the given relationship
* is equal to the given count
*
- * @param relationship
- * @param count
+ * @param relationship to verify
+ * @param count number of expected transfers
*/
void assertTransferCount(String relationship, int count);
@@ -257,10 +249,8 @@ public interface TestRunner {
void assertQueueEmpty();
/**
- * Returns <code>true</code> if the Input Queue to the Processor is empty,
+ * @return <code>true</code> if the Input Queue to the Processor is empty,
* <code>false</code> otherwise
- *
- * @return
*/
boolean isQueueEmpty();
@@ -293,7 +283,7 @@ public interface TestRunner {
/**
* Enqueues the given FlowFiles into the Processor's input queue
*
- * @param flowFiles
+ * @param flowFiles to enqueue
*/
void enqueue(FlowFile... flowFiles);
@@ -302,8 +292,8 @@ public interface TestRunner {
* FlowFile from this content with no attributes and adds this FlowFile to
* the Processor's Input Queue
*
- * @param path
- * @throws IOException
+ * @param path to read content from
+ * @throws IOException if unable to read content
*/
void enqueue(Path path) throws IOException;
@@ -312,9 +302,9 @@ public interface TestRunner {
* FlowFile from this content with the given attributes and adds this
* FlowFile to the Processor's Input Queue
*
- * @param path
- * @param attributes
- * @throws IOException
+ * @param path to read content from
+ * @param attributes attributes to use for new flow file
+ * @throws IOException if unable to read content
*/
void enqueue(Path path, Map<String, String> attributes) throws IOException;
@@ -323,7 +313,7 @@ public interface TestRunner {
* FlowFile from this content with no attributes and adds this FlowFile to
* the Processor's Input Queue
*
- * @param data
+ * @param data to enqueue
*/
void enqueue(byte[] data);
@@ -332,8 +322,8 @@ public interface TestRunner {
* FlowFile from this content with the given attributes and adds this
* FlowFile to the Processor's Input Queue
*
- * @param data
- * @param attributes
+ * @param data to enqueue
+ * @param attributes to use for enqueued items
*/
void enqueue(byte[] data, Map<String, String> attributes);
@@ -342,7 +332,7 @@ public interface TestRunner {
* creates a FlowFile from this content with no attributes and adds this
* FlowFile to the Processor's Input Queue
*
- * @param data
+ * @param data to source data from
*/
void enqueue(InputStream data);
@@ -351,8 +341,8 @@ public interface TestRunner {
* creates a FlowFile from this content with the given attributes and adds
* this FlowFile to the Processor's Input Queue
*
- * @param data
- * @param attributes
+ * @param data source of data
+ * @param attributes to use for flow files
*/
void enqueue(InputStream data, Map<String, String> attributes);
@@ -360,8 +350,8 @@ public interface TestRunner {
* Copies the contents of the given {@link MockFlowFile} into a byte array
* and returns that byte array.
*
- * @param flowFile
- * @return
+ * @param flowFile to get content for
+ * @return byte array of flowfile content
*/
byte[] getContentAsByteArray(MockFlowFile flowFile);
@@ -369,8 +359,8 @@ public interface TestRunner {
* Returns a List of FlowFiles in the order in which they were transferred
* to the given relationship
*
- * @param relationship
- * @return
+ * @param relationship to get flowfiles for
+ * @return flowfiles transfered to given relationship
*/
List<MockFlowFile> getFlowFilesForRelationship(String relationship);
@@ -378,39 +368,31 @@ public interface TestRunner {
* Returns a List of FlowFiles in the order in which they were transferred
* to the given relationship
*
- * @param relationship
- * @return
+ * @param relationship to get flowfiles for
+ * @return flowfiles transfered to given relationship
*/
List<MockFlowFile> getFlowFilesForRelationship(Relationship relationship);
/**
- * Returns the {@link ProvenanceReporter} that will be used by the
- * configured {@link Processor} for reporting Provenance Events.
- *
- * @return
+ * @return the {@link ProvenanceReporter} that will be used by the
+ * configured {@link Processor} for reporting Provenance Events
*/
ProvenanceReporter getProvenanceReporter();
/**
- * Returns the current size of the Processor's Input Queue
- *
- * @return
+ * @return the current size of the Processor's Input Queue
*/
QueueSize getQueueSize();
/**
- * Returns the current value of the counter with the specified name, or null
+ * @param name of counter
+ * @return the current value of the counter with the specified name, or null
* if no counter exists with the specified name
- *
- * @param name
- * @return
*/
Long getCounterValue(String name);
/**
- * Returns the number of FlowFiles that have been removed from the system
- *
- * @return
+ * @return the number of FlowFiles that have been removed from the system
*/
int getRemovedCount();
@@ -418,10 +400,11 @@ public interface TestRunner {
* Indicates to the Framework that the given Relationship should be
* considered "available", meaning that the queues of all Connections that
* contain this Relationship are not full. This is generally used only when
- * dealing with Processors that use the {@link nifi.processor.annotation.TriggerWhenAnyDestinationAvailable
- * @TriggerWhenAnyDestinationAvailable} annotation.
+ * dealing with Processors that use the
+ * {@link nifi.processor.annotation.TriggerWhenAnyDestinationAvailable}
+ * annotation.
*
- * @param relationship
+ * @param relationship to mark as available
*/
void setRelationshipAvailable(Relationship relationship);
@@ -429,9 +412,10 @@ public interface TestRunner {
* Indicates to the Framework that the given Relationship with the given
* name should be considered "available", meaning that the queues of all
* Connections that contain this Relationship are not full. This is
- * generally used only when dealing with Processors that use the {@link nifi.processor.annotation.TriggerWhenAnyDestinationAvailable
- * @param relationshipName
- * @TriggerWhenAnyDestinationAvailable} annotation.
+ * generally used only when dealing with Processors that use the
+ * {@link nifi.processor.annotation.TriggerWhenAnyDestinationAvailable}
+ *
+ * @param relationshipName relationship name
*/
void setRelationshipAvailable(String relationshipName);
@@ -439,10 +423,11 @@ public interface TestRunner {
* Indicates to the Framework that the given Relationship should NOT be
* considered "available", meaning that the queue of at least one Connection
* that contain this Relationship is full. This is generally used only when
- * dealing with Processors that use the {@link nifi.processor.annotation.TriggerWhenAnyDestinationAvailable
- * @TriggerWhenAnyDestinationAvailable} annotation.
+ * dealing with Processors that use the
+ * {@link nifi.processor.annotation.TriggerWhenAnyDestinationAvailable}
+ * annotation.
*
- * @param relationship
+ * @param relationship to mark as unavailable
*/
void setRelationshipUnavailable(Relationship relationship);
@@ -450,9 +435,10 @@ public interface TestRunner {
* Indicates to the Framework that the Relationship with the given name
* should NOT be considered "available", meaning that the queue of at least
* one Connection that contain this Relationship is full. This is generally
- * used only when dealing with Processors that use the {@link nifi.processor.annotation.TriggerWhenAnyDestinationAvailable
- * @param relationshipName
- * @TriggerWhenAnyDestinationAvailable} annotation.
+ * used only when dealing with Processors that use the
+ * {@link nifi.processor.annotation.TriggerWhenAnyDestinationAvailable}
+ *
+ * @param relationshipName name of relationship.
*/
void setRelationshipUnavailable(String relationshipName);
@@ -464,12 +450,13 @@ public interface TestRunner {
* {@link nifi.controller.ControllerServiceInitializationContext ControllerServiceInitializationContext}
* and initialize the ControllerService with no specified properties.
*
- * This will call any method on the given Controller Service that is annotated with
- * the {@link org.apache.nifi.annotation.lifecycle.OnAdded @OnAdded} annotation.
+ * This will call any method on the given Controller Service that is
+ * annotated with the
+ * {@link org.apache.nifi.annotation.lifecycle.OnAdded @OnAdded} annotation.
*
- * @param identifier
- * @param service
- * @throws InitializationException
+ * @param identifier of service
+ * @param service the service
+ * @throws InitializationException ie
*/
void addControllerService(String identifier, ControllerService service) throws InitializationException;
@@ -481,185 +468,206 @@ public interface TestRunner {
* {@link nifi.controller.ControllerServiceInitializationContext ControllerServiceInitializationContext}
* and initialize the ControllerService with the given properties.
*
- * This will call any method on the given Controller Service that is annotated with
- * the {@link org.apache.nifi.annotation.lifecycle.OnAdded @OnAdded} annotation.
- *
- * @param identifier
- * @param service
- * @param properties
- * @throws InitializationException
+ * This will call any method on the given Controller Service that is
+ * annotated with the
+ * {@link org.apache.nifi.annotation.lifecycle.OnAdded @OnAdded} annotation.
+ *
+ * @param identifier of service
+ * @param service the service
+ * @param properties service properties
+ * @throws InitializationException ie
*/
void addControllerService(String identifier, ControllerService service, Map<String, String> properties) throws InitializationException;
/**
* <p>
- * Marks the Controller Service as enabled so that it can be used by other components.
+ * Marks the Controller Service as enabled so that it can be used by other
+ * components.
* </p>
- *
+ *
* <p>
- * This method will result in calling any method in the Controller Service that is
- * annotated with the {@link org.apache.nifi.annotation.lifecycle.OnEnabled @OnEnabled} annotation.
+ * This method will result in calling any method in the Controller Service
+ * that is annotated with the
+ * {@link org.apache.nifi.annotation.lifecycle.OnEnabled @OnEnabled}
+ * annotation.
* </p>
- *
- * @param service
+ *
+ * @param service the service to enable
*/
void enableControllerService(ControllerService service);
-
+
/**
* <p>
- * Marks the Controller Service as disabled so that it cannot be used by other components.
+ * Marks the Controller Service as disabled so that it cannot be used by
+ * other components.
* </p>
- *
+ *
* <p>
- * This method will result in calling any method in the Controller Service that is
- * annotated with the {@link org.apache.nifi.annotation.lifecycle.OnDisabled @OnDisabled} annotation.
+ * This method will result in calling any method in the Controller Service
+ * that is annotated with the
+ * {@link org.apache.nifi.annotation.lifecycle.OnDisabled @OnDisabled}
+ * annotation.
* </p>
- *
- * @param service
+ *
+ * @param service the service to disable
*/
void disableControllerService(ControllerService service);
-
+
/**
- * <p>
- * Returns {@code true} if the given Controller Service is enabled, {@code false} if it is disabled.
- * </p>
- *
- * @param service
- * @return
- *
- * @throws IllegalArgumentException if the given ControllerService is not known by this TestRunner
- * (i.e., it has not been added via the {@link #addControllerService(String, ControllerService)} or
- * {@link #addControllerService(String, ControllerService, Map)} method or if the Controller Service
- * has been removed via the {@link #removeControllerService(ControllerService)} method.
+ * @param service the service
+ * @return {@code true} if the given Controller Service is enabled,
+ * {@code false} if it is disabled
+ *
+ * @throws IllegalArgumentException if the given ControllerService is not
+ * known by this TestRunner (i.e., it has not been added via the
+ * {@link #addControllerService(String, ControllerService)} or
+ * {@link #addControllerService(String, ControllerService, Map)} method or
+ * if the Controller Service has been removed via the
+ * {@link #removeControllerService(ControllerService)} method.
*/
boolean isControllerServiceEnabled(ControllerService service);
-
+
/**
* <p>
- * Removes the Controller Service from the TestRunner. This will call any method on the ControllerService
- * that is annotated with the {@link org.apache.nifi.annotation.lifecycle.OnRemoved @OnRemoved} annotation.
+ * Removes the Controller Service from the TestRunner. This will call any
+ * method on the ControllerService that is annotated with the
+ * {@link org.apache.nifi.annotation.lifecycle.OnRemoved @OnRemoved}
+ * annotation.
* </p>
- *
- * @param service
- *
+ *
+ * @param service the service
+ *
* @throws IllegalStateException if the ControllerService is not disabled
- * @throws IllegalArgumentException if the given ControllerService is not known by this TestRunner
- * (i.e., it has not been added via the {@link #addControllerService(String, ControllerService)} or
- * {@link #addControllerService(String, ControllerService, Map)} method or if the Controller Service
- * has been removed via the {@link #removeControllerService(ControllerService)} method.
- *
+ * @throws IllegalArgumentException if the given ControllerService is not
+ * known by this TestRunner (i.e., it has not been added via the
+ * {@link #addControllerService(String, ControllerService)} or
+ * {@link #addControllerService(String, ControllerService, Map)} method or
+ * if the Controller Service has been removed via the
+ * {@link #removeControllerService(ControllerService)} method.
+ *
*/
void removeControllerService(ControllerService service);
-
+
/**
* Sets the given property on the given ControllerService
- *
- * @param service
- * @param property
- * @param value
- *
+ *
+ * @param service to modify
+ * @param property to modify
+ * @param value value to use
+ * @return result
+ *
* @throws IllegalStateException if the ControllerService is not disabled
- * @throws IllegalArgumentException if the given ControllerService is not known by this TestRunner
- * (i.e., it has not been added via the {@link #addControllerService(String, ControllerService)} or
- * {@link #addControllerService(String, ControllerService, Map)} method or if the Controller Service
- * has been removed via the {@link #removeControllerService(ControllerService)} method.
- *
+ * @throws IllegalArgumentException if the given ControllerService is not
+ * known by this TestRunner (i.e., it has not been added via the
+ * {@link #addControllerService(String, ControllerService)} or
+ * {@link #addControllerService(String, ControllerService, Map)} method or
+ * if the Controller Service has been removed via the
+ * {@link #removeControllerService(ControllerService)} method.
+ *
*/
ValidationResult setProperty(ControllerService service, PropertyDescriptor property, String value);
-
-
+
/**
* Sets the given property on the given ControllerService
- *
- * @param service
- * @param property
- * @param value
- *
+ *
+ * @param service to modify
+ * @param property to modify
+ * @param value value to use
+ * @return result
+ *
* @throws IllegalStateException if the ControllerService is not disabled
- * @throws IllegalArgumentException if the given ControllerService is not known by this TestRunner
- * (i.e., it has not been added via the {@link #addControllerService(String, ControllerService)} or
- * {@link #addControllerService(String, ControllerService, Map)} method or if the Controller Service
- * has been removed via the {@link #removeControllerService(ControllerService)} method.
- *
+ * @throws IllegalArgumentException if the given ControllerService is not
+ * known by this TestRunner (i.e., it has not been added via the
+ * {@link #addControllerService(String, ControllerService)} or
+ * {@link #addControllerService(String, ControllerService, Map)} method or
+ * if the Controller Service has been removed via the
+ * {@link #removeControllerService(ControllerService)} method.
+ *
*/
ValidationResult setProperty(ControllerService service, PropertyDescriptor property, AllowableValue value);
-
-
+
/**
* Sets the property with the given name on the given ControllerService
- *
- * @param service
- * @param property
- * @param value
- *
+ *
+ * @param service to modify
+ * @param propertyName to modify
+ * @param value value to use
+ * @return result
+ *
* @throws IllegalStateException if the ControllerService is not disabled
- * @throws IllegalArgumentException if the given ControllerService is not known by this TestRunner
- * (i.e., it has not been added via the {@link #addControllerService(String, ControllerService)} or
- * {@link #addControllerService(String, ControllerService, Map)} method or if the Controller Service
- * has been removed via the {@link #removeControllerService(ControllerService)} method.
- *
+ * @throws IllegalArgumentException if the given ControllerService is not
+ * known by this TestRunner (i.e., it has not been added via the
+ * {@link #addControllerService(String, ControllerService)} or
+ * {@link #addControllerService(String, ControllerService, Map)} method or
+ * if the Controller Service has been removed via the
+ * {@link #removeControllerService(ControllerService)} method.
+ *
*/
ValidationResult setProperty(ControllerService service, String propertyName, String value);
-
+
/**
- * Sets the annontation data of the given service to the provided annotation data.
+ * Sets the annontation data of the given service to the provided annotation
+ * data.
+ *
+ * @param service to modify
+ * @param annotationData the data
*
- * @param service
- * @param annotationData
- *
* @throws IllegalStateException if the Controller Service is not disabled
*
- * @throws IllegalArgumentException if the given ControllerService is not known by this TestRunner
- * (i.e., it has not been added via the {@link #addControllerService(String, ControllerService)} or
- * {@link #addControllerService(String, ControllerService, Map)} method or if the Controller Service
- * has been removed via the {@link #removeControllerService(ControllerService)} method.
+ * @throws IllegalArgumentException if the given ControllerService is not
+ * known by this TestRunner (i.e., it has not been added via the
+ * {@link #addControllerService(String, ControllerService)} or
+ * {@link #addControllerService(String, ControllerService, Map)} method or
+ * if the Controller Service has been removed via the
+ * {@link #removeControllerService(ControllerService)} method.
*/
void setAnnotationData(ControllerService service, String annotationData);
-
/**
- * Returns the {@link ControllerService} that is registered with the given
+ * @param identifier of controller service
+ * @return the {@link ControllerService} that is registered with the given
* identifier, or <code>null</code> if no Controller Service exists with the
* given identifier
- *
- * @param identifier
- * @return
*/
ControllerService getControllerService(String identifier);
/**
* Assert that the currently configured set of properties/annotation data
* are valid for the given Controller Service.
- *
- * @throws IllegalArgumentException if the given ControllerService is not known by this TestRunner
- * (i.e., it has not been added via the {@link #addControllerService(String, ControllerService)} or
- * {@link #addControllerService(String, ControllerService, Map)} method or if the Controller Service
- * has been removed via the {@link #removeControllerService(ControllerService)} method.
+ *
+ * @param service the service to validate
+ * @throws IllegalArgumentException if the given ControllerService is not
+ * known by this TestRunner (i.e., it has not been added via the
+ * {@link #addControllerService(String, ControllerService)} or
+ * {@link #addControllerService(String, ControllerService, Map)} method or
+ * if the Controller Service has been removed via the
+ * {@link #removeControllerService(ControllerService)} method.
*/
void assertValid(ControllerService service);
/**
* Assert that the currently configured set of properties/annotation data
* are NOT valid for the given Controller Service.
- *
- * @throws IllegalArgumentException if the given ControllerService is not known by this TestRunner
- * (i.e., it has not been added via the {@link #addControllerService(String, ControllerService)} or
- * {@link #addControllerService(String, ControllerService, Map)} method or if the Controller Service
- * has been removed via the {@link #removeControllerService(ControllerService)} method.
- *
+ *
+ * @param service the service to validate
+ * @throws IllegalArgumentException if the given ControllerService is not
+ * known by this TestRunner (i.e., it has not been added via the
+ * {@link #addControllerService(String, ControllerService)} or
+ * {@link #addControllerService(String, ControllerService, Map)} method or
+ * if the Controller Service has been removed via the
+ * {@link #removeControllerService(ControllerService)} method.
+ *
*/
void assertNotValid(ControllerService service);
/**
- * Returns the {@link ControllerService} that is registered with the given
+ * @param <T> type of service
+ * @param identifier identifier of service
+ * @param serviceType type of service
+ * @return the {@link ControllerService} that is registered with the given
* identifier, cast as the provided service type, or <code>null</code> if no
* Controller Service exists with the given identifier
*
- * @param <T>
- * @param identifier
- * @param serviceType
- * @return
- *
* @throws ClassCastException if the identifier given is registered for a
* Controller Service but that Controller Service is not of the type
* specified
@@ -682,7 +690,7 @@ public interface TestRunner {
* </b>{@link PropertyDescriptor.Builder#expressionLanguageSupported(boolean)}
* </p>
*
- * @param validate
+ * @param validate whether there is any need to validate the EL was used
*/
void setValidateExpressionUsage(boolean validate);
@@ -690,8 +698,8 @@ public interface TestRunner {
* Removes the {@link PropertyDescriptor} from the {@link ProcessContext},
* effectively setting its value to null.
*
- * @param descriptor
- * @return
+ * @param descriptor of property to remove
+ * @return true if removed
*/
boolean removeProperty(PropertyDescriptor descriptor);
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java b/nifi/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
index a561982..323a357 100644
--- a/nifi/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
+++ b/nifi/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java
@@ -26,61 +26,63 @@ import org.junit.Test;
@Ignore("This should not be enabled until we actually fail processor unit tests for using deprecated methods, which should happen in 0.1.0")
public class TestStandardProcessorTestRunner {
- @Test(expected=AssertionError.class)
+ @Test(expected = AssertionError.class)
public void testFailOnDeprecatedTypeAnnotation() {
new StandardProcessorTestRunner(new DeprecatedAnnotation());
}
-
+
@Test
public void testDoesNotFailOnNonDeprecatedTypeAnnotation() {
new StandardProcessorTestRunner(new NewAnnotation());
}
-
- @Test(expected=AssertionError.class)
+
+ @Test(expected = AssertionError.class)
public void testFailOnDeprecatedMethodAnnotation() {
new StandardProcessorTestRunner(new DeprecatedMethodAnnotation());
}
-
+
@Test
public void testDoesNotFailOnNonDeprecatedMethodAnnotation() {
new StandardProcessorTestRunner(new NewMethodAnnotation());
}
-
-
@SuppressWarnings("deprecation")
@org.apache.nifi.processor.annotation.Tags({"deprecated"})
private static class DeprecatedAnnotation extends AbstractProcessor {
+
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
}
}
-
+
@org.apache.nifi.annotation.documentation.Tags({"deprecated"})
private static class NewAnnotation extends AbstractProcessor {
+
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
}
}
-
+
private static class NewMethodAnnotation extends AbstractProcessor {
+
@org.apache.nifi.annotation.lifecycle.OnScheduled
public void dummy() {
-
+
}
-
+
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
}
}
-
+
private static class DeprecatedMethodAnnotation extends AbstractProcessor {
+
@SuppressWarnings("deprecation")
@org.apache.nifi.processor.annotation.OnScheduled
public void dummy() {
-
+
}
-
+
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java
index 8a53f00..ea033c5 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java
@@ -54,7 +54,7 @@ public class DocGenerator {
* Generates documentation into the work/docs dir specified by
* NiFiProperties.
*
- * @param properties
+ * @param properties to lookup nifi properties
*/
public static void generate(final NiFiProperties properties) {
@SuppressWarnings("rawtypes")
@@ -90,10 +90,10 @@ public class DocGenerator {
* @param docsDir the work\docs\components dir to stick component
* documentation in
* @param componentClass the class to document
- * @throws InstantiationException
- * @throws IllegalAccessException
- * @throws IOException
- * @throws InitializationException
+ * @throws InstantiationException ie
+ * @throws IllegalAccessException iae
+ * @throws IOException ioe
+ * @throws InitializationException ie
*/
private static void document(final File docsDir, final Class<? extends ConfigurableComponent> componentClass)
throws InstantiationException, IllegalAccessException, IOException, InitializationException {
@@ -163,7 +163,7 @@ public class DocGenerator {
* Checks to see if a directory to write to has an additionalDetails.html in
* it already.
*
- * @param directory
+ * @param directory to check
* @return true if additionalDetails.html exists, false otherwise.
*/
private static boolean hasAdditionalInfo(File directory) {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java
index 243aaa3..a86a416 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlDocumentationWriter.java
@@ -72,13 +72,11 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* Writes the head portion of the HTML documentation.
- *
- * @param configurableComponent
- * the component to describe
- * @param xmlStreamWriter
- * the stream to write to
- * @throws XMLStreamException
- * thrown if there was a problem writing to the stream
+ *
+ * @param configurableComponent the component to describe
+ * @param xmlStreamWriter the stream to write to
+ * @throws XMLStreamException thrown if there was a problem writing to the
+ * stream
*/
protected void writeHead(final ConfigurableComponent configurableComponent,
final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
@@ -99,9 +97,8 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* Gets the class name of the component.
- *
- * @param configurableComponent
- * the component to describe
+ *
+ * @param configurableComponent the component to describe
* @return the class name of the component
*/
protected String getTitle(final ConfigurableComponent configurableComponent) {
@@ -111,15 +108,13 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* Writes the body section of the documentation, this consists of the
* component description, the tags, and the PropertyDescriptors.
- *
- * @param configurableComponent
- * the component to describe
- * @param xmlStreamWriter
- * the stream writer
- * @param hasAdditionalDetails
- * whether there are additional details present or not
- * @throws XMLStreamException
- * thrown if there was a problem writing to the XML stream
+ *
+ * @param configurableComponent the component to describe
+ * @param xmlStreamWriter the stream writer
+ * @param hasAdditionalDetails whether there are additional details present
+ * or not
+ * @throws XMLStreamException thrown if there was a problem writing to the
+ * XML stream
*/
private void writeBody(final ConfigurableComponent configurableComponent,
final XMLStreamWriter xmlStreamWriter, final boolean hasAdditionalDetails)
@@ -136,13 +131,10 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* Writes the list of components that may be linked from this component.
- *
- * @param configurableComponent
- * the component to describe
- * @param xmlStreamWriter
- * the stream writer to use
- * @throws XMLStreamException
- * thrown if there was a problem writing the XML
+ *
+ * @param configurableComponent the component to describe
+ * @param xmlStreamWriter the stream writer to use
+ * @throws XMLStreamException thrown if there was a problem writing the XML
*/
private void writeSeeAlso(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter)
throws XMLStreamException {
@@ -162,7 +154,7 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
++index;
}
-
+
for (final String linkedComponent : seeAlso.classNames()) {
if (index != 0) {
xmlStreamWriter.writeCharacters(", ");
@@ -171,7 +163,7 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
final String link = "../" + linkedComponent + "/index.html";
final int indexOfLastPeriod = linkedComponent.lastIndexOf(".") + 1;
-
+
writeLink(xmlStreamWriter, linkedComponent.substring(indexOfLastPeriod), link);
++index;
@@ -183,26 +175,17 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* This method may be overridden by sub classes to write additional
* information to the body of the documentation.
- *
- * @param configurableComponent
- * the component to describe
- * @param xmlStreamWriter
- * the stream writer
- * @throws XMLStreamException
- * thrown if there was a problem writing to the XML stream
+ *
+ * @param configurableComponent the component to describe
+ * @param xmlStreamWriter the stream writer
+ * @throws XMLStreamException thrown if there was a problem writing to the
+ * XML stream
*/
protected void writeAdditionalBodyInfo(final ConfigurableComponent configurableComponent,
final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
}
- /**
- * Writes the tags attached to a ConfigurableComponent.
- *
- * @param configurableComponent
- * @param xmlStreamWriter
- * @throws XMLStreamException
- */
private void writeTags(final ConfigurableComponent configurableComponent,
final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
final Tags tags = configurableComponent.getClass().getAnnotation(Tags.class);
@@ -218,30 +201,27 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
}
xmlStreamWriter.writeEndElement();
}
-
+
static String join(final String[] toJoin, final String delimiter) {
- final StringBuilder sb = new StringBuilder();
- for (int i=0; i < toJoin.length; i++) {
- sb.append(toJoin[i]);
- if ( i < toJoin.length - 1 ) {
- sb.append(delimiter);
- }
- }
- return sb.toString();
+ final StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < toJoin.length; i++) {
+ sb.append(toJoin[i]);
+ if (i < toJoin.length - 1) {
+ sb.append(delimiter);
+ }
+ }
+ return sb.toString();
}
/**
* Writes a description of the configurable component.
- *
- * @param configurableComponent
- * the component to describe
- * @param xmlStreamWriter
- * the stream writer
- * @param hasAdditionalDetails
- * whether there are additional details available as
- * 'additionalDetails.html'
- * @throws XMLStreamException
- * thrown if there was a problem writing to the XML stream
+ *
+ * @param configurableComponent the component to describe
+ * @param xmlStreamWriter the stream writer
+ * @param hasAdditionalDetails whether there are additional details
+ * available as 'additionalDetails.html'
+ * @throws XMLStreamException thrown if there was a problem writing to the
+ * XML stream
*/
protected void writeDescription(final ConfigurableComponent configurableComponent,
final XMLStreamWriter xmlStreamWriter, final boolean hasAdditionalDetails)
@@ -260,9 +240,8 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* Gets a description of the ConfigurableComponent using the
* CapabilityDescription annotation.
- *
- * @param configurableComponent
- * the component to describe
+ *
+ * @param configurableComponent the component to describe
* @return a description of the configurableComponent
*/
protected String getDescription(final ConfigurableComponent configurableComponent) {
@@ -281,13 +260,11 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* Writes the PropertyDescriptors out as a table.
- *
- * @param configurableComponent
- * the component to describe
- * @param xmlStreamWriter
- * the stream writer
- * @throws XMLStreamException
- * thrown if there was a problem writing to the XML Stream
+ *
+ * @param configurableComponent the component to describe
+ * @param xmlStreamWriter the stream writer
+ * @throws XMLStreamException thrown if there was a problem writing to the
+ * XML Stream
*/
protected void writeProperties(final ConfigurableComponent configurableComponent,
final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
@@ -367,13 +344,7 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
writeSimpleElement(xmlStreamWriter, "p", "This component has no required or optional properties.");
}
}
-
- /**
- * Writes a list of the dynamic properties that a processor supports
- * @param configurableComponent
- * @param xmlStreamWriter
- * @throws XMLStreamException
- */
+
private void writeDynamicProperties(final ConfigurableComponent configurableComponent,
final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
@@ -392,7 +363,7 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
writeSimpleElement(xmlStreamWriter, "th", "Description");
xmlStreamWriter.writeEndElement();
for (final DynamicProperty dynamicProperty : dynamicProperties) {
- xmlStreamWriter.writeStartElement("tr");
+ xmlStreamWriter.writeStartElement("tr");
writeSimpleElement(xmlStreamWriter, "td", dynamicProperty.name(), false, "name");
writeSimpleElement(xmlStreamWriter, "td", dynamicProperty.value(), false, "value");
xmlStreamWriter.writeStartElement("td");
@@ -404,17 +375,12 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
xmlStreamWriter.writeEndElement();
xmlStreamWriter.writeEndElement();
}
-
+
xmlStreamWriter.writeEndElement();
xmlStreamWriter.writeEndElement();
}
}
- /**
- * Gets the dynamic properties for a configurable component
- * @param configurableComponent
- * @return
- */
private List<DynamicProperty> getDynamicProperties(ConfigurableComponent configurableComponent) {
final List<DynamicProperty> dynamicProperties = new ArrayList<>();
final DynamicProperties dynProps = configurableComponent.getClass().getAnnotation(DynamicProperties.class);
@@ -423,22 +389,15 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
dynamicProperties.add(dynProp);
}
}
-
+
final DynamicProperty dynProp = configurableComponent.getClass().getAnnotation(DynamicProperty.class);
if (dynProp != null) {
dynamicProperties.add(dynProp);
}
-
+
return dynamicProperties;
}
- /**
- * Writes an info icon with a description.
- *
- * @param xmlStreamWriter
- * @param description the description of the item
- * @throws XMLStreamException
- */
private void writeValidValueDescription(XMLStreamWriter xmlStreamWriter, String description)
throws XMLStreamException {
xmlStreamWriter.writeCharacters(" ");
@@ -453,13 +412,11 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* Interrogates a PropertyDescriptor to get a list of AllowableValues, if
* there are none, nothing is written to the stream.
- *
- * @param xmlStreamWriter
- * the stream writer to use
- * @param property
- * the property to describe
- * @throws XMLStreamException
- * thrown if there was a problem writing to the XML Stream
+ *
+ * @param xmlStreamWriter the stream writer to use
+ * @param property the property to describe
+ * @throws XMLStreamException thrown if there was a problem writing to the
+ * XML Stream
*/
protected void writeValidValues(XMLStreamWriter xmlStreamWriter, PropertyDescriptor property)
throws XMLStreamException {
@@ -489,40 +446,38 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* Writes a begin element, then text, then end element for the element of a
* users choosing. Example: <p>text</p>
- *
- * @param writer
- * the stream writer to use
- * @param elementName
- * the name of the element
- * @param characters
- * the characters to insert into the element
- * @param strong
- * whether the characters should be strong or not.
- * @throws XMLStreamException
- * thrown if there was a problem writing to the stream.
+ *
+ * @param writer the stream writer to use
+ * @param elementName the name of the element
+ * @param characters the characters to insert into the element
+ * @param strong whether the characters should be strong or not.
+ * @throws XMLStreamException thrown if there was a problem writing to the
+ * stream.
*/
protected final static void writeSimpleElement(final XMLStreamWriter writer, final String elementName,
final String characters, boolean strong) throws XMLStreamException {
- writeSimpleElement(writer, elementName, characters, strong, null);
+ writeSimpleElement(writer, elementName, characters, strong, null);
}
-
+
/**
- * Writes a begin element, an id attribute(if specified), then text, then end element for
- * element of the users choosing. Example: <p id="p-id">text</p>
- *
+ * Writes a begin element, an id attribute(if specified), then text, then
+ * end element for element of the users choosing. Example: <p
+ * id="p-id">text</p>
+ *
* @param writer the stream writer to use
* @param elementName the name of the element
* @param characters the text of the element
* @param strong whether to bold the text of the element or not
- * @param id the id of the element. specifying null will cause no element to be written.
- * @throws XMLStreamException
+ * @param id the id of the element. specifying null will cause no element to
+ * be written.
+ * @throws XMLStreamException xse
*/
protected final static void writeSimpleElement(final XMLStreamWriter writer, final String elementName,
final String characters, boolean strong, String id) throws XMLStreamException {
- writer.writeStartElement(elementName);
- if (id != null) {
- writer.writeAttribute("id", id);
- }
+ writer.writeStartElement(elementName);
+ if (id != null) {
+ writer.writeAttribute("id", id);
+ }
if (strong) {
writer.writeStartElement("strong");
}
@@ -536,15 +491,12 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* Writes a begin element, then text, then end element for the element of a
* users choosing. Example: <p>text</p>
- *
- * @param writer
- * the stream writer to use
- * @param elementName
- * the name of the element
- * @param characters
- * the characters to insert into the element
- * @throws XMLStreamException
- * thrown if there was a problem writing to the stream
+ *
+ * @param writer the stream writer to use
+ * @param elementName the name of the element
+ * @param characters the characters to insert into the element
+ * @throws XMLStreamException thrown if there was a problem writing to the
+ * stream
*/
protected final static void writeSimpleElement(final XMLStreamWriter writer, final String elementName,
final String characters) throws XMLStreamException {
@@ -553,15 +505,12 @@ public class HtmlDocumentationWriter implements DocumentationWriter {
/**
* A helper method to write a link
- *
- * @param xmlStreamWriter
- * the stream to write to
- * @param text
- * the text of the link
- * @param location
- * the location of the link
- * @throws XMLStreamException
- * thrown if there was a problem writing to the stream
+ *
+ * @param xmlStreamWriter the stream to write to
+ * @param text the text of the link
+ * @param location the location of the link
+ * @throws XMLStreamException thrown if there was a problem writing to the
+ * stream
*/
protected void writeLink(final XMLStreamWriter xmlStreamWriter, final String text, final String location)
throws XMLStreamException {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java
index c253a4d..4a15b50 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/html/HtmlProcessorDocumentationWriter.java
@@ -51,13 +51,10 @@ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter {
/**
* Writes all the attributes that a processor says it reads and writes
- *
- * @param processor
- * the processor to describe
- * @param xmlStreamWriter
- * the xml stream writer to use
- * @throws XMLStreamException
- * thrown if there was a problem writing the XML
+ *
+ * @param processor the processor to describe
+ * @param xmlStreamWriter the xml stream writer to use
+ * @throws XMLStreamException thrown if there was a problem writing the XML
*/
private void writeAttributeInfo(Processor processor, XMLStreamWriter xmlStreamWriter)
throws XMLStreamException {
@@ -67,20 +64,18 @@ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter {
}
private String defaultIfBlank(final String test, final String defaultValue) {
- if ( test == null || test.trim().isEmpty() ) {
- return defaultValue;
- }
- return test;
+ if (test == null || test.trim().isEmpty()) {
+ return defaultValue;
+ }
+ return test;
}
-
+
/**
* Writes out just the attributes that are being read in a table form.
- *
- * @param xmlStreamWriter
- * the xml stream writer to use
- * @param processor
- * the processor to describe
- * @throws XMLStreamException
+ *
+ * @param xmlStreamWriter the xml stream writer to use
+ * @param processor the processor to describe
+ * @throws XMLStreamException xse
*/
private void handleReadsAttributes(XMLStreamWriter xmlStreamWriter, final Processor processor)
throws XMLStreamException {
@@ -102,7 +97,7 @@ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter {
writeSimpleElement(xmlStreamWriter, "td",
defaultIfBlank(attribute.description(), "Not Specified"));
xmlStreamWriter.writeEndElement();
-
+
}
xmlStreamWriter.writeEndElement();
@@ -113,12 +108,10 @@ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter {
/**
* Writes out just the attributes that are being written to in a table form.
- *
- * @param xmlStreamWriter
- * the xml stream writer to use
- * @param processor
- * the processor to describe
- * @throws XMLStreamException
+ *
+ * @param xmlStreamWriter the xml stream writer to use
+ * @param processor the processor to describe
+ * @throws XMLStreamException xse
*/
private void handleWritesAttributes(XMLStreamWriter xmlStreamWriter, final Processor processor)
throws XMLStreamException {
@@ -150,9 +143,8 @@ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter {
/**
* Collects the attributes that a processor is reading from.
- *
- * @param processor
- * the processor to describe
+ *
+ * @param processor the processor to describe
* @return the list of attributes that processor is reading
*/
private List<ReadsAttribute> getReadsAttributes(Processor processor) {
@@ -173,9 +165,8 @@ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter {
/**
* Collects the attributes that a processor is writing to.
- *
- * @param processor
- * the processor to describe
+ *
+ * @param processor the processor to describe
* @return the list of attributes the processor is writing
*/
private List<WritesAttribute> getWritesAttributes(Processor processor) {
@@ -196,13 +187,10 @@ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter {
/**
* Writes a table describing the relations a processor has.
- *
- * @param processor
- * the processor to describe
- * @param xmlStreamWriter
- * the stream writer to use
- * @throws XMLStreamException
- * thrown if there was a problem writing the xml
+ *
+ * @param processor the processor to describe
+ * @param xmlStreamWriter the stream writer to use
+ * @throws XMLStreamException thrown if there was a problem writing the xml
*/
private void writeRelationships(final Processor processor, final XMLStreamWriter xmlStreamWriter)
throws XMLStreamException {
@@ -229,15 +217,8 @@ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter {
}
}
- /**
- * Writes dynamic relationship information
- *
- * @param processor
- * @param xmlStreamWriter
- * @throws XMLStreamException
- */
private void writeDynamicRelationships(final Processor processor, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
-
+
List<DynamicRelationship> dynamicRelationships = getDynamicRelationships(processor);
if (dynamicRelationships.size() > 0) {
@@ -264,12 +245,12 @@ public class HtmlProcessorDocumentationWriter extends HtmlDocumentationWriter {
private List<DynamicRelationship> getDynamicRelationships(Processor processor) {
List<DynamicRelationship> results = new ArrayList<>();
-
+
DynamicRelationship dynamicRelationships = processor.getClass().getAnnotation(DynamicRelationship.class);
if (dynamicRelationships != null) {
results.add(dynamicRelationships);
}
-
+
return results;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedControllerService.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedControllerService.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedControllerService.java
index c27f3ba..4320c6e 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedControllerService.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedControllerService.java
@@ -27,31 +27,32 @@ import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.processor.util.StandardValidators;
@CapabilityDescription("A documented controller service that can help you do things")
-@Tags({ "one", "two", "three" })
+@Tags({"one", "two", "three"})
public class FullyDocumentedControllerService extends AbstractControllerService {
- public static final PropertyDescriptor KEYSTORE = new PropertyDescriptor.Builder().name("Keystore Filename")
- .description("The fully-qualified filename of the Keystore").defaultValue(null)
- .addValidator(StandardValidators.FILE_EXISTS_VALIDATOR).sensitive(false).build();
- public static final PropertyDescriptor KEYSTORE_TYPE = new PropertyDescriptor.Builder().name("Keystore Type")
- .description("The Type of the Keystore").allowableValues("JKS", "PKCS12")
- .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).defaultValue("JKS").sensitive(false).build();
- public static final PropertyDescriptor KEYSTORE_PASSWORD = new PropertyDescriptor.Builder()
- .name("Keystore Password").defaultValue(null).description("The password for the Keystore")
- .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).sensitive(true).build();
-
- private static final List<PropertyDescriptor> properties;
-
- static {
- List<PropertyDescriptor> props = new ArrayList<>();
- props.add(KEYSTORE);
- props.add(KEYSTORE_PASSWORD);
- props.add(KEYSTORE_TYPE);
- properties = Collections.unmodifiableList(props);
- }
-
- @Override
- protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
- return properties;
- }
+
+ public static final PropertyDescriptor KEYSTORE = new PropertyDescriptor.Builder().name("Keystore Filename")
+ .description("The fully-qualified filename of the Keystore").defaultValue(null)
+ .addValidator(StandardValidators.FILE_EXISTS_VALIDATOR).sensitive(false).build();
+ public static final PropertyDescriptor KEYSTORE_TYPE = new PropertyDescriptor.Builder().name("Keystore Type")
+ .description("The Type of the Keystore").allowableValues("JKS", "PKCS12")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).defaultValue("JKS").sensitive(false).build();
+ public static final PropertyDescriptor KEYSTORE_PASSWORD = new PropertyDescriptor.Builder()
+ .name("Keystore Password").defaultValue(null).description("The password for the Keystore")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR).sensitive(true).build();
+
+ private static final List<PropertyDescriptor> properties;
+
+ static {
+ List<PropertyDescriptor> props = new ArrayList<>();
+ props.add(KEYSTORE);
+ props.add(KEYSTORE_PASSWORD);
+ props.add(KEYSTORE_TYPE);
+ properties = Collections.unmodifiableList(props);
+ }
+
+ @Override
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return properties;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java
index cc59733..178a144 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedProcessor.java
@@ -40,82 +40,90 @@ import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.processor.util.StandardValidators;
-@Tags({ "one", "two", "three" })
+@Tags({"one", "two", "three"})
@CapabilityDescription("This is a processor that is used to test documentation.")
-@WritesAttributes({@WritesAttribute(attribute="first", description="this is the first attribute i write"), @WritesAttribute(attribute="second")})
-@ReadsAttribute(attribute = "incoming", description="this specifies the format of the thing")
-@SeeAlso(value={FullyDocumentedControllerService.class, FullyDocumentedReportingTask.class}, classNames={"org.apache.nifi.processor.ExampleProcessor"})
-@DynamicProperty(name="Relationship Name", supportsExpressionLanguage=true, value="some XPath", description="Routes FlowFiles to relationships based on XPath")
-@DynamicRelationship(name="name from dynamic property", description="all files that match the properties XPath")
+@WritesAttributes({
+ @WritesAttribute(attribute = "first", description = "this is the first attribute i write"),
+ @WritesAttribute(attribute = "second")})
+@ReadsAttribute(attribute = "incoming", description = "this specifies the format of the thing")
+@SeeAlso(value = {FullyDocumentedControllerService.class, FullyDocumentedReportingTask.class}, classNames = {"org.apache.nifi.processor.ExampleProcessor"})
+@DynamicProperty(name = "Relationship Name", supportsExpressionLanguage = true, value = "some XPath", description = "Routes FlowFiles to relationships based on XPath")
+@DynamicRelationship(name = "name from dynamic property", description = "all files that match the properties XPath")
public class FullyDocumentedProcessor extends AbstractProcessor {
- public static final PropertyDescriptor DIRECTORY = new PropertyDescriptor.Builder().name("Input Directory")
- .description("The input directory from which to pull files").required(true)
- .addValidator(StandardValidators.createDirectoryExistsValidator(true, false))
- .expressionLanguageSupported(true).build();
-
- public static final PropertyDescriptor RECURSE = new PropertyDescriptor.Builder().name("Recurse Subdirectories")
- .description("Indicates whether or not to pull files from subdirectories").required(true)
- .allowableValues(new AllowableValue("true", "true", "Should pull from sub directories"), new AllowableValue("false", "false", "Should not pull from sub directories")).defaultValue("true").build();
-
- public static final PropertyDescriptor POLLING_INTERVAL = new PropertyDescriptor.Builder().name("Polling Interval")
- .description("Indicates how long to wait before performing a directory listing").required(true)
- .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR).defaultValue("0 sec").build();
-
- public static final PropertyDescriptor OPTIONAL_PROPERTY = new PropertyDescriptor.Builder()
- .name("Optional Property").description("This is a property you can use or not").required(false).build();
-
- public static final PropertyDescriptor TYPE_PROPERTY = new PropertyDescriptor.Builder()
- .name("Type").description("This is the type of something that you can choose. It has several possible values").allowableValues("yes", "no", "maybe", "possibly", "not likely", "longer option name").required(true).build();
-
- public static final PropertyDescriptor SERVICE_PROPERTY = new PropertyDescriptor.Builder()
- .name("Controller Service").description("This is the controller service to use to do things")
- .identifiesControllerService(SampleService.class).required(true).build();
-
- public static final Relationship REL_SUCCESS = new Relationship.Builder().name("success")
- .description("Successful files").build();
- public static final Relationship REL_FAILURE = new Relationship.Builder().name("failure")
- .description("Failing files").build();
-
- private List<PropertyDescriptor> properties;
- private Set<Relationship> relationships;
-
- @Override
- protected void init(ProcessorInitializationContext context) {
- final List<PropertyDescriptor> properties = new ArrayList<>();
- properties.add(DIRECTORY);
- properties.add(RECURSE);
- properties.add(POLLING_INTERVAL);
- properties.add(OPTIONAL_PROPERTY);
- properties.add(TYPE_PROPERTY);
- properties.add(SERVICE_PROPERTY);
- this.properties = Collections.unmodifiableList(properties);
-
- final Set<Relationship> relationships = new HashSet<>();
- relationships.add(REL_SUCCESS);
- relationships.add(REL_FAILURE);
- this.relationships = Collections.unmodifiableSet(relationships);
- }
-
- @Override
- protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
- return properties;
- }
-
- @Override
- public Set<Relationship> getRelationships() {
- return relationships;
- }
-
- @Override
- public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
-
- }
-
- @Override
- protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName) {
- return new PropertyDescriptor.Builder().name(propertyDescriptorName)
- .description("This is a property you can use or not").dynamic(true).build();
- }
+ public static final PropertyDescriptor DIRECTORY = new PropertyDescriptor.Builder().name("Input Directory")
+ .description("The input directory from which to pull files").required(true)
+ .addValidator(StandardValidators.createDirectoryExistsValidator(true, false))
+ .expressionLanguageSupported(true).build();
+
+ public static final PropertyDescriptor RECURSE = new PropertyDescriptor.Builder().name("Recurse Subdirectories")
+ .description("Indicates whether or not to pull files from subdirectories").required(true)
+ .allowableValues(
+ new AllowableValue("true", "true", "Should pull from sub directories"),
+ new AllowableValue("false", "false", "Should not pull from sub directories")
+ ).defaultValue("true").build();
+
+ public static final PropertyDescriptor POLLING_INTERVAL = new PropertyDescriptor.Builder().name("Polling Interval")
+ .description("Indicates how long to wait before performing a directory listing").required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR).defaultValue("0 sec").build();
+
+ public static final PropertyDescriptor OPTIONAL_PROPERTY = new PropertyDescriptor.Builder()
+ .name("Optional Property").description("This is a property you can use or not").required(false).build();
+
+ public static final PropertyDescriptor TYPE_PROPERTY = new PropertyDescriptor.Builder()
+ .name("Type")
+ .description("This is the type of something that you can choose. It has several possible values")
+ .allowableValues("yes", "no", "maybe", "possibly", "not likely", "longer option name")
+ .required(true).build();
+
+ public static final PropertyDescriptor SERVICE_PROPERTY = new PropertyDescriptor.Builder()
+ .name("Controller Service").description("This is the controller service to use to do things")
+ .identifiesControllerService(SampleService.class).required(true).build();
+
+ public static final Relationship REL_SUCCESS = new Relationship.Builder().name("success")
+ .description("Successful files").build();
+ public static final Relationship REL_FAILURE = new Relationship.Builder().name("failure")
+ .description("Failing files").build();
+
+ private List<PropertyDescriptor> properties;
+ private Set<Relationship> relationships;
+
+ @Override
+ protected void init(ProcessorInitializationContext context) {
+ final List<PropertyDescriptor> properties = new ArrayList<>();
+ properties.add(DIRECTORY);
+ properties.add(RECURSE);
+ properties.add(POLLING_INTERVAL);
+ properties.add(OPTIONAL_PROPERTY);
+ properties.add(TYPE_PROPERTY);
+ properties.add(SERVICE_PROPERTY);
+ this.properties = Collections.unmodifiableList(properties);
+
+ final Set<Relationship> relationships = new HashSet<>();
+ relationships.add(REL_SUCCESS);
+ relationships.add(REL_FAILURE);
+ this.relationships = Collections.unmodifiableSet(relationships);
+ }
+
+ @Override
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return properties;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return relationships;
+ }
+
+ @Override
+ public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
+
+ }
+
+ @Override
+ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName) {
+ return new PropertyDescriptor.Builder().name(propertyDescriptorName)
+ .description("This is a property you can use or not").dynamic(true).build();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedReportingTask.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedReportingTask.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedReportingTask.java
index 275905b..17e446a 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedReportingTask.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/FullyDocumentedReportingTask.java
@@ -26,25 +26,25 @@ import org.apache.nifi.reporting.AbstractReportingTask;
import org.apache.nifi.reporting.ReportingContext;
@CapabilityDescription("A helper reporting task to do...")
-@Tags({ "first", "second", "third" })
+@Tags({"first", "second", "third"})
public class FullyDocumentedReportingTask extends AbstractReportingTask {
- public static final PropertyDescriptor SHOW_DELTAS = new PropertyDescriptor.Builder()
- .name("Show Deltas")
- .description(
- "Specifies whether or not to show the difference in values between the current status and the previous status")
- .required(true).allowableValues("true", "false").defaultValue("true").build();
+ public static final PropertyDescriptor SHOW_DELTAS = new PropertyDescriptor.Builder()
+ .name("Show Deltas")
+ .description(
+ "Specifies whether or not to show the difference in values between the current status and the previous status")
+ .required(true).allowableValues("true", "false").defaultValue("true").build();
- @Override
- public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
- final List<PropertyDescriptor> descriptors = new ArrayList<>();
- descriptors.add(SHOW_DELTAS);
- return descriptors;
- }
+ @Override
+ public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> descriptors = new ArrayList<>();
+ descriptors.add(SHOW_DELTAS);
+ return descriptors;
+ }
- @Override
- public void onTrigger(ReportingContext context) {
- // TODO Auto-generated method stub
+ @Override
+ public void onTrigger(ReportingContext context) {
+ // TODO Auto-generated method stub
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/NakedProcessor.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/NakedProcessor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/NakedProcessor.java
index ee7f315..e288f0a 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/NakedProcessor.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/NakedProcessor.java
@@ -23,9 +23,9 @@ import org.apache.nifi.processor.exception.ProcessException;
public class NakedProcessor extends AbstractProcessor {
- @Override
- public void onTrigger(ProcessContext arg0, ProcessSession arg1) throws ProcessException {
-
- }
+ @Override
+ public void onTrigger(ProcessContext arg0, ProcessSession arg1) throws ProcessException {
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/SampleService.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/SampleService.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/SampleService.java
index 6224364..6f84c15 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/SampleService.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/example/SampleService.java
@@ -20,6 +20,6 @@ import org.apache.nifi.controller.ControllerService;
public interface SampleService extends ControllerService {
- public void doSomething();
+ public void doSomething();
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java
index 90ff09f..e897262 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/HtmlDocumentationWriterTest.java
@@ -34,68 +34,68 @@ import static org.junit.Assert.assertEquals;
public class HtmlDocumentationWriterTest {
- @Test
- public void testJoin() {
- assertEquals("a, b, c", HtmlDocumentationWriter.join(new String[] {"a", "b", "c"}, ", "));
- assertEquals("a, b", HtmlDocumentationWriter.join(new String[] {"a", "b"}, ", "));
- assertEquals("a", HtmlDocumentationWriter.join(new String[] {"a"}, ", "));
- }
-
- @Test
- public void testDocumentControllerService() throws InitializationException, IOException {
+ @Test
+ public void testJoin() {
+ assertEquals("a, b, c", HtmlDocumentationWriter.join(new String[]{"a", "b", "c"}, ", "));
+ assertEquals("a, b", HtmlDocumentationWriter.join(new String[]{"a", "b"}, ", "));
+ assertEquals("a", HtmlDocumentationWriter.join(new String[]{"a"}, ", "));
+ }
- ControllerService controllerService = new FullyDocumentedControllerService();
- controllerService.initialize(new MockControllerServiceInitializationContext());
+ @Test
+ public void testDocumentControllerService() throws InitializationException, IOException {
- DocumentationWriter writer = new HtmlDocumentationWriter();
+ ControllerService controllerService = new FullyDocumentedControllerService();
+ controllerService.initialize(new MockControllerServiceInitializationContext());
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DocumentationWriter writer = new HtmlDocumentationWriter();
- writer.write(controllerService, baos, false);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
- String results = new String(baos.toByteArray());
- XmlValidator.assertXmlValid(results);
+ writer.write(controllerService, baos, false);
- // description
- assertContains(results, "A documented controller service that can help you do things");
+ String results = new String(baos.toByteArray());
+ XmlValidator.assertXmlValid(results);
- // tags
- assertContains(results, "one, two, three");
+ // description
+ assertContains(results, "A documented controller service that can help you do things");
- // properties
- assertContains(results, "Keystore Filename");
- assertContains(results, "The fully-qualified filename of the Keystore");
- assertContains(results, "Keystore Type");
- assertContains(results, "JKS");
- assertContains(results, "PKCS12");
- assertContains(results, "Sensitive Property: true");
- }
+ // tags
+ assertContains(results, "one, two, three");
- @Test
- public void testDocumentReportingTask() throws InitializationException, IOException {
+ // properties
+ assertContains(results, "Keystore Filename");
+ assertContains(results, "The fully-qualified filename of the Keystore");
+ assertContains(results, "Keystore Type");
+ assertContains(results, "JKS");
+ assertContains(results, "PKCS12");
+ assertContains(results, "Sensitive Property: true");
+ }
- ReportingTask reportingTask = new FullyDocumentedReportingTask();
- reportingTask.initialize(new MockReportingInitializationContext());
+ @Test
+ public void testDocumentReportingTask() throws InitializationException, IOException {
- DocumentationWriter writer = new HtmlDocumentationWriter();
+ ReportingTask reportingTask = new FullyDocumentedReportingTask();
+ reportingTask.initialize(new MockReportingInitializationContext());
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DocumentationWriter writer = new HtmlDocumentationWriter();
- writer.write(reportingTask, baos, false);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
- String results = new String(baos.toByteArray());
- XmlValidator.assertXmlValid(results);
+ writer.write(reportingTask, baos, false);
- // description
- assertContains(results, "A helper reporting task to do...");
+ String results = new String(baos.toByteArray());
+ XmlValidator.assertXmlValid(results);
- // tags
- assertContains(results, "first, second, third");
+ // description
+ assertContains(results, "A helper reporting task to do...");
- // properties
- assertContains(results, "Show Deltas");
- assertContains(results, "Specifies whether or not to show the difference in values between the current status and the previous status");
- assertContains(results, "true");
- assertContains(results, "false");
- }
+ // tags
+ assertContains(results, "first, second, third");
+
+ // properties
+ assertContains(results, "Show Deltas");
+ assertContains(results, "Specifies whether or not to show the difference in values between the current status and the previous status");
+ assertContains(results, "true");
+ assertContains(results, "false");
+ }
}
[3/7] incubator-nifi git commit: NIFI-271 checkpoint
Posted by jo...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/DatagramChannelReader.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/DatagramChannelReader.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/DatagramChannelReader.java
index 1eb5c7e..db76279 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/DatagramChannelReader.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/DatagramChannelReader.java
@@ -23,10 +23,6 @@ import java.nio.channels.SelectionKey;
import org.apache.nifi.io.nio.consumer.StreamConsumerFactory;
-/**
- *
- * @author none
- */
public final class DatagramChannelReader extends AbstractChannelReader {
public static final int MAX_UDP_PACKET_SIZE = 65507;
@@ -39,10 +35,10 @@ public final class DatagramChannelReader extends AbstractChannelReader {
* Will receive UDP data from channel and won't receive anything unless the
* given buffer has enough space for at least one full max udp packet.
*
- * @param key
- * @param buffer
- * @return
- * @throws IOException
+ * @param key selection key
+ * @param buffer to fill
+ * @return bytes read
+ * @throws IOException if error filling buffer from channel
*/
@Override
protected int fillBuffer(final SelectionKey key, final ByteBuffer buffer) throws IOException {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/SocketChannelReader.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/SocketChannelReader.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/SocketChannelReader.java
index db2c102..29c2973 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/SocketChannelReader.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/SocketChannelReader.java
@@ -22,10 +22,6 @@ import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import org.apache.nifi.io.nio.consumer.StreamConsumerFactory;
-/**
- *
- * @author none
- */
public final class SocketChannelReader extends AbstractChannelReader {
public SocketChannelReader(final String id, final SelectionKey key, final BufferPool empties, final StreamConsumerFactory consumerFactory) {
@@ -35,10 +31,10 @@ public final class SocketChannelReader extends AbstractChannelReader {
/**
* Receives TCP data from the socket channel for the given key.
*
- * @param key
- * @param buffer
- * @return
- * @throws IOException
+ * @param key selection key
+ * @param buffer byte buffer to fill
+ * @return bytes read
+ * @throws IOException if error reading bytes
*/
@Override
protected int fillBuffer(final SelectionKey key, final ByteBuffer buffer) throws IOException {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/consumer/StreamConsumer.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/consumer/StreamConsumer.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/consumer/StreamConsumer.java
index d75b7d7..cac8d8b 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/consumer/StreamConsumer.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/consumer/StreamConsumer.java
@@ -25,7 +25,6 @@ import org.apache.nifi.io.nio.BufferPool;
* thread providing data to process and another thread that is processing that
* data.
*
- * @author none
*/
public interface StreamConsumer {
@@ -36,7 +35,7 @@ public interface StreamConsumer {
* associated add to this given queue. If not, buffers will run out and all
* stream processing will halt. READ THIS!!!
*
- * @param returnQueue
+ * @param returnQueue pool of buffers to use
*/
void setReturnBufferQueue(BufferPool returnQueue);
@@ -45,7 +44,7 @@ public interface StreamConsumer {
* data to be processed. If the consumer is finished this should simply
* return the given buffer to the return buffer queue (after it is cleared)
*
- * @param buffer
+ * @param buffer filled buffer
*/
void addFilledBuffer(ByteBuffer buffer);
@@ -53,7 +52,8 @@ public interface StreamConsumer {
* Will be called by the thread that executes the consumption of data. May
* be called many times though once <code>isConsumerFinished</code> returns
* true this method will likely do nothing.
- * @throws java.io.IOException
+ *
+ * @throws java.io.IOException if there is an issue processing
*/
void process() throws IOException;
@@ -66,14 +66,14 @@ public interface StreamConsumer {
* If true signals the consumer is done consuming data and will not process
* any more buffers.
*
- * @return
+ * @return true if finished
*/
boolean isConsumerFinished();
/**
* Uniquely identifies the consumer
*
- * @return
+ * @return identifier of consumer
*/
String getId();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SSLContextFactory.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SSLContextFactory.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SSLContextFactory.java
index 7ed5ad4..9c6cb82 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SSLContextFactory.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SSLContextFactory.java
@@ -81,12 +81,12 @@ public class SSLContextFactory {
*
*
* @return a SSLContext instance
- * @throws java.security.KeyStoreException
- * @throws java.io.IOException
- * @throws java.security.NoSuchAlgorithmException
- * @throws java.security.cert.CertificateException
- * @throws java.security.UnrecoverableKeyException
- * @throws java.security.KeyManagementException
+ * @throws java.security.KeyStoreException if problem with keystore
+ * @throws java.io.IOException if unable to create context
+ * @throws java.security.NoSuchAlgorithmException if algorithm isn't known
+ * @throws java.security.cert.CertificateException if certificate is invalid
+ * @throws java.security.UnrecoverableKeyException if the key cannot be recovered
+ * @throws java.security.KeyManagementException if the key is improper
*/
public SSLContext createSslContext() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException,
UnrecoverableKeyException, KeyManagementException {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/ServerSocketConfiguration.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/ServerSocketConfiguration.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/ServerSocketConfiguration.java
index fc279fb..d6aca92 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/ServerSocketConfiguration.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/ServerSocketConfiguration.java
@@ -26,9 +26,6 @@ import java.security.cert.CertificateException;
import javax.net.ssl.SSLContext;
-/**
- * @author unattributed
- */
public final class ServerSocketConfiguration {
private boolean needClientAuth;
@@ -40,7 +37,8 @@ public final class ServerSocketConfiguration {
public ServerSocketConfiguration() {
}
- public SSLContext createSSLContext() throws KeyManagementException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, CertificateException, FileNotFoundException, IOException {
+ public SSLContext createSSLContext()
+ throws KeyManagementException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, CertificateException, FileNotFoundException, IOException {
return sslContextFactory == null ? null : sslContextFactory.createSslContext();
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketConfiguration.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketConfiguration.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketConfiguration.java
index c24b540..8b803dc 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketConfiguration.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketConfiguration.java
@@ -26,9 +26,6 @@ import java.security.cert.CertificateException;
import javax.net.ssl.SSLContext;
-/**
- * @author unattributed
- */
public final class SocketConfiguration {
private Integer socketTimeout;
@@ -41,7 +38,8 @@ public final class SocketConfiguration {
private Integer trafficClass;
private SSLContextFactory sslContextFactory;
- public SSLContext createSSLContext() throws KeyManagementException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, CertificateException, FileNotFoundException, IOException {
+ public SSLContext createSSLContext()
+ throws KeyManagementException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, CertificateException, FileNotFoundException, IOException {
return sslContextFactory == null ? null : sslContextFactory.createSslContext();
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketUtils.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketUtils.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketUtils.java
index fb6a00c..27d676a 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketUtils.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketUtils.java
@@ -35,9 +35,6 @@ import org.apache.nifi.logging.NiFiLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * @author unattributed
- */
public final class SocketUtils {
private static final Logger logger = new NiFiLog(LoggerFactory.getLogger(SocketUtils.class));
@@ -99,7 +96,8 @@ public final class SocketUtils {
return socket;
}
- public static ServerSocket createServerSocket(final int port, final ServerSocketConfiguration config) throws IOException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException {
+ public static ServerSocket createServerSocket(final int port, final ServerSocketConfiguration config)
+ throws IOException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException {
if (config == null) {
throw new NullPointerException("Configuration may not be null.");
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/multicast/MulticastListener.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/multicast/MulticastListener.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/multicast/MulticastListener.java
index e562c25..1ce2ea0 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/multicast/MulticastListener.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/multicast/MulticastListener.java
@@ -35,7 +35,6 @@ import org.slf4j.LoggerFactory;
* then the message is wrapped with a MulticastProtocolMessage before being sent
* to the originator.
*
- * @author unattributed
*/
public abstract class MulticastListener {
@@ -80,8 +79,8 @@ public abstract class MulticastListener {
* Implements the action to perform when a new datagram is received. This
* class must not close the multicast socket.
*
- * @param multicastSocket
- * @param packet the datagram socket
+ * @param multicastSocket socket
+ * @param packet the datagram packet
*/
public abstract void dispatchRequest(final MulticastSocket multicastSocket, final DatagramPacket packet);
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/test/java/org/apache/nifi/io/nio/example/TCPClient.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/test/java/org/apache/nifi/io/nio/example/TCPClient.java b/nifi/nifi-commons/nifi-socket-utils/src/test/java/org/apache/nifi/io/nio/example/TCPClient.java
index b3d214e..447d701 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/test/java/org/apache/nifi/io/nio/example/TCPClient.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/test/java/org/apache/nifi/io/nio/example/TCPClient.java
@@ -78,7 +78,8 @@ public class TCPClient {
for (int i = 0; i < 1000; i++) {
sock.getOutputStream().write(bytes);
totalBytes += bytes.length;
- } sock.getOutputStream().flush();
+ }
+ sock.getOutputStream().flush();
}
logger.info("Total bytes sent: " + totalBytes + " to port " + port);
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/MinimalLockingWriteAheadLog.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/MinimalLockingWriteAheadLog.java b/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/MinimalLockingWriteAheadLog.java
index 5b20b93..5c8b4c8 100644
--- a/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/MinimalLockingWriteAheadLog.java
+++ b/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/MinimalLockingWriteAheadLog.java
@@ -72,7 +72,7 @@ import org.slf4j.LoggerFactory;
* updates for a given Record at any one time.
* </p>
*
- * @param <T>
+ * @param <T> type of record this WAL is for
*/
public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepository<T> {
@@ -113,14 +113,12 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
* @param paths a sorted set of Paths to use for the partitions/journals and
* the snapshot. The snapshot will always be written to the first path
* specified.
- *
* @param partitionCount the number of partitions/journals to use. For best
* performance, this should be close to the number of threads that are
* expected to update the repository simultaneously
- *
- * @param serde
- * @param syncListener
- * @throws IOException
+ * @param serde the serializer/deserializer for records
+ * @param syncListener the listener
+ * @throws IOException if unable to initialize due to IO issue
*/
@SuppressWarnings("unchecked")
public MinimalLockingWriteAheadLog(final SortedSet<Path> paths, final int partitionCount, final SerDe<T> serde, final SyncListener syncListener) throws IOException {
@@ -209,7 +207,9 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
while (true) {
final int numBlackListed = numberBlackListedPartitions.get();
if (numBlackListed >= partitions.length) {
- throw new IOException("All Partitions have been blacklisted due to failures when attempting to update. If the Write-Ahead Log is able to perform a checkpoint, this issue may resolve itself. Otherwise, manual intervention will be required.");
+ throw new IOException("All Partitions have been blacklisted due to "
+ + "failures when attempting to update. If the Write-Ahead Log is able to perform a checkpoint, "
+ + "this issue may resolve itself. Otherwise, manual intervention will be required.");
}
final long partitionIdx = partitionIndex.getAndIncrement();
@@ -248,7 +248,9 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
} else if (updateType == UpdateType.SWAP_OUT) {
final String newLocation = serde.getLocation(record);
if (newLocation == null) {
- logger.error("Received Record (ID=" + recordIdentifier + ") with UpdateType of SWAP_OUT but no indicator of where the Record is to be Swapped Out to; these records may be lost when the repository is restored!");
+ logger.error("Received Record (ID=" + recordIdentifier + ") with UpdateType of SWAP_OUT but "
+ + "no indicator of where the Record is to be Swapped Out to; these records may be "
+ + "lost when the repository is restored!");
} else {
recordMap.remove(recordIdentifier);
this.externalLocations.add(newLocation);
@@ -256,7 +258,9 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
} else if (updateType == UpdateType.SWAP_IN) {
final String newLocation = serde.getLocation(record);
if (newLocation == null) {
- logger.error("Received Record (ID=" + recordIdentifier + ") with UpdateType of SWAP_IN but no indicator of where the Record is to be Swapped In from; these records may be duplicated when the repository is restored!");
+ logger.error("Received Record (ID=" + recordIdentifier + ") with UpdateType of SWAP_IN but no "
+ + "indicator of where the Record is to be Swapped In from; these records may be duplicated "
+ + "when the repository is restored!");
} else {
externalLocations.remove(newLocation);
}
@@ -345,11 +349,13 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
final int waliImplementationVersion = dataIn.readInt();
if (!waliImplementationClass.equals(MinimalLockingWriteAheadLog.class.getName())) {
- throw new IOException("Write-Ahead Log located at " + snapshotPath + " was written using the " + waliImplementationClass + " class; cannot restore using " + getClass().getName());
+ throw new IOException("Write-Ahead Log located at " + snapshotPath + " was written using the "
+ + waliImplementationClass + " class; cannot restore using " + getClass().getName());
}
if (waliImplementationVersion > getVersion()) {
- throw new IOException("Write-Ahead Log located at " + snapshotPath + " was written using version " + waliImplementationVersion + " of the " + waliImplementationClass + " class; cannot restore using Version " + getVersion());
+ throw new IOException("Write-Ahead Log located at " + snapshotPath + " was written using version "
+ + waliImplementationVersion + " of the " + waliImplementationClass + " class; cannot restore using Version " + getVersion());
}
dataIn.readUTF(); // ignore serde class name for now
@@ -380,7 +386,8 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
}
this.recoveredExternalLocations.addAll(swapLocations);
- logger.debug("{} restored {} Records and {} Swap Files from Snapshot, ending with Transaction ID {}", new Object[]{this, numRecords, recoveredExternalLocations.size(), maxTransactionId});
+ logger.debug("{} restored {} Records and {} Swap Files from Snapshot, ending with Transaction ID {}",
+ new Object[]{this, numRecords, recoveredExternalLocations.size(), maxTransactionId});
return maxTransactionId;
}
}
@@ -390,10 +397,9 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
* if recovery of a Partition requires the Write-Ahead Log be checkpointed
* before modification.
*
- * @param modifiableRecordMap
- * @param maxTransactionIdRestored
- * @return
- * @throws IOException
+ * @param modifiableRecordMap map
+ * @param maxTransactionIdRestored index of max restored transaction
+ * @throws IOException if unable to recover from edits
*/
private void recoverFromEdits(final Map<Object, T> modifiableRecordMap, final Long maxTransactionIdRestored) throws IOException {
final Map<Object, T> updateMap = new HashMap<>();
@@ -422,7 +428,8 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
try {
partition.recoverNextTransaction(ignorableMap, updateMap, ignorableSwapLocations);
} catch (final EOFException e) {
- logger.error("{} unexpectedly reached End of File while reading from {} for Transaction {}; assuming crash and ignoring this transaction.",
+ logger.error("{} unexpectedly reached End of File while reading from {} for Transaction {}; "
+ + "assuming crash and ignoring this transaction.",
new Object[]{this, partition, transactionId});
}
}
@@ -442,7 +449,8 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
modifiableRecordMap.remove(id);
}
} catch (final EOFException e) {
- logger.error("{} unexpectedly reached End-of-File when reading from {} for Transaction ID {}; assuming crash and ignoring this transaction",
+ logger.error("{} unexpectedly reached End-of-File when reading from {} for Transaction ID {}; "
+ + "assuming crash and ignoring this transaction",
new Object[]{this, nextPartition, firstTransactionId});
}
@@ -452,7 +460,8 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
try {
subsequentTransactionId = nextPartition.getNextRecoverableTransactionId();
} catch (final IOException e) {
- logger.error("{} unexpectedly found End-of-File when reading from {} for Transaction ID {}; assuming crash and ignoring this transaction",
+ logger.error("{} unexpectedly found End-of-File when reading from {} for Transaction ID {}; "
+ + "assuming crash and ignoring this transaction",
new Object[]{this, nextPartition, firstTransactionId});
}
@@ -576,7 +585,8 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
final long partitionMillis = TimeUnit.MILLISECONDS.convert(partitionEnd - partitionStart, TimeUnit.NANOSECONDS);
final long stopTheWorldMillis = TimeUnit.NANOSECONDS.toMillis(stopTheWorldNanos);
- logger.info("{} checkpointed with {} Records and {} Swap Files in {} milliseconds (Stop-the-world time = {} milliseconds, Clear Edit Logs time = {} millis), max Transaction ID {}",
+ logger.info("{} checkpointed with {} Records and {} Swap Files in {} milliseconds (Stop-the-world "
+ + "time = {} milliseconds, Clear Edit Logs time = {} millis), max Transaction ID {}",
new Object[]{this, records.size(), swapLocations.size(), millis, stopTheWorldMillis, partitionMillis, maxTransactionId});
return records.size();
@@ -605,9 +615,9 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
*
* All methods with the exceptions of {@link #claim()}, {@link #tryClaim()},
* and {@link #releaseClaim()} in this Partition MUST be called while
- * holding the claim (via {@link #claim} or {@link #tryClaim()).
+ * holding the claim (via {@link #claim} or {@link #tryClaim()}).
*
- * @param <S>
+ * @param <S> type of record held in the partitions
*/
private static class Partition<S> {
@@ -703,7 +713,7 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
* Closes resources pointing to the current journal and begins writing
* to a new one
*
- * @throws IOException
+ * @throws IOException if failure to rollover
*/
public void rollover() throws IOException {
lock.lock();
@@ -777,7 +787,8 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
if (isJournalFile(file)) {
paths.add(file.toPath());
} else {
- logger.warn("Found file {}, but could not access it, or it was not in the expected format; will ignore this file", file.getAbsolutePath());
+ logger.warn("Found file {}, but could not access it, or it was not in the expected format; "
+ + "will ignore this file", file.getAbsolutePath());
}
}
@@ -836,7 +847,8 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
return true;
}
- public void update(final Collection<S> records, final long transactionId, final Map<Object, S> recordMap, final boolean forceSync) throws IOException {
+ public void update(final Collection<S> records, final long transactionId, final Map<Object, S> recordMap, final boolean forceSync)
+ throws IOException {
if (this.closed) {
throw new IllegalStateException("Partition is closed");
}
@@ -889,7 +901,8 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
final long waliVersion = recoveryIn.readInt();
if (waliVersion > writeAheadLogVersion) {
- throw new IOException("Cannot recovery from file " + nextRecoveryPath + " because it was written using WALI version " + waliVersion + ", but the version used to restore it is only " + writeAheadLogVersion);
+ throw new IOException("Cannot recovery from file " + nextRecoveryPath + " because it was written using "
+ + "WALI version " + waliVersion + ", but the version used to restore it is only " + writeAheadLogVersion);
}
@SuppressWarnings("unused")
@@ -936,7 +949,8 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
final Path nextRecoveryPath = this.recoveryFiles.poll();
if (nextRecoveryPath != null) {
- throw new IllegalStateException("Signaled to end recovery, but there are more recovery files for Partition in directory " + editDirectory);
+ throw new IllegalStateException("Signaled to end recovery, but there are more recovery files for Partition "
+ + "in directory " + editDirectory);
}
final Path newEditPath = getNewEditPath();
@@ -999,7 +1013,7 @@ public final class MinimalLockingWriteAheadLog<T> implements WriteAheadRepositor
/**
* Must be called after recovery has finished
*
- * @return
+ * @return max recovered transaction id
*/
public long getMaxRecoveredTransactionId() {
return maxTransactionId.get();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/SerDe.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/SerDe.java b/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/SerDe.java
index bbc7efb..cc984a6 100644
--- a/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/SerDe.java
+++ b/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/SerDe.java
@@ -35,10 +35,10 @@ public interface SerDe<T> {
* {@link DataOutputStream}.
* </p>
*
- * @param previousRecordState
- * @param newRecordState
- * @param out
- * @throws IOException
+ * @param previousRecordState previous state
+ * @param newRecordState new state
+ * @param out stream to write to
+ * @throws IOException if fail during write
*/
void serializeEdit(T previousRecordState, T newRecordState, DataOutputStream out) throws IOException;
@@ -48,9 +48,9 @@ public interface SerDe<T> {
* {@link DataOutputStream}.
* </p>
*
- * @param record
- * @param out
- * @throws IOException
+ * @param record to serialize
+ * @param out to write to
+ * @throws IOException if failed to write
*/
void serializeRecord(T record, DataOutputStream out) throws IOException;
@@ -63,13 +63,13 @@ public interface SerDe<T> {
* This method must never return <code>null</code>.
* </p>
*
- * @param in
+ * @param in to deserialize from
* @param currentRecordStates an unmodifiable map of Record ID's to the
* current state of that record
* @param version the version of the SerDe that was used to serialize the
* edit record
- * @return
- * @throws IOException
+ * @return deserialized record
+ * @throws IOException if failure reading
*/
T deserializeEdit(DataInputStream in, Map<Object, T> currentRecordStates, int version) throws IOException;
@@ -79,27 +79,27 @@ public interface SerDe<T> {
* record. If no data is available, returns <code>null</code>.
* </p>
*
- * @param in
+ * @param in stream to read from
* @param version the version of the SerDe that was used to serialize the
* record
- * @return
- * @throws IOException
+ * @return record
+ * @throws IOException failure reading
*/
T deserializeRecord(DataInputStream in, int version) throws IOException;
/**
* Returns the unique ID for the given record
*
- * @param record
- * @return
+ * @param record to obtain identifier for
+ * @return identifier of record
*/
Object getRecordIdentifier(T record);
/**
* Returns the UpdateType for the given record
*
- * @param record
- * @return
+ * @param record to retrieve update type for
+ * @return update type
*/
UpdateType getUpdateType(T record);
@@ -112,8 +112,8 @@ public interface SerDe<T> {
* WALI with a record of type {@link UpdateType#CREATE} that indicates a
* Location of file://tmp/external1
*
- * @param record
- * @return
+ * @param record to get location of
+ * @return location
*/
String getLocation(T record);
@@ -122,7 +122,7 @@ public interface SerDe<T> {
* when serializing/deserializing the edit logs so that if the version
* changes, we are still able to deserialize old versions
*
- * @return
+ * @return version
*/
int getVersion();
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/WriteAheadRepository.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/WriteAheadRepository.java b/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/WriteAheadRepository.java
index 4567872..7f0e828 100644
--- a/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/WriteAheadRepository.java
+++ b/nifi/nifi-commons/nifi-write-ahead-log/src/main/java/org/wali/WriteAheadRepository.java
@@ -48,7 +48,7 @@ import java.util.Set;
* one partition or may allow many partitions.
* </p>
*
- * @param <T>
+ * @param <T> the type of Record this repository is for
*/
public interface WriteAheadRepository<T> {
@@ -63,7 +63,7 @@ public interface WriteAheadRepository<T> {
* to be flushed to disk. If false, the data may be stored in Operating
* System buffers, which improves performance but could cause loss of data
* if power is lost or the Operating System crashes
- * @throws IOException
+ * @throws IOException if failure to update repo
* @throws IllegalArgumentException if multiple records within the given
* Collection have the same ID, as specified by {@link Record#getId()}
* method
@@ -78,8 +78,8 @@ public interface WriteAheadRepository<T> {
* before any updates are issued to the Repository.
* </p>
*
- * @return
- * @throws IOException
+ * @return recovered records
+ * @throws IOException if failure to read from repo
* @throws IllegalStateException if any updates have been issued against
* this Repository before this method is invoked
*/
@@ -92,8 +92,8 @@ public interface WriteAheadRepository<T> {
* BEFORE {@link update}.
* </p>
*
- * @return
- * @throws IOException
+ * @return swap location
+ * @throws IOException if failure reading swap locations
*/
Set<String> getRecoveredSwapLocations() throws IOException;
@@ -107,7 +107,7 @@ public interface WriteAheadRepository<T> {
*
*
* @return the number of records that were written to the new snapshot
- * @throws java.io.IOException
+ * @throws java.io.IOException if failure during checkpoint
*/
int checkpoint() throws IOException;
@@ -116,7 +116,7 @@ public interface WriteAheadRepository<T> {
* Causes the repository to checkpoint and then close any open resources.
* </p>
*
- * @throws IOException
+ * @throws IOException if failure to shutdown cleanly
*/
void shutdown() throws IOException;
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceInitializationContext.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceInitializationContext.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceInitializationContext.java
index fd3c2de..bff1d62 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceInitializationContext.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceInitializationContext.java
@@ -29,7 +29,7 @@ public class MockControllerServiceInitializationContext extends MockControllerSe
public MockControllerServiceInitializationContext(final ControllerService controllerService, final String identifier) {
this(controllerService, identifier, new MockProcessorLog(identifier, controllerService));
}
-
+
public MockControllerServiceInitializationContext(final ControllerService controllerService, final String identifier, final ComponentLog logger) {
this.identifier = identifier;
this.logger = logger;
@@ -40,17 +40,17 @@ public class MockControllerServiceInitializationContext extends MockControllerSe
public String getIdentifier() {
return identifier;
}
-
+
@Override
public String getControllerServiceName(final String serviceIdentifier) {
- return null;
+ return null;
}
@Override
public ControllerServiceLookup getControllerServiceLookup() {
return this;
}
-
+
@Override
public ComponentLog getLogger() {
return logger;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceLookup.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceLookup.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceLookup.java
index 2734440..219ee24 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceLookup.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceLookup.java
@@ -40,17 +40,17 @@ public abstract class MockControllerServiceLookup implements ControllerServiceLo
public void removeControllerService(ControllerService service) {
final ControllerService canonical = getControllerService(service.getIdentifier());
- if ( canonical == null || canonical != service ) {
+ if (canonical == null || canonical != service) {
throw new IllegalArgumentException("Controller Service " + service + " is not known");
}
-
+
controllerServiceMap.remove(service.getIdentifier());
}
protected void addControllerServices(final MockControllerServiceLookup other) {
this.controllerServiceMap.putAll(other.controllerServiceMap);
}
-
+
protected ControllerServiceConfiguration getConfiguration(final String identifier) {
return controllerServiceMap.get(identifier);
}
@@ -80,7 +80,7 @@ public abstract class MockControllerServiceLookup implements ControllerServiceLo
public boolean isControllerServiceEnabling(final String serviceIdentifier) {
return false;
}
-
+
@Override
public Set<String> getControllerServiceIdentifiers(final Class<? extends ControllerService> serviceType) {
final Set<String> ids = new HashSet<>();
@@ -91,10 +91,10 @@ public abstract class MockControllerServiceLookup implements ControllerServiceLo
}
return ids;
}
-
+
@Override
public String getControllerServiceName(String serviceIdentifier) {
- final ControllerServiceConfiguration status = controllerServiceMap.get(serviceIdentifier);
- return status == null ? null : serviceIdentifier;
+ final ControllerServiceConfiguration status = controllerServiceMap.get(serviceIdentifier);
+ return status == null ? null : serviceIdentifier;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java
index 1be0293..e9fb9d6 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java
@@ -185,8 +185,8 @@ public class MockFlowFile implements FlowFile {
* Asserts that the content of this FlowFile is the same as the content of
* the given file
*
- * @param file
- * @throws IOException
+ * @param file to compare content against
+ * @throws IOException if fails doing IO during comparison
*/
public void assertContentEquals(final File file) throws IOException {
assertContentEquals(file.toPath());
@@ -196,8 +196,8 @@ public class MockFlowFile implements FlowFile {
* Asserts that the content of this FlowFile is the same as the content of
* the given path
*
- * @param path
- * @throws IOException
+ * @param path where to find content to compare to
+ * @throws IOException if io error occurs while comparing content
*/
public void assertContentEquals(final Path path) throws IOException {
try (final InputStream in = Files.newInputStream(path, StandardOpenOption.READ)) {
@@ -209,8 +209,8 @@ public class MockFlowFile implements FlowFile {
* Asserts that the content of this FlowFile is the same as the content of
* the given byte array
*
- * @param data
- * @throws IOException
+ * @param data the data to compare
+ * @throws IOException if any ioe occurs while reading flowfile
*/
public void assertContentEquals(final byte[] data) throws IOException {
try (final InputStream in = new ByteArrayInputStream(data)) {
@@ -236,8 +236,8 @@ public class MockFlowFile implements FlowFile {
* the given InputStream. This method closes the InputStream when it is
* finished.
*
- * @param in
- * @throws IOException
+ * @param in the stream to source comparison data from
+ * @throws IOException if any issues reading from given source
*/
public void assertContentEquals(final InputStream in) throws IOException {
int bytesRead = 0;
@@ -264,9 +264,7 @@ public class MockFlowFile implements FlowFile {
}
/**
- * Returns a copy of the the contents of the FlowFile as a byte array
- *
- * @return
+ * @return a copy of the the contents of the FlowFile as a byte array
*/
public byte[] toByteArray() {
return Arrays.copyOf(this.data, this.data.length);
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java
index 6536928..20a2f7c 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java
@@ -54,7 +54,7 @@ public class MockProcessContext extends MockControllerServiceLookup implements S
/**
* Creates a new MockProcessContext for the given Processor
*
- * @param component
+ * @param component being mocked
*/
public MockProcessContext(final ConfigurableComponent component) {
this.component = Objects.requireNonNull(component);
@@ -73,7 +73,7 @@ public class MockProcessContext extends MockControllerServiceLookup implements S
// do nothing...the service is being loaded
}
}
-
+
@Override
public PropertyValue getProperty(final PropertyDescriptor descriptor) {
return getProperty(descriptor.getName());
@@ -107,9 +107,9 @@ public class MockProcessContext extends MockControllerServiceLookup implements S
* either case, the ValidationResult is returned, indicating whether or not
* the property is valid
*
- * @param descriptor
- * @param value
- * @return
+ * @param descriptor of property to modify
+ * @param value new value
+ * @return result
*/
public ValidationResult setProperty(final PropertyDescriptor descriptor, final String value) {
requireNonNull(descriptor);
@@ -154,7 +154,6 @@ public class MockProcessContext extends MockControllerServiceLookup implements S
config.setProperties(properties);
config.setAnnotationData(annotationData);
}
-
@Override
public int getMaxConcurrentTasks() {
@@ -268,10 +267,10 @@ public class MockProcessContext extends MockControllerServiceLookup implements S
}
public Set<Relationship> getAvailableRelationships() {
- if ( !(component instanceof Processor) ) {
+ if (!(component instanceof Processor)) {
return Collections.emptySet();
}
-
+
final Set<Relationship> relationships = new HashSet<>(((Processor) component).getRelationships());
relationships.removeAll(unavailableRelationships);
return relationships;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java
index 83c75c6..e9bb778 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java
@@ -329,7 +329,6 @@ public class MockProcessSession implements ProcessSession {
return newFlowFile;
}
-
@Override
public MockFlowFile merge(final Collection<FlowFile> sources, final FlowFile destination) {
for (final FlowFile source : sources) {
@@ -676,11 +675,9 @@ public class MockProcessSession implements ProcessSession {
}
/**
- * Returns a List of FlowFiles in the order in which they were transferred
+ * @param relationship to get flowfiles for
+ * @return a List of FlowFiles in the order in which they were transferred
* to the given relationship
- *
- * @param relationship
- * @return
*/
public List<MockFlowFile> getFlowFilesForRelationship(final String relationship) {
final Relationship procRel = new Relationship.Builder().name(relationship).build();
@@ -783,7 +780,7 @@ public class MockProcessSession implements ProcessSession {
* will capture the uuid of a certain number of source objects and may not
* capture all of them. How many it will capture is unspecified.
*
- * @param sources
+ * @param sources to inherit common attributes from
*/
private FlowFile inheritAttributes(final Collection<FlowFile> sources, final FlowFile destination) {
final StringBuilder parentUuidBuilder = new StringBuilder();
@@ -883,8 +880,8 @@ public class MockProcessSession implements ProcessSession {
* Assert that the number of FlowFiles transferred to the given relationship
* is equal to the given count
*
- * @param relationship
- * @param count
+ * @param relationship to validate transfer count of
+ * @param count items transfer to given relationship
*/
public void assertTransferCount(final Relationship relationship, final int count) {
final int transferCount = getFlowFilesForRelationship(relationship).size();
@@ -896,8 +893,8 @@ public class MockProcessSession implements ProcessSession {
* Assert that the number of FlowFiles transferred to the given relationship
* is equal to the given count
*
- * @param relationship
- * @param count
+ * @param relationship to validate transfer count of
+ * @param count items transfer to given relationship
*/
public void assertTransferCount(final String relationship, final int count) {
assertTransferCount(new Relationship.Builder().name(relationship).build(), count);
@@ -921,7 +918,7 @@ public class MockProcessSession implements ProcessSession {
* Asserts that all FlowFiles that were transferred were transferred to the
* given relationship
*
- * @param relationship
+ * @param relationship to check for transferred flow files
*/
public void assertAllFlowFilesTransferred(final String relationship) {
assertAllFlowFilesTransferred(new Relationship.Builder().name(relationship).build());
@@ -931,7 +928,7 @@ public class MockProcessSession implements ProcessSession {
* Asserts that all FlowFiles that were transferred were transferred to the
* given relationship
*
- * @param relationship
+ * @param relationship to validate
*/
public void assertAllFlowFilesTransferred(final Relationship relationship) {
for (final Map.Entry<Relationship, List<MockFlowFile>> entry : transferMap.entrySet()) {
@@ -956,8 +953,8 @@ public class MockProcessSession implements ProcessSession {
* given relationship and that the number of FlowFiles transferred is equal
* to <code>count</code>
*
- * @param relationship
- * @param count
+ * @param relationship to validate
+ * @param count number of items sent to that relationship (expected)
*/
public void assertAllFlowFilesTransferred(final Relationship relationship, final int count) {
assertAllFlowFilesTransferred(relationship);
@@ -969,17 +966,15 @@ public class MockProcessSession implements ProcessSession {
* given relationship and that the number of FlowFiles transferred is equal
* to <code>count</code>
*
- * @param relationship
- * @param count
+ * @param relationship to validate
+ * @param count number of items sent to that relationship (expected)
*/
public void assertAllFlowFilesTransferred(final String relationship, final int count) {
assertAllFlowFilesTransferred(new Relationship.Builder().name(relationship).build(), count);
}
/**
- * Returns the number of FlowFiles that were removed
- *
- * @return
+ * @return the number of FlowFiles that were removed
*/
public int getRemovedCount() {
return removedCount;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorInitializationContext.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorInitializationContext.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorInitializationContext.java
index 0aa2749..2e5d3eb 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorInitializationContext.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorInitializationContext.java
@@ -64,9 +64,9 @@ public class MockProcessorInitializationContext implements ProcessorInitializati
@Override
public String getControllerServiceName(String serviceIdentifier) {
- return context.getControllerServiceName(serviceIdentifier);
+ return context.getControllerServiceName(serviceIdentifier);
}
-
+
@Override
public boolean isControllerServiceEnabled(String serviceIdentifier) {
return context.isControllerServiceEnabled(serviceIdentifier);
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorLog.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorLog.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorLog.java
index 5505e88..837784b 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorLog.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessorLog.java
@@ -66,21 +66,11 @@ public class MockProcessorLog implements ProcessorLog {
return (os != null && os.length > 0 && (os[os.length - 1] instanceof Throwable));
}
- /**
- *
- * @param msg
- * @param t
- */
@Override
public void warn(final String msg, final Throwable t) {
warn("{} " + msg, new Object[]{component}, t);
}
- /**
- *
- * @param msg
- * @param os
- */
@Override
public void warn(String msg, Object[] os) {
if (lastArgIsException(os)) {
@@ -92,12 +82,6 @@ public class MockProcessorLog implements ProcessorLog {
}
}
- /**
- *
- * @param msg
- * @param os
- * @param t
- */
@Override
public void warn(String msg, Object[] os, final Throwable t) {
os = addProcessorAndThrowable(os, t);
@@ -109,21 +93,12 @@ public class MockProcessorLog implements ProcessorLog {
}
}
- /**
- *
- * @param msg
- */
@Override
public void warn(String msg) {
msg = "{} " + msg;
logger.warn(msg, component);
}
- /**
- *
- * @param msg
- * @param t
- */
@Override
public void trace(String msg, Throwable t) {
msg = "{} " + msg;
@@ -131,11 +106,6 @@ public class MockProcessorLog implements ProcessorLog {
logger.trace(msg, os, t);
}
- /**
- *
- * @param msg
- * @param os
- */
@Override
public void trace(String msg, Object[] os) {
msg = "{} " + msg;
@@ -143,10 +113,6 @@ public class MockProcessorLog implements ProcessorLog {
logger.trace(msg, os);
}
- /**
- *
- * @param msg
- */
@Override
public void trace(String msg) {
msg = "{} " + msg;
@@ -154,12 +120,6 @@ public class MockProcessorLog implements ProcessorLog {
logger.trace(msg, os);
}
- /**
- *
- * @param msg
- * @param os
- * @param t
- */
@Override
public void trace(String msg, Object[] os, Throwable t) {
os = addProcessorAndThrowable(os, t);
@@ -169,56 +129,31 @@ public class MockProcessorLog implements ProcessorLog {
logger.trace("", t);
}
- /**
- *
- * @return
- */
@Override
public boolean isWarnEnabled() {
return logger.isWarnEnabled();
}
- /**
- *
- * @return
- */
@Override
public boolean isTraceEnabled() {
return logger.isTraceEnabled();
}
- /**
- *
- * @return
- */
@Override
public boolean isInfoEnabled() {
return logger.isInfoEnabled();
}
- /**
- *
- * @return
- */
@Override
public boolean isErrorEnabled() {
return logger.isErrorEnabled();
}
- /**
- *
- * @return
- */
@Override
public boolean isDebugEnabled() {
return logger.isDebugEnabled();
}
- /**
- *
- * @param msg
- * @param t
- */
@Override
public void info(String msg, Throwable t) {
msg = "{} " + msg;
@@ -230,11 +165,6 @@ public class MockProcessorLog implements ProcessorLog {
}
}
- /**
- *
- * @param msg
- * @param os
- */
@Override
public void info(String msg, Object[] os) {
msg = "{} " + msg;
@@ -243,10 +173,6 @@ public class MockProcessorLog implements ProcessorLog {
logger.info(msg, os);
}
- /**
- *
- * @param msg
- */
@Override
public void info(String msg) {
msg = "{} " + msg;
@@ -255,12 +181,6 @@ public class MockProcessorLog implements ProcessorLog {
logger.info(msg, os);
}
- /**
- *
- * @param msg
- * @param os
- * @param t
- */
@Override
public void info(String msg, Object[] os, Throwable t) {
os = addProcessorAndThrowable(os, t);
@@ -272,20 +192,11 @@ public class MockProcessorLog implements ProcessorLog {
}
}
- /**
- *
- * @return
- */
@Override
public String getName() {
return logger.getName();
}
- /**
- *
- * @param msg
- * @param t
- */
@Override
public void error(String msg, Throwable t) {
msg = "{} " + msg;
@@ -297,11 +208,6 @@ public class MockProcessorLog implements ProcessorLog {
}
}
- /**
- *
- * @param msg
- * @param os
- */
@Override
public void error(String msg, Object[] os) {
if (lastArgIsException(os)) {
@@ -313,10 +219,6 @@ public class MockProcessorLog implements ProcessorLog {
}
}
- /**
- *
- * @param msg
- */
@Override
public void error(String msg) {
msg = "{} " + msg;
@@ -325,12 +227,6 @@ public class MockProcessorLog implements ProcessorLog {
logger.error(msg, os);
}
- /**
- *
- * @param msg
- * @param os
- * @param t
- */
@Override
public void error(String msg, Object[] os, Throwable t) {
os = addProcessorAndThrowable(os, t);
@@ -342,11 +238,6 @@ public class MockProcessorLog implements ProcessorLog {
}
}
- /**
- *
- * @param msg
- * @param t
- */
@Override
public void debug(String msg, Throwable t) {
msg = "{} " + msg;
@@ -355,11 +246,6 @@ public class MockProcessorLog implements ProcessorLog {
logger.debug(msg, os, t);
}
- /**
- *
- * @param msg
- * @param os
- */
@Override
public void debug(String msg, Object[] os) {
os = addProcessor(os);
@@ -368,12 +254,6 @@ public class MockProcessorLog implements ProcessorLog {
logger.debug(msg, os);
}
- /**
- *
- * @param msg
- * @param os
- * @param t
- */
@Override
public void debug(String msg, Object[] os, Throwable t) {
os = addProcessorAndThrowable(os, t);
@@ -385,10 +265,6 @@ public class MockProcessorLog implements ProcessorLog {
}
}
- /**
- *
- * @param msg
- */
@Override
public void debug(String msg) {
msg = "{} " + msg;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProvenanceReporter.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProvenanceReporter.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProvenanceReporter.java
index 3451f12..097eafd 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProvenanceReporter.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockProvenanceReporter.java
@@ -88,7 +88,7 @@ public class MockProvenanceReporter implements ProvenanceReporter {
public void fork(FlowFile parent, java.util.Collection<FlowFile> children, String details, long forkDuration) {
}
-
+
@Override
public void join(Collection<FlowFile> parents, FlowFile child) {
@@ -108,7 +108,7 @@ public class MockProvenanceReporter implements ProvenanceReporter {
public void join(java.util.Collection<FlowFile> parents, FlowFile child, String details, long joinDuration) {
}
-
+
@Override
public void clone(FlowFile parent, FlowFile child) {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingContext.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingContext.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingContext.java
index ca4350c..63a9876 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingContext.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingContext.java
@@ -100,11 +100,9 @@ public class MockReportingContext extends MockControllerServiceLookup implements
}
/**
- * Returns all Bulletins that have been created for the component with the
+ * @param componentId identifier of component to get bulletins for
+ * @return all Bulletins that have been created for the component with the
* given ID
- *
- * @param componentId
- * @return
*/
public List<Bulletin> getComponentBulletins(final String componentId) {
final List<Bulletin> created = componentBulletinsCreated.get(componentId);
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingInitializationContext.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingInitializationContext.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingInitializationContext.java
index 7cabef2..0aea00a 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingInitializationContext.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingInitializationContext.java
@@ -81,7 +81,7 @@ public class MockReportingInitializationContext extends MockControllerServiceLoo
public SchedulingStrategy getSchedulingStrategy() {
return SchedulingStrategy.TIMER_DRIVEN;
}
-
+
@Override
public ComponentLog getLogger() {
return logger;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockValidationContext.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockValidationContext.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockValidationContext.java
index c9b1cda..d73a09b 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockValidationContext.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockValidationContext.java
@@ -38,10 +38,10 @@ public class MockValidationContext implements ValidationContext, ControllerServi
public MockValidationContext(final MockProcessContext processContext) {
this.context = processContext;
-
+
final Map<PropertyDescriptor, String> properties = processContext.getProperties();
expressionLanguageSupported = new HashMap<>(properties.size());
- for ( final PropertyDescriptor descriptor : properties.keySet() ) {
+ for (final PropertyDescriptor descriptor : properties.keySet()) {
expressionLanguageSupported.put(descriptor.getName(), descriptor.isExpressionLanguageSupported());
}
}
@@ -101,13 +101,13 @@ public class MockValidationContext implements ValidationContext, ControllerServi
public boolean isControllerServiceEnabled(final ControllerService service) {
return context.isControllerServiceEnabled(service);
}
-
+
@Override
public String getControllerServiceName(final String serviceIdentifier) {
- final ControllerServiceConfiguration configuration = context.getConfiguration(serviceIdentifier);
- return configuration == null ? null : serviceIdentifier;
+ final ControllerServiceConfiguration configuration = context.getConfiguration(serviceIdentifier);
+ return configuration == null ? null : serviceIdentifier;
}
-
+
@Override
public boolean isValidationRequired(final ControllerService service) {
return true;
@@ -117,16 +117,16 @@ public class MockValidationContext implements ValidationContext, ControllerServi
public boolean isControllerServiceEnabling(String serviceIdentifier) {
return context.isControllerServiceEnabling(serviceIdentifier);
}
-
+
public boolean isExpressionLanguagePresent(final String value) {
- if ( value == null ) {
+ if (value == null) {
return false;
}
-
+
final List<Range> elRanges = Query.extractExpressionRanges(value);
return (elRanges != null && !elRanges.isEmpty());
}
-
+
@Override
public boolean isExpressionLanguageSupported(final String propertyName) {
final Boolean supported = expressionLanguageSupported.get(propertyName);
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/ReflectionUtils.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/ReflectionUtils.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/ReflectionUtils.java
index 9d52eb3..940eeea 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/ReflectionUtils.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/ReflectionUtils.java
@@ -34,14 +34,15 @@ public class ReflectionUtils {
* are supplied by the <code>args</code> parameter than needed, the extra
* arguments will be ignored.
*
- * @param annotation
- * @param instance
- * @param args
- * @throws InvocationTargetException
- * @throws IllegalArgumentException
- * @throws IllegalAccessException
+ * @param annotation the annotation to look for
+ * @param instance to invoke a method of
+ * @param args to supply in a method call
+ * @throws InvocationTargetException ite
+ * @throws IllegalArgumentException iae
+ * @throws IllegalAccessException if not allowed to invoke that method
*/
- public static void invokeMethodsWithAnnotation(final Class<? extends Annotation> annotation, final Object instance, final Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ public static void invokeMethodsWithAnnotation(final Class<? extends Annotation> annotation, final Object instance, final Object... args)
+ throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
for (final Method method : instance.getClass().getMethods()) {
if (method.isAnnotationPresent(annotation)) {
final boolean isAccessible = method.isAccessible();
@@ -90,9 +91,9 @@ public class ReflectionUtils {
* are supplied by the <code>args</code> parameter than needed, the extra
* arguments will be ignored.
*
- * @param annotation
- * @param instance
- * @param args
+ * @param annotation the annotation to look for
+ * @param instance to invoke a method of
+ * @param args to supply in a method call
* @return <code>true</code> if all appropriate methods were invoked and
* returned without throwing an Exception, <code>false</code> if one of the
* methods threw an Exception or could not be invoked; if <code>false</code>
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/SharedSessionState.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/SharedSessionState.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/SharedSessionState.java
index 13a87de..65d79a6 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/SharedSessionState.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/SharedSessionState.java
@@ -32,7 +32,6 @@ public class SharedSessionState {
private final AtomicLong flowFileIdGenerator;
private final ConcurrentMap<String, AtomicLong> counterMap = new ConcurrentHashMap<>();
-
public SharedSessionState(final Processor processor, final AtomicLong flowFileIdGenerator) {
flowFileQueue = new MockFlowFileQueue();
provenanceReporter = new MockProvenanceReporter();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
index d66ed81..7048cfe 100644
--- a/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
+++ b/nifi/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
@@ -86,14 +86,14 @@ public class StandardProcessorTestRunner implements TestRunner {
private static final Logger logger = LoggerFactory.getLogger(StandardProcessorTestRunner.class);
private static final Set<Class<? extends Annotation>> deprecatedTypeAnnotations = new HashSet<>();
private static final Set<Class<? extends Annotation>> deprecatedMethodAnnotations = new HashSet<>();
-
+
static {
// do this in a separate method, just so that we can add a @SuppressWarnings annotation
// because we want to indicate explicitly that we know that we are using deprecated
// classes here.
populateDeprecatedMethods();
}
-
+
StandardProcessorTestRunner(final Processor processor) {
this.processor = processor;
this.idGenerator = new AtomicLong(0L);
@@ -103,7 +103,7 @@ public class StandardProcessorTestRunner implements TestRunner {
this.context = new MockProcessContext(processor);
detectDeprecatedAnnotations(processor);
-
+
final MockProcessorInitializationContext mockInitContext = new MockProcessorInitializationContext(processor, context);
processor.initialize(mockInitContext);
@@ -126,7 +126,7 @@ public class StandardProcessorTestRunner implements TestRunner {
deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.TriggerWhenEmpty.class);
deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.TriggerWhenAnyDestinationAvailable.class);
deprecatedTypeAnnotations.add(org.apache.nifi.processor.annotation.TriggerSerially.class);
-
+
deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnRemoved.class);
deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnAdded.class);
deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnScheduled.class);
@@ -134,24 +134,24 @@ public class StandardProcessorTestRunner implements TestRunner {
deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnStopped.class);
deprecatedMethodAnnotations.add(org.apache.nifi.processor.annotation.OnUnscheduled.class);
}
-
+
private static void detectDeprecatedAnnotations(final Processor processor) {
- for ( final Class<? extends Annotation> annotationClass : deprecatedTypeAnnotations ) {
- if ( processor.getClass().isAnnotationPresent(annotationClass) ) {
+ for (final Class<? extends Annotation> annotationClass : deprecatedTypeAnnotations) {
+ if (processor.getClass().isAnnotationPresent(annotationClass)) {
Assert.fail("Processor is using deprecated Annotation " + annotationClass.getCanonicalName());
}
}
-
- for ( final Class<? extends Annotation> annotationClass : deprecatedMethodAnnotations ) {
- for ( final Method method : processor.getClass().getMethods() ) {
- if ( method.isAnnotationPresent(annotationClass) ) {
+
+ for (final Class<? extends Annotation> annotationClass : deprecatedMethodAnnotations) {
+ for (final Method method : processor.getClass().getMethods()) {
+ if (method.isAnnotationPresent(annotationClass)) {
Assert.fail("Processor is using deprecated Annotation " + annotationClass.getCanonicalName() + " for method " + method);
}
}
}
-
+
}
-
+
@Override
public void setValidateExpressionUsage(final boolean validate) {
context.setValidateExpressionUsage(validate);
@@ -181,7 +181,7 @@ public class StandardProcessorTestRunner implements TestRunner {
public void run(final int iterations, final boolean stopOnFinish) {
run(iterations, stopOnFinish, true);
}
-
+
@Override
public void run(final int iterations, final boolean stopOnFinish, final boolean initialize) {
if (iterations < 1) {
@@ -191,7 +191,7 @@ public class StandardProcessorTestRunner implements TestRunner {
context.assertValid();
context.enableExpressionValidation();
try {
- if ( initialize ) {
+ if (initialize) {
try {
ReflectionUtils.invokeMethodsWithAnnotation(OnScheduled.class, processor, context);
} catch (Exception e) {
@@ -519,7 +519,7 @@ public class StandardProcessorTestRunner implements TestRunner {
// Assert.fail("Controller Service " + service + " is using deprecated Annotation " + org.apache.nifi.controller.annotation.OnConfigured.class + " for method " + method);
// }
// }
-
+
final ComponentLog logger = new MockProcessorLog(identifier, service);
final MockControllerServiceInitializationContext initContext = new MockControllerServiceInitializationContext(requireNonNull(service), requireNonNull(identifier), logger);
service.initialize(initContext);
@@ -538,66 +538,64 @@ public class StandardProcessorTestRunner implements TestRunner {
context.addControllerService(identifier, service, resolvedProps, null);
}
-
@Override
public void assertNotValid(final ControllerService service) {
final ValidationContext validationContext = new MockValidationContext(context).getControllerServiceValidationContext(service);
final Collection<ValidationResult> results = context.getControllerService(service.getIdentifier()).validate(validationContext);
-
- for ( final ValidationResult result : results ) {
- if ( !result.isValid() ) {
+
+ for (final ValidationResult result : results) {
+ if (!result.isValid()) {
return;
}
}
-
+
Assert.fail("Expected Controller Service " + service + " to be invalid but it is valid");
}
-
+
@Override
public void assertValid(final ControllerService service) {
final ValidationContext validationContext = new MockValidationContext(context).getControllerServiceValidationContext(service);
final Collection<ValidationResult> results = context.getControllerService(service.getIdentifier()).validate(validationContext);
-
- for ( final ValidationResult result : results ) {
- if ( !result.isValid() ) {
+
+ for (final ValidationResult result : results) {
+ if (!result.isValid()) {
Assert.fail("Expected Controller Service to be valid but it is invalid due to: " + result.toString());
}
}
}
-
-
+
@Override
public void disableControllerService(final ControllerService service) {
final ControllerServiceConfiguration configuration = context.getConfiguration(service.getIdentifier());
- if ( configuration == null ) {
+ if (configuration == null) {
throw new IllegalArgumentException("Controller Service " + service + " is not known");
}
-
- if ( !configuration.isEnabled() ) {
+
+ if (!configuration.isEnabled()) {
throw new IllegalStateException("Controller service " + service + " cannot be disabled because it is not enabled");
}
-
+
try {
ReflectionUtils.invokeMethodsWithAnnotation(OnDisabled.class, service);
} catch (final Exception e) {
e.printStackTrace();
Assert.fail("Failed to disable Controller Service " + service + " due to " + e);
}
-
+
configuration.setEnabled(false);
}
-
+
@Override
public void enableControllerService(final ControllerService service) {
final ControllerServiceConfiguration configuration = context.getConfiguration(service.getIdentifier());
- if ( configuration == null ) {
+ if (configuration == null) {
throw new IllegalArgumentException("Controller Service " + service + " is not known");
}
-
- if ( configuration.isEnabled() ) {
+
+ if (configuration.isEnabled()) {
throw new IllegalStateException("Cannot enable Controller Service " + service + " because it is not disabled");
}
-
+
try {
final ConfigurationContext configContext = new MockConfigurationContext(configuration.getProperties(), context);
ReflectionUtils.invokeMethodsWithAnnotation(OnEnabled.class, service, configContext);
@@ -609,87 +607,86 @@ public class StandardProcessorTestRunner implements TestRunner {
Assert.fail("Failed to enable Controller Service " + service + " due to " + e);
}
- configuration.setEnabled(true);
+ configuration.setEnabled(true);
}
-
+
@Override
public boolean isControllerServiceEnabled(final ControllerService service) {
final ControllerServiceConfiguration configuration = context.getConfiguration(service.getIdentifier());
- if ( configuration == null ) {
+ if (configuration == null) {
throw new IllegalArgumentException("Controller Service " + service + " is not known");
}
return configuration.isEnabled();
}
-
+
@Override
public void removeControllerService(final ControllerService service) {
disableControllerService(service);
-
+
try {
ReflectionUtils.invokeMethodsWithAnnotation(OnRemoved.class, service);
} catch (final Exception e) {
e.printStackTrace();
Assert.fail("Failed to remove Controller Service " + service + " due to " + e);
}
-
+
context.removeControllerService(service);
}
-
+
@Override
public void setAnnotationData(final ControllerService service, final String annotationData) {
final ControllerServiceConfiguration configuration = getConfigToUpdate(service);
configuration.setAnnotationData(annotationData);
}
-
+
private ControllerServiceConfiguration getConfigToUpdate(final ControllerService service) {
final ControllerServiceConfiguration configuration = context.getConfiguration(service.getIdentifier());
- if ( configuration == null ) {
+ if (configuration == null) {
throw new IllegalArgumentException("Controller Service " + service + " is not known");
}
-
- if ( configuration.isEnabled() ) {
+
+ if (configuration.isEnabled()) {
throw new IllegalStateException("Controller service " + service + " cannot be modified because it is not disabled");
}
-
+
return configuration;
}
-
+
@Override
public ValidationResult setProperty(final ControllerService service, final PropertyDescriptor property, final AllowableValue value) {
return setProperty(service, property, value.getValue());
}
-
+
@Override
public ValidationResult setProperty(final ControllerService service, final PropertyDescriptor property, final String value) {
final ControllerServiceConfiguration configuration = getConfigToUpdate(service);
final Map<PropertyDescriptor, String> curProps = configuration.getProperties();
final Map<PropertyDescriptor, String> updatedProps = new HashMap<>(curProps);
-
+
final ValidationContext validationContext = new MockValidationContext(context).getControllerServiceValidationContext(service);
final ValidationResult validationResult = property.validate(value, validationContext);
-
+
updatedProps.put(property, value);
configuration.setProperties(updatedProps);
-
+
return validationResult;
}
-
+
@Override
public ValidationResult setProperty(final ControllerService service, final String propertyName, final String value) {
final PropertyDescriptor descriptor = service.getPropertyDescriptor(propertyName);
- if ( descriptor == null ) {
+ if (descriptor == null) {
return new ValidationResult.Builder()
- .input(propertyName)
- .explanation(propertyName + " is not a known Property for Controller Service " + service)
- .subject("Invalid property")
- .valid(false)
- .build();
+ .input(propertyName)
+ .explanation(propertyName + " is not a known Property for Controller Service " + service)
+ .subject("Invalid property")
+ .valid(false)
+ .build();
}
return setProperty(service, descriptor, value);
}
-
-
+
@Override
public ControllerService getControllerService(final String identifier) {
return context.getControllerService(identifier);
[7/7] incubator-nifi git commit: NIFI-271 checkpoint
Posted by jo...@apache.org.
NIFI-271 checkpoint
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/b612b6bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/b612b6bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/b612b6bc
Branch: refs/heads/NIFI-271
Commit: b612b6bcd9f2f29a4466360d5fbbeccee62ae650
Parents: afb4fe5
Author: joewitt <jo...@apache.org>
Authored: Tue Apr 21 23:39:31 2015 -0400
Committer: joewitt <jo...@apache.org>
Committed: Tue Apr 21 23:39:31 2015 -0400
----------------------------------------------------------------------
.../nifi/processor/util/FlowFileFilters.java | 2 +-
.../nifi/processor/util/SSLProperties.java | 8 +-
.../nifi/processor/util/StandardValidators.java | 140 +++-
.../processor/util/TestStandardValidators.java | 18 +-
.../nifi-site-to-site-client/pom.xml | 64 +-
.../remote/AbstractCommunicationsSession.java | 9 +-
.../org/apache/nifi/remote/Communicant.java | 23 +-
.../main/java/org/apache/nifi/remote/Peer.java | 20 +-
.../org/apache/nifi/remote/PeerDescription.java | 7 +-
.../java/org/apache/nifi/remote/PeerStatus.java | 7 +-
.../nifi/remote/RemoteResourceInitiator.java | 48 +-
.../org/apache/nifi/remote/Transaction.java | 295 +++----
.../nifi/remote/TransactionCompletion.java | 49 +-
.../apache/nifi/remote/TransferDirection.java | 13 +-
.../nifi/remote/client/SiteToSiteClient.java | 831 ++++++++++---------
.../remote/client/SiteToSiteClientConfig.java | 170 ++--
.../client/socket/EndpointConnection.java | 15 +-
.../client/socket/EndpointConnectionPool.java | 627 +++++++-------
.../nifi/remote/client/socket/SocketClient.java | 319 ++++---
.../apache/nifi/remote/codec/FlowFileCodec.java | 15 +-
.../remote/codec/StandardFlowFileCodec.java | 33 +-
.../remote/exception/HandshakeException.java | 9 +-
.../exception/PortNotRunningException.java | 7 +-
.../remote/exception/ProtocolException.java | 4 +-
.../remote/exception/UnknownPortException.java | 6 +-
.../SocketChannelCommunicationsSession.java | 23 +-
.../remote/io/socket/SocketChannelInput.java | 11 +-
.../remote/io/socket/SocketChannelOutput.java | 11 +-
.../SSLSocketChannelCommunicationsSession.java | 23 +-
.../io/socket/ssl/SSLSocketChannelInput.java | 9 +-
.../io/socket/ssl/SSLSocketChannelOutput.java | 5 +-
.../nifi/remote/protocol/ClientProtocol.java | 18 +-
.../remote/protocol/CommunicationsInput.java | 5 +-
.../remote/protocol/CommunicationsSession.java | 6 +-
.../apache/nifi/remote/protocol/DataPacket.java | 33 +-
.../protocol/socket/HandshakeProperty.java | 38 +-
.../nifi/remote/protocol/socket/Response.java | 11 +-
.../remote/protocol/socket/ResponseCode.java | 65 +-
.../protocol/socket/SocketClientProtocol.java | 388 ++++-----
.../socket/SocketClientTransaction.java | 468 +++++------
.../SocketClientTransactionCompletion.java | 2 +-
.../nifi/remote/util/NiFiRestApiUtil.java | 24 +-
.../nifi/remote/util/PeerStatusCache.java | 3 +-
.../nifi/remote/util/StandardDataPacket.java | 44 +-
.../socket/TestEndpointConnectionStatePool.java | 17 +-
.../client/socket/TestSiteToSiteClient.java | 42 +-
.../nifi/io/nio/AbstractChannelReader.java | 10 +-
.../java/org/apache/nifi/io/nio/BufferPool.java | 10 +-
.../apache/nifi/io/nio/ChannelDispatcher.java | 14 +-
.../org/apache/nifi/io/nio/ChannelListener.java | 7 +-
.../nifi/io/nio/DatagramChannelReader.java | 12 +-
.../apache/nifi/io/nio/SocketChannelReader.java | 12 +-
.../nifi/io/nio/consumer/StreamConsumer.java | 12 +-
.../nifi/io/socket/SSLContextFactory.java | 12 +-
.../io/socket/ServerSocketConfiguration.java | 6 +-
.../nifi/io/socket/SocketConfiguration.java | 6 +-
.../org/apache/nifi/io/socket/SocketUtils.java | 6 +-
.../io/socket/multicast/MulticastListener.java | 5 +-
.../apache/nifi/io/nio/example/TCPClient.java | 3 +-
.../org/wali/MinimalLockingWriteAheadLog.java | 70 +-
.../src/main/java/org/wali/SerDe.java | 40 +-
.../java/org/wali/WriteAheadRepository.java | 16 +-
...kControllerServiceInitializationContext.java | 8 +-
.../nifi/util/MockControllerServiceLookup.java | 14 +-
.../java/org/apache/nifi/util/MockFlowFile.java | 20 +-
.../apache/nifi/util/MockProcessContext.java | 15 +-
.../apache/nifi/util/MockProcessSession.java | 33 +-
.../MockProcessorInitializationContext.java | 4 +-
.../org/apache/nifi/util/MockProcessorLog.java | 124 ---
.../nifi/util/MockProvenanceReporter.java | 4 +-
.../apache/nifi/util/MockReportingContext.java | 6 +-
.../MockReportingInitializationContext.java | 2 +-
.../apache/nifi/util/MockValidationContext.java | 20 +-
.../org/apache/nifi/util/ReflectionUtils.java | 21 +-
.../apache/nifi/util/SharedSessionState.java | 1 -
.../nifi/util/StandardProcessorTestRunner.java | 123 ++-
.../java/org/apache/nifi/util/TestRunner.java | 428 +++++-----
.../util/TestStandardProcessorTestRunner.java | 30 +-
.../apache/nifi/documentation/DocGenerator.java | 12 +-
.../html/HtmlDocumentationWriter.java | 231 ++----
.../html/HtmlProcessorDocumentationWriter.java | 77 +-
.../FullyDocumentedControllerService.java | 51 +-
.../example/FullyDocumentedProcessor.java | 156 ++--
.../example/FullyDocumentedReportingTask.java | 32 +-
.../documentation/example/NakedProcessor.java | 8 +-
.../documentation/example/SampleService.java | 2 +-
.../html/HtmlDocumentationWriterTest.java | 94 +--
.../html/ProcessorDocumentationWriterTest.java | 135 ++-
.../nifi/documentation/html/XmlValidator.java | 29 +-
.../org/apache/nifi/nar/ExtensionManager.java | 14 +-
.../org/apache/nifi/nar/NarClassLoader.java | 24 +-
.../org/apache/nifi/nar/NarClassLoaders.java | 40 +-
.../java/org/apache/nifi/nar/NarUnpacker.java | 14 +-
.../java/org/apache/nifi/util/FileUtils.java | 28 +-
94 files changed, 2944 insertions(+), 3082 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/FlowFileFilters.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/FlowFileFilters.java b/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/FlowFileFilters.java
index 1f77093..2d1a407 100644
--- a/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/FlowFileFilters.java
+++ b/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/FlowFileFilters.java
@@ -32,7 +32,7 @@ public class FlowFileFilters {
* @param maxSize the maximum size of the group of FlowFiles
* @param unit the unit of the <code>maxSize</code> argument
* @param maxCount the maximum number of FlowFiles to pull
- * @return
+ * @return filter
*/
public static FlowFileFilter newSizeBasedFilter(final double maxSize, final DataUnit unit, final int maxCount) {
final double maxBytes = DataUnit.B.convert(maxSize, unit);
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/SSLProperties.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/SSLProperties.java b/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/SSLProperties.java
index 0d66df5..87d63de 100644
--- a/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/SSLProperties.java
+++ b/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/SSLProperties.java
@@ -130,7 +130,13 @@ public class SSLProperties {
try {
final boolean storeValid = CertificateUtils.isStoreValid(file.toURI().toURL(), KeystoreType.valueOf(type), password.toCharArray());
if (!storeValid) {
- results.add(new ValidationResult.Builder().subject(keystoreDesc + " Properties").valid(false).explanation("Invalid KeyStore Password or Type specified for file " + filename).build());
+ results.add(
+ new ValidationResult.Builder()
+ .subject(keystoreDesc + " Properties")
+ .valid(false)
+ .explanation("Invalid KeyStore Password or Type specified for file " + filename)
+ .build()
+ );
}
} catch (MalformedURLException e) {
results.add(new ValidationResult.Builder().subject(keystoreDesc + " Properties").valid(false).explanation("Malformed URL from file: " + e).build());
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/StandardValidators.java b/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
index d1621ed..37ba7d8 100644
--- a/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
+++ b/nifi/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
@@ -46,10 +46,10 @@ public class StandardValidators {
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
final ValidationResult.Builder builder = new ValidationResult.Builder();
builder.subject(subject).input(input);
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return builder.valid(true).explanation("Contains Expression Language").build();
}
-
+
try {
FlowFile.KeyValidator.validateKey(input);
builder.valid(true);
@@ -66,10 +66,10 @@ public class StandardValidators {
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
final ValidationResult.Builder builder = new ValidationResult.Builder();
builder.subject("Property Name").input(subject);
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return builder.valid(true).explanation("Contains Expression Language").build();
}
-
+
try {
FlowFile.KeyValidator.validateKey(subject);
builder.valid(true);
@@ -84,10 +84,10 @@ public class StandardValidators {
public static final Validator POSITIVE_INTEGER_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build();
}
-
+
String reason = null;
try {
final int intVal = Integer.parseInt(value);
@@ -106,7 +106,7 @@ public class StandardValidators {
public static final Validator POSITIVE_LONG_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build();
}
@@ -137,7 +137,7 @@ public class StandardValidators {
public static final Validator BOOLEAN_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build();
}
@@ -150,7 +150,7 @@ public class StandardValidators {
public static final Validator INTEGER_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build();
}
@@ -168,7 +168,7 @@ public class StandardValidators {
public static final Validator LONG_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build();
}
@@ -186,7 +186,7 @@ public class StandardValidators {
public static final Validator NON_NEGATIVE_INTEGER_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build();
}
@@ -208,7 +208,7 @@ public class StandardValidators {
public static final Validator CHARACTER_SET_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build();
}
@@ -235,7 +235,7 @@ public class StandardValidators {
public static final Validator URI_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
@@ -253,7 +253,7 @@ public class StandardValidators {
public static final Validator ATTRIBUTE_EXPRESSION_LANGUAGE_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
@@ -270,7 +270,7 @@ public class StandardValidators {
public static final Validator TIME_PERIOD_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
@@ -280,7 +280,14 @@ public class StandardValidators {
if (Pattern.compile(FormatUtils.TIME_DURATION_REGEX).matcher(input.toLowerCase()).matches()) {
return new ValidationResult.Builder().subject(subject).input(input).valid(true).build();
} else {
- return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Must be of format <duration> <TimeUnit> where <duration> is a non-negative integer and TimeUnit is a supported Time Unit, such as: nanos, millis, secs, mins, hrs, days").build();
+ return new ValidationResult.Builder()
+ .subject(subject)
+ .input(input)
+ .valid(false)
+ .explanation("Must be of format <duration> <TimeUnit> where <duration> is a "
+ + "non-negative integer and TimeUnit is a supported Time Unit, such "
+ + "as: nanos, millis, secs, mins, hrs, days")
+ .build();
}
}
};
@@ -288,17 +295,28 @@ public class StandardValidators {
public static final Validator DATA_SIZE_VALIDATOR = new Validator() {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
if (input == null) {
- return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Data Size cannot be null").build();
+ return new ValidationResult.Builder()
+ .subject(subject)
+ .input(input)
+ .valid(false)
+ .explanation("Data Size cannot be null")
+ .build();
}
if (Pattern.compile(DataUnit.DATA_SIZE_REGEX).matcher(input.toUpperCase()).matches()) {
return new ValidationResult.Builder().subject(subject).input(input).valid(true).build();
} else {
- return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Must be of format <Data Size> <Data Unit> where <Data Size> is a non-negative integer and <Data Unit> is a supported Data Unit, such as: B, KB, MB, GB, TB").build();
+ return new ValidationResult.Builder()
+ .subject(subject).input(input)
+ .valid(false)
+ .explanation("Must be of format <Data Size> <Data Unit> where <Data Size>"
+ + " is a non-negative integer and <Data Unit> is a supported Data"
+ + " Unit, such as: B, KB, MB, GB, TB")
+ .build();
}
}
};
@@ -318,7 +336,7 @@ public class StandardValidators {
return new Validator() {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
@@ -346,19 +364,19 @@ public class StandardValidators {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
final ValidationResult vr = DATA_SIZE_VALIDATOR.validate(subject, input, context);
- if(!vr.isValid()){
+ if (!vr.isValid()) {
return vr;
}
final long dataSizeBytes = DataUnit.parseDataSize(input, DataUnit.B).longValue();
- if(dataSizeBytes < minBytesInclusive){
+ if (dataSizeBytes < minBytesInclusive) {
return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Cannot be smaller than " + minBytesInclusive + " bytes").build();
}
- if(dataSizeBytes > maxBytesInclusive){
+ if (dataSizeBytes > maxBytesInclusive) {
return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Cannot be larger than " + maxBytesInclusive + " bytes").build();
}
return new ValidationResult.Builder().subject(subject).input(input).valid(true).build();
@@ -371,7 +389,7 @@ public class StandardValidators {
return new Validator() {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
@@ -397,10 +415,11 @@ public class StandardValidators {
* Language will not support FlowFile Attributes but only System/JVM
* Properties
*
- * @param minCapturingGroups
- * @param maxCapturingGroups
- * @param supportAttributeExpressionLanguage
- * @return
+ * @param minCapturingGroups minimum capturing groups allowed
+ * @param maxCapturingGroups maximum capturing groups allowed
+ * @param supportAttributeExpressionLanguage whether or not to support
+ * expression language
+ * @return validator
*/
public static Validator createRegexValidator(final int minCapturingGroups, final int maxCapturingGroups, final boolean supportAttributeExpressionLanguage) {
return new Validator() {
@@ -412,7 +431,12 @@ public class StandardValidators {
try {
substituted = context.newPropertyValue(value).evaluateAttributeExpressions().getValue();
} catch (final Exception e) {
- return new ValidationResult.Builder().subject(subject).input(value).valid(false).explanation("Failed to evaluate the Attribute Expression Language due to " + e.toString()).build();
+ return new ValidationResult.Builder()
+ .subject(subject)
+ .input(value)
+ .valid(false)
+ .explanation("Failed to evaluate the Attribute Expression Language due to " + e.toString())
+ .build();
}
} else {
substituted = value;
@@ -421,12 +445,22 @@ public class StandardValidators {
final Pattern pattern = Pattern.compile(substituted);
final int numGroups = pattern.matcher("").groupCount();
if (numGroups < minCapturingGroups || numGroups > maxCapturingGroups) {
- return new ValidationResult.Builder().subject(subject).input(value).valid(false).explanation("RegEx is required to have between " + minCapturingGroups + " and " + maxCapturingGroups + " Capturing Groups but has " + numGroups).build();
+ return new ValidationResult.Builder()
+ .subject(subject)
+ .input(value)
+ .valid(false)
+ .explanation("RegEx is required to have between " + minCapturingGroups + " and " + maxCapturingGroups + " Capturing Groups but has " + numGroups)
+ .build();
}
return new ValidationResult.Builder().subject(subject).input(value).valid(true).build();
} catch (final Exception e) {
- return new ValidationResult.Builder().subject(subject).input(value).valid(false).explanation("Not a valid Java Regular Expression").build();
+ return new ValidationResult.Builder()
+ .subject(subject)
+ .input(value)
+ .valid(false)
+ .explanation("Not a valid Java Regular Expression")
+ .build();
}
}
@@ -444,7 +478,12 @@ public class StandardValidators {
final ResultType resultType = allowExtraCharacters ? ResultType.STRING : context.newExpressionLanguageCompiler().getResultType(input);
if (!resultType.equals(expectedResultType)) {
- return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Expected Attribute Query to return type " + expectedResultType + " but query returns type " + resultType).build();
+ return new ValidationResult.Builder()
+ .subject(subject)
+ .input(input)
+ .valid(false)
+ .explanation("Expected Attribute Query to return type " + expectedResultType + " but query returns type " + resultType)
+ .build();
}
return new ValidationResult.Builder().subject(subject).input(input).valid(true).build();
@@ -456,7 +495,7 @@ public class StandardValidators {
return new Validator() {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
@@ -502,7 +541,7 @@ public class StandardValidators {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
@@ -523,7 +562,8 @@ public class StandardValidators {
}
} else {
builder.subject(subject).input(input).valid(false)
- .explanation("Must be of format <duration> <TimeUnit> where <duration> is a non-negative integer and TimeUnit is a supported Time Unit, such as: nanos, millis, secs, mins, hrs, days");
+ .explanation("Must be of format <duration> <TimeUnit> where <duration> is a non-negative "
+ + "integer and TimeUnit is a supported Time Unit, such as: nanos, millis, secs, mins, hrs, days");
}
return builder.build();
}
@@ -539,7 +579,7 @@ public class StandardValidators {
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build();
}
@@ -574,7 +614,7 @@ public class StandardValidators {
@Override
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
return new ValidationResult.Builder().subject(subject).input(value).explanation("Expression Language Present").valid(true).build();
}
@@ -617,17 +657,19 @@ public class StandardValidators {
/**
* Creates a validator based on existence of a {@link ControllerService}.
- *
- * @param serviceClass the controller service API your {@link ConfigurableComponent} depends on
+ *
+ * @param serviceClass the controller service API your
+ * {@link ConfigurableComponent} depends on
* @return a Validator
- * @deprecated As of release 0.1.0-incubating, replaced by {@link org.apache.nifi.components.PropertyDescriptor.Builder#identifiesControllerService(Class)}
+ * @deprecated As of release 0.1.0-incubating, replaced by
+ * {@link org.apache.nifi.components.PropertyDescriptor.Builder#identifiesControllerService(Class)}
*/
@Deprecated
public static Validator createControllerServiceExistsValidator(final Class<? extends ControllerService> serviceClass) {
return new Validator() {
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
- if ( context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input) ) {
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
}
@@ -638,14 +680,24 @@ public class StandardValidators {
}
if (!serviceClass.isAssignableFrom(svc.getClass())) {
- return new ValidationResult.Builder().valid(false).input(input).subject(subject).explanation("Controller Service with this ID is of type " + svc.getClass().getName() + " but is expected to be of type " + serviceClass.getName()).build();
+ return new ValidationResult.Builder()
+ .valid(false)
+ .input(input)
+ .subject(subject)
+ .explanation("Controller Service with this ID is of type " + svc.getClass().getName() + " but is expected to be of type " + serviceClass.getName())
+ .build();
}
final ValidationContext serviceValidationContext = context.getControllerServiceValidationContext(svc);
final Collection<ValidationResult> serviceValidationResults = svc.validate(serviceValidationContext);
for (final ValidationResult result : serviceValidationResults) {
if (!result.isValid()) {
- return new ValidationResult.Builder().valid(false).input(input).subject(subject).explanation("Controller Service " + input + " is not valid: " + result.getExplanation()).build();
+ return new ValidationResult.Builder()
+ .valid(false)
+ .input(input)
+ .subject(subject)
+ .explanation("Controller Service " + input + " is not valid: " + result.getExplanation())
+ .build();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-processor-utilities/src/test/java/org/apache/nifi/processor/util/TestStandardValidators.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-processor-utilities/src/test/java/org/apache/nifi/processor/util/TestStandardValidators.java b/nifi/nifi-commons/nifi-processor-utilities/src/test/java/org/apache/nifi/processor/util/TestStandardValidators.java
index a8f4bae..bcd402d 100644
--- a/nifi/nifi-commons/nifi-processor-utilities/src/test/java/org/apache/nifi/processor/util/TestStandardValidators.java
+++ b/nifi/nifi-commons/nifi-processor-utilities/src/test/java/org/apache/nifi/processor/util/TestStandardValidators.java
@@ -35,7 +35,7 @@ public class TestStandardValidators {
ValidationResult vr;
final ValidationContext validationContext = Mockito.mock(ValidationContext.class);
-
+
vr = val.validate("TimePeriodTest", "0 sense made", validationContext);
assertFalse(vr.isValid());
@@ -54,22 +54,22 @@ public class TestStandardValidators {
vr = val.validate("TimePeriodTest", "1 sec", validationContext);
assertTrue(vr.isValid());
}
-
+
@Test
public void testDataSizeBoundsValidator() {
Validator val = StandardValidators.createDataSizeBoundsValidator(100, 1000);
- ValidationResult vr;
-
+ ValidationResult vr;
+
final ValidationContext validationContext = Mockito.mock(ValidationContext.class);
vr = val.validate("DataSizeBounds", "5 GB", validationContext);
assertFalse(vr.isValid());
-
+
vr = val.validate("DataSizeBounds", "0 B", validationContext);
assertFalse(vr.isValid());
vr = val.validate("DataSizeBounds", "99 B", validationContext);
assertFalse(vr.isValid());
-
+
vr = val.validate("DataSizeBounds", "100 B", validationContext);
assertTrue(vr.isValid());
@@ -78,12 +78,12 @@ public class TestStandardValidators {
vr = val.validate("DataSizeBounds", "1000 B", validationContext);
assertTrue(vr.isValid());
-
+
vr = val.validate("DataSizeBounds", "1001 B", validationContext);
assertFalse(vr.isValid());
-
+
vr = val.validate("DataSizeBounds", "water", validationContext);
assertFalse(vr.isValid());
-
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/pom.xml
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/pom.xml b/nifi/nifi-commons/nifi-site-to-site-client/pom.xml
index 5d3d93e..c024be6 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/pom.xml
+++ b/nifi/nifi-commons/nifi-site-to-site-client/pom.xml
@@ -14,41 +14,41 @@
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.nifi</groupId>
- <artifactId>nifi-commons</artifactId>
- <version>0.1.0-incubating-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-commons</artifactId>
+ <version>0.1.0-incubating-SNAPSHOT</version>
+ </parent>
- <artifactId>nifi-site-to-site-client</artifactId>
+ <artifactId>nifi-site-to-site-client</artifactId>
- <dependencies>
- <dependency>
- <groupId>org.apache.nifi</groupId>
- <artifactId>nifi-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.nifi</groupId>
- <artifactId>nifi-utils</artifactId>
- </dependency>
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-mapper-asl</artifactId>
- <version>1.9.13</version>
- </dependency>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>1.9.13</version>
+ </dependency>
- <dependency>
- <groupId>org.apache.nifi</groupId>
- <artifactId>nifi-client-dto</artifactId>
- <version>0.1.0-incubating-SNAPSHOT</version>
- </dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-client-dto</artifactId>
+ <version>0.1.0-incubating-SNAPSHOT</version>
+ </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/AbstractCommunicationsSession.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/AbstractCommunicationsSession.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/AbstractCommunicationsSession.java
index 4babb92..dacfd64 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/AbstractCommunicationsSession.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/AbstractCommunicationsSession.java
@@ -19,14 +19,15 @@ package org.apache.nifi.remote;
import org.apache.nifi.remote.protocol.CommunicationsSession;
public abstract class AbstractCommunicationsSession implements CommunicationsSession {
+
private String userDn;
-
+
private volatile String uri;
-
+
public AbstractCommunicationsSession(final String uri) {
this.uri = uri;
}
-
+
@Override
public String toString() {
return uri;
@@ -46,7 +47,7 @@ public abstract class AbstractCommunicationsSession implements CommunicationsSes
public String getUserDn() {
return userDn;
}
-
+
@Override
public void setUserDn(final String dn) {
this.userDn = dn;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java
index ac2d498..17b990e 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Communicant.java
@@ -20,28 +20,27 @@ package org.apache.nifi.remote;
* Represents the remote entity that the client is communicating with
*/
public interface Communicant {
+
/**
- * Returns the NiFi site-to-site URL for the remote NiFi instance
- * @return
+ * @return the NiFi site-to-site URL for the remote NiFi instance
*/
String getUrl();
-
+
/**
- * The Host of the remote NiFi instance
- * @return
+ * @return The Host of the remote NiFi instance
*/
String getHost();
-
+
/**
- * The Port that the remote NiFi instance is listening on for site-to-site communications
- * @return
+ * @return The Port that the remote NiFi instance is listening on for
+ * site-to-site communications
*/
int getPort();
-
+
/**
- * The distinguished name that the remote NiFi instance has provided in its certificate if
- * using secure communications, or <code>null</code> if the Distinguished Name is unknown
- * @return
+ * @return The distinguished name that the remote NiFi instance has provided
+ * in its certificate if using secure communications, or <code>null</code>
+ * if the Distinguished Name is unknown
*/
String getDistinguishedName();
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Peer.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Peer.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Peer.java
index 2428078..5cb37b0 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Peer.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Peer.java
@@ -31,7 +31,7 @@ public class Peer implements Communicant {
private final String clusterUrl;
private final String host;
private final int port;
-
+
private final Map<String, Long> penaltyExpirationMap = new HashMap<>();
private boolean closed = false;
@@ -53,14 +53,14 @@ public class Peer implements Communicant {
public PeerDescription getDescription() {
return description;
}
-
+
@Override
public String getUrl() {
return url;
}
-
+
public String getClusterUrl() {
- return clusterUrl;
+ return clusterUrl;
}
public CommunicationsSession getCommunicationsSession() {
@@ -79,24 +79,24 @@ public class Peer implements Communicant {
}
/**
- * Penalizes this peer for the given destination only for the provided number of milliseconds
- * @param destinationId
- * @param millis
+ * Penalizes this peer for the given destination only for the provided
+ * number of milliseconds
+ *
+ * @param destinationId id of destination
+ * @param millis period of time to penalize peer
*/
public void penalize(final String destinationId, final long millis) {
final Long currentPenalty = penaltyExpirationMap.get(destinationId);
final long proposedPenalty = System.currentTimeMillis() + millis;
- if ( currentPenalty == null || proposedPenalty > currentPenalty ) {
+ if (currentPenalty == null || proposedPenalty > currentPenalty) {
penaltyExpirationMap.put(destinationId, proposedPenalty);
}
}
-
public boolean isPenalized(final String destinationId) {
final Long currentPenalty = penaltyExpirationMap.get(destinationId);
return (currentPenalty != null && currentPenalty > System.currentTimeMillis());
}
-
public boolean isClosed() {
return closed;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java
index 0e8e498..6fc90e4 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerDescription.java
@@ -17,10 +17,11 @@
package org.apache.nifi.remote;
public class PeerDescription {
+
private final String hostname;
private final int port;
private final boolean secure;
-
+
public PeerDescription(final String hostname, final int port, final boolean secure) {
this.hostname = hostname;
this.port = port;
@@ -64,7 +65,7 @@ public class PeerDescription {
if (getClass() != obj.getClass()) {
return false;
}
-
+
final PeerDescription other = (PeerDescription) obj;
if (hostname == null) {
if (other.hostname != null) {
@@ -73,7 +74,7 @@ public class PeerDescription {
} else if (!hostname.equals(other.hostname)) {
return false;
}
-
+
return port == other.port;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerStatus.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerStatus.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerStatus.java
index b68ac33..6c8a4ec 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerStatus.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/PeerStatus.java
@@ -17,6 +17,7 @@
package org.apache.nifi.remote;
public class PeerStatus {
+
private final PeerDescription description;
private final int numFlowFiles;
@@ -28,15 +29,15 @@ public class PeerStatus {
public PeerDescription getPeerDescription() {
return description;
}
-
+
public int getFlowFileCount() {
return numFlowFiles;
}
@Override
public String toString() {
- return "PeerStatus[hostname=" + description.getHostname() + ",port=" + description.getPort() +
- ",secure=" + description.isSecure() + ",flowFileCount=" + numFlowFiles + "]";
+ return "PeerStatus[hostname=" + description.getHostname() + ",port=" + description.getPort()
+ + ",secure=" + description.isSecure() + ",flowFileCount=" + numFlowFiles + "]";
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/RemoteResourceInitiator.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/RemoteResourceInitiator.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/RemoteResourceInitiator.java
index f469724..582916e 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/RemoteResourceInitiator.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/RemoteResourceInitiator.java
@@ -25,49 +25,51 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RemoteResourceInitiator {
- public static final int RESOURCE_OK = 20;
- public static final int DIFFERENT_RESOURCE_VERSION = 21;
- public static final int ABORT = 255;
- private static final Logger logger = LoggerFactory.getLogger(RemoteResourceInitiator.class);
-
- public static VersionedRemoteResource initiateResourceNegotiation(final VersionedRemoteResource resource, final DataInputStream dis, final DataOutputStream dos) throws IOException, HandshakeException {
+ public static final int RESOURCE_OK = 20;
+ public static final int DIFFERENT_RESOURCE_VERSION = 21;
+ public static final int ABORT = 255;
+
+ private static final Logger logger = LoggerFactory.getLogger(RemoteResourceInitiator.class);
+
+ public static VersionedRemoteResource initiateResourceNegotiation(final VersionedRemoteResource resource, final DataInputStream dis, final DataOutputStream dos)
+ throws IOException, HandshakeException {
// Write the classname of the RemoteStreamCodec, followed by its version
- logger.debug("Negotiating resource; proposal is {}", resource);
- dos.writeUTF(resource.getResourceName());
- final VersionNegotiator negotiator = resource.getVersionNegotiator();
- dos.writeInt(negotiator.getVersion());
- dos.flush();
-
+ logger.debug("Negotiating resource; proposal is {}", resource);
+ dos.writeUTF(resource.getResourceName());
+ final VersionNegotiator negotiator = resource.getVersionNegotiator();
+ dos.writeInt(negotiator.getVersion());
+ dos.flush();
+
// wait for response from server.
- logger.debug("Receiving response from remote instance");
+ logger.debug("Receiving response from remote instance");
final int statusCode = dis.read();
switch (statusCode) {
- case RESOURCE_OK: // server accepted our proposal of codec name/version
+ case RESOURCE_OK: // server accepted our proposal of codec name/version
logger.debug("Response was RESOURCE_OK");
return resource;
- case DIFFERENT_RESOURCE_VERSION: // server accepted our proposal of codec name but not the version
+ case DIFFERENT_RESOURCE_VERSION: // server accepted our proposal of codec name but not the version
logger.debug("Response was DIFFERENT_RESOURCE_VERSION");
// Get server's preferred version
- final int newVersion = dis.readInt();
-
+ final int newVersion = dis.readInt();
+
// Determine our new preferred version that is no greater than the server's preferred version.
final Integer newPreference = negotiator.getPreferredVersion(newVersion);
// If we could not agree with server on a version, fail now.
- if ( newPreference == null ) {
+ if (newPreference == null) {
throw new HandshakeException("Could not agree on version for " + resource);
}
-
+
negotiator.setVersion(newPreference);
-
+
// Attempt negotiation of resource based on our new preferred version.
return initiateResourceNegotiation(resource, dis, dos);
case ABORT:
logger.debug("Response was ABORT");
- throw new HandshakeException("Remote destination aborted connection with message: " + dis.readUTF());
+ throw new HandshakeException("Remote destination aborted connection with message: " + dis.readUTF());
default:
logger.debug("Response was {}; unable to negotiate codec", statusCode);
- return null; // Unable to negotiate codec
+ return null; // Unable to negotiate codec
}
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Transaction.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Transaction.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Transaction.java
index eb7312d..bfa5c82 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Transaction.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/Transaction.java
@@ -21,52 +21,57 @@ import java.util.Map;
import org.apache.nifi.remote.protocol.DataPacket;
-
/**
* <p>
* Provides a transaction for performing site-to-site data transfers.
* </p>
- *
+ *
* <p>
- * A Transaction is created by calling the
- * {@link org.apache.nifi.remote.client.SiteToSiteClient#createTransaction(TransferDirection) createTransaction(TransferDirection)}
- * method of a {@link org.apache.nifi.remote.client.SiteToSiteClient SiteToSiteClient}. The resulting Transaction
- * can be used to either send or receive data but not both. A new Transaction must be created in order perform the
- * other operation.
+ * A Transaction is created by calling the
+ * {@link org.apache.nifi.remote.client.SiteToSiteClient#createTransaction(TransferDirection) createTransaction(TransferDirection)}
+ * method of a
+ * {@link org.apache.nifi.remote.client.SiteToSiteClient SiteToSiteClient}. The
+ * resulting Transaction can be used to either send or receive data but not
+ * both. A new Transaction must be created in order perform the other operation.
* </p>
- *
+ *
* <p>
* The general flow of execute of a Transaction is as follows:
* <ol>
- * <li>Create the transaction as described above.</li>
- * <li>Send data via the {@link #send(DataPacket)} method or receive data via the {@link #receive()} method. This method
- * will be called 1 or more times. In the case of receive, this method should be called until the method returns {@code null},
- * signifying that the remote instance is finished sending data. <b>Note:</b> <code>receive()</code> should not be
- * called a second time without first fully consuming the stream from the previous Packet that was received.</li>
- * <li>Confirm the transaction via the {@link #confirm()} method.</li>
- * <li>Either complete the transaction via the {@link #complete(boolean)} method or cancel the transaction
- * via the {@link #cancel()} method.</li>
+ * <li>Create the transaction as described above.</li>
+ * <li>Send data via the {@link #send(DataPacket)} method or receive data via
+ * the {@link #receive()} method. This method will be called 1 or more times. In
+ * the case of receive, this method should be called until the method returns
+ * {@code null}, signifying that the remote instance is finished sending data.
+ * <b>Note:</b> <code>receive()</code> should not be called a second time
+ * without first fully consuming the stream from the previous Packet that was
+ * received.</li>
+ * <li>Confirm the transaction via the {@link #confirm()} method.</li>
+ * <li>Either complete the transaction via the {@link #complete(boolean)} method
+ * or cancel the transaction via the {@link #cancel()} method.</li>
* </ol>
* </p>
- *
+ *
* <p>
- * It is important that the Transaction be terminated in order to free the resources held
- * by the Transaction. If a Transaction is not terminated, its resources will not be freed and
- * if the Transaction holds connections from a connection pool, the connections in that pool
- * will eventually become exhausted. A Transaction is terminated by calling one of the following
+ * It is important that the Transaction be terminated in order to free the
+ * resources held by the Transaction. If a Transaction is not terminated, its
+ * resources will not be freed and if the Transaction holds connections from a
+ * connection pool, the connections in that pool will eventually become
+ * exhausted. A Transaction is terminated by calling one of the following
* methods:
- * <ul>
- * <li>{@link #complete(boolean)}</li>
- * <li>{@link #cancel()}</li>
- * <li>{@link #error()}</li>
- * </ul>
+ * <ul>
+ * <li>{@link #complete(boolean)}</li>
+ * <li>{@link #cancel()}</li>
+ * <li>{@link #error()}</li>
+ * </ul>
* </p>
- *
+ *
* <p>
- * If at any point an IOException is thrown from one of the methods of the Transaction, that Transaction
- * is automatically closed via a call to {@link #error()}.
+ * If at any point an IOException is thrown from one of the methods of the
+ * Transaction, that Transaction is automatically closed via a call to
+ * {@link #error()}.
* </p>
- *
+ *
* <p>
* The Transaction class should not be assumed to be thread-safe.
* </p>
@@ -75,140 +80,146 @@ public interface Transaction {
/**
* Sends information to the remote NiFi instance.
- *
+ *
* @param dataPacket the data packet to send
- * @throws IOException
+ * @throws IOException if unable to send
*/
void send(DataPacket dataPacket) throws IOException;
-
+
/**
- * Sends the given byte array as the content of a {@link DataPacket} along with the
- * provided attributes
- *
- * @param content
- * @param attributes
- * @throws IOException
+ * Sends the given byte array as the content of a {@link DataPacket} along
+ * with the provided attributes
+ *
+ * @param content to send
+ * @param attributes of the content
+ * @throws IOException if unable to send
*/
void send(byte[] content, Map<String, String> attributes) throws IOException;
-
+
/**
- * Retrieves information from the remote NiFi instance, if any is available. If no data is available, will return
- * {@code null}. It is important to consume all data from the remote NiFi instance before attempting to
- * call {@link #confirm()}. This is because the sender is always responsible for determining when the Transaction
- * has finished. This is done in order to prevent the need for a round-trip network request to receive data for
+ * Retrieves information from the remote NiFi instance, if any is available.
+ * If no data is available, will return {@code null}. It is important to
+ * consume all data from the remote NiFi instance before attempting to call
+ * {@link #confirm()}. This is because the sender is always responsible for
+ * determining when the Transaction has finished. This is done in order to
+ * prevent the need for a round-trip network request to receive data for
* each data packet.
- *
- * @return the DataPacket received, or {@code null} if there is no more data to receive.
- * @throws IOException
+ *
+ * @return the DataPacket received, or {@code null} if there is no more data
+ * to receive.
+ * @throws IOException if unable to receive
*/
DataPacket receive() throws IOException;
/**
* <p>
- * Confirms the data that was sent or received by comparing CRC32's of the data sent and the data received.
+ * Confirms the data that was sent or received by comparing CRC32's of the
+ * data sent and the data received.
+ * </p>
+ *
+ * <p>
+ * Even if the protocol being used to send the data is reliable and
+ * guarantees ordering of packets (such as TCP), it is still required that
+ * we confirm the transaction before completing the transaction. This is
+ * done as "safety net" or a defensive programming technique. Mistakes
+ * happen, and this mechanism helps to ensure that if a bug exists somewhere
+ * along the line that we do not end up sending or receiving corrupt data.
+ * If the CRC32 of the sender and the CRC32 of the receiver do not match, an
+ * IOException will be thrown and both the sender and receiver will cancel
+ * the transaction automatically.
* </p>
- *
+ *
* <p>
- * Even if the protocol being used to send the data is reliable and guarantees ordering of packets (such as TCP),
- * it is still required that we confirm the transaction before completing the transaction. This is done as
- * "safety net" or a defensive programming technique. Mistakes happen, and this mechanism helps to ensure that if
- * a bug exists somewhere along the line that we do not end up sending or receiving corrupt data. If the
- * CRC32 of the sender and the CRC32 of the receiver do not match, an IOException will be thrown and both the
- * sender and receiver will cancel the transaction automatically.
+ * If the {@link TransferDirection} of this Transaction is RECEIVE, this
+ * method will throw an Exception unless all data from the remote instance
+ * has been consumed (i.e., a call to {@link #receive()} returns
+ * {@code null}).
* </p>
- *
+ *
+ * <p>
+ * If the {@link TransferDirection} of this Transaction is SEND, calling
+ * this method dictates that no more data will be sent in this transaction.
+ * I.e., there will be no more calls to {@link #send(DataPacket)}.
+ * </p>
+ *
+ * @throws IOException if unable to confirm transaction
+ */
+ void confirm() throws IOException;
+
+ /**
* <p>
- * If the {@link TransferDirection} of this Transaction is RECEIVE, this method will throw an Exception unless
- * all data from the remote instance has been consumed (i.e., a call to {@link #receive()} returns {@code null}).
+ * Completes the transaction and indicates to both the sender and receiver
+ * that the data transfer was successful.
* </p>
- *
+ *
+ * @throws IOException if unable to complete
+ *
+ * @return a TransactionCompletion that contains details about the
+ * Transaction
+ */
+ TransactionCompletion complete() throws IOException;
+
+ /**
* <p>
- * If the {@link TransferDirection} of this Transaction is SEND, calling this method dictates that no more data will be
- * sent in this transaction. I.e., there will be no more calls to {@link #send(DataPacket)}.
+ * Cancels this transaction, indicating to the sender that the data has not
+ * been successfully received so that the sender can retry or handle however
+ * is appropriate.
* </p>
- *
- * @throws IOException
+ *
+ * @param explanation an explanation to tell the other party why the
+ * transaction was canceled.
+ * @throws IOException if unable to cancel
*/
- void confirm() throws IOException;
-
- /**
+ void cancel(final String explanation) throws IOException;
+
+ /**
* <p>
- * Completes the transaction and indicates to both the sender and receiver that the data transfer was
- * successful.
+ * Sets the TransactionState of the Transaction to
+ * {@link TransactionState#ERROR}, and closes the Transaction. The
+ * underlying connection should not be returned to a connection pool in this
+ * case.
* </p>
- *
- * @throws IOException
- *
- * @return a TransactionCompletion that contains details about the Transaction
*/
- TransactionCompletion complete() throws IOException;
-
- /**
- * <p>
- * Cancels this transaction, indicating to the sender that the data has not been successfully received so that
- * the sender can retry or handle however is appropriate.
- * </p>
- *
- * @param explanation an explanation to tell the other party why the transaction was canceled.
- * @throws IOException
- */
- void cancel(final String explanation) throws IOException;
-
-
- /**
- * <p>
- * Sets the TransactionState of the Transaction to {@link TransactionState#ERROR}, and closes
- * the Transaction. The underlying connection should not be returned to a connection pool in this case.
- * </p>
- */
- void error();
-
-
- /**
- * Returns the current state of the Transaction.
- * @return
- * @throws IOException
- */
- TransactionState getState() throws IOException;
-
- /**
- * Returns a Communicant that represents the other side of this Transaction (i.e.,
- * the remote NiFi instance)
- * @return
- */
- Communicant getCommunicant();
-
-
- public enum TransactionState {
- /**
- * Transaction has been started but no data has been sent or received.
- */
- TRANSACTION_STARTED,
-
- /**
- * Transaction has been started and data has been sent or received.
- */
- DATA_EXCHANGED,
-
- /**
- * Data that has been transferred has been confirmed via its CRC. Transaction is
- * ready to be completed.
- */
- TRANSACTION_CONFIRMED,
-
- /**
- * Transaction has been successfully completed.
- */
- TRANSACTION_COMPLETED,
-
- /**
- * The Transaction has been canceled.
- */
- TRANSACTION_CANCELED,
-
- /**
- * The Transaction ended in an error.
- */
- ERROR;
- }
+ void error();
+
+ /**
+ * @return the current state of the Transaction.
+ * @throws IOException ioe
+ */
+ TransactionState getState() throws IOException;
+
+ /**
+ * @return a Communicant that represents the other side of this Transaction
+ * (i.e., the remote NiFi instance)
+ */
+ Communicant getCommunicant();
+
+ public enum TransactionState {
+
+ /**
+ * Transaction has been started but no data has been sent or received.
+ */
+ TRANSACTION_STARTED,
+ /**
+ * Transaction has been started and data has been sent or received.
+ */
+ DATA_EXCHANGED,
+ /**
+ * Data that has been transferred has been confirmed via its CRC.
+ * Transaction is ready to be completed.
+ */
+ TRANSACTION_CONFIRMED,
+ /**
+ * Transaction has been successfully completed.
+ */
+ TRANSACTION_COMPLETED,
+ /**
+ * The Transaction has been canceled.
+ */
+ TRANSACTION_CANCELED,
+ /**
+ * The Transaction ended in an error.
+ */
+ ERROR;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java
index be5f73a..1587e87 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransactionCompletion.java
@@ -21,43 +21,44 @@ import java.util.concurrent.TimeUnit;
import org.apache.nifi.remote.protocol.DataPacket;
-
/**
- * A TransactionCompletion provides information about a {@link Transaction} that has completed successfully.
+ * A TransactionCompletion provides information about a {@link Transaction} that
+ * has completed successfully.
*/
public interface TransactionCompletion {
-
+
/**
- * When a sending to a NiFi instance, the server may accept the content sent to it
- * but indicate that its queues are full and that the client should backoff sending
- * data for a bit. This method returns <code>true</code> if the server did in fact
- * request that, <code>false</code> otherwise.
- * @return
+ * When a sending to a NiFi instance, the server may accept the content sent
+ * to it but indicate that its queues are full and that the client should
+ * backoff sending data for a bit.
+ *
+ * @return <code>true</code> if the server did in fact request that,
+ * <code>false</code> otherwise
*/
boolean isBackoff();
-
+
/**
- * Returns the number of Data Packets that were sent to or received from the remote
- * NiFi instance in the Transaction
- * @return
+ * @return the number of Data Packets that were sent to or received from the
+ * remote NiFi instance in the Transaction
*/
int getDataPacketsTransferred();
-
+
/**
- * Returns the number of bytes of DataPacket content that were sent to or received from
- * the remote NiFI instance in the Transaction. Note that this is different than the number
- * of bytes actually transferred between the client and server, as it does not take into
- * account the attributes or protocol-specific information that is exchanged but rather
- * takes into account only the data in the {@link InputStream} of the {@link DataPacket}
- * @return
+ * @return the number of bytes of DataPacket content that were sent to or
+ * received from the remote NiFI instance in the Transaction. Note that this
+ * is different than the number of bytes actually transferred between the
+ * client and server, as it does not take into account the attributes or
+ * protocol-specific information that is exchanged but rather takes into
+ * account only the data in the {@link InputStream} of the
+ * {@link DataPacket}
*/
long getBytesTransferred();
-
+
/**
- * Returns the amount of time that the Transaction took, from the time that the Transaction
- * was created to the time that the Transaction was completed.
- * @param timeUnit
- * @return
+ * @param timeUnit unit of time for which to report the duration
+ * @return the amount of time that the Transaction took, from the time that
+ * the Transaction was created to the time that the Transaction was
+ * completed
*/
long getDuration(TimeUnit timeUnit);
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransferDirection.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransferDirection.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransferDirection.java
index 45029a4..979ad9c 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransferDirection.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/TransferDirection.java
@@ -16,17 +16,16 @@
*/
package org.apache.nifi.remote;
-
/**
- * An enumeration for specifying the direction in which data should be transferred between a client
- * and a remote NiFi instance.
+ * An enumeration for specifying the direction in which data should be
+ * transferred between a client and a remote NiFi instance.
*/
public enum TransferDirection {
- /**
- * The client is to send data to the remote instance.
- */
+
+ /**
+ * The client is to send data to the remote instance.
+ */
SEND,
-
/**
* The client is to receive data from the remote instance.
*/
[4/7] incubator-nifi git commit: NIFI-271 checkpoint
Posted by jo...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/DataPacket.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/DataPacket.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/DataPacket.java
index 3f0ec4f..e7b6d06 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/DataPacket.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/DataPacket.java
@@ -19,27 +19,30 @@ package org.apache.nifi.remote.protocol;
import java.io.InputStream;
import java.util.Map;
-
/**
- * Represents a piece of data that is to be sent to or that was received from a NiFi instance.
+ * Represents a piece of data that is to be sent to or that was received from a
+ * NiFi instance.
*/
public interface DataPacket {
/**
* The key-value attributes that are to be associated with the data
- * @return
+ *
+ * @return all attributes
+ */
+ Map<String, String> getAttributes();
+
+ /**
+ * An InputStream from which the content can be read
+ *
+ * @return input stream to the data
*/
- Map<String, String> getAttributes();
-
- /**
- * An InputStream from which the content can be read
- * @return
- */
- InputStream getData();
+ InputStream getData();
- /**
- * The length of the InputStream.
- * @return
- */
- long getSize();
+ /**
+ * The length of the InputStream.
+ *
+ * @return length of the inputstream.
+ */
+ long getSize();
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/HandshakeProperty.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/HandshakeProperty.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/HandshakeProperty.java
index 41dc276..016690c 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/HandshakeProperty.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/HandshakeProperty.java
@@ -16,46 +16,44 @@
*/
package org.apache.nifi.remote.protocol.socket;
-
/**
- * Enumeration of Properties that can be used for the Site-to-Site Socket Protocol.
+ * Enumeration of Properties that can be used for the Site-to-Site Socket
+ * Protocol.
*/
public enum HandshakeProperty {
+
/**
- * Boolean value indicating whether or not the contents of a FlowFile should be
- * GZipped when transferred.
+ * Boolean value indicating whether or not the contents of a FlowFile should
+ * be GZipped when transferred.
*/
GZIP,
-
/**
* The unique identifier of the port to communicate with
*/
PORT_IDENTIFIER,
-
/**
- * Indicates the number of milliseconds after the request was made that the client
- * will wait for a response. If no response has been received by the time this value
- * expires, the server can move on without attempting to service the request because
- * the client will have already disconnected.
+ * Indicates the number of milliseconds after the request was made that the
+ * client will wait for a response. If no response has been received by the
+ * time this value expires, the server can move on without attempting to
+ * service the request because the client will have already disconnected.
*/
REQUEST_EXPIRATION_MILLIS,
-
/**
- * The preferred number of FlowFiles that the server should send to the client
- * when pulling data. This property was introduced in version 5 of the protocol.
+ * The preferred number of FlowFiles that the server should send to the
+ * client when pulling data. This property was introduced in version 5 of
+ * the protocol.
*/
BATCH_COUNT,
-
/**
- * The preferred number of bytes that the server should send to the client when
- * pulling data. This property was introduced in version 5 of the protocol.
+ * The preferred number of bytes that the server should send to the client
+ * when pulling data. This property was introduced in version 5 of the
+ * protocol.
*/
BATCH_SIZE,
-
/**
- * The preferred amount of time that the server should send data to the client
- * when pulling data. This property was introduced in version 5 of the protocol.
- * Value is in milliseconds.
+ * The preferred amount of time that the server should send data to the
+ * client when pulling data. This property was introduced in version 5 of
+ * the protocol. Value is in milliseconds.
*/
BATCH_DURATION;
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/Response.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/Response.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/Response.java
index eae1940..6ad2ba0 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/Response.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/Response.java
@@ -22,28 +22,29 @@ import java.io.IOException;
import org.apache.nifi.remote.exception.ProtocolException;
public class Response {
+
private final ResponseCode code;
private final String message;
-
+
private Response(final ResponseCode code, final String explanation) {
this.code = code;
this.message = explanation;
}
-
+
public ResponseCode getCode() {
return code;
}
-
+
public String getMessage() {
return message;
}
-
+
public static Response read(final DataInputStream in) throws IOException, ProtocolException {
final ResponseCode code = ResponseCode.readCode(in);
final String message = code.containsMessage() ? in.readUTF() : null;
return new Response(code, message);
}
-
+
@Override
public String toString() {
return code + ": " + message;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/ResponseCode.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/ResponseCode.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/ResponseCode.java
index 8860e73..0e1359e 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/ResponseCode.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/ResponseCode.java
@@ -23,131 +23,126 @@ import java.io.InputStream;
import org.apache.nifi.remote.exception.ProtocolException;
-
public enum ResponseCode {
+
RESERVED(0, "Reserved for Future Use", false), // This will likely be used if we ever need to expand the length of
- // ResponseCode, so that we can indicate a 0 followed by some other bytes
-
+ // ResponseCode, so that we can indicate a 0 followed by some other bytes
+
// handshaking properties
PROPERTIES_OK(1, "Properties OK", false),
UNKNOWN_PROPERTY_NAME(230, "Unknown Property Name", true),
ILLEGAL_PROPERTY_VALUE(231, "Illegal Property Value", true),
MISSING_PROPERTY(232, "Missing Property", true),
-
// transaction indicators
CONTINUE_TRANSACTION(10, "Continue Transaction", false),
FINISH_TRANSACTION(11, "Finish Transaction", false),
- CONFIRM_TRANSACTION(12, "Confirm Transaction", true), // "Explanation" of this code is the checksum
+ CONFIRM_TRANSACTION(12, "Confirm Transaction", true), // "Explanation" of this code is the checksum
TRANSACTION_FINISHED(13, "Transaction Finished", false),
TRANSACTION_FINISHED_BUT_DESTINATION_FULL(14, "Transaction Finished But Destination is Full", false),
CANCEL_TRANSACTION(15, "Cancel Transaction", true),
BAD_CHECKSUM(19, "Bad Checksum", false),
-
// data availability indicators
MORE_DATA(20, "More Data Exists", false),
NO_MORE_DATA(21, "No More Data Exists", false),
-
// port state indicators
UNKNOWN_PORT(200, "Unknown Port", false),
PORT_NOT_IN_VALID_STATE(201, "Port Not in a Valid State", true),
PORTS_DESTINATION_FULL(202, "Port's Destination is Full", false),
-
// authorization
UNAUTHORIZED(240, "User Not Authorized", true),
-
// error indicators
ABORT(250, "Abort", true),
UNRECOGNIZED_RESPONSE_CODE(254, "Unrecognized Response Code", false),
END_OF_STREAM(255, "End of Stream", false);
-
+
private static final ResponseCode[] codeArray = new ResponseCode[256];
-
+
static {
- for ( final ResponseCode responseCode : ResponseCode.values() ) {
+ for (final ResponseCode responseCode : ResponseCode.values()) {
codeArray[responseCode.getCode()] = responseCode;
}
}
-
+
private static final byte CODE_SEQUENCE_VALUE_1 = (byte) 'R';
private static final byte CODE_SEQUENCE_VALUE_2 = (byte) 'C';
private final int code;
private final byte[] codeSequence;
private final String description;
private final boolean containsMessage;
-
+
private ResponseCode(final int code, final String description, final boolean containsMessage) {
- this.codeSequence = new byte[] {CODE_SEQUENCE_VALUE_1, CODE_SEQUENCE_VALUE_2, (byte) code};
+ this.codeSequence = new byte[]{CODE_SEQUENCE_VALUE_1, CODE_SEQUENCE_VALUE_2, (byte) code};
this.code = code;
this.description = description;
this.containsMessage = containsMessage;
}
-
+
public int getCode() {
return code;
}
-
+
public byte[] getCodeSequence() {
return codeSequence;
}
-
+
@Override
public String toString() {
return description;
}
-
+
public boolean containsMessage() {
return containsMessage;
}
-
+
public void writeResponse(final DataOutputStream out) throws IOException {
- if ( containsMessage() ) {
+ if (containsMessage()) {
throw new IllegalArgumentException("ResponseCode " + code + " expects an explanation");
}
-
+
out.write(getCodeSequence());
out.flush();
}
-
+
public void writeResponse(final DataOutputStream out, final String explanation) throws IOException {
- if ( !containsMessage() ) {
+ if (!containsMessage()) {
throw new IllegalArgumentException("ResponseCode " + code + " does not expect an explanation");
}
-
+
out.write(getCodeSequence());
out.writeUTF(explanation);
out.flush();
}
-
+
static ResponseCode readCode(final InputStream in) throws IOException, ProtocolException {
final int byte1 = in.read();
- if ( byte1 < 0 ) {
+ if (byte1 < 0) {
throw new EOFException();
- } else if ( byte1 != CODE_SEQUENCE_VALUE_1 ) {
+ } else if (byte1 != CODE_SEQUENCE_VALUE_1) {
throw new ProtocolException("Expected to receive ResponseCode, but the stream did not have a ResponseCode");
}
-
+
final int byte2 = in.read();
- if ( byte2 < 0 ) {
+ if (byte2 < 0) {
throw new EOFException();
- } else if ( byte2 != CODE_SEQUENCE_VALUE_2 ) {
+ } else if (byte2 != CODE_SEQUENCE_VALUE_2) {
throw new ProtocolException("Expected to receive ResponseCode, but the stream did not have a ResponseCode");
}
final int byte3 = in.read();
- if ( byte3 < 0 ) {
+ if (byte3 < 0) {
throw new EOFException();
}
-
+
final ResponseCode responseCode = codeArray[byte3];
if (responseCode == null) {
throw new ProtocolException("Received Response Code of " + byte3 + " but do not recognize this code");
}
return responseCode;
}
-
+
public static ResponseCode fromSequence(final byte[] value) {
final int code = value[3] & 0xFF;
final ResponseCode responseCode = codeArray[code];
return (responseCode == null) ? UNRECOGNIZED_RESPONSE_CODE : responseCode;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientProtocol.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientProtocol.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientProtocol.java
index 83c5305..de845ee 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientProtocol.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientProtocol.java
@@ -58,120 +58,121 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SocketClientProtocol implements ClientProtocol {
+
private final VersionNegotiator versionNegotiator = new StandardVersionNegotiator(5, 4, 3, 2, 1);
private RemoteDestination destination;
private boolean useCompression = false;
-
+
private String commsIdentifier;
private boolean handshakeComplete = false;
-
+
private final Logger logger = LoggerFactory.getLogger(SocketClientProtocol.class);
-
+
private Response handshakeResponse = null;
private boolean readyForFileTransfer = false;
private String transitUriPrefix = null;
private int timeoutMillis = 30000;
-
+
private int batchCount;
private long batchSize;
private long batchMillis;
private EventReporter eventReporter;
private static final long BATCH_SEND_NANOS = TimeUnit.SECONDS.toNanos(5L); // send batches of up to 5 seconds
-
+
public SocketClientProtocol() {
}
public void setPreferredBatchCount(final int count) {
this.batchCount = count;
}
-
+
public void setPreferredBatchSize(final long bytes) {
this.batchSize = bytes;
}
-
+
public void setPreferredBatchDuration(final long millis) {
this.batchMillis = millis;
}
-
+
public void setEventReporter(final EventReporter eventReporter) {
- this.eventReporter = eventReporter;
+ this.eventReporter = eventReporter;
}
-
+
public void setDestination(final RemoteDestination destination) {
this.destination = destination;
this.useCompression = destination.isUseCompression();
}
-
+
public void setTimeout(final int timeoutMillis) {
- this.timeoutMillis = timeoutMillis;
+ this.timeoutMillis = timeoutMillis;
}
-
+
@Override
public void handshake(final Peer peer) throws IOException, HandshakeException {
- handshake(peer, destination.getIdentifier());
+ handshake(peer, destination.getIdentifier());
}
-
+
public void handshake(final Peer peer, final String destinationId) throws IOException, HandshakeException {
- if ( handshakeComplete ) {
+ if (handshakeComplete) {
throw new IllegalStateException("Handshake has already been completed");
}
commsIdentifier = UUID.randomUUID().toString();
logger.debug("{} handshaking with {}", this, peer);
-
+
final Map<HandshakeProperty, String> properties = new HashMap<>();
properties.put(HandshakeProperty.GZIP, String.valueOf(useCompression));
-
- if ( destinationId != null ) {
- properties.put(HandshakeProperty.PORT_IDENTIFIER, destinationId);
+
+ if (destinationId != null) {
+ properties.put(HandshakeProperty.PORT_IDENTIFIER, destinationId);
}
-
- properties.put(HandshakeProperty.REQUEST_EXPIRATION_MILLIS, String.valueOf(timeoutMillis) );
-
- if ( versionNegotiator.getVersion() >= 5 ) {
- if ( batchCount > 0 ) {
+
+ properties.put(HandshakeProperty.REQUEST_EXPIRATION_MILLIS, String.valueOf(timeoutMillis));
+
+ if (versionNegotiator.getVersion() >= 5) {
+ if (batchCount > 0) {
properties.put(HandshakeProperty.BATCH_COUNT, String.valueOf(batchCount));
}
- if ( batchSize > 0L ) {
+ if (batchSize > 0L) {
properties.put(HandshakeProperty.BATCH_SIZE, String.valueOf(batchSize));
}
- if ( batchMillis > 0L ) {
+ if (batchMillis > 0L) {
properties.put(HandshakeProperty.BATCH_DURATION, String.valueOf(batchMillis));
}
}
-
+
final CommunicationsSession commsSession = peer.getCommunicationsSession();
commsSession.setTimeout(timeoutMillis);
final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream());
final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream());
-
+
dos.writeUTF(commsIdentifier);
-
- if ( versionNegotiator.getVersion() >= 3 ) {
+
+ if (versionNegotiator.getVersion() >= 3) {
dos.writeUTF(peer.getUrl());
transitUriPrefix = peer.getUrl();
-
- if ( !transitUriPrefix.endsWith("/") ) {
+
+ if (!transitUriPrefix.endsWith("/")) {
transitUriPrefix = transitUriPrefix + "/";
}
}
-
+
logger.debug("Handshaking with properties {}", properties);
dos.writeInt(properties.size());
- for ( final Map.Entry<HandshakeProperty, String> entry : properties.entrySet() ) {
+ for (final Map.Entry<HandshakeProperty, String> entry : properties.entrySet()) {
dos.writeUTF(entry.getKey().name());
dos.writeUTF(entry.getValue());
}
-
+
dos.flush();
-
+
try {
handshakeResponse = Response.read(dis);
} catch (final ProtocolException e) {
throw new HandshakeException(e);
}
-
+
switch (handshakeResponse.getCode()) {
case PORT_NOT_IN_VALID_STATE:
case UNKNOWN_PORT:
@@ -181,71 +182,75 @@ public class SocketClientProtocol implements ClientProtocol {
readyForFileTransfer = true;
break;
default:
- logger.error("{} received unexpected response {} from {} when negotiating Codec", new Object[] {
+ logger.error("{} received unexpected response {} from {} when negotiating Codec", new Object[]{
this, handshakeResponse, peer});
peer.close();
throw new HandshakeException("Received unexpected response " + handshakeResponse);
}
-
+
logger.debug("{} Finished handshake with {}", this, peer);
handshakeComplete = true;
}
-
+
+ @Override
public boolean isReadyForFileTransfer() {
return readyForFileTransfer;
}
-
+
+ @Override
public boolean isPortInvalid() {
- if ( !handshakeComplete ) {
+ if (!handshakeComplete) {
throw new IllegalStateException("Handshake has not completed successfully");
}
return handshakeResponse.getCode() == ResponseCode.PORT_NOT_IN_VALID_STATE;
}
-
+
+ @Override
public boolean isPortUnknown() {
- if ( !handshakeComplete ) {
+ if (!handshakeComplete) {
throw new IllegalStateException("Handshake has not completed successfully");
}
return handshakeResponse.getCode() == ResponseCode.UNKNOWN_PORT;
}
-
+
+ @Override
public boolean isDestinationFull() {
- if ( !handshakeComplete ) {
+ if (!handshakeComplete) {
throw new IllegalStateException("Handshake has not completed successfully");
}
return handshakeResponse.getCode() == ResponseCode.PORTS_DESTINATION_FULL;
}
-
+
@Override
public Set<PeerStatus> getPeerStatuses(final Peer peer) throws IOException {
- if ( !handshakeComplete ) {
+ if (!handshakeComplete) {
throw new IllegalStateException("Handshake has not been performed");
}
-
+
logger.debug("{} Get Peer Statuses from {}", this, peer);
final CommunicationsSession commsSession = peer.getCommunicationsSession();
final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream());
final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream());
-
+
RequestType.REQUEST_PEER_LIST.writeRequestType(dos);
dos.flush();
final int numPeers = dis.readInt();
final Set<PeerStatus> peers = new HashSet<>(numPeers);
- for (int i=0; i < numPeers; i++) {
+ for (int i = 0; i < numPeers; i++) {
final String hostname = dis.readUTF();
final int port = dis.readInt();
final boolean secure = dis.readBoolean();
final int flowFileCount = dis.readInt();
peers.add(new PeerStatus(new PeerDescription(hostname, port, secure), flowFileCount));
}
-
+
logger.debug("{} Received {} Peer Statuses from {}", this, peers.size(), peer);
return peers;
}
-
+
@Override
public FlowFileCodec negotiateCodec(final Peer peer) throws IOException, ProtocolException {
- if ( !handshakeComplete ) {
+ if (!handshakeComplete) {
throw new IllegalStateException("Handshake has not been performed");
}
@@ -255,177 +260,174 @@ public class SocketClientProtocol implements ClientProtocol {
final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream());
RequestType.NEGOTIATE_FLOWFILE_CODEC.writeRequestType(dos);
-
+
FlowFileCodec codec = new StandardFlowFileCodec();
try {
codec = (FlowFileCodec) RemoteResourceInitiator.initiateResourceNegotiation(codec, dis, dos);
} catch (HandshakeException e) {
throw new ProtocolException(e.toString());
}
- logger.debug("{} negotiated FlowFileCodec {} with {}", new Object[] {this, codec, commsSession});
+ logger.debug("{} negotiated FlowFileCodec {} with {}", new Object[]{this, codec, commsSession});
return codec;
}
-
@Override
public Transaction startTransaction(final Peer peer, final FlowFileCodec codec, final TransferDirection direction) throws IOException, ProtocolException {
- if ( !handshakeComplete ) {
+ if (!handshakeComplete) {
throw new IllegalStateException("Handshake has not been performed");
}
- if ( !readyForFileTransfer ) {
+ if (!readyForFileTransfer) {
throw new IllegalStateException("Cannot start transaction; handshake resolution was " + handshakeResponse);
}
-
- return new SocketClientTransaction(versionNegotiator.getVersion(), destination.getIdentifier(), peer, codec,
- direction, useCompression, (int) destination.getYieldPeriod(TimeUnit.MILLISECONDS), eventReporter);
- }
+ return new SocketClientTransaction(versionNegotiator.getVersion(), destination.getIdentifier(), peer, codec,
+ direction, useCompression, (int) destination.getYieldPeriod(TimeUnit.MILLISECONDS), eventReporter);
+ }
@Override
public int receiveFlowFiles(final Peer peer, final ProcessContext context, final ProcessSession session, final FlowFileCodec codec) throws IOException, ProtocolException {
- final String userDn = peer.getCommunicationsSession().getUserDn();
- final Transaction transaction = startTransaction(peer, codec, TransferDirection.RECEIVE);
-
- final StopWatch stopWatch = new StopWatch(true);
- final Set<FlowFile> flowFilesReceived = new HashSet<>();
- long bytesReceived = 0L;
-
- while (true) {
- final long start = System.nanoTime();
- final DataPacket dataPacket = transaction.receive();
- if ( dataPacket == null ) {
- if ( flowFilesReceived.isEmpty() ) {
- peer.penalize(destination.getIdentifier(), destination.getYieldPeriod(TimeUnit.MILLISECONDS));
- }
- break;
- }
-
- FlowFile flowFile = session.create();
- flowFile = session.putAllAttributes(flowFile, dataPacket.getAttributes());
- flowFile = session.importFrom(dataPacket.getData(), flowFile);
- final long receiveNanos = System.nanoTime() - start;
-
- String sourceFlowFileIdentifier = dataPacket.getAttributes().get(CoreAttributes.UUID.key());
- if ( sourceFlowFileIdentifier == null ) {
- sourceFlowFileIdentifier = "<Unknown Identifier>";
- }
-
- final String transitUri = (transitUriPrefix == null) ? peer.getUrl() : transitUriPrefix + sourceFlowFileIdentifier;
- session.getProvenanceReporter().receive(flowFile, transitUri, "urn:nifi:" + sourceFlowFileIdentifier, "Remote Host=" + peer.getHost() + ", Remote DN=" + userDn, TimeUnit.NANOSECONDS.toMillis(receiveNanos));
-
- session.transfer(flowFile, Relationship.ANONYMOUS);
- bytesReceived += dataPacket.getSize();
- }
-
- // Confirm that what we received was the correct data.
- transaction.confirm();
-
- // Commit the session so that we have persisted the data
- session.commit();
-
- transaction.complete();
- logger.debug("{} Sending TRANSACTION_FINISHED_BUT_DESTINATION_FULL to {}", this, peer);
-
- if ( !flowFilesReceived.isEmpty() ) {
- stopWatch.stop();
- final String flowFileDescription = flowFilesReceived.size() < 20 ? flowFilesReceived.toString() : flowFilesReceived.size() + " FlowFiles";
- final String uploadDataRate = stopWatch.calculateDataRate(bytesReceived);
- final long uploadMillis = stopWatch.getDuration(TimeUnit.MILLISECONDS);
- final String dataSize = FormatUtils.formatDataSize(bytesReceived);
- logger.info("{} Successfully receveied {} ({}) from {} in {} milliseconds at a rate of {}", new Object[] {
- this, flowFileDescription, dataSize, peer, uploadMillis, uploadDataRate });
- }
-
- return flowFilesReceived.size();
+ final String userDn = peer.getCommunicationsSession().getUserDn();
+ final Transaction transaction = startTransaction(peer, codec, TransferDirection.RECEIVE);
+
+ final StopWatch stopWatch = new StopWatch(true);
+ final Set<FlowFile> flowFilesReceived = new HashSet<>();
+ long bytesReceived = 0L;
+
+ while (true) {
+ final long start = System.nanoTime();
+ final DataPacket dataPacket = transaction.receive();
+ if (dataPacket == null) {
+ if (flowFilesReceived.isEmpty()) {
+ peer.penalize(destination.getIdentifier(), destination.getYieldPeriod(TimeUnit.MILLISECONDS));
+ }
+ break;
+ }
+
+ FlowFile flowFile = session.create();
+ flowFile = session.putAllAttributes(flowFile, dataPacket.getAttributes());
+ flowFile = session.importFrom(dataPacket.getData(), flowFile);
+ final long receiveNanos = System.nanoTime() - start;
+
+ String sourceFlowFileIdentifier = dataPacket.getAttributes().get(CoreAttributes.UUID.key());
+ if (sourceFlowFileIdentifier == null) {
+ sourceFlowFileIdentifier = "<Unknown Identifier>";
+ }
+
+ final String transitUri = (transitUriPrefix == null) ? peer.getUrl() : transitUriPrefix + sourceFlowFileIdentifier;
+ session.getProvenanceReporter().receive(flowFile, transitUri, "urn:nifi:" + sourceFlowFileIdentifier, "Remote Host="
+ + peer.getHost() + ", Remote DN=" + userDn, TimeUnit.NANOSECONDS.toMillis(receiveNanos));
+
+ session.transfer(flowFile, Relationship.ANONYMOUS);
+ bytesReceived += dataPacket.getSize();
+ }
+
+ // Confirm that what we received was the correct data.
+ transaction.confirm();
+
+ // Commit the session so that we have persisted the data
+ session.commit();
+
+ transaction.complete();
+ logger.debug("{} Sending TRANSACTION_FINISHED_BUT_DESTINATION_FULL to {}", this, peer);
+
+ if (!flowFilesReceived.isEmpty()) {
+ stopWatch.stop();
+ final String flowFileDescription = flowFilesReceived.size() < 20 ? flowFilesReceived.toString() : flowFilesReceived.size() + " FlowFiles";
+ final String uploadDataRate = stopWatch.calculateDataRate(bytesReceived);
+ final long uploadMillis = stopWatch.getDuration(TimeUnit.MILLISECONDS);
+ final String dataSize = FormatUtils.formatDataSize(bytesReceived);
+ logger.info("{} Successfully receveied {} ({}) from {} in {} milliseconds at a rate of {}", new Object[]{
+ this, flowFileDescription, dataSize, peer, uploadMillis, uploadDataRate});
+ }
+
+ return flowFilesReceived.size();
}
-
@Override
public int transferFlowFiles(final Peer peer, final ProcessContext context, final ProcessSession session, final FlowFileCodec codec) throws IOException, ProtocolException {
- FlowFile flowFile = session.get();
- if (flowFile == null) {
- return 0;
- }
-
- try {
- final String userDn = peer.getCommunicationsSession().getUserDn();
- final long startSendingNanos = System.nanoTime();
- final StopWatch stopWatch = new StopWatch(true);
- long bytesSent = 0L;
-
- final Transaction transaction = startTransaction(peer, codec, TransferDirection.SEND);
-
- final Set<FlowFile> flowFilesSent = new HashSet<>();
- boolean continueTransaction = true;
- while (continueTransaction) {
- final long startNanos = System.nanoTime();
- // call codec.encode within a session callback so that we have the InputStream to read the FlowFile
- final FlowFile toWrap = flowFile;
- session.read(flowFile, new InputStreamCallback() {
- @Override
- public void process(final InputStream in) throws IOException {
- final DataPacket dataPacket = new StandardDataPacket(toWrap.getAttributes(), in, toWrap.getSize());
- transaction.send(dataPacket);
- }
- });
-
- final long transferNanos = System.nanoTime() - startNanos;
- final long transferMillis = TimeUnit.MILLISECONDS.convert(transferNanos, TimeUnit.NANOSECONDS);
-
- flowFilesSent.add(flowFile);
- bytesSent += flowFile.getSize();
- logger.debug("{} Sent {} to {}", this, flowFile, peer);
-
- final String transitUri = (transitUriPrefix == null) ? peer.getUrl() : transitUriPrefix + flowFile.getAttribute(CoreAttributes.UUID.key());
- session.getProvenanceReporter().send(flowFile, transitUri, "Remote Host=" + peer.getHost() + ", Remote DN=" + userDn, transferMillis, false);
- session.remove(flowFile);
-
- final long sendingNanos = System.nanoTime() - startSendingNanos;
- if ( sendingNanos < BATCH_SEND_NANOS ) {
- flowFile = session.get();
- } else {
- flowFile = null;
- }
-
- continueTransaction = (flowFile != null);
- }
-
- transaction.confirm();
-
- // consume input stream entirely, ignoring its contents. If we
- // don't do this, the Connection will not be returned to the pool
- stopWatch.stop();
- final String uploadDataRate = stopWatch.calculateDataRate(bytesSent);
- final long uploadMillis = stopWatch.getDuration(TimeUnit.MILLISECONDS);
- final String dataSize = FormatUtils.formatDataSize(bytesSent);
-
- session.commit();
- transaction.complete();
-
- final String flowFileDescription = (flowFilesSent.size() < 20) ? flowFilesSent.toString() : flowFilesSent.size() + " FlowFiles";
- logger.info("{} Successfully sent {} ({}) to {} in {} milliseconds at a rate of {}", new Object[] {
- this, flowFileDescription, dataSize, peer, uploadMillis, uploadDataRate});
-
- return flowFilesSent.size();
- } catch (final Exception e) {
- session.rollback();
- throw e;
- }
+ FlowFile flowFile = session.get();
+ if (flowFile == null) {
+ return 0;
+ }
+
+ try {
+ final String userDn = peer.getCommunicationsSession().getUserDn();
+ final long startSendingNanos = System.nanoTime();
+ final StopWatch stopWatch = new StopWatch(true);
+ long bytesSent = 0L;
+
+ final Transaction transaction = startTransaction(peer, codec, TransferDirection.SEND);
+
+ final Set<FlowFile> flowFilesSent = new HashSet<>();
+ boolean continueTransaction = true;
+ while (continueTransaction) {
+ final long startNanos = System.nanoTime();
+ // call codec.encode within a session callback so that we have the InputStream to read the FlowFile
+ final FlowFile toWrap = flowFile;
+ session.read(flowFile, new InputStreamCallback() {
+ @Override
+ public void process(final InputStream in) throws IOException {
+ final DataPacket dataPacket = new StandardDataPacket(toWrap.getAttributes(), in, toWrap.getSize());
+ transaction.send(dataPacket);
+ }
+ });
+
+ final long transferNanos = System.nanoTime() - startNanos;
+ final long transferMillis = TimeUnit.MILLISECONDS.convert(transferNanos, TimeUnit.NANOSECONDS);
+
+ flowFilesSent.add(flowFile);
+ bytesSent += flowFile.getSize();
+ logger.debug("{} Sent {} to {}", this, flowFile, peer);
+
+ final String transitUri = (transitUriPrefix == null) ? peer.getUrl() : transitUriPrefix + flowFile.getAttribute(CoreAttributes.UUID.key());
+ session.getProvenanceReporter().send(flowFile, transitUri, "Remote Host=" + peer.getHost() + ", Remote DN=" + userDn, transferMillis, false);
+ session.remove(flowFile);
+
+ final long sendingNanos = System.nanoTime() - startSendingNanos;
+ if (sendingNanos < BATCH_SEND_NANOS) {
+ flowFile = session.get();
+ } else {
+ flowFile = null;
+ }
+
+ continueTransaction = (flowFile != null);
+ }
+
+ transaction.confirm();
+
+ // consume input stream entirely, ignoring its contents. If we
+ // don't do this, the Connection will not be returned to the pool
+ stopWatch.stop();
+ final String uploadDataRate = stopWatch.calculateDataRate(bytesSent);
+ final long uploadMillis = stopWatch.getDuration(TimeUnit.MILLISECONDS);
+ final String dataSize = FormatUtils.formatDataSize(bytesSent);
+
+ session.commit();
+ transaction.complete();
+
+ final String flowFileDescription = (flowFilesSent.size() < 20) ? flowFilesSent.toString() : flowFilesSent.size() + " FlowFiles";
+ logger.info("{} Successfully sent {} ({}) to {} in {} milliseconds at a rate of {}", new Object[]{
+ this, flowFileDescription, dataSize, peer, uploadMillis, uploadDataRate});
+
+ return flowFilesSent.size();
+ } catch (final Exception e) {
+ session.rollback();
+ throw e;
+ }
}
-
-
+
@Override
public VersionNegotiator getVersionNegotiator() {
return versionNegotiator;
}
-
+
@Override
public void shutdown(final Peer peer) throws IOException {
readyForFileTransfer = false;
final CommunicationsSession commsSession = peer.getCommunicationsSession();
final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream());
-
+
logger.debug("{} Shutting down with {}", this, peer);
// Indicate that we would like to have some data
RequestType.SHUTDOWN.writeRequestType(dos);
@@ -436,7 +438,7 @@ public class SocketClientProtocol implements ClientProtocol {
public String getResourceName() {
return "SocketFlowFileProtocol";
}
-
+
@Override
public String toString() {
return "SocketClientProtocol[CommsID=" + commsIdentifier + "]";
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransaction.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransaction.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransaction.java
index e69104f..e83ea28 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransaction.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransaction.java
@@ -45,50 +45,51 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SocketClientTransaction implements Transaction {
- private static final Logger logger = LoggerFactory.getLogger(SocketClientTransaction.class);
-
- private final long creationNanoTime = System.nanoTime();
- private final CRC32 crc = new CRC32();
- private final int protocolVersion;
- private final FlowFileCodec codec;
- private final DataInputStream dis;
- private final DataOutputStream dos;
- private final TransferDirection direction;
- private final boolean compress;
- private final Peer peer;
- private final int penaltyMillis;
- private final String destinationId;
- private final EventReporter eventReporter;
-
- private boolean dataAvailable = false;
- private int transfers = 0;
- private long contentBytes = 0;
- private TransactionState state;
-
- SocketClientTransaction(final int protocolVersion, final String destinationId, final Peer peer, final FlowFileCodec codec,
- final TransferDirection direction, final boolean useCompression, final int penaltyMillis, final EventReporter eventReporter) throws IOException {
- this.protocolVersion = protocolVersion;
- this.destinationId = destinationId;
- this.peer = peer;
- this.codec = codec;
- this.direction = direction;
- this.dis = new DataInputStream(peer.getCommunicationsSession().getInput().getInputStream());
- this.dos = new DataOutputStream(peer.getCommunicationsSession().getOutput().getOutputStream());
- this.compress = useCompression;
- this.state = TransactionState.TRANSACTION_STARTED;
- this.penaltyMillis = penaltyMillis;
- this.eventReporter = eventReporter;
-
- initialize();
- }
-
- private void initialize() throws IOException {
- try {
- if ( direction == TransferDirection.RECEIVE ) {
+
+ private static final Logger logger = LoggerFactory.getLogger(SocketClientTransaction.class);
+
+ private final long creationNanoTime = System.nanoTime();
+ private final CRC32 crc = new CRC32();
+ private final int protocolVersion;
+ private final FlowFileCodec codec;
+ private final DataInputStream dis;
+ private final DataOutputStream dos;
+ private final TransferDirection direction;
+ private final boolean compress;
+ private final Peer peer;
+ private final int penaltyMillis;
+ private final String destinationId;
+ private final EventReporter eventReporter;
+
+ private boolean dataAvailable = false;
+ private int transfers = 0;
+ private long contentBytes = 0;
+ private TransactionState state;
+
+ SocketClientTransaction(final int protocolVersion, final String destinationId, final Peer peer, final FlowFileCodec codec,
+ final TransferDirection direction, final boolean useCompression, final int penaltyMillis, final EventReporter eventReporter) throws IOException {
+ this.protocolVersion = protocolVersion;
+ this.destinationId = destinationId;
+ this.peer = peer;
+ this.codec = codec;
+ this.direction = direction;
+ this.dis = new DataInputStream(peer.getCommunicationsSession().getInput().getInputStream());
+ this.dos = new DataOutputStream(peer.getCommunicationsSession().getOutput().getOutputStream());
+ this.compress = useCompression;
+ this.state = TransactionState.TRANSACTION_STARTED;
+ this.penaltyMillis = penaltyMillis;
+ this.eventReporter = eventReporter;
+
+ initialize();
+ }
+
+ private void initialize() throws IOException {
+ try {
+ if (direction == TransferDirection.RECEIVE) {
// Indicate that we would like to have some data
RequestType.RECEIVE_FLOWFILES.writeRequestType(dos);
dos.flush();
-
+
final Response dataAvailableCode = Response.read(dis);
switch (dataAvailableCode.getCode()) {
case MORE_DATA:
@@ -102,39 +103,38 @@ public class SocketClientTransaction implements Transaction {
default:
throw new ProtocolException("Got unexpected response when asking for data: " + dataAvailableCode);
}
-
+
} else {
// Indicate that we would like to have some data
RequestType.SEND_FLOWFILES.writeRequestType(dos);
dos.flush();
}
- } catch (final Exception e) {
- error();
- throw e;
- }
- }
-
-
- @Override
- public DataPacket receive() throws IOException {
- try {
- try {
- if ( state != TransactionState.DATA_EXCHANGED && state != TransactionState.TRANSACTION_STARTED) {
- throw new IllegalStateException("Cannot receive data from " + peer + " because Transaction State is " + state);
- }
-
- if ( direction == TransferDirection.SEND ) {
- throw new IllegalStateException("Attempting to receive data from " + peer + " but started a SEND Transaction");
- }
-
- // if we already know there's no data, just return null
- if ( !dataAvailable ) {
- return null;
- }
-
- // if we have already received a packet, check if another is available.
- if ( transfers > 0 ) {
- // Determine if Peer will send us data or has no data to send us
+ } catch (final Exception e) {
+ error();
+ throw e;
+ }
+ }
+
+ @Override
+ public DataPacket receive() throws IOException {
+ try {
+ try {
+ if (state != TransactionState.DATA_EXCHANGED && state != TransactionState.TRANSACTION_STARTED) {
+ throw new IllegalStateException("Cannot receive data from " + peer + " because Transaction State is " + state);
+ }
+
+ if (direction == TransferDirection.SEND) {
+ throw new IllegalStateException("Attempting to receive data from " + peer + " but started a SEND Transaction");
+ }
+
+ // if we already know there's no data, just return null
+ if (!dataAvailable) {
+ return null;
+ }
+
+ // if we have already received a packet, check if another is available.
+ if (transfers > 0) {
+ // Determine if Peer will send us data or has no data to send us
final Response dataAvailableCode = Response.read(dis);
switch (dataAvailableCode.getCode()) {
case CONTINUE_TRANSACTION:
@@ -149,170 +149,166 @@ public class SocketClientTransaction implements Transaction {
throw new ProtocolException("Got unexpected response from " + peer + " when asking for data: " + dataAvailableCode);
}
}
-
- // if no data available, return null
- if ( !dataAvailable ) {
- return null;
- }
-
+
+ // if no data available, return null
+ if (!dataAvailable) {
+ return null;
+ }
+
logger.debug("{} Receiving data from {}", this, peer);
final InputStream dataIn = compress ? new CompressionInputStream(dis) : dis;
final DataPacket packet = codec.decode(new CheckedInputStream(dataIn, crc));
-
- if ( packet == null ) {
+
+ if (packet == null) {
this.dataAvailable = false;
} else {
- transfers++;
- contentBytes += packet.getSize();
+ transfers++;
+ contentBytes += packet.getSize();
}
-
+
this.state = TransactionState.DATA_EXCHANGED;
return packet;
- } catch (final IOException ioe) {
- throw new IOException("Failed to receive data from " + peer + " due to " + ioe, ioe);
- }
- } catch (final Exception e) {
- error();
- throw e;
- }
- }
-
-
- @Override
- public void send(final byte[] content, final Map<String, String> attributes) throws IOException {
- send(new StandardDataPacket(attributes, new ByteArrayInputStream(content), content.length));
- }
-
- @Override
- public void send(final DataPacket dataPacket) throws IOException {
- try {
- try {
- if ( state != TransactionState.DATA_EXCHANGED && state != TransactionState.TRANSACTION_STARTED) {
- throw new IllegalStateException("Cannot send data to " + peer + " because Transaction State is " + state);
- }
-
- if ( direction == TransferDirection.RECEIVE ) {
+ } catch (final IOException ioe) {
+ throw new IOException("Failed to receive data from " + peer + " due to " + ioe, ioe);
+ }
+ } catch (final Exception e) {
+ error();
+ throw e;
+ }
+ }
+
+ @Override
+ public void send(final byte[] content, final Map<String, String> attributes) throws IOException {
+ send(new StandardDataPacket(attributes, new ByteArrayInputStream(content), content.length));
+ }
+
+ @Override
+ public void send(final DataPacket dataPacket) throws IOException {
+ try {
+ try {
+ if (state != TransactionState.DATA_EXCHANGED && state != TransactionState.TRANSACTION_STARTED) {
+ throw new IllegalStateException("Cannot send data to " + peer + " because Transaction State is " + state);
+ }
+
+ if (direction == TransferDirection.RECEIVE) {
throw new IllegalStateException("Attempting to send data to " + peer + " but started a RECEIVE Transaction");
}
-
- if ( transfers > 0 ) {
+
+ if (transfers > 0) {
ResponseCode.CONTINUE_TRANSACTION.writeResponse(dos);
}
-
+
logger.debug("{} Sending data to {}", this, peer);
-
+
final OutputStream dataOut = compress ? new CompressionOutputStream(dos) : dos;
- final OutputStream out = new CheckedOutputStream(dataOut, crc);
+ final OutputStream out = new CheckedOutputStream(dataOut, crc);
codec.encode(dataPacket, out);
-
+
// need to close the CompressionOutputStream in order to force it write out any remaining bytes.
// Otherwise, do NOT close it because we don't want to close the underlying stream
// (CompressionOutputStream will not close the underlying stream when it's closed)
- if ( compress ) {
- out.close();
+ if (compress) {
+ out.close();
}
-
+
transfers++;
contentBytes += dataPacket.getSize();
this.state = TransactionState.DATA_EXCHANGED;
- } catch (final IOException ioe) {
- throw new IOException("Failed to send data to " + peer + " due to " + ioe, ioe);
- }
- } catch (final Exception e) {
- error();
- throw e;
- }
- }
-
-
- @Override
- public void cancel(final String explanation) throws IOException {
- if ( state == TransactionState.TRANSACTION_CANCELED || state == TransactionState.TRANSACTION_COMPLETED || state == TransactionState.ERROR ) {
- throw new IllegalStateException("Cannot cancel transaction because state is already " + state);
- }
-
- try {
- ResponseCode.CANCEL_TRANSACTION.writeResponse(dos, explanation == null ? "<No explanation given>" : explanation);
- state = TransactionState.TRANSACTION_CANCELED;
- } catch (final IOException ioe) {
- error();
- throw new IOException("Failed to send 'cancel transaction' message to " + peer + " due to " + ioe, ioe);
- }
- }
-
-
- @Override
- public TransactionCompletion complete() throws IOException {
- try {
- try {
- if ( state != TransactionState.TRANSACTION_CONFIRMED ) {
- throw new IllegalStateException("Cannot complete transaction with " + peer + " because state is " + state +
- "; Transaction can only be completed when state is " + TransactionState.TRANSACTION_CONFIRMED);
- }
-
- boolean backoff = false;
- if ( direction == TransferDirection.RECEIVE ) {
- if ( transfers == 0 ) {
- state = TransactionState.TRANSACTION_COMPLETED;
- return new SocketClientTransactionCompletion(false, 0, 0L, System.nanoTime() - creationNanoTime);
- }
-
+ } catch (final IOException ioe) {
+ throw new IOException("Failed to send data to " + peer + " due to " + ioe, ioe);
+ }
+ } catch (final Exception e) {
+ error();
+ throw e;
+ }
+ }
+
+ @Override
+ public void cancel(final String explanation) throws IOException {
+ if (state == TransactionState.TRANSACTION_CANCELED || state == TransactionState.TRANSACTION_COMPLETED || state == TransactionState.ERROR) {
+ throw new IllegalStateException("Cannot cancel transaction because state is already " + state);
+ }
+
+ try {
+ ResponseCode.CANCEL_TRANSACTION.writeResponse(dos, explanation == null ? "<No explanation given>" : explanation);
+ state = TransactionState.TRANSACTION_CANCELED;
+ } catch (final IOException ioe) {
+ error();
+ throw new IOException("Failed to send 'cancel transaction' message to " + peer + " due to " + ioe, ioe);
+ }
+ }
+
+ @Override
+ public TransactionCompletion complete() throws IOException {
+ try {
+ try {
+ if (state != TransactionState.TRANSACTION_CONFIRMED) {
+ throw new IllegalStateException("Cannot complete transaction with " + peer + " because state is " + state
+ + "; Transaction can only be completed when state is " + TransactionState.TRANSACTION_CONFIRMED);
+ }
+
+ boolean backoff = false;
+ if (direction == TransferDirection.RECEIVE) {
+ if (transfers == 0) {
+ state = TransactionState.TRANSACTION_COMPLETED;
+ return new SocketClientTransactionCompletion(false, 0, 0L, System.nanoTime() - creationNanoTime);
+ }
+
// Confirm that we received the data and the peer can now discard it
logger.debug("{} Sending TRANSACTION_FINISHED to {}", this, peer);
ResponseCode.TRANSACTION_FINISHED.writeResponse(dos);
-
+
state = TransactionState.TRANSACTION_COMPLETED;
} else {
final Response transactionResponse;
try {
transactionResponse = Response.read(dis);
} catch (final IOException e) {
- throw new IOException(this + " Failed to receive a response from " + peer + " when expecting a TransactionFinished Indicator. " +
- "It is unknown whether or not the peer successfully received/processed the data.", e);
+ throw new IOException(this + " Failed to receive a response from " + peer + " when expecting a TransactionFinished Indicator. "
+ + "It is unknown whether or not the peer successfully received/processed the data.", e);
}
-
+
logger.debug("{} Received {} from {}", this, transactionResponse, peer);
- if ( transactionResponse.getCode() == ResponseCode.TRANSACTION_FINISHED_BUT_DESTINATION_FULL ) {
+ if (transactionResponse.getCode() == ResponseCode.TRANSACTION_FINISHED_BUT_DESTINATION_FULL) {
peer.penalize(destinationId, penaltyMillis);
backoff = true;
- } else if ( transactionResponse.getCode() != ResponseCode.TRANSACTION_FINISHED ) {
+ } else if (transactionResponse.getCode() != ResponseCode.TRANSACTION_FINISHED) {
throw new ProtocolException("After sending data to " + peer + ", expected TRANSACTION_FINISHED response but got " + transactionResponse);
}
-
+
state = TransactionState.TRANSACTION_COMPLETED;
}
-
- return new SocketClientTransactionCompletion(backoff, transfers, contentBytes, System.nanoTime() - creationNanoTime);
- } catch (final IOException ioe) {
- throw new IOException("Failed to complete transaction with " + peer + " due to " + ioe, ioe);
- }
- } catch (final Exception e) {
- error();
- throw e;
- }
- }
-
-
- @Override
- public void confirm() throws IOException {
- try {
- try {
- if ( state == TransactionState.TRANSACTION_STARTED && !dataAvailable && direction == TransferDirection.RECEIVE ) {
- // client requested to receive data but no data available. no need to confirm.
- state = TransactionState.TRANSACTION_CONFIRMED;
- return;
- }
-
- if ( state != TransactionState.DATA_EXCHANGED ) {
- throw new IllegalStateException("Cannot confirm Transaction because state is " + state +
- "; Transaction can only be confirmed when state is " + TransactionState.DATA_EXCHANGED );
- }
-
- if ( direction == TransferDirection.RECEIVE ) {
- if ( dataAvailable ) {
+
+ return new SocketClientTransactionCompletion(backoff, transfers, contentBytes, System.nanoTime() - creationNanoTime);
+ } catch (final IOException ioe) {
+ throw new IOException("Failed to complete transaction with " + peer + " due to " + ioe, ioe);
+ }
+ } catch (final Exception e) {
+ error();
+ throw e;
+ }
+ }
+
+ @Override
+ public void confirm() throws IOException {
+ try {
+ try {
+ if (state == TransactionState.TRANSACTION_STARTED && !dataAvailable && direction == TransferDirection.RECEIVE) {
+ // client requested to receive data but no data available. no need to confirm.
+ state = TransactionState.TRANSACTION_CONFIRMED;
+ return;
+ }
+
+ if (state != TransactionState.DATA_EXCHANGED) {
+ throw new IllegalStateException("Cannot confirm Transaction because state is " + state
+ + "; Transaction can only be confirmed when state is " + TransactionState.DATA_EXCHANGED);
+ }
+
+ if (direction == TransferDirection.RECEIVE) {
+ if (dataAvailable) {
throw new IllegalStateException("Cannot complete transaction because the sender has already sent more data than client has consumed.");
}
-
+
// we received a FINISH_TRANSACTION indicator. Send back a CONFIRM_TRANSACTION message
// to peer so that we can verify that the connection is still open. This is a two-phase commit,
// which helps to prevent the chances of data duplication. Without doing this, we may commit the
@@ -323,84 +319,88 @@ public class SocketClientTransaction implements Transaction {
logger.trace("{} Sending CONFIRM_TRANSACTION Response Code to {}", this, peer);
final String calculatedCRC = String.valueOf(crc.getValue());
ResponseCode.CONFIRM_TRANSACTION.writeResponse(dos, calculatedCRC);
-
+
final Response confirmTransactionResponse;
try {
confirmTransactionResponse = Response.read(dis);
} catch (final IOException ioe) {
logger.error("Failed to receive response code from {} when expecting confirmation of transaction", peer);
- if ( eventReporter != null ) {
- eventReporter.reportEvent(Severity.ERROR, "Site-to-Site", "Failed to receive response code from " + peer + " when expecting confirmation of transaction");
+ if (eventReporter != null) {
+ eventReporter.reportEvent(Severity.ERROR, "Site-to-Site", "Failed to receive response code from " + peer + " when expecting confirmation of transaction");
}
throw ioe;
}
-
+
logger.trace("{} Received {} from {}", this, confirmTransactionResponse, peer);
-
+
switch (confirmTransactionResponse.getCode()) {
case CONFIRM_TRANSACTION:
break;
case BAD_CHECKSUM:
throw new IOException(this + " Received a BadChecksum response from peer " + peer);
default:
- throw new ProtocolException(this + " Received unexpected Response from peer " + peer + " : " + confirmTransactionResponse + "; expected 'Confirm Transaction' Response Code");
+ throw new ProtocolException(this + " Received unexpected Response from peer " + peer + " : "
+ + confirmTransactionResponse + "; expected 'Confirm Transaction' Response Code");
}
-
+
state = TransactionState.TRANSACTION_CONFIRMED;
} else {
logger.debug("{} Sent FINISH_TRANSACTION indicator to {}", this, peer);
ResponseCode.FINISH_TRANSACTION.writeResponse(dos);
-
+
final String calculatedCRC = String.valueOf(crc.getValue());
-
+
// we've sent a FINISH_TRANSACTION. Now we'll wait for the peer to send a 'Confirm Transaction' response
final Response transactionConfirmationResponse = Response.read(dis);
- if ( transactionConfirmationResponse.getCode() == ResponseCode.CONFIRM_TRANSACTION ) {
+ if (transactionConfirmationResponse.getCode() == ResponseCode.CONFIRM_TRANSACTION) {
// Confirm checksum and echo back the confirmation.
logger.trace("{} Received {} from {}", this, transactionConfirmationResponse, peer);
final String receivedCRC = transactionConfirmationResponse.getMessage();
-
+
// CRC was not used before version 4
- if ( protocolVersion > 3 ) {
- if ( !receivedCRC.equals(calculatedCRC) ) {
+ if (protocolVersion > 3) {
+ if (!receivedCRC.equals(calculatedCRC)) {
ResponseCode.BAD_CHECKSUM.writeResponse(dos);
- throw new IOException(this + " Sent data to peer " + peer + " but calculated CRC32 Checksum as " + calculatedCRC + " while peer calculated CRC32 Checksum as " + receivedCRC + "; canceling transaction and rolling back session");
+ throw new IOException(this + " Sent data to peer " + peer + " but calculated CRC32 Checksum as "
+ + calculatedCRC + " while peer calculated CRC32 Checksum as "
+ + receivedCRC + "; canceling transaction and rolling back session");
}
}
-
+
ResponseCode.CONFIRM_TRANSACTION.writeResponse(dos, "");
} else {
- throw new ProtocolException("Expected to receive 'Confirm Transaction' response from peer " + peer + " but received " + transactionConfirmationResponse);
+ throw new ProtocolException("Expected to receive 'Confirm Transaction' response from peer "
+ + peer + " but received " + transactionConfirmationResponse);
}
-
+
state = TransactionState.TRANSACTION_CONFIRMED;
}
- } catch (final IOException ioe) {
- throw new IOException("Failed to confirm transaction with " + peer + " due to " + ioe, ioe);
- }
- } catch (final Exception e) {
- error();
- throw e;
- }
- }
-
- @Override
- public void error() {
- this.state = TransactionState.ERROR;
- }
-
- @Override
- public TransactionState getState() {
- return state;
- }
-
- @Override
- public Communicant getCommunicant() {
- return peer;
- }
-
+ } catch (final IOException ioe) {
+ throw new IOException("Failed to confirm transaction with " + peer + " due to " + ioe, ioe);
+ }
+ } catch (final Exception e) {
+ error();
+ throw e;
+ }
+ }
+
+ @Override
+ public void error() {
+ this.state = TransactionState.ERROR;
+ }
+
+ @Override
+ public TransactionState getState() {
+ return state;
+ }
+
+ @Override
+ public Communicant getCommunicant() {
+ return peer;
+ }
+
@Override
public String toString() {
- return "SocketClientTransaction[Url=" + peer.getUrl() + ", TransferDirection=" + direction + ", State=" + state + "]";
+ return "SocketClientTransaction[Url=" + peer.getUrl() + ", TransferDirection=" + direction + ", State=" + state + "]";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java
index 5eb6c91..bd95013 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/socket/SocketClientTransactionCompletion.java
@@ -26,7 +26,7 @@ public class SocketClientTransactionCompletion implements TransactionCompletion
private final int dataPacketsTransferred;
private final long bytesTransferred;
private final long durationNanos;
-
+
public SocketClientTransactionCompletion(final boolean backoff, final int dataPacketsTransferred, final long bytesTransferred, final long durationNanos) {
this.backoff = backoff;
this.dataPacketsTransferred = dataPacketsTransferred;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java
index 10352ec..d746abf 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/NiFiRestApiUtil.java
@@ -32,43 +32,44 @@ import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
public class NiFiRestApiUtil {
+
public static final int RESPONSE_CODE_OK = 200;
-
+
private final SSLContext sslContext;
-
+
public NiFiRestApiUtil(final SSLContext sslContext) {
this.sslContext = sslContext;
}
-
+
private HttpURLConnection getConnection(final String connUrl, final int timeoutMillis) throws IOException {
final URL url = new URL(connUrl);
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(timeoutMillis);
connection.setReadTimeout(timeoutMillis);
-
+
// special handling for https
if (sslContext != null && connection instanceof HttpsURLConnection) {
HttpsURLConnection secureConnection = (HttpsURLConnection) connection;
secureConnection.setSSLSocketFactory(sslContext.getSocketFactory());
// check the trusted hostname property and override the HostnameVerifier
- secureConnection.setHostnameVerifier(new OverrideHostnameVerifier(url.getHost(),
+ secureConnection.setHostnameVerifier(new OverrideHostnameVerifier(url.getHost(),
secureConnection.getHostnameVerifier()));
}
-
+
return connection;
}
-
+
public ControllerDTO getController(final String url, final int timeoutMillis) throws IOException {
final HttpURLConnection connection = getConnection(url, timeoutMillis);
connection.setRequestMethod("GET");
final int responseCode = connection.getResponseCode();
-
+
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamUtils.copy(connection.getInputStream(), baos);
final String responseMessage = baos.toString();
-
- if ( responseCode == RESPONSE_CODE_OK ) {
+
+ if (responseCode == RESPONSE_CODE_OK) {
final ObjectMapper mapper = new ObjectMapper();
final JsonNode jsonNode = mapper.readTree(responseMessage);
final JsonNode controllerNode = jsonNode.get("controller");
@@ -77,8 +78,9 @@ public class NiFiRestApiUtil {
throw new IOException("Got HTTP response Code " + responseCode + ": " + connection.getResponseMessage() + " with explanation: " + responseMessage);
}
}
-
+
private static class OverrideHostnameVerifier implements HostnameVerifier {
+
private final String trustedHostname;
private final HostnameVerifier delegate;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/PeerStatusCache.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/PeerStatusCache.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/PeerStatusCache.java
index 6dab77b..c52b4b7 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/PeerStatusCache.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/PeerStatusCache.java
@@ -21,7 +21,8 @@ import java.util.Set;
import org.apache.nifi.remote.PeerStatus;
public class PeerStatusCache {
- private final Set<PeerStatus> statuses;
+
+ private final Set<PeerStatus> statuses;
private final long timestamp;
public PeerStatusCache(final Set<PeerStatus> statuses) {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/StandardDataPacket.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/StandardDataPacket.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/StandardDataPacket.java
index bd1b50c..70bb324 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/StandardDataPacket.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/StandardDataPacket.java
@@ -25,26 +25,26 @@ import org.apache.nifi.stream.io.MinimumLengthInputStream;
public class StandardDataPacket implements DataPacket {
- private final Map<String, String> attributes;
- private final InputStream stream;
- private final long size;
-
- public StandardDataPacket(final Map<String, String> attributes, final InputStream stream, final long size) {
- this.attributes = attributes;
- this.stream = new MinimumLengthInputStream(new LimitingInputStream(stream, size), size);
- this.size = size;
- }
-
- public Map<String, String> getAttributes() {
- return attributes;
- }
-
- public InputStream getData() {
- return stream;
- }
-
- public long getSize() {
- return size;
- }
-
+ private final Map<String, String> attributes;
+ private final InputStream stream;
+ private final long size;
+
+ public StandardDataPacket(final Map<String, String> attributes, final InputStream stream, final long size) {
+ this.attributes = attributes;
+ this.stream = new MinimumLengthInputStream(new LimitingInputStream(stream, size), size);
+ this.size = size;
+ }
+
+ public Map<String, String> getAttributes() {
+ return attributes;
+ }
+
+ public InputStream getData() {
+ return stream;
+ }
+
+ public long getSize() {
+ return size;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestEndpointConnectionStatePool.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestEndpointConnectionStatePool.java b/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestEndpointConnectionStatePool.java
index c5cca78..8336745 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestEndpointConnectionStatePool.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestEndpointConnectionStatePool.java
@@ -40,11 +40,11 @@ public class TestEndpointConnectionStatePool {
clusterNodeInfo.setNodeInformation(collection);
final List<PeerStatus> destinations = EndpointConnectionPool.formulateDestinationList(clusterNodeInfo, TransferDirection.RECEIVE);
- for ( final PeerStatus peerStatus : destinations ) {
+ for (final PeerStatus peerStatus : destinations) {
System.out.println(peerStatus.getPeerDescription());
}
}
-
+
@Test
public void testFormulateDestinationListForOutputHugeDifference() throws IOException {
final ClusterNodeInformation clusterNodeInfo = new ClusterNodeInformation();
@@ -54,14 +54,11 @@ public class TestEndpointConnectionStatePool {
clusterNodeInfo.setNodeInformation(collection);
final List<PeerStatus> destinations = EndpointConnectionPool.formulateDestinationList(clusterNodeInfo, TransferDirection.RECEIVE);
- for ( final PeerStatus peerStatus : destinations ) {
+ for (final PeerStatus peerStatus : destinations) {
System.out.println(peerStatus.getPeerDescription());
}
}
-
-
-
-
+
@Test
public void testFormulateDestinationListForInputPorts() throws IOException {
final ClusterNodeInformation clusterNodeInfo = new ClusterNodeInformation();
@@ -74,11 +71,11 @@ public class TestEndpointConnectionStatePool {
clusterNodeInfo.setNodeInformation(collection);
final List<PeerStatus> destinations = EndpointConnectionPool.formulateDestinationList(clusterNodeInfo, TransferDirection.SEND);
- for ( final PeerStatus peerStatus : destinations ) {
+ for (final PeerStatus peerStatus : destinations) {
System.out.println(peerStatus.getPeerDescription());
}
}
-
+
@Test
public void testFormulateDestinationListForInputPortsHugeDifference() throws IOException {
final ClusterNodeInformation clusterNodeInfo = new ClusterNodeInformation();
@@ -88,7 +85,7 @@ public class TestEndpointConnectionStatePool {
clusterNodeInfo.setNodeInformation(collection);
final List<PeerStatus> destinations = EndpointConnectionPool.formulateDestinationList(clusterNodeInfo, TransferDirection.SEND);
- for ( final PeerStatus peerStatus : destinations ) {
+ for (final PeerStatus peerStatus : destinations) {
System.out.println(peerStatus.getPeerDescription());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestSiteToSiteClient.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestSiteToSiteClient.java b/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestSiteToSiteClient.java
index b73e44d..155fc95 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestSiteToSiteClient.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/test/java/org/apache/nifi/remote/client/socket/TestSiteToSiteClient.java
@@ -21,7 +21,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
import org.apache.nifi.remote.Transaction;
import org.apache.nifi.remote.TransferDirection;
@@ -39,32 +38,32 @@ public class TestSiteToSiteClient {
@Ignore("For local testing only; not really a unit test but a manual test")
public void testReceive() throws IOException {
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG");
-
+
final SiteToSiteClient client = new SiteToSiteClient.Builder()
- .url("http://localhost:8080/nifi")
- .portName("cba")
- .requestBatchCount(10)
- .build();
-
+ .url("http://localhost:8080/nifi")
+ .portName("cba")
+ .requestBatchCount(10)
+ .build();
+
try {
- for (int i=0; i < 1000; i++) {
+ for (int i = 0; i < 1000; i++) {
final Transaction transaction = client.createTransaction(TransferDirection.RECEIVE);
Assert.assertNotNull(transaction);
-
+
DataPacket packet;
while (true) {
packet = transaction.receive();
- if ( packet == null ) {
+ if (packet == null) {
break;
}
final InputStream in = packet.getData();
final long size = packet.getSize();
final byte[] buff = new byte[(int) size];
-
+
StreamUtils.fillBuffer(in, buff);
}
-
+
transaction.confirm();
transaction.complete();
}
@@ -72,34 +71,33 @@ public class TestSiteToSiteClient {
client.close();
}
}
-
-
+
@Test
@Ignore("For local testing only; not really a unit test but a manual test")
public void testSend() throws IOException {
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG");
-
+
final SiteToSiteClient client = new SiteToSiteClient.Builder()
- .url("http://localhost:8080/nifi")
- .portName("input")
- .build();
-
+ .url("http://localhost:8080/nifi")
+ .portName("input")
+ .build();
+
try {
final Transaction transaction = client.createTransaction(TransferDirection.SEND);
Assert.assertNotNull(transaction);
-
+
final Map<String, String> attrs = new HashMap<>();
attrs.put("site-to-site", "yes, please!");
final byte[] bytes = "Hello".getBytes();
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final DataPacket packet = new StandardDataPacket(attrs, bais, bytes.length);
transaction.send(packet);
-
+
transaction.confirm();
transaction.complete();
} finally {
client.close();
}
}
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/AbstractChannelReader.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/AbstractChannelReader.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/AbstractChannelReader.java
index 172c593..cc24575 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/AbstractChannelReader.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/AbstractChannelReader.java
@@ -33,10 +33,6 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- *
- * @author none
- */
public abstract class AbstractChannelReader implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractChannelReader.class);
@@ -91,12 +87,12 @@ public abstract class AbstractChannelReader implements Runnable {
* Allows a subclass to specifically handle how it reads from the given
* key's channel into the given buffer.
*
- * @param key
- * @param buffer
+ * @param key of channel to read from
+ * @param buffer to fill
* @return the number of bytes read in the final read cycle. A value of zero
* or more indicates the channel is still open but a value of -1 indicates
* end of stream.
- * @throws IOException
+ * @throws IOException if reading from channel causes failure
*/
protected abstract int fillBuffer(SelectionKey key, ByteBuffer buffer) throws IOException;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/BufferPool.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/BufferPool.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/BufferPool.java
index a413ad2..007034b 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/BufferPool.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/BufferPool.java
@@ -25,10 +25,6 @@ import java.util.concurrent.LinkedBlockingDeque;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- *
- * @author none
- */
public class BufferPool implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(BufferPool.class);
@@ -50,9 +46,9 @@ public class BufferPool implements Runnable {
/**
* Returns the given buffer to the pool - and clears it.
*
- * @param buffer
- * @param bytesProcessed
- * @return
+ * @param buffer buffer to return
+ * @param bytesProcessed bytes processed for this buffer being returned
+ * @return true if buffer returned to pool
*/
public synchronized boolean returnBuffer(ByteBuffer buffer, final int bytesProcessed) {
totalBytesExtracted += bytesProcessed;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelDispatcher.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelDispatcher.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelDispatcher.java
index 2ae2c07..824f2df 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelDispatcher.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelDispatcher.java
@@ -35,10 +35,6 @@ import org.apache.nifi.io.nio.consumer.StreamConsumerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- *
- * @author none
- */
public final class ChannelDispatcher implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(ChannelDispatcher.class);
@@ -81,8 +77,8 @@ public final class ChannelDispatcher implements Runnable {
/*
* When serverSocketsChannels are registered with the selector, want each invoke of this method to loop through all
* channels' keys.
- *
- * @throws IOException
+ *
+ * @throws IOException if unable to select keys
*/
private void selectServerSocketKeys() throws IOException {
int numSelected = serverSocketSelector.select(timeout);
@@ -121,8 +117,8 @@ public final class ChannelDispatcher implements Runnable {
* When invoking this method, only want to iterate through the selected keys once. When a key is entered into the selectors
* selected key set, select will return a positive value. The next select will return 0 if nothing has changed. Note that
* the selected key set is not manually changed via a remove operation.
- *
- * @throws IOException
+ *
+ * @throws IOException if unable to select keys
*/
private void selectSocketChannelKeys() throws IOException {
// once a channel associated with a key in this selector is 'ready', it causes this select to immediately return.
@@ -138,7 +134,7 @@ public final class ChannelDispatcher implements Runnable {
// there are 2 kinds of channels in this selector, both which have their own readers and are executed in their own
// threads. We will get here whenever a new SocketChannel is created due to an incoming connection. However,
// for a DatagramChannel we don't want to create a new reader unless it is a new DatagramChannel. The only
- // way to tell if it's new is the lack of an attachment.
+ // way to tell if it's new is the lack of an attachment.
if (channel instanceof DatagramChannel && socketChannelKey.attachment() == null) {
reader = new DatagramChannelReader(UUID.randomUUID().toString(), socketChannelKey, emptyBuffers, factory);
socketChannelKey.attach(reader);
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelListener.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelListener.java b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelListener.java
index b0a1cfb..7cbf589 100644
--- a/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelListener.java
+++ b/nifi/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/nio/ChannelListener.java
@@ -62,7 +62,6 @@ import org.slf4j.LoggerFactory;
* All ChannelReaders will get throttled by the unavailability of buffers in the
* provided BufferPool. This is designed to create back pressure.
*
- * @author none
*/
public final class ChannelListener {
@@ -99,7 +98,7 @@ public final class ChannelListener {
* @param port - port to bind to
* @param receiveBufferSize - size of OS receive buffer to request. If less
* than 0 then will not be set and OS default will win.
- * @throws IOException
+ * @throws IOException if unable to add socket
*/
public void addServerSocket(final InetAddress nicIPAddress, final int port, final int receiveBufferSize)
throws IOException {
@@ -129,7 +128,7 @@ public final class ChannelListener {
* @param port - the port to listen on
* @param receiveBufferSize - the number of bytes to request for a receive
* buffer from OS
- * @throws IOException
+ * @throws IOException if unable to add channel
*/
public void addDatagramChannel(final InetAddress nicIPAddress, final int port, final int receiveBufferSize)
throws IOException {
@@ -156,7 +155,7 @@ public final class ChannelListener {
* any network interface on the local host.
* @param sendingPort - the port used by the sender of datagrams. Only
* datagrams from this port will be received.
- * @throws IOException
+ * @throws IOException if unable to add channel
*/
public void addDatagramChannel(final InetAddress nicIPAddress, final int port, final int receiveBufferSize, final String sendingHost,
final Integer sendingPort) throws IOException {
[6/7] incubator-nifi git commit: NIFI-271 checkpoint
Posted by jo...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java
index 629032a..5c4ce55 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClient.java
@@ -36,358 +36,383 @@ import org.apache.nifi.remote.protocol.DataPacket;
/**
* <p>
- * The SiteToSiteClient provides a mechanism for sending data to a remote instance of NiFi
- * (or NiFi cluster) and retrieving data from a remote instance of NiFi (or NiFi cluster).
+ * The SiteToSiteClient provides a mechanism for sending data to a remote
+ * instance of NiFi (or NiFi cluster) and retrieving data from a remote instance
+ * of NiFi (or NiFi cluster).
* </p>
- *
+ *
* <p>
- * When configuring the client via the {@link SiteToSiteClient.Builder}, the Builder must
- * be provided the URL of the remote NiFi instance. If the URL points to a standalone instance
- * of NiFi, all interaction will take place with that instance of NiFi. However, if the URL
- * points to the NiFi Cluster Manager of a cluster, the client will automatically handle load
- * balancing the transactions across the different nodes in the cluster.
+ * When configuring the client via the {@link SiteToSiteClient.Builder}, the
+ * Builder must be provided the URL of the remote NiFi instance. If the URL
+ * points to a standalone instance of NiFi, all interaction will take place with
+ * that instance of NiFi. However, if the URL points to the NiFi Cluster Manager
+ * of a cluster, the client will automatically handle load balancing the
+ * transactions across the different nodes in the cluster.
* </p>
- *
+ *
* <p>
- * The SiteToSiteClient provides a {@link Transaction} through which all interaction with the
- * remote instance takes place. After data has been exchanged or it is determined that no data
- * is available, the Transaction can then be canceled (via the {@link Transaction#cancel(String)}
- * method) or can be completed (via the {@link Transaction#complete(boolean)} method).
+ * The SiteToSiteClient provides a {@link Transaction} through which all
+ * interaction with the remote instance takes place. After data has been
+ * exchanged or it is determined that no data is available, the Transaction can
+ * then be canceled (via the {@link Transaction#cancel(String)} method) or can
+ * be completed (via the {@link Transaction#complete(boolean)} method).
* </p>
- *
+ *
* <p>
- * An instance of SiteToSiteClient can be obtained by constructing a new instance of the
- * {@link SiteToSiteClient.Builder} class, calling the appropriate methods to configured the
- * client as desired, and then calling the {@link SiteToSiteClient.Builder#build() build()} method.
+ * An instance of SiteToSiteClient can be obtained by constructing a new
+ * instance of the {@link SiteToSiteClient.Builder} class, calling the
+ * appropriate methods to configured the client as desired, and then calling the
+ * {@link SiteToSiteClient.Builder#build() build()} method.
* </p>
*
* <p>
- * The SiteToSiteClient itself is immutable once constructed and is thread-safe. Many threads can
- * share access to the same client. However, the {@link Transaction} that is created by the client
- * is not thread safe and should not be shared among threads.
+ * The SiteToSiteClient itself is immutable once constructed and is thread-safe.
+ * Many threads can share access to the same client. However, the
+ * {@link Transaction} that is created by the client is not thread safe and
+ * should not be shared among threads.
* </p>
*/
public interface SiteToSiteClient extends Closeable {
- /**
- * <p>
- * Creates a new Transaction that can be used to either send data to a remote NiFi instance
- * or receive data from a remote NiFi instance, depending on the value passed for the {@code direction} argument.
- * </p>
- *
- * <p>
- * <b>Note:</b> If all of the nodes are penalized (See {@link Builder#nodePenalizationPeriod(long, TimeUnit)}), then
- * this method will return <code>null</code>.
- * </p>
- *
- * @param direction specifies which direction the data should be transferred. A value of {@link TransferDirection#SEND}
- * indicates that this Transaction will send data to the remote instance; a value of {@link TransferDirection#RECEIVE} indicates
- * that this Transaction will be used to receive data from the remote instance.
- *
- * @return a Transaction to use for sending or receiving data, or <code>null</code> if all nodes are penalized.
- * @throws IOException
- */
- Transaction createTransaction(TransferDirection direction) throws HandshakeException, PortNotRunningException, ProtocolException, UnknownPortException, IOException;
-
- /**
- * <p>
- * Returns {@code true} if site-to-site communications with the remote instance are secure,
- * {@code false} if site-to-site communications with the remote instance are not secure. Whether or not
- * communications are secure depends on the server, not the client.
- * </p>
- *
- * <p>
- * In order to determine whether the server is configured for secure communications, the client may have
- * to query the server's RESTful interface. Doing so could result in an IOException.
- * </p>
- *
- * @return
- * @throws IOException if unable to query the remote instance's RESTful interface or if the remote
- * instance is not configured to allow site-to-site communications
- */
- boolean isSecure() throws IOException;
-
- /**
- * <p>
- * Returns the configuration object that was built by the Builder
- * </p>
- * @return
- */
- SiteToSiteClientConfig getConfig();
-
- /**
- * <p>
- * The Builder is the mechanism by which all configuration is passed to the SiteToSiteClient.
- * Once constructed, the SiteToSiteClient cannot be reconfigured (i.e., it is immutable). If
- * a change in configuration should be desired, the client should be {@link Closeable#close() closed}
- * and a new client created.
- * </p>
- */
- public static class Builder implements Serializable {
+ /**
+ * <p>
+ * Creates a new Transaction that can be used to either send data to a
+ * remote NiFi instance or receive data from a remote NiFi instance,
+ * depending on the value passed for the {@code direction} argument.
+ * </p>
+ *
+ * <p>
+ * <b>Note:</b> If all of the nodes are penalized (See
+ * {@link Builder#nodePenalizationPeriod(long, TimeUnit)}), then this method
+ * will return <code>null</code>.
+ * </p>
+ *
+ * @param direction specifies which direction the data should be
+ * transferred. A value of {@link TransferDirection#SEND} indicates that
+ * this Transaction will send data to the remote instance; a value of
+ * {@link TransferDirection#RECEIVE} indicates that this Transaction will be
+ * used to receive data from the remote instance.
+ *
+ * @return a Transaction to use for sending or receiving data, or
+ * <code>null</code> if all nodes are penalized.
+ * @throws org.apache.nifi.remote.exception.HandshakeException he
+ * @throws org.apache.nifi.remote.exception.PortNotRunningException pnre
+ * @throws IOException ioe
+ * @throws org.apache.nifi.remote.exception.UnknownPortException upe
+ */
+ Transaction createTransaction(TransferDirection direction) throws HandshakeException, PortNotRunningException, ProtocolException, UnknownPortException, IOException;
+
+ /**
+ * <p>
+ * In order to determine whether the server is configured for secure
+ * communications, the client may have to query the server's RESTful
+ * interface. Doing so could result in an IOException.
+ * </p>
+ *
+ * @return {@code true} if site-to-site communications with the remote
+ * instance are secure, {@code false} if site-to-site communications with
+ * the remote instance are not secure. Whether or not communications are
+ * secure depends on the server, not the client
+ * @throws IOException if unable to query the remote instance's RESTful
+ * interface or if the remote instance is not configured to allow
+ * site-to-site communications
+ */
+ boolean isSecure() throws IOException;
+
+ /**
+ *
+ * @return the configuration object that was built by the Builder
+ */
+ SiteToSiteClientConfig getConfig();
+
+ /**
+ * <p>
+ * The Builder is the mechanism by which all configuration is passed to the
+ * SiteToSiteClient. Once constructed, the SiteToSiteClient cannot be
+ * reconfigured (i.e., it is immutable). If a change in configuration should
+ * be desired, the client should be {@link Closeable#close() closed} and a
+ * new client created.
+ * </p>
+ */
+ public static class Builder implements Serializable {
+
private static final long serialVersionUID = -4954962284343090219L;
-
+
private String url;
- private long timeoutNanos = TimeUnit.SECONDS.toNanos(30);
- private long penalizationNanos = TimeUnit.SECONDS.toNanos(3);
- private long idleExpirationNanos = TimeUnit.SECONDS.toNanos(30L);
- private SSLContext sslContext;
- private EventReporter eventReporter;
- private File peerPersistenceFile;
- private boolean useCompression;
- private String portName;
- private String portIdentifier;
- private int batchCount;
- private long batchSize;
- private long batchNanos;
-
- /**
- * Populates the builder with values from the provided config
- * @param config
- * @return
- */
- public Builder fromConfig(final SiteToSiteClientConfig config) {
- this.url = config.getUrl();
- this.timeoutNanos = config.getTimeout(TimeUnit.NANOSECONDS);
- this.penalizationNanos = config.getPenalizationPeriod(TimeUnit.NANOSECONDS);
- this.idleExpirationNanos = config.getIdleConnectionExpiration(TimeUnit.NANOSECONDS);
- this.sslContext = config.getSslContext();
- this.eventReporter = config.getEventReporter();
- this.peerPersistenceFile = config.getPeerPersistenceFile();
- this.useCompression = config.isUseCompression();
- this.portName = config.getPortName();
- this.portIdentifier = config.getPortIdentifier();
- this.batchCount = config.getPreferredBatchCount();
- this.batchSize = config.getPreferredBatchSize();
- this.batchNanos = config.getPreferredBatchDuration(TimeUnit.NANOSECONDS);
-
- return this;
- }
-
- /**
- * Specifies the URL of the remote NiFi instance. If this URL points to the Cluster Manager of
- * a NiFi cluster, data transfer to and from nodes will be automatically load balanced across
- * the different nodes.
- *
- * @param url
- * @return
- */
- public Builder url(final String url) {
- this.url = url;
- return this;
- }
-
- /**
- * Specifies the communications timeouts to use when interacting with the remote instances. The
- * default value is 30 seconds.
- *
- * @param timeout
- * @param unit
- * @return
- */
- public Builder timeout(final long timeout, final TimeUnit unit) {
- this.timeoutNanos = unit.toNanos(timeout);
- return this;
- }
-
- /**
- * Specifies the amount of time that a connection can remain idle in the connection pool before it
- * is "expired" and shutdown. The default value is 30 seconds.
- *
- * @param timeout
- * @param unit
- * @return
- */
- public Builder idleExpiration(final long timeout, final TimeUnit unit) {
- this.idleExpirationNanos = unit.toNanos(timeout);
- return this;
- }
-
- /**
- * If there is a problem communicating with a node (i.e., any node in the remote NiFi cluster
- * or the remote instance of NiFi if it is standalone), specifies how long the client should
- * wait before attempting to communicate with that node again. While a particular node is penalized,
- * all other nodes in the remote cluster (if any) will still be available for communication.
- * The default value is 3 seconds.
- *
- * @param period
- * @param unit
- * @return
- */
- public Builder nodePenalizationPeriod(final long period, final TimeUnit unit) {
- this.penalizationNanos = unit.toNanos(period);
- return this;
- }
-
- /**
- * Specifies the SSL Context to use when communicating with the remote NiFi instance(s). If not
- * specified, communications will not be secure. The remote instance of NiFi always determines
- * whether or not Site-to-Site communications are secure (i.e., the client will always use
- * secure or non-secure communications, depending on what the server dictates).
- *
- * @param sslContext
- * @return
- */
- public Builder sslContext(final SSLContext sslContext) {
- this.sslContext = sslContext;
- return this;
- }
-
-
- /**
- * Provides an EventReporter that can be used by the client in order to report any events that
- * could be of interest when communicating with the remote instance. The EventReporter provided
- * must be threadsafe.
- *
- * @param eventReporter
- * @return
- */
- public Builder eventReporter(final EventReporter eventReporter) {
- this.eventReporter = eventReporter;
- return this;
- }
-
-
- /**
- * Specifies a file that the client can write to in order to persist the list of nodes in the
- * remote cluster and recover the list of nodes upon restart. This allows the client to function
- * if the remote Cluster Manager is unavailable, even after a restart of the client software.
- * If not specified, the list of nodes will not be persisted and a failure of the Cluster Manager
- * will result in not being able to communicate with the remote instance if a new client
- * is created.
- *
- * @param peerPersistenceFile
- * @return
- */
- public Builder peerPersistenceFile(final File peerPersistenceFile) {
- this.peerPersistenceFile = peerPersistenceFile;
- return this;
- }
-
- /**
- * Specifies whether or not data should be compressed before being transferred to or from the
- * remote instance.
- *
- * @param compress
- * @return
- */
- public Builder useCompression(final boolean compress) {
- this.useCompression = compress;
- return this;
- }
-
- /**
- * Specifies the name of the port to communicate with. Either the port name or the port identifier
- * must be specified.
- *
- * @param portName
- * @return
- */
- public Builder portName(final String portName) {
- this.portName = portName;
- return this;
- }
-
- /**
- * Specifies the unique identifier of the port to communicate with. If it is known, this is preferred over providing
- * the port name, as the port name may change.
- *
- * @param portIdentifier
- * @return
- */
- public Builder portIdentifier(final String portIdentifier) {
- this.portIdentifier = portIdentifier;
- return this;
- }
-
- /**
- * When pulling data from a NiFi instance, the sender chooses how large a Transaction is. However,
- * the client has the ability to request a particular batch size/duration. This method specifies
- * the preferred number of {@link DataPacket}s to include in a Transaction.
- *
- * @return
- */
- public Builder requestBatchCount(final int count) {
- this.batchCount = count;
- return this;
- }
-
- /**
- * When pulling data from a NiFi instance, the sender chooses how large a Transaction is. However,
- * the client has the ability to request a particular batch size/duration. This method specifies
- * the preferred number of bytes to include in a Transaction.
- *
- * @return
- */
- public Builder requestBatchSize(final long bytes) {
- this.batchSize = bytes;
- return this;
- }
-
+ private long timeoutNanos = TimeUnit.SECONDS.toNanos(30);
+ private long penalizationNanos = TimeUnit.SECONDS.toNanos(3);
+ private long idleExpirationNanos = TimeUnit.SECONDS.toNanos(30L);
+ private SSLContext sslContext;
+ private EventReporter eventReporter;
+ private File peerPersistenceFile;
+ private boolean useCompression;
+ private String portName;
+ private String portIdentifier;
+ private int batchCount;
+ private long batchSize;
+ private long batchNanos;
+
+ /**
+ * Populates the builder with values from the provided config
+ *
+ * @param config to start with
+ * @return the builder
+ */
+ public Builder fromConfig(final SiteToSiteClientConfig config) {
+ this.url = config.getUrl();
+ this.timeoutNanos = config.getTimeout(TimeUnit.NANOSECONDS);
+ this.penalizationNanos = config.getPenalizationPeriod(TimeUnit.NANOSECONDS);
+ this.idleExpirationNanos = config.getIdleConnectionExpiration(TimeUnit.NANOSECONDS);
+ this.sslContext = config.getSslContext();
+ this.eventReporter = config.getEventReporter();
+ this.peerPersistenceFile = config.getPeerPersistenceFile();
+ this.useCompression = config.isUseCompression();
+ this.portName = config.getPortName();
+ this.portIdentifier = config.getPortIdentifier();
+ this.batchCount = config.getPreferredBatchCount();
+ this.batchSize = config.getPreferredBatchSize();
+ this.batchNanos = config.getPreferredBatchDuration(TimeUnit.NANOSECONDS);
+
+ return this;
+ }
+
+ /**
+ * Specifies the URL of the remote NiFi instance. If this URL points to
+ * the Cluster Manager of a NiFi cluster, data transfer to and from
+ * nodes will be automatically load balanced across the different nodes.
+ *
+ * @param url url of remote instance
+ * @return the builder
+ */
+ public Builder url(final String url) {
+ this.url = url;
+ return this;
+ }
+
+ /**
+ * Specifies the communications timeouts to use when interacting with
+ * the remote instances. The default value is 30 seconds.
+ *
+ * @param timeout to use when interacting with remote instances
+ * @param unit unit of time over which to interpret the given timeout
+ * @return the builder
+ */
+ public Builder timeout(final long timeout, final TimeUnit unit) {
+ this.timeoutNanos = unit.toNanos(timeout);
+ return this;
+ }
+
+ /**
+ * Specifies the amount of time that a connection can remain idle in the
+ * connection pool before it is "expired" and shutdown. The default
+ * value is 30 seconds.
+ *
+ * @param timeout to use when interacting with remote instances
+ * @param unit unit of time over which to interpret the given timeout
+ * @return the builder
+ */
+ public Builder idleExpiration(final long timeout, final TimeUnit unit) {
+ this.idleExpirationNanos = unit.toNanos(timeout);
+ return this;
+ }
+
+ /**
+ * If there is a problem communicating with a node (i.e., any node in
+ * the remote NiFi cluster or the remote instance of NiFi if it is
+ * standalone), specifies how long the client should wait before
+ * attempting to communicate with that node again. While a particular
+ * node is penalized, all other nodes in the remote cluster (if any)
+ * will still be available for communication. The default value is 3
+ * seconds.
+ *
+ * @param period time to wait between communication attempts
+ * @param unit over which to evaluate the given period
+ * @return the builder
+ */
+ public Builder nodePenalizationPeriod(final long period, final TimeUnit unit) {
+ this.penalizationNanos = unit.toNanos(period);
+ return this;
+ }
+
/**
- * When pulling data from a NiFi instance, the sender chooses how large a Transaction is. However,
- * the client has the ability to request a particular batch size/duration. This method specifies
- * the preferred amount of time that a Transaction should span.
- *
- * @return
+ * Specifies the SSL Context to use when communicating with the remote
+ * NiFi instance(s). If not specified, communications will not be
+ * secure. The remote instance of NiFi always determines whether or not
+ * Site-to-Site communications are secure (i.e., the client will always
+ * use secure or non-secure communications, depending on what the server
+ * dictates).
+ *
+ * @param sslContext the context
+ * @return the builder
*/
- public Builder requestBatchDuration(final long value, final TimeUnit unit) {
- this.batchNanos = unit.toNanos(value);
- return this;
- }
-
- /**
- * Returns a {@link SiteToSiteClientConfig} for the configured values but does not create a SiteToSiteClient
- * @return
- */
- public SiteToSiteClientConfig buildConfig() {
- final SiteToSiteClientConfig config = new SiteToSiteClientConfig() {
+ public Builder sslContext(final SSLContext sslContext) {
+ this.sslContext = sslContext;
+ return this;
+ }
+
+ /**
+ * Provides an EventReporter that can be used by the client in order to
+ * report any events that could be of interest when communicating with
+ * the remote instance. The EventReporter provided must be threadsafe.
+ *
+ * @param eventReporter reporter
+ * @return the builder
+ */
+ public Builder eventReporter(final EventReporter eventReporter) {
+ this.eventReporter = eventReporter;
+ return this;
+ }
+
+ /**
+ * Specifies a file that the client can write to in order to persist the
+ * list of nodes in the remote cluster and recover the list of nodes
+ * upon restart. This allows the client to function if the remote
+ * Cluster Manager is unavailable, even after a restart of the client
+ * software. If not specified, the list of nodes will not be persisted
+ * and a failure of the Cluster Manager will result in not being able to
+ * communicate with the remote instance if a new client is created.
+ *
+ * @param peerPersistenceFile file
+ * @return the builder
+ */
+ public Builder peerPersistenceFile(final File peerPersistenceFile) {
+ this.peerPersistenceFile = peerPersistenceFile;
+ return this;
+ }
+
+ /**
+ * Specifies whether or not data should be compressed before being
+ * transferred to or from the remote instance.
+ *
+ * @param compress true if should compress
+ * @return the builder
+ */
+ public Builder useCompression(final boolean compress) {
+ this.useCompression = compress;
+ return this;
+ }
+
+ /**
+ * Specifies the name of the port to communicate with. Either the port
+ * name or the port identifier must be specified.
+ *
+ * @param portName name of port
+ * @return the builder
+ */
+ public Builder portName(final String portName) {
+ this.portName = portName;
+ return this;
+ }
+
+ /**
+ * Specifies the unique identifier of the port to communicate with. If
+ * it is known, this is preferred over providing the port name, as the
+ * port name may change.
+ *
+ * @param portIdentifier identifier of port
+ * @return the builder
+ */
+ public Builder portIdentifier(final String portIdentifier) {
+ this.portIdentifier = portIdentifier;
+ return this;
+ }
+
+ /**
+ * When pulling data from a NiFi instance, the sender chooses how large
+ * a Transaction is. However, the client has the ability to request a
+ * particular batch size/duration. This method specifies the preferred
+ * number of {@link DataPacket}s to include in a Transaction.
+ *
+ * @param count client preferred batch size
+ * @return the builder
+ */
+ public Builder requestBatchCount(final int count) {
+ this.batchCount = count;
+ return this;
+ }
+
+ /**
+ * When pulling data from a NiFi instance, the sender chooses how large
+ * a Transaction is. However, the client has the ability to request a
+ * particular batch size/duration. This method specifies the preferred
+ * number of bytes to include in a Transaction.
+ *
+ * @param bytes client preferred batch size
+ * @return the builder
+ */
+ public Builder requestBatchSize(final long bytes) {
+ this.batchSize = bytes;
+ return this;
+ }
+
+ /**
+ * When pulling data from a NiFi instance, the sender chooses how large
+ * a Transaction is. However, the client has the ability to request a
+ * particular batch size/duration. This method specifies the preferred
+ * amount of time that a Transaction should span.
+ *
+ * @param value client preferred batch duration
+ * @param unit client preferred batch duration unit
+ * @return the builder
+ */
+ public Builder requestBatchDuration(final long value, final TimeUnit unit) {
+ this.batchNanos = unit.toNanos(value);
+ return this;
+ }
+
+ /**
+ * @return a {@link SiteToSiteClientConfig} for the configured values
+ * but does not create a SiteToSiteClient
+ */
+ public SiteToSiteClientConfig buildConfig() {
+ final SiteToSiteClientConfig config = new SiteToSiteClientConfig() {
private static final long serialVersionUID = 1323119754841633818L;
@Override
public boolean isUseCompression() {
return Builder.this.isUseCompression();
}
-
+
@Override
public String getUrl() {
return Builder.this.getUrl();
}
-
+
@Override
public long getTimeout(final TimeUnit timeUnit) {
return Builder.this.getTimeout(timeUnit);
}
-
+
@Override
public long getIdleConnectionExpiration(final TimeUnit timeUnit) {
return Builder.this.getIdleConnectionExpiration(timeUnit);
}
-
+
@Override
public SSLContext getSslContext() {
return Builder.this.getSslContext();
}
-
+
@Override
public String getPortName() {
return Builder.this.getPortName();
}
-
+
@Override
public String getPortIdentifier() {
return Builder.this.getPortIdentifier();
}
-
+
@Override
public long getPenalizationPeriod(final TimeUnit timeUnit) {
return Builder.this.getPenalizationPeriod(timeUnit);
}
-
+
@Override
public File getPeerPersistenceFile() {
return Builder.this.getPeerPersistenceFile();
}
-
+
@Override
public EventReporter getEventReporter() {
return Builder.this.getEventReporter();
@@ -397,123 +422,117 @@ public interface SiteToSiteClient extends Closeable {
public long getPreferredBatchDuration(final TimeUnit timeUnit) {
return timeUnit.convert(Builder.this.batchNanos, TimeUnit.NANOSECONDS);
}
-
+
@Override
public long getPreferredBatchSize() {
return Builder.this.batchSize;
}
-
+
@Override
public int getPreferredBatchCount() {
return Builder.this.batchCount;
}
};
-
+
return config;
- }
-
- /**
- * Builds a new SiteToSiteClient that can be used to send and receive data with remote instances of NiFi
- * @return
- *
- * @throws IllegalStateException if either the url is not set or neither the port name nor port identifier
- * is set.
- */
- public SiteToSiteClient build() {
- if ( url == null ) {
- throw new IllegalStateException("Must specify URL to build Site-to-Site client");
- }
-
- if ( portName == null && portIdentifier == null ) {
- throw new IllegalStateException("Must specify either Port Name or Port Identifier to builder Site-to-Site client");
- }
-
- return new SocketClient(buildConfig());
- }
-
- /**
- * Returns the configured URL for the remote NiFi instance
- * @return
- */
- public String getUrl() {
- return url;
- }
-
- /**
- * Returns the communications timeout
- * @return
- */
- public long getTimeout(final TimeUnit timeUnit) {
- return timeUnit.convert(timeoutNanos, TimeUnit.NANOSECONDS);
- }
-
- /**
- * Returns the amount of of time that a connection can remain idle in the connection
- * pool before being shutdown
- * @param timeUnit
- * @return
- */
- public long getIdleConnectionExpiration(final TimeUnit timeUnit) {
- return timeUnit.convert(idleExpirationNanos, TimeUnit.NANOSECONDS);
- }
-
- /**
- * Returns the amount of time that a particular node will be ignored after a
- * communications error with that node occurs
- * @param timeUnit
- * @return
- */
- public long getPenalizationPeriod(TimeUnit timeUnit) {
- return timeUnit.convert(penalizationNanos, TimeUnit.NANOSECONDS);
- }
-
- /**
- * Returns the SSL Context that is configured for this builder
- * @return
- */
- public SSLContext getSslContext() {
- return sslContext;
- }
-
- /**
- * Returns the EventReporter that is to be used by clients to report events
- * @return
- */
- public EventReporter getEventReporter() {
- return eventReporter;
- }
-
- /**
- * Returns the file that is to be used for persisting the nodes of a remote cluster, if any.
- * @return
- */
- public File getPeerPersistenceFile() {
- return peerPersistenceFile;
- }
-
- /**
- * Returns a boolean indicating whether or not compression will be used to transfer data
- * to and from the remote instance
- * @return
- */
- public boolean isUseCompression() {
- return useCompression;
- }
-
- /**
- * Returns the name of the port that the client is to communicate with.
- * @return
- */
- public String getPortName() {
- return portName;
- }
-
- /**
- * Returns the identifier of the port that the client is to communicate with.
- * @return
- */
- public String getPortIdentifier() {
- return portIdentifier;
- }
- }
+ }
+
+ /**
+ * @return a new SiteToSiteClient that can be used to send and receive
+ * data with remote instances of NiFi
+ *
+ * @throws IllegalStateException if either the url is not set or neither
+ * the port name nor port identifier is set.
+ */
+ public SiteToSiteClient build() {
+ if (url == null) {
+ throw new IllegalStateException("Must specify URL to build Site-to-Site client");
+ }
+
+ if (portName == null && portIdentifier == null) {
+ throw new IllegalStateException("Must specify either Port Name or Port Identifier to builder Site-to-Site client");
+ }
+
+ return new SocketClient(buildConfig());
+ }
+
+ /**
+ * @return the configured URL for the remote NiFi instance
+ */
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * @param timeUnit unit over which to interpret the timeout
+ * @return the communications timeout
+ */
+ public long getTimeout(final TimeUnit timeUnit) {
+ return timeUnit.convert(timeoutNanos, TimeUnit.NANOSECONDS);
+ }
+
+ /**
+ * @param timeUnit unit over which to interpret the time
+ * @return the amount of of time that a connection can remain idle in
+ * the connection pool before being shutdown
+ */
+ public long getIdleConnectionExpiration(final TimeUnit timeUnit) {
+ return timeUnit.convert(idleExpirationNanos, TimeUnit.NANOSECONDS);
+ }
+
+ /**
+ * @param timeUnit unit of reported time
+ * @return the amount of time that a particular node will be ignored
+ * after a communications error with that node occurs
+ */
+ public long getPenalizationPeriod(TimeUnit timeUnit) {
+ return timeUnit.convert(penalizationNanos, TimeUnit.NANOSECONDS);
+ }
+
+ /**
+ * @return the SSL Context that is configured for this builder
+ */
+ public SSLContext getSslContext() {
+ return sslContext;
+ }
+
+ /**
+ * @return the EventReporter that is to be used by clients to report
+ * events
+ */
+ public EventReporter getEventReporter() {
+ return eventReporter;
+ }
+
+ /**
+ * @return the file that is to be used for persisting the nodes of a
+ * remote cluster, if any
+ */
+ public File getPeerPersistenceFile() {
+ return peerPersistenceFile;
+ }
+
+ /**
+ * @return a boolean indicating whether or not compression will be used
+ * to transfer data to and from the remote instance
+ */
+ public boolean isUseCompression() {
+ return useCompression;
+ }
+
+ /**
+ * @return the name of the port that the client is to communicate with
+ */
+ public String getPortName() {
+ return portName;
+ }
+
+ /**
+ * @return the identifier of the port that the client is to communicate
+ * with
+ */
+ public String getPortIdentifier() {
+ return portIdentifier;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java
index 5e7fbe8..c4b0d22 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteToSiteClientConfig.java
@@ -27,97 +27,91 @@ import org.apache.nifi.remote.protocol.DataPacket;
public interface SiteToSiteClientConfig extends Serializable {
- /**
- * Returns the configured URL for the remote NiFi instance
- * @return
- */
- String getUrl();
-
- /**
- * Returns the communications timeout in nanoseconds
- * @return
- */
- long getTimeout(final TimeUnit timeUnit);
-
- /**
- * Returns the amount of time that a connection can remain idle before it is
- * "expired" and shut down
- * @param timeUnit
- * @return
- */
- long getIdleConnectionExpiration(TimeUnit timeUnit);
-
- /**
- * Returns the amount of time that a particular node will be ignored after a
- * communications error with that node occurs
- * @param timeUnit
- * @return
- */
- long getPenalizationPeriod(TimeUnit timeUnit);
-
- /**
- * Returns the SSL Context that is configured for this builder
- * @return
- */
- SSLContext getSslContext();
-
- /**
- * Returns the file that is to be used for persisting the nodes of a remote cluster, if any.
- * @return
- */
- File getPeerPersistenceFile();
-
- /**
- * Returns a boolean indicating whether or not compression will be used to transfer data
- * to and from the remote instance
- * @return
- */
- boolean isUseCompression();
-
- /**
- * Returns the name of the port that the client is to communicate with.
- * @return
- */
- String getPortName();
-
- /**
- * Returns the identifier of the port that the client is to communicate with.
- * @return
- */
- String getPortIdentifier();
-
- /**
- * When pulling data from a NiFi instance, the sender chooses how large a Transaction is. However,
- * the client has the ability to request a particular batch size/duration. This returns the maximum
- * amount of time that we will request a NiFi instance to send data to us in a Transaction.
- *
- * @param timeUnit
- * @return
- */
- long getPreferredBatchDuration(TimeUnit timeUnit);
-
/**
- * When pulling data from a NiFi instance, the sender chooses how large a Transaction is. However,
- * the client has the ability to request a particular batch size/duration. This returns the maximum
- * number of bytes that we will request a NiFi instance to send data to us in a Transaction.
- *
- * @return
+ * @return the configured URL for the remote NiFi instance
*/
- long getPreferredBatchSize();
-
-
- /**
- * When pulling data from a NiFi instance, the sender chooses how large a Transaction is. However,
- * the client has the ability to request a particular batch size/duration. This returns the maximum
- * number of {@link DataPacket}s that we will request a NiFi instance to send data to us in a Transaction.
- *
- * @return
+ String getUrl();
+
+ /**
+ * @param timeUnit unit over which to report the timeout
+ * @return the communications timeout in given unit
+ */
+ long getTimeout(final TimeUnit timeUnit);
+
+ /**
+ * @param timeUnit the unit for which to report the time
+ * @return the amount of time that a connection can remain idle before it is
+ * "expired" and shut down
+ */
+ long getIdleConnectionExpiration(TimeUnit timeUnit);
+
+ /**
+ * @param timeUnit unit over which to report the time
+ * @return the amount of time that a particular node will be ignored after a
+ * communications error with that node occurs
+ */
+ long getPenalizationPeriod(TimeUnit timeUnit);
+
+ /**
+ * @return the SSL Context that is configured for this builder
+ */
+ SSLContext getSslContext();
+
+ /**
+ * @return the file that is to be used for persisting the nodes of a remote
+ * cluster, if any
+ */
+ File getPeerPersistenceFile();
+
+ /**
+ * @return a boolean indicating whether or not compression will be used to
+ * transfer data to and from the remote instance
*/
- int getPreferredBatchCount();
-
- /**
- * Returns the EventReporter that is to be used by clients to report events
- * @return
+ boolean isUseCompression();
+
+ /**
+ * @return the name of the port that the client is to communicate with
+ */
+ String getPortName();
+
+ /**
+ * @return the identifier of the port that the client is to communicate with
+ */
+ String getPortIdentifier();
+
+ /**
+ * When pulling data from a NiFi instance, the sender chooses how large a
+ * Transaction is. However, the client has the ability to request a
+ * particular batch size/duration.
+ *
+ * @param timeUnit unit of time over which to report the duration
+ * @return the maximum amount of time that we will request a NiFi instance
+ * to send data to us in a Transaction
+ */
+ long getPreferredBatchDuration(TimeUnit timeUnit);
+
+ /**
+ * When pulling data from a NiFi instance, the sender chooses how large a
+ * Transaction is. However, the client has the ability to request a
+ * particular batch size/duration.
+ *
+ * @return returns the maximum number of bytes that we will request a NiFi
+ * instance to send data to us in a Transaction
+ */
+ long getPreferredBatchSize();
+
+ /**
+ * When pulling data from a NiFi instance, the sender chooses how large a
+ * Transaction is. However, the client has the ability to request a
+ * particular batch size/duration.
+ *
+ * @return the maximum number of {@link DataPacket}s that we will request a
+ * NiFi instance to send data to us in a Transaction
+ */
+ int getPreferredBatchCount();
+
+ /**
+ * @return the EventReporter that is to be used by clients to report events
*/
EventReporter getEventReporter();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnection.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnection.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnection.java
index 651ae50..1a16b02 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnection.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnection.java
@@ -21,33 +21,34 @@ import org.apache.nifi.remote.codec.FlowFileCodec;
import org.apache.nifi.remote.protocol.socket.SocketClientProtocol;
public class EndpointConnection {
- private final Peer peer;
+
+ private final Peer peer;
private final SocketClientProtocol socketClientProtocol;
private final FlowFileCodec codec;
private volatile long lastUsed;
-
+
public EndpointConnection(final Peer peer, final SocketClientProtocol socketClientProtocol, final FlowFileCodec codec) {
this.peer = peer;
this.socketClientProtocol = socketClientProtocol;
this.codec = codec;
}
-
+
public FlowFileCodec getCodec() {
return codec;
}
-
+
public SocketClientProtocol getSocketClientProtocol() {
return socketClientProtocol;
}
-
+
public Peer getPeer() {
return peer;
}
-
+
public void setLastTimeUsed() {
lastUsed = System.currentTimeMillis();
}
-
+
public long getLastTimeUsed() {
return lastUsed;
}
[5/7] incubator-nifi git commit: NIFI-271 checkpoint
Posted by jo...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java
index 1b5412c..36d8bac 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/EndpointConnectionPool.java
@@ -91,21 +91,22 @@ import org.slf4j.LoggerFactory;
import org.slf4j.helpers.MessageFormatter;
public class EndpointConnectionPool {
+
public static final long PEER_REFRESH_PERIOD = 60000L;
public static final String CATEGORY = "Site-to-Site";
public static final long REMOTE_REFRESH_MILLIS = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES);
private static final long PEER_CACHE_MILLIS = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES);
- private static final Logger logger = LoggerFactory.getLogger(EndpointConnectionPool.class);
-
- private final ConcurrentMap<PeerDescription, BlockingQueue<EndpointConnection>> connectionQueueMap = new ConcurrentHashMap<>();
+ private static final Logger logger = LoggerFactory.getLogger(EndpointConnectionPool.class);
+
+ private final ConcurrentMap<PeerDescription, BlockingQueue<EndpointConnection>> connectionQueueMap = new ConcurrentHashMap<>();
private final ConcurrentMap<PeerDescription, Long> peerTimeoutExpirations = new ConcurrentHashMap<>();
private final URI clusterUrl;
private final String apiUri;
-
+
private final AtomicLong peerIndex = new AtomicLong(0L);
-
+
private final ReentrantLock peerRefreshLock = new ReentrantLock();
private volatile List<PeerStatus> peerStatuses;
private volatile long peerRefreshTime = 0L;
@@ -118,132 +119,129 @@ public class EndpointConnectionPool {
private final ScheduledExecutorService taskExecutor;
private final int idleExpirationMillis;
private final RemoteDestination remoteDestination;
-
+
private final ReadWriteLock listeningPortRWLock = new ReentrantReadWriteLock();
private final Lock remoteInfoReadLock = listeningPortRWLock.readLock();
private final Lock remoteInfoWriteLock = listeningPortRWLock.writeLock();
private Integer siteToSitePort;
private Boolean siteToSiteSecure;
private long remoteRefreshTime;
- private final Map<String, String> inputPortMap = new HashMap<>(); // map input port name to identifier
- private final Map<String, String> outputPortMap = new HashMap<>(); // map output port name to identifier
-
+ private final Map<String, String> inputPortMap = new HashMap<>(); // map input port name to identifier
+ private final Map<String, String> outputPortMap = new HashMap<>(); // map output port name to identifier
+
private volatile int commsTimeout;
private volatile boolean shutdown = false;
-
-
- public EndpointConnectionPool(final String clusterUrl, final RemoteDestination remoteDestination, final int commsTimeoutMillis,
- final int idleExpirationMillis, final EventReporter eventReporter, final File persistenceFile)
- {
- this(clusterUrl, remoteDestination, commsTimeoutMillis, idleExpirationMillis, null, eventReporter, persistenceFile);
- }
-
+
+ public EndpointConnectionPool(final String clusterUrl, final RemoteDestination remoteDestination, final int commsTimeoutMillis,
+ final int idleExpirationMillis, final EventReporter eventReporter, final File persistenceFile) {
+ this(clusterUrl, remoteDestination, commsTimeoutMillis, idleExpirationMillis, null, eventReporter, persistenceFile);
+ }
+
public EndpointConnectionPool(final String clusterUrl, final RemoteDestination remoteDestination, final int commsTimeoutMillis, final int idleExpirationMillis,
- final SSLContext sslContext, final EventReporter eventReporter, final File persistenceFile)
- {
+ final SSLContext sslContext, final EventReporter eventReporter, final File persistenceFile) {
Objects.requireNonNull(clusterUrl, "URL cannot be null");
Objects.requireNonNull(remoteDestination, "Remote Destination/Port Identifier cannot be null");
- try {
- this.clusterUrl = new URI(clusterUrl);
- } catch (final URISyntaxException e) {
- throw new IllegalArgumentException("Invalid Cluster URL: " + clusterUrl);
- }
-
- // Trim the trailing /
+ try {
+ this.clusterUrl = new URI(clusterUrl);
+ } catch (final URISyntaxException e) {
+ throw new IllegalArgumentException("Invalid Cluster URL: " + clusterUrl);
+ }
+
+ // Trim the trailing /
String uriPath = this.clusterUrl.getPath();
if (uriPath.endsWith("/")) {
uriPath = uriPath.substring(0, uriPath.length() - 1);
}
apiUri = this.clusterUrl.getScheme() + "://" + this.clusterUrl.getHost() + ":" + this.clusterUrl.getPort() + uriPath + "-api";
-
+
this.remoteDestination = remoteDestination;
- this.sslContext = sslContext;
- this.peersFile = persistenceFile;
- this.eventReporter = eventReporter;
- this.commsTimeout = commsTimeoutMillis;
- this.idleExpirationMillis = idleExpirationMillis;
-
- Set<PeerStatus> recoveredStatuses;
- if ( persistenceFile != null && persistenceFile.exists() ) {
- try {
- recoveredStatuses = recoverPersistedPeerStatuses(peersFile);
- this.peerStatusCache = new PeerStatusCache(recoveredStatuses, peersFile.lastModified());
- } catch (final IOException ioe) {
- logger.warn("Failed to recover peer statuses from {} due to {}; will continue without loading information from file", persistenceFile, ioe);
- }
- } else {
- peerStatusCache = null;
- }
-
- // Initialize a scheduled executor and run some maintenance tasks in the background to kill off old, unused
- // connections and keep our list of peers up-to-date.
- taskExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
- private final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
-
- @Override
- public Thread newThread(final Runnable r) {
- final Thread thread = defaultFactory.newThread(r);
- thread.setName("NiFi Site-to-Site Connection Pool Maintenance");
- return thread;
- }
- });
-
- taskExecutor.scheduleWithFixedDelay(new Runnable() {
- @Override
- public void run() {
- refreshPeers();
- }
- }, 0, 5, TimeUnit.SECONDS);
-
- taskExecutor.scheduleWithFixedDelay(new Runnable() {
- @Override
- public void run() {
- cleanupExpiredSockets();
- }
- }, 5, 5, TimeUnit.SECONDS);
- }
-
+ this.sslContext = sslContext;
+ this.peersFile = persistenceFile;
+ this.eventReporter = eventReporter;
+ this.commsTimeout = commsTimeoutMillis;
+ this.idleExpirationMillis = idleExpirationMillis;
+
+ Set<PeerStatus> recoveredStatuses;
+ if (persistenceFile != null && persistenceFile.exists()) {
+ try {
+ recoveredStatuses = recoverPersistedPeerStatuses(peersFile);
+ this.peerStatusCache = new PeerStatusCache(recoveredStatuses, peersFile.lastModified());
+ } catch (final IOException ioe) {
+ logger.warn("Failed to recover peer statuses from {} due to {}; will continue without loading information from file", persistenceFile, ioe);
+ }
+ } else {
+ peerStatusCache = null;
+ }
+
+ // Initialize a scheduled executor and run some maintenance tasks in the background to kill off old, unused
+ // connections and keep our list of peers up-to-date.
+ taskExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
+ private final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
+
+ @Override
+ public Thread newThread(final Runnable r) {
+ final Thread thread = defaultFactory.newThread(r);
+ thread.setName("NiFi Site-to-Site Connection Pool Maintenance");
+ return thread;
+ }
+ });
+
+ taskExecutor.scheduleWithFixedDelay(new Runnable() {
+ @Override
+ public void run() {
+ refreshPeers();
+ }
+ }, 0, 5, TimeUnit.SECONDS);
+
+ taskExecutor.scheduleWithFixedDelay(new Runnable() {
+ @Override
+ public void run() {
+ cleanupExpiredSockets();
+ }
+ }, 5, 5, TimeUnit.SECONDS);
+ }
+
void warn(final String msg, final Object... args) {
- logger.warn(msg, args);
- if ( eventReporter != null ) {
- eventReporter.reportEvent(Severity.WARNING, "Site-to-Site", MessageFormatter.arrayFormat(msg, args).getMessage());
- }
+ logger.warn(msg, args);
+ if (eventReporter != null) {
+ eventReporter.reportEvent(Severity.WARNING, "Site-to-Site", MessageFormatter.arrayFormat(msg, args).getMessage());
+ }
}
-
+
void warn(final String msg, final Throwable t) {
- logger.warn(msg, t);
-
- if ( eventReporter != null ) {
- eventReporter.reportEvent(Severity.WARNING, "Site-to-Site", msg + ": " + t.toString());
- }
+ logger.warn(msg, t);
+
+ if (eventReporter != null) {
+ eventReporter.reportEvent(Severity.WARNING, "Site-to-Site", msg + ": " + t.toString());
+ }
}
-
+
void error(final String msg, final Object... args) {
- logger.error(msg, args);
- if ( eventReporter != null ) {
- eventReporter.reportEvent(Severity.ERROR, "Site-to-Site", MessageFormatter.arrayFormat(msg, args).getMessage());
- }
+ logger.error(msg, args);
+ if (eventReporter != null) {
+ eventReporter.reportEvent(Severity.ERROR, "Site-to-Site", MessageFormatter.arrayFormat(msg, args).getMessage());
+ }
}
-
+
private String getPortIdentifier(final TransferDirection transferDirection) throws IOException {
- if ( remoteDestination.getIdentifier() != null ) {
+ if (remoteDestination.getIdentifier() != null) {
return remoteDestination.getIdentifier();
}
-
- if ( transferDirection == TransferDirection.RECEIVE ) {
+
+ if (transferDirection == TransferDirection.RECEIVE) {
return getOutputPortIdentifier(remoteDestination.getName());
} else {
return getInputPortIdentifier(remoteDestination.getName());
}
}
-
+
public EndpointConnection getEndpointConnection(final TransferDirection direction) throws IOException, HandshakeException, PortNotRunningException, UnknownPortException, ProtocolException {
return getEndpointConnection(direction, null);
}
-
-
- public EndpointConnection getEndpointConnection(final TransferDirection direction, final SiteToSiteClientConfig config) throws IOException, HandshakeException, PortNotRunningException, UnknownPortException, ProtocolException {
- //
+
+ public EndpointConnection getEndpointConnection(final TransferDirection direction, final SiteToSiteClientConfig config)
+ throws IOException, HandshakeException, PortNotRunningException, UnknownPortException, ProtocolException {
+ //
// Attempt to get a connection state that already exists for this URL.
//
FlowFileCodec codec = null;
@@ -255,42 +253,42 @@ public class EndpointConnectionPool {
logger.debug("{} getting next peer status", this);
final PeerStatus peerStatus = getNextPeerStatus(direction);
logger.debug("{} next peer status = {}", this, peerStatus);
- if ( peerStatus == null ) {
+ if (peerStatus == null) {
return null;
}
final PeerDescription peerDescription = peerStatus.getPeerDescription();
BlockingQueue<EndpointConnection> connectionQueue = connectionQueueMap.get(peerStatus);
- if ( connectionQueue == null ) {
+ if (connectionQueue == null) {
connectionQueue = new LinkedBlockingQueue<>();
BlockingQueue<EndpointConnection> existing = connectionQueueMap.putIfAbsent(peerDescription, connectionQueue);
- if ( existing != null ) {
+ if (existing != null) {
connectionQueue = existing;
}
}
-
+
final List<EndpointConnection> addBack = new ArrayList<>();
try {
do {
connection = connectionQueue.poll();
logger.debug("{} Connection State for {} = {}", this, clusterUrl, connection);
final String portId = getPortIdentifier(direction);
-
- if ( connection == null && !addBack.isEmpty() ) {
+
+ if (connection == null && !addBack.isEmpty()) {
// all available connections have been penalized.
logger.debug("{} all Connections for {} are penalized; returning no Connection", this, portId);
return null;
}
-
- if ( connection != null && connection.getPeer().isPenalized(portId) ) {
+
+ if (connection != null && connection.getPeer().isPenalized(portId)) {
// we have a connection, but it's penalized. We want to add it back to the queue
// when we've found one to use.
addBack.add(connection);
continue;
}
-
+
// if we can't get an existing Connection, create one
- if ( connection == null ) {
+ if (connection == null) {
logger.debug("{} No Connection available for Port {}; creating new Connection", this, portId);
protocol = new SocketClientProtocol();
protocol.setDestination(new IdEnrichedRemoteDestination(remoteDestination, portId));
@@ -304,7 +302,7 @@ public class EndpointConnectionPool {
penalize(peerStatus.getPeerDescription(), penalizationMillis);
throw ioe;
}
-
+
final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream());
final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream());
try {
@@ -314,72 +312,72 @@ public class EndpointConnectionPool {
try {
commsSession.close();
} catch (final IOException ioe) {
- throw e;
+ throw e;
}
}
-
+
final String peerUrl = "nifi://" + peerDescription.getHostname() + ":" + peerDescription.getPort();
peer = new Peer(peerDescription, commsSession, peerUrl, clusterUrl.toString());
-
+
// set properties based on config
- if ( config != null ) {
+ if (config != null) {
protocol.setTimeout((int) config.getTimeout(TimeUnit.MILLISECONDS));
protocol.setPreferredBatchCount(config.getPreferredBatchCount());
protocol.setPreferredBatchSize(config.getPreferredBatchSize());
protocol.setPreferredBatchDuration(config.getPreferredBatchDuration(TimeUnit.MILLISECONDS));
}
-
+
// perform handshake
try {
logger.debug("{} performing handshake", this);
protocol.handshake(peer);
-
+
// handle error cases
- if ( protocol.isDestinationFull() ) {
- logger.warn("{} {} indicates that port {}'s destination is full; penalizing peer",
- this, peer, config.getPortName() == null ? config.getPortIdentifier() : config.getPortName());
-
+ if (protocol.isDestinationFull()) {
+ logger.warn("{} {} indicates that port {}'s destination is full; penalizing peer",
+ this, peer, config.getPortName() == null ? config.getPortIdentifier() : config.getPortName());
+
penalize(peer, penalizationMillis);
try {
- peer.close();
+ peer.close();
} catch (final IOException ioe) {
}
-
+
continue;
- } else if ( protocol.isPortInvalid() ) {
- penalize(peer, penalizationMillis);
- cleanup(protocol, peer);
- throw new PortNotRunningException(peer.toString() + " indicates that port " + portId + " is not running");
- } else if ( protocol.isPortUnknown() ) {
- penalize(peer, penalizationMillis);
- cleanup(protocol, peer);
- throw new UnknownPortException(peer.toString() + " indicates that port " + portId + " is not known");
+ } else if (protocol.isPortInvalid()) {
+ penalize(peer, penalizationMillis);
+ cleanup(protocol, peer);
+ throw new PortNotRunningException(peer.toString() + " indicates that port " + portId + " is not running");
+ } else if (protocol.isPortUnknown()) {
+ penalize(peer, penalizationMillis);
+ cleanup(protocol, peer);
+ throw new UnknownPortException(peer.toString() + " indicates that port " + portId + " is not known");
}
-
+
// negotiate the FlowFileCodec to use
logger.debug("{} negotiating codec", this);
codec = protocol.negotiateCodec(peer);
logger.debug("{} negotiated codec is {}", this, codec);
} catch (final PortNotRunningException | UnknownPortException e) {
- throw e;
+ throw e;
} catch (final Exception e) {
penalize(peer, penalizationMillis);
cleanup(protocol, peer);
-
+
final String message = String.format("%s failed to communicate with %s due to %s", this, peer == null ? clusterUrl : peer, e.toString());
error(message);
- if ( logger.isDebugEnabled() ) {
+ if (logger.isDebugEnabled()) {
logger.error("", e);
}
throw e;
}
-
+
connection = new EndpointConnection(peer, protocol, codec);
} else {
final long lastTimeUsed = connection.getLastTimeUsed();
final long millisSinceLastUse = System.currentTimeMillis() - lastTimeUsed;
-
- if ( commsTimeout > 0L && millisSinceLastUse >= commsTimeout ) {
+
+ if (commsTimeout > 0L && millisSinceLastUse >= commsTimeout) {
cleanup(connection.getSocketClientProtocol(), connection.getPeer());
connection = null;
} else {
@@ -389,68 +387,70 @@ public class EndpointConnectionPool {
protocol = connection.getSocketClientProtocol();
}
}
- } while ( connection == null || codec == null || commsSession == null || protocol == null );
+ } while (connection == null || codec == null || commsSession == null || protocol == null);
} catch (final Throwable t) {
- if ( commsSession != null ) {
- try {
- commsSession.close();
- } catch (final IOException ioe) {
- }
- }
-
- throw t;
+ if (commsSession != null) {
+ try {
+ commsSession.close();
+ } catch (final IOException ioe) {
+ }
+ }
+
+ throw t;
} finally {
- if ( !addBack.isEmpty() ) {
+ if (!addBack.isEmpty()) {
connectionQueue.addAll(addBack);
}
}
-
+
activeConnections.add(connection);
return connection;
}
-
-
+
public boolean offer(final EndpointConnection endpointConnection) {
- final Peer peer = endpointConnection.getPeer();
- if ( peer == null ) {
- return false;
- }
-
- final BlockingQueue<EndpointConnection> connectionQueue = connectionQueueMap.get(peer.getDescription());
- if ( connectionQueue == null ) {
- return false;
- }
-
- activeConnections.remove(endpointConnection);
- if ( shutdown ) {
- terminate(endpointConnection);
- return false;
- } else {
- endpointConnection.setLastTimeUsed();
- return connectionQueue.offer(endpointConnection);
- }
- }
-
+ final Peer peer = endpointConnection.getPeer();
+ if (peer == null) {
+ return false;
+ }
+
+ final BlockingQueue<EndpointConnection> connectionQueue = connectionQueueMap.get(peer.getDescription());
+ if (connectionQueue == null) {
+ return false;
+ }
+
+ activeConnections.remove(endpointConnection);
+ if (shutdown) {
+ terminate(endpointConnection);
+ return false;
+ } else {
+ endpointConnection.setLastTimeUsed();
+ return connectionQueue.offer(endpointConnection);
+ }
+ }
+
private void penalize(final PeerDescription peerDescription, final long penalizationMillis) {
Long expiration = peerTimeoutExpirations.get(peerDescription);
- if ( expiration == null ) {
+ if (expiration == null) {
expiration = Long.valueOf(0L);
}
-
+
final long newExpiration = Math.max(expiration, System.currentTimeMillis() + penalizationMillis);
peerTimeoutExpirations.put(peerDescription, Long.valueOf(newExpiration));
}
-
+
/**
- * Updates internal state map to penalize a PeerStatus that points to the specified peer
- * @param peer
+ * Updates internal state map to penalize a PeerStatus that points to the
+ * specified peer
+ *
+ * @param peer the peer
+ * @param penalizationMillis period of time to penalize a given peer
*/
public void penalize(final Peer peer, final long penalizationMillis) {
penalize(peer.getDescription(), penalizationMillis);
}
-
+
private void cleanup(final SocketClientProtocol protocol, final Peer peer) {
- if ( protocol != null && peer != null ) {
+ if (protocol != null && peer != null) {
try {
protocol.shutdown(peer);
} catch (final TransmissionDisabledException e) {
@@ -459,8 +459,8 @@ public class EndpointConnectionPool {
} catch (IOException e1) {
}
}
-
- if ( peer != null ) {
+
+ if (peer != null) {
try {
peer.close();
} catch (final TransmissionDisabledException e) {
@@ -470,15 +470,14 @@ public class EndpointConnectionPool {
}
}
}
-
+
private boolean isPeerRefreshNeeded(final List<PeerStatus> peerList) {
return (peerList == null || peerList.isEmpty() || System.currentTimeMillis() > peerRefreshTime + PEER_REFRESH_PERIOD);
}
-
-
+
private PeerStatus getNextPeerStatus(final TransferDirection direction) {
List<PeerStatus> peerList = peerStatuses;
- if ( isPeerRefreshNeeded(peerList) ) {
+ if (isPeerRefreshNeeded(peerList)) {
peerRefreshLock.lock();
try {
// now that we have the lock, check again that we need to refresh (because another thread
@@ -490,15 +489,15 @@ public class EndpointConnectionPool {
} catch (final Exception e) {
final String message = String.format("%s Failed to update list of peers due to %s", this, e.toString());
warn(message);
- if ( logger.isDebugEnabled() ) {
+ if (logger.isDebugEnabled()) {
logger.warn("", e);
}
-
- if ( eventReporter != null ) {
- eventReporter.reportEvent(Severity.WARNING, CATEGORY, message);
+
+ if (eventReporter != null) {
+ eventReporter.reportEvent(Severity.WARNING, CATEGORY, message);
}
}
-
+
this.peerStatuses = peerList;
peerRefreshTime = System.currentTimeMillis();
}
@@ -507,46 +506,46 @@ public class EndpointConnectionPool {
}
}
- if ( peerList == null || peerList.isEmpty() ) {
+ if (peerList == null || peerList.isEmpty()) {
return null;
}
PeerStatus peerStatus;
- for (int i=0; i < peerList.size(); i++) {
+ for (int i = 0; i < peerList.size(); i++) {
final long idx = peerIndex.getAndIncrement();
final int listIndex = (int) (idx % peerList.size());
peerStatus = peerList.get(listIndex);
-
- if ( isPenalized(peerStatus) ) {
+
+ if (isPenalized(peerStatus)) {
logger.debug("{} {} is penalized; will not communicate with this peer", this, peerStatus);
} else {
return peerStatus;
}
}
-
+
logger.debug("{} All peers appear to be penalized; returning null", this);
return null;
}
-
+
private boolean isPenalized(final PeerStatus peerStatus) {
final Long expirationEnd = peerTimeoutExpirations.get(peerStatus.getPeerDescription());
- return (expirationEnd == null ? false : expirationEnd > System.currentTimeMillis() );
+ return (expirationEnd == null ? false : expirationEnd > System.currentTimeMillis());
}
-
+
private List<PeerStatus> createPeerStatusList(final TransferDirection direction) throws IOException, HandshakeException, UnknownPortException, PortNotRunningException {
Set<PeerStatus> statuses = getPeerStatuses();
- if ( statuses == null ) {
+ if (statuses == null) {
refreshPeers();
statuses = getPeerStatuses();
- if ( statuses == null ) {
+ if (statuses == null) {
logger.debug("{} found no peers to connect to", this);
return Collections.emptyList();
}
}
-
+
final ClusterNodeInformation clusterNodeInfo = new ClusterNodeInformation();
final List<NodeInformation> nodeInfos = new ArrayList<>();
- for ( final PeerStatus peerStatus : statuses ) {
+ for (final PeerStatus peerStatus : statuses) {
final PeerDescription description = peerStatus.getPeerDescription();
final NodeInformation nodeInfo = new NodeInformation(description.getHostname(), description.getPort(), 0, description.isSecure(), peerStatus.getFlowFileCount());
nodeInfos.add(nodeInfo);
@@ -554,8 +553,7 @@ public class EndpointConnectionPool {
clusterNodeInfo.setNodeInformation(nodeInfos);
return formulateDestinationList(clusterNodeInfo, direction);
}
-
-
+
private Set<PeerStatus> getPeerStatuses() {
final PeerStatusCache cache = this.peerStatusCache;
if (cache == null || cache.getStatuses() == null || cache.getStatuses().isEmpty()) {
@@ -576,14 +574,14 @@ public class EndpointConnectionPool {
}
private Set<PeerStatus> fetchRemotePeerStatuses() throws IOException, HandshakeException, UnknownPortException, PortNotRunningException {
- final String hostname = clusterUrl.getHost();
+ final String hostname = clusterUrl.getHost();
final Integer port = getSiteToSitePort();
- if ( port == null ) {
+ if (port == null) {
throw new IOException("Remote instance of NiFi is not configured to allow site-to-site communications");
}
-
+
final PeerDescription clusterPeerDescription = new PeerDescription(hostname, port, clusterUrl.toString().startsWith("https://"));
- final CommunicationsSession commsSession = establishSiteToSiteConnection(hostname, port);
+ final CommunicationsSession commsSession = establishSiteToSiteConnection(hostname, port);
final Peer peer = new Peer(clusterPeerDescription, commsSession, "nifi://" + hostname + ":" + port, clusterUrl.toString());
final SocketClientProtocol clientProtocol = new SocketClientProtocol();
final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream());
@@ -593,11 +591,11 @@ public class EndpointConnectionPool {
clientProtocol.setTimeout(commsTimeout);
if (clientProtocol.getVersionNegotiator().getVersion() < 5) {
String portId = getPortIdentifier(TransferDirection.RECEIVE);
- if ( portId == null ) {
+ if (portId == null) {
portId = getPortIdentifier(TransferDirection.SEND);
}
-
- if ( portId == null ) {
+
+ if (portId == null) {
peer.close();
throw new IOException("Failed to determine the identifier of port " + remoteDestination.getName());
}
@@ -605,7 +603,7 @@ public class EndpointConnectionPool {
} else {
clientProtocol.handshake(peer, null);
}
-
+
final Set<PeerStatus> peerStatuses = clientProtocol.getPeerStatuses(peer);
persistPeerStatuses(peerStatuses);
@@ -632,14 +630,13 @@ public class EndpointConnectionPool {
return peerStatuses;
}
-
private void persistPeerStatuses(final Set<PeerStatus> statuses) {
- if ( peersFile == null ) {
- return;
- }
-
+ if (peersFile == null) {
+ return;
+ }
+
try (final OutputStream fos = new FileOutputStream(peersFile);
- final OutputStream out = new BufferedOutputStream(fos)) {
+ final OutputStream out = new BufferedOutputStream(fos)) {
for (final PeerStatus status : statuses) {
final PeerDescription description = status.getPeerDescription();
@@ -679,53 +676,52 @@ public class EndpointConnectionPool {
return statuses;
}
-
-
+
private CommunicationsSession establishSiteToSiteConnection(final PeerStatus peerStatus) throws IOException {
final PeerDescription description = peerStatus.getPeerDescription();
- return establishSiteToSiteConnection(description.getHostname(), description.getPort());
+ return establishSiteToSiteConnection(description.getHostname(), description.getPort());
}
-
+
private CommunicationsSession establishSiteToSiteConnection(final String hostname, final int port) throws IOException {
- final boolean siteToSiteSecure = isSecure();
+ final boolean siteToSiteSecure = isSecure();
final String destinationUri = "nifi://" + hostname + ":" + port;
CommunicationsSession commsSession = null;
try {
- if ( siteToSiteSecure ) {
- if ( sslContext == null ) {
- throw new IOException("Unable to communicate with " + hostname + ":" + port + " because it requires Secure Site-to-Site communications, but this instance is not configured for secure communications");
- }
-
- final SSLSocketChannel socketChannel = new SSLSocketChannel(sslContext, hostname, port, true);
- socketChannel.connect();
-
- commsSession = new SSLSocketChannelCommunicationsSession(socketChannel, destinationUri);
-
- try {
- commsSession.setUserDn(socketChannel.getDn());
- } catch (final CertificateNotYetValidException | CertificateExpiredException ex) {
- throw new IOException(ex);
- }
- } else {
- final SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress(hostname, port));
- commsSession = new SocketChannelCommunicationsSession(socketChannel, destinationUri);
- }
-
- commsSession.getOutput().getOutputStream().write(CommunicationsSession.MAGIC_BYTES);
- commsSession.setUri(destinationUri);
+ if (siteToSiteSecure) {
+ if (sslContext == null) {
+ throw new IOException("Unable to communicate with " + hostname + ":" + port
+ + " because it requires Secure Site-to-Site communications, but this instance is not configured for secure communications");
+ }
+
+ final SSLSocketChannel socketChannel = new SSLSocketChannel(sslContext, hostname, port, true);
+ socketChannel.connect();
+
+ commsSession = new SSLSocketChannelCommunicationsSession(socketChannel, destinationUri);
+
+ try {
+ commsSession.setUserDn(socketChannel.getDn());
+ } catch (final CertificateNotYetValidException | CertificateExpiredException ex) {
+ throw new IOException(ex);
+ }
+ } else {
+ final SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress(hostname, port));
+ commsSession = new SocketChannelCommunicationsSession(socketChannel, destinationUri);
+ }
+
+ commsSession.getOutput().getOutputStream().write(CommunicationsSession.MAGIC_BYTES);
+ commsSession.setUri(destinationUri);
} catch (final IOException ioe) {
- if ( commsSession != null ) {
+ if (commsSession != null) {
commsSession.close();
}
-
+
throw ioe;
}
-
+
return commsSession;
}
-
-
+
static List<PeerStatus> formulateDestinationList(final ClusterNodeInformation clusterNodeInfo, final TransferDirection direction) {
final Collection<NodeInformation> nodeInfoSet = clusterNodeInfo.getNodeInformation();
final int numDestinations = Math.max(128, nodeInfoSet.size());
@@ -743,26 +739,26 @@ public class EndpointConnectionPool {
final double percentageOfFlowFiles = Math.min(0.8D, ((double) flowFileCount / (double) totalFlowFileCount));
final double relativeWeighting = (direction == TransferDirection.SEND) ? (1 - percentageOfFlowFiles) : percentageOfFlowFiles;
final int entries = Math.max(1, (int) (numDestinations * relativeWeighting));
-
+
entryCountMap.put(nodeInfo, Math.max(1, entries));
totalEntries += entries;
}
-
+
final List<PeerStatus> destinations = new ArrayList<>(totalEntries);
- for (int i=0; i < totalEntries; i++) {
+ for (int i = 0; i < totalEntries; i++) {
destinations.add(null);
}
- for ( final Map.Entry<NodeInformation, Integer> entry : entryCountMap.entrySet() ) {
+ for (final Map.Entry<NodeInformation, Integer> entry : entryCountMap.entrySet()) {
final NodeInformation nodeInfo = entry.getKey();
final int numEntries = entry.getValue();
-
+
int skipIndex = numEntries;
- for (int i=0; i < numEntries; i++) {
+ for (int i = 0; i < numEntries; i++) {
int n = (skipIndex * i);
while (true) {
final int index = n % destinations.size();
PeerStatus status = destinations.get(index);
- if ( status == null ) {
+ if (status == null) {
final PeerDescription description = new PeerDescription(nodeInfo.getHostname(), nodeInfo.getSiteToSitePort(), nodeInfo.isSiteToSiteSecure());
status = new PeerStatus(description, nodeInfo.getTotalFlowFiles());
destinations.set(index, status);
@@ -776,7 +772,7 @@ public class EndpointConnectionPool {
final StringBuilder distributionDescription = new StringBuilder();
distributionDescription.append("New Weighted Distribution of Nodes:");
- for ( final Map.Entry<NodeInformation, Integer> entry : entryCountMap.entrySet() ) {
+ for (final Map.Entry<NodeInformation, Integer> entry : entryCountMap.entrySet()) {
final double percentage = entry.getValue() * 100D / (double) destinations.size();
distributionDescription.append("\n").append(entry.getKey()).append(" will receive ").append(percentage).append("% of data");
}
@@ -785,55 +781,54 @@ public class EndpointConnectionPool {
// Jumble the list of destinations.
return destinations;
}
-
-
+
private void cleanupExpiredSockets() {
- for ( final BlockingQueue<EndpointConnection> connectionQueue : connectionQueueMap.values()) {
+ for (final BlockingQueue<EndpointConnection> connectionQueue : connectionQueueMap.values()) {
final List<EndpointConnection> connections = new ArrayList<>();
-
+
EndpointConnection connection;
while ((connection = connectionQueue.poll()) != null) {
// If the socket has not been used in 10 seconds, shut it down.
final long lastUsed = connection.getLastTimeUsed();
- if ( lastUsed < System.currentTimeMillis() - idleExpirationMillis ) {
+ if (lastUsed < System.currentTimeMillis() - idleExpirationMillis) {
try {
connection.getSocketClientProtocol().shutdown(connection.getPeer());
} catch (final Exception e) {
- logger.debug("Failed to shut down {} using {} due to {}",
- new Object[] {connection.getSocketClientProtocol(), connection.getPeer(), e} );
+ logger.debug("Failed to shut down {} using {} due to {}",
+ new Object[]{connection.getSocketClientProtocol(), connection.getPeer(), e});
}
-
+
terminate(connection);
} else {
connections.add(connection);
}
}
-
+
connectionQueue.addAll(connections);
}
}
-
+
public void shutdown() {
shutdown = true;
- taskExecutor.shutdown();
- peerTimeoutExpirations.clear();
-
- for ( final EndpointConnection conn : activeConnections ) {
- conn.getPeer().getCommunicationsSession().interrupt();
+ taskExecutor.shutdown();
+ peerTimeoutExpirations.clear();
+
+ for (final EndpointConnection conn : activeConnections) {
+ conn.getPeer().getCommunicationsSession().interrupt();
}
- for ( final BlockingQueue<EndpointConnection> connectionQueue : connectionQueueMap.values() ) {
+ for (final BlockingQueue<EndpointConnection> connectionQueue : connectionQueueMap.values()) {
EndpointConnection state;
- while ( (state = connectionQueue.poll()) != null) {
+ while ((state = connectionQueue.poll()) != null) {
cleanup(state.getSocketClientProtocol(), state.getPeer());
}
}
}
-
+
public void terminate(final EndpointConnection connection) {
cleanup(connection.getSocketClientProtocol(), connection.getPeer());
}
-
+
private void refreshPeers() {
final PeerStatusCache existingCache = peerStatusCache;
if (existingCache != null && (existingCache.getTimestamp() + PEER_CACHE_MILLIS > System.currentTimeMillis())) {
@@ -851,69 +846,66 @@ public class EndpointConnectionPool {
}
}
}
-
-
+
public String getInputPortIdentifier(final String portName) throws IOException {
return getPortIdentifier(portName, inputPortMap);
}
-
+
public String getOutputPortIdentifier(final String portName) throws IOException {
- return getPortIdentifier(portName, outputPortMap);
+ return getPortIdentifier(portName, outputPortMap);
}
-
-
+
private String getPortIdentifier(final String portName, final Map<String, String> portMap) throws IOException {
- String identifier;
- remoteInfoReadLock.lock();
+ String identifier;
+ remoteInfoReadLock.lock();
try {
- identifier = portMap.get(portName);
+ identifier = portMap.get(portName);
} finally {
- remoteInfoReadLock.unlock();
+ remoteInfoReadLock.unlock();
}
-
- if ( identifier != null ) {
- return identifier;
+
+ if (identifier != null) {
+ return identifier;
}
-
+
refreshRemoteInfo();
- remoteInfoReadLock.lock();
+ remoteInfoReadLock.lock();
try {
- return portMap.get(portName);
+ return portMap.get(portName);
} finally {
- remoteInfoReadLock.unlock();
+ remoteInfoReadLock.unlock();
}
}
-
-
+
private ControllerDTO refreshRemoteInfo() throws IOException {
- final boolean webInterfaceSecure = clusterUrl.toString().startsWith("https");
+ final boolean webInterfaceSecure = clusterUrl.toString().startsWith("https");
final NiFiRestApiUtil utils = new NiFiRestApiUtil(webInterfaceSecure ? sslContext : null);
- final ControllerDTO controller = utils.getController(apiUri + "/controller", commsTimeout);
-
+ final ControllerDTO controller = utils.getController(apiUri + "/controller", commsTimeout);
+
remoteInfoWriteLock.lock();
try {
this.siteToSitePort = controller.getRemoteSiteListeningPort();
this.siteToSiteSecure = controller.isSiteToSiteSecure();
-
+
inputPortMap.clear();
for (final PortDTO inputPort : controller.getInputPorts()) {
- inputPortMap.put(inputPort.getName(), inputPort.getId());
+ inputPortMap.put(inputPort.getName(), inputPort.getId());
}
-
+
outputPortMap.clear();
- for ( final PortDTO outputPort : controller.getOutputPorts()) {
- outputPortMap.put(outputPort.getName(), outputPort.getId());
+ for (final PortDTO outputPort : controller.getOutputPorts()) {
+ outputPortMap.put(outputPort.getName(), outputPort.getId());
}
-
+
this.remoteRefreshTime = System.currentTimeMillis();
} finally {
- remoteInfoWriteLock.unlock();
+ remoteInfoWriteLock.unlock();
}
-
+
return controller;
}
-
+
/**
* @return the port that the remote instance is listening on for
* site-to-site communication, or <code>null</code> if the remote instance
@@ -930,7 +922,7 @@ public class EndpointConnectionPool {
return listeningPort;
}
} finally {
- remoteInfoReadLock.unlock();
+ remoteInfoReadLock.unlock();
}
final ControllerDTO controller = refreshRemoteInfo();
@@ -938,19 +930,16 @@ public class EndpointConnectionPool {
return listeningPort;
}
-
+
@Override
public String toString() {
return "EndpointConnectionPool[Cluster URL=" + clusterUrl + "]";
}
-
-
+
/**
- * Returns {@code true} if the remote instance is configured for secure site-to-site communications,
- * {@code false} otherwise.
- *
- * @return
- * @throws IOException
+ * @return {@code true} if the remote instance is configured for secure
+ * site-to-site communications, {@code false} otherwise
+ * @throws IOException if unable to check if secure
*/
public boolean isSecure() throws IOException {
remoteInfoReadLock.lock();
@@ -960,23 +949,23 @@ public class EndpointConnectionPool {
return secure;
}
} finally {
- remoteInfoReadLock.unlock();
+ remoteInfoReadLock.unlock();
}
final ControllerDTO controller = refreshRemoteInfo();
final Boolean isSecure = controller.isSiteToSiteSecure();
- if ( isSecure == null ) {
+ if (isSecure == null) {
throw new IOException("Remote NiFi instance " + clusterUrl + " is not currently configured to accept site-to-site connections");
}
-
+
return isSecure;
}
-
-
+
private class IdEnrichedRemoteDestination implements RemoteDestination {
+
private final RemoteDestination original;
private final String identifier;
-
+
public IdEnrichedRemoteDestination(final RemoteDestination original, final String identifier) {
this.original = original;
this.identifier = identifier;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/SocketClient.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/SocketClient.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/SocketClient.java
index 4aab3f7..33e4a66 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/SocketClient.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/socket/SocketClient.java
@@ -33,71 +33,71 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SocketClient implements SiteToSiteClient {
+
private static final Logger logger = LoggerFactory.getLogger(SocketClient.class);
-
+
private final SiteToSiteClientConfig config;
- private final EndpointConnectionPool pool;
- private final boolean compress;
- private final String portName;
- private final long penalizationNanos;
- private volatile String portIdentifier;
- private volatile boolean closed = false;
-
- public SocketClient(final SiteToSiteClientConfig config) {
- pool = new EndpointConnectionPool(config.getUrl(),
- createRemoteDestination(config.getPortIdentifier(), config.getPortName()),
- (int) config.getTimeout(TimeUnit.MILLISECONDS),
- (int) config.getIdleConnectionExpiration(TimeUnit.MILLISECONDS),
- config.getSslContext(), config.getEventReporter(), config.getPeerPersistenceFile());
-
- this.config = config;
- this.compress = config.isUseCompression();
- this.portIdentifier = config.getPortIdentifier();
- this.portName = config.getPortName();
- this.penalizationNanos = config.getPenalizationPeriod(TimeUnit.NANOSECONDS);
- }
-
- @Override
- public SiteToSiteClientConfig getConfig() {
- return config;
- }
-
- @Override
- public boolean isSecure() throws IOException {
- return pool.isSecure();
- }
-
- private String getPortIdentifier(final TransferDirection direction) throws IOException {
- final String id = this.portIdentifier;
- if ( id != null ) {
- return id;
- }
-
- final String portId;
- if ( direction == TransferDirection.SEND ) {
- portId = pool.getInputPortIdentifier(this.portName);
- } else {
- portId = pool.getOutputPortIdentifier(this.portName);
- }
-
- if (portId == null) {
- logger.debug("Unable to resolve port [{}] to an identifier", portName);
- } else {
- logger.debug("Resolved port [{}] to identifier [{}]", portName, portId);
- this.portIdentifier = portId;
- }
-
- return portId;
- }
-
-
- private RemoteDestination createRemoteDestination(final String portId, final String portName) {
- return new RemoteDestination() {
+ private final EndpointConnectionPool pool;
+ private final boolean compress;
+ private final String portName;
+ private final long penalizationNanos;
+ private volatile String portIdentifier;
+ private volatile boolean closed = false;
+
+ public SocketClient(final SiteToSiteClientConfig config) {
+ pool = new EndpointConnectionPool(config.getUrl(),
+ createRemoteDestination(config.getPortIdentifier(), config.getPortName()),
+ (int) config.getTimeout(TimeUnit.MILLISECONDS),
+ (int) config.getIdleConnectionExpiration(TimeUnit.MILLISECONDS),
+ config.getSslContext(), config.getEventReporter(), config.getPeerPersistenceFile());
+
+ this.config = config;
+ this.compress = config.isUseCompression();
+ this.portIdentifier = config.getPortIdentifier();
+ this.portName = config.getPortName();
+ this.penalizationNanos = config.getPenalizationPeriod(TimeUnit.NANOSECONDS);
+ }
+
+ @Override
+ public SiteToSiteClientConfig getConfig() {
+ return config;
+ }
+
+ @Override
+ public boolean isSecure() throws IOException {
+ return pool.isSecure();
+ }
+
+ private String getPortIdentifier(final TransferDirection direction) throws IOException {
+ final String id = this.portIdentifier;
+ if (id != null) {
+ return id;
+ }
+
+ final String portId;
+ if (direction == TransferDirection.SEND) {
+ portId = pool.getInputPortIdentifier(this.portName);
+ } else {
+ portId = pool.getOutputPortIdentifier(this.portName);
+ }
+
+ if (portId == null) {
+ logger.debug("Unable to resolve port [{}] to an identifier", portName);
+ } else {
+ logger.debug("Resolved port [{}] to identifier [{}]", portName, portId);
+ this.portIdentifier = portId;
+ }
+
+ return portId;
+ }
+
+ private RemoteDestination createRemoteDestination(final String portId, final String portName) {
+ return new RemoteDestination() {
@Override
public String getIdentifier() {
return portId;
}
-
+
@Override
public String getName() {
return portName;
@@ -113,113 +113,112 @@ public class SocketClient implements SiteToSiteClient {
return compress;
}
};
- }
-
- @Override
- public Transaction createTransaction(final TransferDirection direction) throws IOException {
- if ( closed ) {
- throw new IllegalStateException("Client is closed");
- }
- final String portId = getPortIdentifier(direction);
-
- if ( portId == null ) {
- throw new IOException("Could not find Port with name '" + portName + "' for remote NiFi instance");
- }
-
- final EndpointConnection connectionState = pool.getEndpointConnection(direction, getConfig());
- if ( connectionState == null ) {
- return null;
- }
-
- final Transaction transaction;
- try {
- transaction = connectionState.getSocketClientProtocol().startTransaction(
- connectionState.getPeer(), connectionState.getCodec(), direction);
- } catch (final Throwable t) {
- pool.terminate(connectionState);
- throw new IOException("Unable to create Transaction to communicate with " + connectionState.getPeer(), t);
- }
-
- // Wrap the transaction in a new one that will return the EndpointConnectionState back to the pool whenever
- // the transaction is either completed or canceled.
- final ObjectHolder<EndpointConnection> connectionStateRef = new ObjectHolder<>(connectionState);
- return new Transaction() {
- @Override
- public void confirm() throws IOException {
- transaction.confirm();
- }
-
- @Override
- public TransactionCompletion complete() throws IOException {
- try {
- return transaction.complete();
- } finally {
- final EndpointConnection state = connectionStateRef.get();
- if ( state != null ) {
- pool.offer(connectionState);
- connectionStateRef.set(null);
- }
- }
- }
-
- @Override
- public void cancel(final String explanation) throws IOException {
- try {
- transaction.cancel(explanation);
- } finally {
+ }
+
+ @Override
+ public Transaction createTransaction(final TransferDirection direction) throws IOException {
+ if (closed) {
+ throw new IllegalStateException("Client is closed");
+ }
+ final String portId = getPortIdentifier(direction);
+
+ if (portId == null) {
+ throw new IOException("Could not find Port with name '" + portName + "' for remote NiFi instance");
+ }
+
+ final EndpointConnection connectionState = pool.getEndpointConnection(direction, getConfig());
+ if (connectionState == null) {
+ return null;
+ }
+
+ final Transaction transaction;
+ try {
+ transaction = connectionState.getSocketClientProtocol().startTransaction(
+ connectionState.getPeer(), connectionState.getCodec(), direction);
+ } catch (final Throwable t) {
+ pool.terminate(connectionState);
+ throw new IOException("Unable to create Transaction to communicate with " + connectionState.getPeer(), t);
+ }
+
+ // Wrap the transaction in a new one that will return the EndpointConnectionState back to the pool whenever
+ // the transaction is either completed or canceled.
+ final ObjectHolder<EndpointConnection> connectionStateRef = new ObjectHolder<>(connectionState);
+ return new Transaction() {
+ @Override
+ public void confirm() throws IOException {
+ transaction.confirm();
+ }
+
+ @Override
+ public TransactionCompletion complete() throws IOException {
+ try {
+ return transaction.complete();
+ } finally {
final EndpointConnection state = connectionStateRef.get();
- if ( state != null ) {
+ if (state != null) {
+ pool.offer(connectionState);
+ connectionStateRef.set(null);
+ }
+ }
+ }
+
+ @Override
+ public void cancel(final String explanation) throws IOException {
+ try {
+ transaction.cancel(explanation);
+ } finally {
+ final EndpointConnection state = connectionStateRef.get();
+ if (state != null) {
pool.terminate(connectionState);
connectionStateRef.set(null);
}
- }
- }
-
- @Override
- public void error() {
- try {
- transaction.error();
- } finally {
+ }
+ }
+
+ @Override
+ public void error() {
+ try {
+ transaction.error();
+ } finally {
final EndpointConnection state = connectionStateRef.get();
- if ( state != null ) {
+ if (state != null) {
pool.terminate(connectionState);
connectionStateRef.set(null);
}
- }
- }
-
- @Override
- public void send(final DataPacket dataPacket) throws IOException {
- transaction.send(dataPacket);
- }
-
- @Override
- public void send(final byte[] content, final Map<String, String> attributes) throws IOException {
- transaction.send(content, attributes);
- }
-
- @Override
- public DataPacket receive() throws IOException {
- return transaction.receive();
- }
-
- @Override
- public TransactionState getState() throws IOException {
- return transaction.getState();
- }
-
- @Override
- public Communicant getCommunicant() {
- return transaction.getCommunicant();
- }
- };
- }
-
-
- @Override
- public void close() throws IOException {
- closed = true;
- pool.shutdown();
- }
-
+ }
+ }
+
+ @Override
+ public void send(final DataPacket dataPacket) throws IOException {
+ transaction.send(dataPacket);
+ }
+
+ @Override
+ public void send(final byte[] content, final Map<String, String> attributes) throws IOException {
+ transaction.send(content, attributes);
+ }
+
+ @Override
+ public DataPacket receive() throws IOException {
+ return transaction.receive();
+ }
+
+ @Override
+ public TransactionState getState() throws IOException {
+ return transaction.getState();
+ }
+
+ @Override
+ public Communicant getCommunicant() {
+ return transaction.getCommunicant();
+ }
+ };
+ }
+
+ @Override
+ public void close() throws IOException {
+ closed = true;
+ pool.shutdown();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/FlowFileCodec.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/FlowFileCodec.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/FlowFileCodec.java
index 1380e1b..e79fc47 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/FlowFileCodec.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/FlowFileCodec.java
@@ -38,13 +38,13 @@ public interface FlowFileCodec extends VersionedRemoteResource {
* Returns a List of all versions that this codec is able to support, in the
* order that they are preferred by the codec
*
- * @return
+ * @return all supported versions
*/
public List<Integer> getSupportedVersions();
/**
- * Encodes a DataPacket and its content as a single stream of data and writes
- * that stream to the output.
+ * Encodes a DataPacket and its content as a single stream of data and
+ * writes that stream to the output.
*
* @param dataPacket the data to serialize
* @param outStream the stream to write the data to
@@ -58,12 +58,13 @@ public interface FlowFileCodec extends VersionedRemoteResource {
* Decodes the contents of the InputStream, interpreting the data to
* determine the next DataPacket's attributes and content.
*
- * @param stream an InputStream containing DataPacket's content and attributes
+ * @param stream an InputStream containing DataPacket's content and
+ * attributes
*
- * @return the DataPacket that was created, or <code>null</code> if the stream
- * was out of data
+ * @return the DataPacket that was created, or <code>null</code> if the
+ * stream was out of data
*
- * @throws IOException
+ * @throws IOException if unable to read stream
* @throws ProtocolException if the input is malformed
* @throws TransmissionDisabledException if a user terminates the connection
*/
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/StandardFlowFileCodec.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/StandardFlowFileCodec.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/StandardFlowFileCodec.java
index 6fd92de..0bee537 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/StandardFlowFileCodec.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/codec/StandardFlowFileCodec.java
@@ -34,7 +34,8 @@ import org.apache.nifi.remote.util.StandardDataPacket;
import org.apache.nifi.stream.io.StreamUtils;
public class StandardFlowFileCodec implements FlowFileCodec {
- public static final int MAX_NUM_ATTRIBUTES = 25000;
+
+ public static final int MAX_NUM_ATTRIBUTES = 25000;
public static final String DEFAULT_FLOWFILE_PATH = "./";
@@ -43,30 +44,29 @@ public class StandardFlowFileCodec implements FlowFileCodec {
public StandardFlowFileCodec() {
versionNegotiator = new StandardVersionNegotiator(1);
}
-
+
@Override
public void encode(final DataPacket dataPacket, final OutputStream encodedOut) throws IOException {
final DataOutputStream out = new DataOutputStream(encodedOut);
-
+
final Map<String, String> attributes = dataPacket.getAttributes();
out.writeInt(attributes.size());
- for ( final Map.Entry<String, String> entry : attributes.entrySet() ) {
+ for (final Map.Entry<String, String> entry : attributes.entrySet()) {
writeString(entry.getKey(), out);
writeString(entry.getValue(), out);
}
-
+
out.writeLong(dataPacket.getSize());
-
+
final InputStream in = dataPacket.getData();
StreamUtils.copy(in, encodedOut);
encodedOut.flush();
}
-
@Override
public DataPacket decode(final InputStream stream) throws IOException, ProtocolException {
final DataInputStream in = new DataInputStream(stream);
-
+
final int numAttributes;
try {
numAttributes = in.readInt();
@@ -74,22 +74,22 @@ public class StandardFlowFileCodec implements FlowFileCodec {
// we're out of data.
return null;
}
-
+
// This is here because if the stream is not properly formed, we could get up to Integer.MAX_VALUE attributes, which will
// generally result in an OutOfMemoryError.
- if ( numAttributes > MAX_NUM_ATTRIBUTES ) {
- throw new ProtocolException("FlowFile exceeds maximum number of attributes with a total of " + numAttributes);
+ if (numAttributes > MAX_NUM_ATTRIBUTES) {
+ throw new ProtocolException("FlowFile exceeds maximum number of attributes with a total of " + numAttributes);
}
-
+
final Map<String, String> attributes = new HashMap<>(numAttributes);
- for (int i=0; i < numAttributes; i++) {
+ for (int i = 0; i < numAttributes; i++) {
final String attrName = readString(in);
final String attrValue = readString(in);
attributes.put(attrName, attrValue);
}
-
+
final long numBytes = in.readLong();
-
+
return new StandardDataPacket(attributes, stream, numBytes);
}
@@ -99,14 +99,13 @@ public class StandardFlowFileCodec implements FlowFileCodec {
out.write(bytes);
}
-
private String readString(final DataInputStream in) throws IOException {
final int numBytes = in.readInt();
final byte[] bytes = new byte[numBytes];
StreamUtils.fillBuffer(in, bytes, true);
return new String(bytes, "UTF-8");
}
-
+
@Override
public List<Integer> getSupportedVersions() {
return versionNegotiator.getSupportedVersions();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/HandshakeException.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/HandshakeException.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/HandshakeException.java
index d4d55e1..198aaef 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/HandshakeException.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/HandshakeException.java
@@ -18,13 +18,14 @@ package org.apache.nifi.remote.exception;
import java.io.IOException;
-
/**
- * A HandshakeException occurs when the client and the remote NiFi instance do not agree
- * on some condition during the handshake. For example, if the NiFi instance does not recognize
- * one of the parameters that the client passes during the Handshaking phase.
+ * A HandshakeException occurs when the client and the remote NiFi instance do
+ * not agree on some condition during the handshake. For example, if the NiFi
+ * instance does not recognize one of the parameters that the client passes
+ * during the Handshaking phase.
*/
public class HandshakeException extends IOException {
+
private static final long serialVersionUID = 178192341908726L;
public HandshakeException(final String message) {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/PortNotRunningException.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/PortNotRunningException.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/PortNotRunningException.java
index 8b97832..09fc05c 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/PortNotRunningException.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/PortNotRunningException.java
@@ -17,11 +17,12 @@
package org.apache.nifi.remote.exception;
/**
- * PortNotRunningException occurs when the remote NiFi instance reports
- * that the Port that the client is attempting to communicate with is not
- * currently running and therefore communications with that Port are not allowed.
+ * PortNotRunningException occurs when the remote NiFi instance reports that the
+ * Port that the client is attempting to communicate with is not currently
+ * running and therefore communications with that Port are not allowed.
*/
public class PortNotRunningException extends ProtocolException {
+
private static final long serialVersionUID = -2790940982005516375L;
public PortNotRunningException(final String message) {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/ProtocolException.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/ProtocolException.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/ProtocolException.java
index 45a4e15..cc6ae50 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/ProtocolException.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/ProtocolException.java
@@ -19,8 +19,8 @@ package org.apache.nifi.remote.exception;
import java.io.IOException;
/**
- * A ProtocolException occurs when unexpected data is received, for example
- * an invalid Response Code.
+ * A ProtocolException occurs when unexpected data is received, for example an
+ * invalid Response Code.
*/
public class ProtocolException extends IOException {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/UnknownPortException.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/UnknownPortException.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/UnknownPortException.java
index 592a1b3..4249075 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/UnknownPortException.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/exception/UnknownPortException.java
@@ -17,10 +17,12 @@
package org.apache.nifi.remote.exception;
/**
- * An UnknownPortException indicates that the remote NiFi instance has reported that
- * the endpoint that the client attempted to communicate with does not exist.
+ * An UnknownPortException indicates that the remote NiFi instance has reported
+ * that the endpoint that the client attempted to communicate with does not
+ * exist.
*/
public class UnknownPortException extends ProtocolException {
+
private static final long serialVersionUID = -2790940982005516375L;
public UnknownPortException(final String message) {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelCommunicationsSession.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelCommunicationsSession.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelCommunicationsSession.java
index 8065f57..6180c3c 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelCommunicationsSession.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelCommunicationsSession.java
@@ -22,11 +22,12 @@ import java.nio.channels.SocketChannel;
import org.apache.nifi.remote.AbstractCommunicationsSession;
public class SocketChannelCommunicationsSession extends AbstractCommunicationsSession {
+
private final SocketChannel channel;
private final SocketChannelInput request;
private final SocketChannelOutput response;
private int timeout = 30000;
-
+
public SocketChannelCommunicationsSession(final SocketChannel socketChannel, final String uri) throws IOException {
super(uri);
request = new SocketChannelInput(socketChannel);
@@ -34,12 +35,12 @@ public class SocketChannelCommunicationsSession extends AbstractCommunicationsSe
channel = socketChannel;
socketChannel.configureBlocking(false);
}
-
+
@Override
public boolean isClosed() {
return !channel.isConnected();
}
-
+
@Override
public SocketChannelInput getInput() {
return request;
@@ -65,28 +66,28 @@ public class SocketChannelCommunicationsSession extends AbstractCommunicationsSe
@Override
public void close() throws IOException {
IOException suppressed = null;
-
+
try {
request.consume();
} catch (final IOException ioe) {
suppressed = ioe;
}
-
+
try {
channel.close();
} catch (final IOException ioe) {
- if ( suppressed != null ) {
+ if (suppressed != null) {
ioe.addSuppressed(suppressed);
}
-
+
throw ioe;
}
-
- if ( suppressed != null ) {
+
+ if (suppressed != null) {
throw suppressed;
}
}
-
+
@Override
public boolean isDataAvailable() {
return request.isDataAvailable();
@@ -101,7 +102,7 @@ public class SocketChannelCommunicationsSession extends AbstractCommunicationsSe
public long getBytesRead() {
return request.getBytesRead();
}
-
+
@Override
public void interrupt() {
request.interrupt();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelInput.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelInput.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelInput.java
index 7dffddd..68a8dc4 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelInput.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelInput.java
@@ -26,18 +26,19 @@ import org.apache.nifi.remote.io.InterruptableInputStream;
import org.apache.nifi.remote.protocol.CommunicationsInput;
public class SocketChannelInput implements CommunicationsInput {
+
private final SocketChannelInputStream socketIn;
private final ByteCountingInputStream countingIn;
private final InputStream bufferedIn;
private final InterruptableInputStream interruptableIn;
-
+
public SocketChannelInput(final SocketChannel socketChannel) throws IOException {
this.socketIn = new SocketChannelInputStream(socketChannel);
countingIn = new ByteCountingInputStream(socketIn);
bufferedIn = new BufferedInputStream(countingIn);
interruptableIn = new InterruptableInputStream(bufferedIn);
}
-
+
@Override
public InputStream getInputStream() throws IOException {
return interruptableIn;
@@ -46,7 +47,7 @@ public class SocketChannelInput implements CommunicationsInput {
public void setTimeout(final int millis) {
socketIn.setTimeout(millis);
}
-
+
public boolean isDataAvailable() {
try {
return interruptableIn.available() > 0;
@@ -54,12 +55,12 @@ public class SocketChannelInput implements CommunicationsInput {
return false;
}
}
-
+
@Override
public long getBytesRead() {
return countingIn.getBytesRead();
}
-
+
public void interrupt() {
interruptableIn.interrupt();
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelOutput.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelOutput.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelOutput.java
index 26c0164..13974a5 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelOutput.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/SocketChannelOutput.java
@@ -26,32 +26,33 @@ import org.apache.nifi.remote.io.InterruptableOutputStream;
import org.apache.nifi.remote.protocol.CommunicationsOutput;
public class SocketChannelOutput implements CommunicationsOutput {
+
private final SocketChannelOutputStream socketOutStream;
private final ByteCountingOutputStream countingOut;
private final OutputStream bufferedOut;
private final InterruptableOutputStream interruptableOut;
-
+
public SocketChannelOutput(final SocketChannel socketChannel) throws IOException {
socketOutStream = new SocketChannelOutputStream(socketChannel);
countingOut = new ByteCountingOutputStream(socketOutStream);
bufferedOut = new BufferedOutputStream(countingOut);
interruptableOut = new InterruptableOutputStream(bufferedOut);
}
-
+
@Override
public OutputStream getOutputStream() throws IOException {
return interruptableOut;
}
-
+
public void setTimeout(final int timeout) {
socketOutStream.setTimeout(timeout);
}
-
+
@Override
public long getBytesWritten() {
return countingOut.getBytesWritten();
}
-
+
public void interrupt() {
interruptableOut.interrupt();
}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelCommunicationsSession.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelCommunicationsSession.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelCommunicationsSession.java
index 50e9162..5e5abc7 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelCommunicationsSession.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelCommunicationsSession.java
@@ -21,17 +21,18 @@ import java.io.IOException;
import org.apache.nifi.remote.AbstractCommunicationsSession;
public class SSLSocketChannelCommunicationsSession extends AbstractCommunicationsSession {
+
private final SSLSocketChannel channel;
private final SSLSocketChannelInput request;
private final SSLSocketChannelOutput response;
-
+
public SSLSocketChannelCommunicationsSession(final SSLSocketChannel channel, final String uri) {
super(uri);
request = new SSLSocketChannelInput(channel);
response = new SSLSocketChannelOutput(channel);
this.channel = channel;
}
-
+
@Override
public SSLSocketChannelInput getInput() {
return request;
@@ -55,33 +56,33 @@ public class SSLSocketChannelCommunicationsSession extends AbstractCommunication
@Override
public void close() throws IOException {
IOException suppressed = null;
-
+
try {
request.consume();
} catch (final IOException ioe) {
suppressed = ioe;
}
-
+
try {
channel.close();
} catch (final IOException ioe) {
- if ( suppressed != null ) {
+ if (suppressed != null) {
ioe.addSuppressed(suppressed);
}
-
+
throw ioe;
}
-
- if ( suppressed != null ) {
+
+ if (suppressed != null) {
throw suppressed;
}
}
-
+
@Override
public boolean isClosed() {
return channel.isClosed();
}
-
+
@Override
public boolean isDataAvailable() {
try {
@@ -105,7 +106,7 @@ public class SSLSocketChannelCommunicationsSession extends AbstractCommunication
public void interrupt() {
channel.interrupt();
}
-
+
@Override
public String toString() {
return super.toString() + "[SSLSocketChannel=" + channel + "]";
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelInput.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelInput.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelInput.java
index 01fb9f2..6cd2344 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelInput.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelInput.java
@@ -24,25 +24,26 @@ import org.apache.nifi.stream.io.ByteCountingInputStream;
import org.apache.nifi.remote.protocol.CommunicationsInput;
public class SSLSocketChannelInput implements CommunicationsInput {
+
private final SSLSocketChannelInputStream in;
private final ByteCountingInputStream countingIn;
private final InputStream bufferedIn;
-
+
public SSLSocketChannelInput(final SSLSocketChannel socketChannel) {
in = new SSLSocketChannelInputStream(socketChannel);
countingIn = new ByteCountingInputStream(in);
this.bufferedIn = new BufferedInputStream(countingIn);
}
-
+
@Override
public InputStream getInputStream() throws IOException {
return bufferedIn;
}
-
+
public boolean isDataAvailable() throws IOException {
return bufferedIn.available() > 0;
}
-
+
@Override
public long getBytesRead() {
return countingIn.getBytesRead();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelOutput.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelOutput.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelOutput.java
index dc3d68f..33d13cb 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelOutput.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/io/socket/ssl/SSLSocketChannelOutput.java
@@ -24,9 +24,10 @@ import org.apache.nifi.stream.io.ByteCountingOutputStream;
import org.apache.nifi.remote.protocol.CommunicationsOutput;
public class SSLSocketChannelOutput implements CommunicationsOutput {
+
private final OutputStream out;
private final ByteCountingOutputStream countingOut;
-
+
public SSLSocketChannelOutput(final SSLSocketChannel channel) {
countingOut = new ByteCountingOutputStream(new SSLSocketChannelOutputStream(channel));
out = new BufferedOutputStream(countingOut);
@@ -36,7 +37,7 @@ public class SSLSocketChannelOutput implements CommunicationsOutput {
public OutputStream getOutputStream() throws IOException {
return out;
}
-
+
@Override
public long getBytesWritten() {
return countingOut.getBytesWritten();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/ClientProtocol.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/ClientProtocol.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/ClientProtocol.java
index 36a0e8d..2efea11 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/ClientProtocol.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/ClientProtocol.java
@@ -48,37 +48,27 @@ public interface ClientProtocol extends VersionedRemoteResource {
boolean isReadyForFileTransfer();
-
-
-
Transaction startTransaction(Peer peer, FlowFileCodec codec, TransferDirection direction) throws IOException;
-
-
+
/**
- * returns <code>true</code> if remote instance indicates that the port is
+ * @return <code>true</code> if remote instance indicates that the port is
* invalid
- *
- * @return
* @throws IllegalStateException if a handshake has not successfully
* completed
*/
boolean isPortInvalid() throws IllegalStateException;
/**
- * returns <code>true</code> if remote instance indicates that the port is
+ * @return <code>true</code> if remote instance indicates that the port is
* unknown
- *
- * @return
* @throws IllegalStateException if a handshake has not successfully
* completed
*/
boolean isPortUnknown();
/**
- * returns <code>true</code> if remote instance indicates that the port's
+ * @return <code>true</code> if remote instance indicates that the port's
* destination is full
- *
- * @return
* @throws IllegalStateException if a handshake has not successfully
* completed
*/
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsInput.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsInput.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsInput.java
index 5e56902..3fa3e96 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsInput.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsInput.java
@@ -23,10 +23,11 @@ public interface CommunicationsInput {
/**
* Reads all data currently on the socket and throws it away
- * @throws IOException
+ *
+ * @throws IOException if unable to consume
*/
void consume() throws IOException;
-
+
InputStream getInputStream() throws IOException;
long getBytesRead();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsSession.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsSession.java b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsSession.java
index d009cec..aff73ba 100644
--- a/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsSession.java
+++ b/nifi/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/protocol/CommunicationsSession.java
@@ -55,10 +55,8 @@ public interface CommunicationsSession extends Closeable {
void interrupt();
/**
- * Returns <code>true</code> if the connection is closed, <code>false</code>
- * otherwise.
- *
- * @return
+ * @return <code>true</code> if the connection is closed, <code>false</code>
+ * otherwise
*/
boolean isClosed();
}