13 | * When a class or method
14 | * is so designated it will not change within a minor release,
15 | * i.e. 1.1 -> 1.2, in a way that would make it no longer backwardly compatible
16 | * with an earlier version within the release.
17 | *
18 | * Classes or methods with the annotation may still change in major releases,
19 | * i.e. 1.x -> 2.0.
20 | *
21 | */
22 | @Target( {ElementType.TYPE,ElementType.METHOD} )
23 | @Retention(RetentionPolicy.RUNTIME)
24 | @Documented
25 | public @interface StableApi
26 | {
27 | }
28 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/content/ContentIOException.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content;
2 |
3 | import org.gengine.api.StableApi;
4 | import org.gengine.error.GengineRuntimeException;
5 |
6 |
7 | /**
8 | * Wraps a general Exceptions that occurred while reading or writing
9 | * content.
10 | *
11 | * @see Throwable#getCause()
12 | *
13 | */
14 | @StableApi
15 | public class ContentIOException extends GengineRuntimeException
16 | {
17 | private static final long serialVersionUID = 3258130249983276087L;
18 |
19 | public ContentIOException(String msg)
20 | {
21 | super(msg);
22 | }
23 |
24 | public ContentIOException(String msg, Throwable cause)
25 | {
26 | super(msg, cause);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/content/ContentReference.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content;
2 |
3 | import org.gengine.content.handler.ContentReferenceHandler;
4 |
5 | /**
6 | * A reference to content by its URI and media type (mimetype).
7 | *
8 | * @see {@link ContentReferenceHandler}
9 | *
10 | */
11 | public class ContentReference
12 | {
13 |
14 | private String uri;
15 | private String mediaType;
16 | private Long size;
17 |
18 | public ContentReference()
19 | {
20 | }
21 |
22 | public ContentReference(String uri, String mediaType)
23 | {
24 | super();
25 | this.uri = uri;
26 | this.mediaType = mediaType;
27 | }
28 |
29 | public ContentReference(String uri, String mediaType, Long size)
30 | {
31 | super();
32 | this.uri = uri;
33 | this.mediaType = mediaType;
34 | this.size = size;
35 | }
36 |
37 | /**
38 | * Gets the URI for the content reference
39 | *
40 | * @return the content URI
41 | */
42 | public String getUri()
43 | {
44 | return uri;
45 | }
46 |
47 | /**
48 | * Sets the URI for the content reference
49 | *
50 | * @param uri
51 | */
52 | public void setUri(String uri)
53 | {
54 | this.uri = uri;
55 | }
56 |
57 | /**
58 | * Gets the media type (mimetype) of the content reference
59 | *
60 | * @return media type
61 | */
62 | public String getMediaType()
63 | {
64 | return mediaType;
65 | }
66 |
67 | /**
68 | * Sets the media type (mimetype) of the content reference
69 | *
70 | * @param mediaType
71 | */
72 | public void setMediaType(String mediaType)
73 | {
74 | this.mediaType = mediaType;
75 | }
76 |
77 | /**
78 | * Gets the size of the content binary if available
79 | *
80 | * @return
81 | */
82 | public Long getSize()
83 | {
84 | return size;
85 | }
86 |
87 | /**
88 | * Sets the size of the content binary
89 | *
90 | * @param size
91 | */
92 | public void setSize(Long size)
93 | {
94 | this.size = size;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/content/ContentWorkResult.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * The result of some operation on content which includes a content reference
7 | * and details about the operation.
8 | *
9 | * The content reference could indicate the source content reference on which the
10 | * work was requested or could be a new target content reference.
11 | *
12 | */
13 | public class ContentWorkResult
14 | {
15 | private ContentReference contentReference;
16 | private Map details;
17 |
18 | public ContentWorkResult()
19 | {
20 | }
21 |
22 | public ContentWorkResult(ContentReference contentReference, Map details)
23 | {
24 | this.contentReference = contentReference;
25 | this.details = details;
26 | }
27 |
28 | /**
29 | * Gets the content reference associated with the result.
30 | *
31 | * @return the content reference
32 | */
33 | public ContentReference getContentReference()
34 | {
35 | return contentReference;
36 | }
37 |
38 | /**
39 | * Sets the content reference associated with the result.
40 | *
41 | * @param contentReference
42 | */
43 | public void setContentReference(ContentReference contentReference)
44 | {
45 | this.contentReference = contentReference;
46 | }
47 |
48 | /**
49 | * Gets the additional details of the result of the content work.
50 | *
51 | * @return additional details
52 | */
53 | public Map getDetails()
54 | {
55 | return details;
56 | }
57 |
58 | /**
59 | * Sets the additional details of the result of the content work.
60 | *
61 | * @param details
62 | */
63 | public void setDetails(Map details)
64 | {
65 | this.details = details;
66 | }
67 |
68 | /**
69 | * Convenience method for getting a specific result detail.
70 | *
71 | * @param detailKey
72 | * @return the result detail
73 | */
74 | public Object getDetail(String detailKey)
75 | {
76 | if (details == null)
77 | {
78 | return null;
79 | }
80 | return details.get(detailKey);
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/content/ContentWorker.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content;
2 |
3 | /**
4 | * Defines a low-level worker that performs some action on content, i.e. performing
5 | * a transformation, extracting metadata, computing a hash, etc.
6 | *
7 | */
8 | public interface ContentWorker
9 | {
10 |
11 | /**
12 | * Gets whether or not the dependencies of the worker have been
13 | * properly configured for its normal operation, i.e. content reference handlers,
14 | * command line applications, etc.
15 | *
16 | * @return true if the worker is available
17 | */
18 | public boolean isAvailable();
19 |
20 | /**
21 | * Gets a string returning name and version information.
22 | *
23 | * @return the version string
24 | */
25 | public String getVersionString();
26 |
27 |
28 | /**
29 | * Gets a string returning detailed version information such as JVM
30 | * or command line application's version output
31 | *
32 | * @return the version string
33 | */
34 | public String getVersionDetailsString();
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/content/file/FileProvider.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.file;
2 |
3 | import java.io.File;
4 |
5 | /**
6 | * Defines methods to create files. Implementations might include leverage Java's temporary
7 | * file components, explicit user-defined directories, etc.
8 | *
9 | */
10 | public interface FileProvider
11 | {
12 |
13 | /**
14 | * Create a file with the given prefix and suffix.
15 | *
16 | * @param prefix
17 | * @param suffix
18 | * @return the newly created File object
19 | */
20 | public File createFile(String prefix, String suffix);
21 |
22 | /**
23 | * Determines whether or not the file provider is available.
24 | *
25 | * Some implementations might check permissions via this method.
26 | *
27 | * @return whether or not the file provider is available as configured
28 | */
29 | public boolean isAvailable();
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/content/handler/FileContentReferenceHandler.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.handler;
2 |
3 | import java.io.File;
4 |
5 | import org.gengine.content.ContentIOException;
6 | import org.gengine.content.ContentReference;
7 |
8 | /**
9 | * Adds file handling to the ContentReferenceHandler interface.
10 | *
11 | */
12 | public interface FileContentReferenceHandler extends ContentReferenceHandler
13 | {
14 |
15 | /**
16 | * Gets a File object for the given content reference, optionally waiting for the
17 | * file to be available and match the expected file size.
18 | *
19 | * This is useful for implementations that already use a file-based implementation
20 | * and can prevent workers from unnecessarily copying I/O streams.
21 | *
22 | * @param contentReference
23 | * @param waitForTransfer
24 | * @return the File for the content reference
25 | * @throws ContentIOException
26 | * @throws InterruptedException
27 | */
28 | public File getFile(ContentReference contentReference, boolean waitForTransfer) throws ContentIOException, InterruptedException;
29 | }
30 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/content/mediatype/FileMediaTypeService.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.mediatype;
2 |
3 | import java.io.File;
4 |
5 | /**
6 | * Defines a service for getting extensions for media types and vice versa.
7 | *
8 | */
9 | public interface FileMediaTypeService
10 | {
11 |
12 | /**
13 | * Get the extension for the specified internet media type
14 | *
15 | * @param mediaType a valid media type
16 | * @return Returns the default extension for the media type
17 | */
18 | public String getExtension(String mediaType);
19 |
20 | /**
21 | * Get the internet media type for the specified extension
22 | *
23 | * @param extension a valid file extension
24 | * @return Returns a valid media type if found, or null if does not exist
25 | */
26 | public String getMediaType(String extension);
27 |
28 | /**
29 | * Get the internet media type for the specified file using only its
30 | * file name, no inspection
31 | *
32 | * @param file
33 | * @return Returns a valid media type if found, or null if does not exist
34 | */
35 | public String getMediaTypeByName(File file);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/content/mediatype/FileMediaTypeServiceImpl.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.mediatype;
2 |
3 | import java.io.File;
4 |
5 | import org.apache.commons.logging.Log;
6 | import org.apache.commons.logging.LogFactory;
7 | import org.apache.tika.Tika;
8 | import org.apache.tika.config.TikaConfig;
9 | import org.apache.tika.mime.MimeType;
10 | import org.apache.tika.mime.MimeTypeException;
11 | import org.gengine.error.GengineRuntimeException;
12 |
13 | /**
14 | * Implementation of FileMediaTypeService which delegates to Apache Tika
15 | * to do the actual work.
16 | *
17 | */
18 | public class FileMediaTypeServiceImpl implements FileMediaTypeService
19 | {
20 |
21 | private static final Log logger = LogFactory.getLog(FileMediaTypeServiceImpl.class);
22 |
23 | protected TikaConfig tikaConfig;
24 | protected Tika tika;
25 |
26 | public FileMediaTypeServiceImpl(TikaConfig tikaConfig)
27 | {
28 | this.tikaConfig = tikaConfig;
29 | init();
30 | }
31 |
32 | public void init()
33 | {
34 | if (tikaConfig == null)
35 | {
36 | logger.debug("Initializing with default Tika config");
37 | tikaConfig = TikaConfig.getDefaultConfig();
38 | }
39 | if (tika == null)
40 | {
41 | tika = new Tika(tikaConfig);
42 | }
43 | }
44 |
45 | @Override
46 | public String getExtension(String mimetype)
47 | {
48 | try
49 | {
50 | MimeType tikaMimeType = tikaConfig.getMimeRepository().forName(mimetype);
51 | if (tikaMimeType != null)
52 | {
53 | String tikaExtension = tikaMimeType.getExtension();
54 | if (tikaExtension.startsWith("."))
55 | {
56 | tikaExtension = tikaExtension.substring(1, tikaExtension.length());
57 | }
58 | return tikaExtension;
59 | }
60 | }
61 | catch (MimeTypeException e)
62 | {
63 | throw new GengineRuntimeException("Could not get extension for mimetype", e);
64 | }
65 |
66 | return null;
67 | }
68 |
69 | @Override
70 | public String getMediaType(String extension)
71 | {
72 | return tika.detect("*." + extension);
73 | }
74 |
75 | @Override
76 | public String getMediaTypeByName(File file)
77 | {
78 | return tika.detect(file.getName());
79 | }
80 |
81 | public MimeType getTikaMimeType(String mimetype) throws MimeTypeException
82 | {
83 | return tikaConfig.getMimeRepository().forName(mimetype);
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/util/CloneField.java:
--------------------------------------------------------------------------------
1 | package org.gengine.util;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Annotation to be placed on getter methods to indicate the field should
10 | * be copied during copying and merging
11 | *
12 | */
13 | @Retention(RetentionPolicy.RUNTIME)
14 | @Target(ElementType.METHOD)
15 | public @interface CloneField
16 | {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/util/Mergable.java:
--------------------------------------------------------------------------------
1 | package org.gengine.util;
2 |
3 | /**
4 | * Defines that a class can be merged with the overriding values from another
5 | * object of the same type.
6 | *
7 | * @param
8 | */
9 | public interface Mergable
10 | {
11 |
12 | /**
13 | * Merge the non-null field values from the given override object
14 | *
15 | * @param override
16 | */
17 | public void merge(T override);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/gengine-commons/src/main/java/org/gengine/util/ToStringProperty.java:
--------------------------------------------------------------------------------
1 | package org.gengine.util;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Annotation to indicate that a method should be included in toString
10 | *
11 | */
12 | @Retention(RetentionPolicy.RUNTIME)
13 | @Target(ElementType.METHOD)
14 | public @interface ToStringProperty
15 | {
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/java/org/gengine/content/file/OverridingTempFileProvider.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.file;
2 |
3 | /**
4 | * Class which overrides TempFileProvider's temp file dir for testing
5 | *
6 | */
7 | public class OverridingTempFileProvider extends TempFileProvider
8 | {
9 | public static final String OVERRIDE_TEMP_FILE_DIR = "GengineTest";
10 |
11 | protected static String getApplicationTempFileDir()
12 | {
13 | return OVERRIDE_TEMP_FILE_DIR;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/java/org/gengine/content/file/OverridingTempFileProviderTest.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.file;
2 |
3 | import java.io.File;
4 |
5 | import org.junit.Test;
6 | import static org.junit.Assert.*;
7 |
8 | /**
9 | * Tests that TempFileProvider's temp file dir can be overridden
10 | *
11 | */
12 | public class OverridingTempFileProviderTest
13 | {
14 |
15 | /**
16 | * Tests that TempFileProvider's temp file dir can be overridden
17 | */
18 | @Test
19 | public void testDir()
20 | {
21 | File tempFile = OverridingTempFileProvider.getTempDir();
22 | assertTrue(tempFile.getPath().contains(OverridingTempFileProvider.APPLICATION_TEMP_FILE_DIR));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/java/org/gengine/content/file/TempFileProviderTest.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.file;
2 |
3 | import java.io.File;
4 |
5 | import junit.framework.TestCase;
6 |
7 | /**
8 | * Unit test for TempFileProvider
9 | *
10 | * @see org.gengine.content.file.TempFileProvider
11 | *
12 | */
13 | public class TempFileProviderTest extends TestCase
14 | {
15 | /**
16 | * test of getTempDir
17 | *
18 | * @throws Exception
19 | */
20 | public void testTempDir() throws Exception
21 | {
22 | File tempDir = TempFileProvider.getTempDir();
23 | assertTrue("Not a directory", tempDir.isDirectory());
24 | File tempDirParent = tempDir.getParentFile();
25 |
26 | // create a temp file
27 | File tempFile = File.createTempFile("AAAA", ".tmp");
28 | File tempFileParent = tempFile.getParentFile();
29 |
30 | // they should be equal
31 | assertEquals("Our temp dir not subdirectory system temp directory",
32 | tempFileParent, tempDirParent);
33 | }
34 |
35 | /**
36 | * test create a temporary file
37 | *
38 | * create another file with the same prefix and suffix.
39 | * @throws Exception
40 | */
41 | public void testTempFile() throws Exception
42 | {
43 | File tempFile = TempFileProvider.createTempFile("AAAA", ".tmp");
44 | File tempFileParent = tempFile.getParentFile();
45 | File tempDir = TempFileProvider.getTempDir();
46 | assertEquals("Temp file not located in our temp directory",
47 | tempDir, tempFileParent);
48 |
49 | /**
50 | * Create another temp file and then delete it.
51 | */
52 | File tempFile2 = TempFileProvider.createTempFile("AAAA", ".tmp");
53 | tempFile2.delete();
54 | }
55 |
56 | /**
57 | * test create a temporary file with a directory
58 | *
59 | * create another file with the same prefix and suffix.
60 | * @throws Exception
61 | */
62 | public void testTempFileWithDir() throws Exception
63 | {
64 | File tempDir = TempFileProvider.getTempDir();
65 | File tempFile = TempFileProvider.createTempFile("AAAA", ".tmp", tempDir);
66 | File tempFileParent = tempFile.getParentFile();
67 | assertEquals("Temp file not located in our temp directory",
68 | tempDir, tempFileParent);
69 |
70 | /**
71 | * Create another temp file and then delete it.
72 | */
73 | File tempFile2 = TempFileProvider.createTempFile("AAAA", ".tmp", tempDir);
74 | tempFile2.delete();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/java/org/gengine/content/handler/FileContentReferenceHandlerImplTest.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.handler;
2 |
3 | import java.util.UUID;
4 |
5 | import org.apache.commons.lang3.StringUtils;
6 | import org.gengine.content.ContentReference;
7 | import org.gengine.content.file.FileProvider;
8 | import org.gengine.content.file.FileProviderImpl;
9 | import org.gengine.content.file.TempFileProvider;
10 | import org.junit.Before;
11 | import org.junit.Test;
12 |
13 | import static junit.framework.Assert.*;
14 |
15 | /**
16 | * Tests of the file content reference handler
17 | *
18 | * @see {@link FileContentReferenceHandler}
19 | */
20 | public class FileContentReferenceHandlerImplTest
21 | {
22 | private ContentReferenceHandler handler;
23 |
24 | @Before
25 | public void setUp()
26 | {
27 | FileProvider fileProvider = new FileProviderImpl(
28 | TempFileProvider.getTempDir().getPath());
29 | handler = new FileContentReferenceHandlerImpl();
30 | ((FileContentReferenceHandlerImpl) handler).setFileProvider(fileProvider);
31 | }
32 |
33 | protected void checkReference(String fileName, String mediaType)
34 | {
35 | ContentReference reference = handler.createContentReference(fileName, mediaType);
36 | assertEquals(mediaType, reference.getMediaType());
37 |
38 | String uri = reference.getUri();
39 | String createdFileName = uri.split("\\/")[uri.split("\\/").length-1];
40 |
41 | String origPrefix = fileName.substring(0, StringUtils.lastIndexOf(fileName, "."));
42 | String origSuffix = fileName.substring(StringUtils.lastIndexOf(fileName, "."), fileName.length());
43 | assertTrue("ContentReference file name '" + createdFileName +
44 | "' did not contain original file name prefix '" + origPrefix + "'",
45 | createdFileName.contains(origPrefix));
46 | assertTrue("ContentReference file name '" + createdFileName +
47 | "' did not contain original file name suffix '" + origPrefix + "'",
48 | createdFileName.contains(origSuffix));
49 | }
50 |
51 | @Test
52 | public void testSimpleReference()
53 | {
54 | checkReference("myfile.txt", "text/plain");
55 | }
56 |
57 | @Test
58 | public void testPathReference()
59 | {
60 | checkReference("my.file.txt", "text/plain");
61 | }
62 |
63 | @Test
64 | public void testFileExists()
65 | {
66 | String fileName = "test-" + UUID.randomUUID().toString() + ".txt";
67 | ContentReference reference = handler.createContentReference(fileName, "text/plain");
68 | assertTrue(handler.isContentReferenceExists(reference));
69 |
70 | String nonExistentFileUri = reference.getUri().replace(fileName, "NONEXISTENTFILE.txt");
71 | ContentReference nonExistentReference = new ContentReference(nonExistentFileUri, "text/plain");
72 | assertFalse(handler.isContentReferenceExists(nonExistentReference));
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/java/org/gengine/content/mediatype/MediaTypeServiceTest.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.mediatype;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 |
6 | import static junit.framework.Assert.*;
7 |
8 | /**
9 | * Tests the media type service
10 | *
11 | * @see {@link FileMediaTypeService}
12 | *
13 | */
14 | public class MediaTypeServiceTest
15 | {
16 |
17 | private FileMediaTypeService mediaTypeService;
18 |
19 | @Before
20 | public void setUp()
21 | {
22 | mediaTypeService = new FileMediaTypeServiceImpl(null);
23 | ((FileMediaTypeServiceImpl) mediaTypeService).init();
24 | }
25 |
26 | @Test
27 | public void testGetMediaTypeFromExtension()
28 | {
29 | assertEquals("text/plain", mediaTypeService.getMediaType("txt"));
30 | assertEquals("application/pdf", mediaTypeService.getMediaType("pdf"));
31 | }
32 |
33 | @Test
34 | public void testGetExtensionFromMediaType()
35 | {
36 | assertEquals("txt", mediaTypeService.getExtension("text/plain"));
37 | assertEquals("pdf", mediaTypeService.getExtension("application/pdf"));
38 | }
39 |
40 | @Test
41 | public void testFileMediaType()
42 | {
43 | assertEquals("text/plain", FileMediaType.TEXT_PLAIN.getMediaType());
44 | assertEquals("application/pdf", FileMediaType.PDF.getMediaType());
45 | assertEquals("video/x-m4v", FileMediaType.VIDEO_M4V.getMediaType());
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/resources/content-handler-a/file-a-1.txt:
--------------------------------------------------------------------------------
1 | This is file 1a
2 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/resources/content-handler-a/file-a-2.txt:
--------------------------------------------------------------------------------
1 | This is file 2a
2 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/resources/content-handler-b/file-b-1.txt:
--------------------------------------------------------------------------------
1 | This is file 1b
2 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/resources/content-handler-b/file-b-2.txt:
--------------------------------------------------------------------------------
1 | This is file 2b
2 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/resources/content-handler-c/file-c-1.txt:
--------------------------------------------------------------------------------
1 | This is file 1c
2 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/resources/content-handler-c/file-c-2.txt:
--------------------------------------------------------------------------------
1 | This is file 2c
2 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # Set root logger level to error
2 | log4j.rootLogger=error, Console
3 |
4 | ###### Console appender definition #######
5 |
6 | # All outputs currently set to be a ConsoleAppender.
7 | log4j.appender.Console=org.apache.log4j.ConsoleAppender
8 | log4j.appender.Console.layout=org.apache.log4j.PatternLayout
9 |
10 | # use log4j NDC to replace %x with tenant domain / username
11 | log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %x %-5p [%c{3}] [%t] %m%n
12 | #log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
13 |
14 | log4j.logger.org.gengine=debug
15 | log4j.logger.org.apache.tika=debug
16 |
--------------------------------------------------------------------------------
/gengine-commons/src/test/resources/quick/quick.mpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChenInfo/Gengine/3d32e7c36836a11863d795700e867cc49c48c796/gengine-commons/src/test/resources/quick/quick.mpg
--------------------------------------------------------------------------------
/gengine-commons/src/test/resources/quick/quick.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChenInfo/Gengine/3d32e7c36836a11863d795700e867cc49c48c796/gengine-commons/src/test/resources/quick/quick.pdf
--------------------------------------------------------------------------------
/gengine-content-handlers/gengine-content-handler-s3/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | A `ContentReferenceHandler` implementation which can read and write files to Amazon S3.
6 |
--------------------------------------------------------------------------------
/gengine-content-handlers/gengine-content-handler-tempfile/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | A `ContentReferenceHandler` implementation which creates a file provider with a
6 | directory path of the `CleaningTempFileProvider`'s temp dir.
7 |
8 | The `CleaningTempFileProvider` also provides a [Quartz|http://quartz-scheduler.org/] `TempFileCleanerJob`.
9 |
--------------------------------------------------------------------------------
/gengine-content-handlers/gengine-content-handler-tempfile/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-content-handlers
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-content-handler-tempfile
12 |
13 |
14 | 2.3.2
15 | 1.7.35
16 |
17 |
18 |
19 |
20 | org.gengine
21 | gengine-commons
22 | ${project.version}
23 |
24 |
25 | org.quartz-scheduler
26 | quartz
27 | ${dependency.quartz.version}
28 |
29 |
30 | org.slf4j
31 | slf4j-api
32 | ${dependency.sl4j.version}
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/gengine-content-handlers/gengine-content-handler-tempfile/src/main/java/org/gengine/content/handler/tempfile/TempFileContentReferenceHandlerImpl.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.handler.tempfile;
2 |
3 | import org.gengine.content.file.FileProviderImpl;
4 | import org.gengine.content.file.CleaningTempFileProvider;
5 | import org.gengine.content.handler.FileContentReferenceHandlerImpl;
6 |
7 | /**
8 | * A convenience FileContentReferenceHandlerImpl extension which creates a file
9 | * provider with a directory path of the {@link CleaningTempFileProvider}'s temp dir.
10 | *
11 | */
12 | public class TempFileContentReferenceHandlerImpl extends FileContentReferenceHandlerImpl
13 | {
14 | public TempFileContentReferenceHandlerImpl()
15 | {
16 | super();
17 | FileProviderImpl fileProvider = new FileProviderImpl();
18 | fileProvider.setDirectoryPath(CleaningTempFileProvider.getTempDir().getPath());
19 | setFileProvider(fileProvider);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/gengine-content-handlers/gengine-content-handler-webdav/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | A `ContentReferenceHandler` implementation which can read and write files to a WebDAV server.
6 |
--------------------------------------------------------------------------------
/gengine-content-handlers/gengine-content-handler-webdav/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-content-handlers
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-content-handler-webdav
12 |
13 |
14 | 5.1
15 |
16 |
17 |
18 |
19 | org.gengine
20 | gengine-commons
21 | ${project.version}
22 |
23 |
24 | com.github.lookfirst
25 | sardine
26 | ${dependency.sardine.version}
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/gengine-content-handlers/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-parent
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-content-handlers
12 | pom
13 |
14 |
15 | 4.5.13
16 | 4.4.14
17 | 1.15
18 |
19 |
20 |
21 | gengine-content-handler-s3
22 | gengine-content-handler-webdav
23 | gengine-content-handler-tempfile
24 |
25 |
26 |
27 |
28 | javax.xml.bind
29 | jaxb-api
30 | 2.3.1
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-commons/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | Contains the basic definitions of `ContentHashWorker`s.
6 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-commons/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-hash
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-hash-commons
12 |
13 |
14 |
15 | org.gengine
16 | gengine-commons
17 | ${project.version}
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-commons/src/main/java/org/gengine/content/hash/ContentHashException.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.hash;
2 |
3 | /**
4 | * Thrown when an implementation can not perform the requested hashing due
5 | * to configuration or environment.
6 | *
7 | */
8 | public class ContentHashException extends Exception
9 | {
10 | private static final long serialVersionUID = -5334480453136472986L;
11 |
12 | public ContentHashException()
13 | {
14 | }
15 |
16 | public ContentHashException(String message)
17 | {
18 | super(message);
19 | }
20 |
21 | public ContentHashException(Throwable cause)
22 | {
23 | super(cause);
24 | }
25 |
26 | public ContentHashException(String message, Throwable cause)
27 | {
28 | super(message, cause);
29 | }
30 |
31 | public ContentHashException(String message, Throwable cause, boolean enableSuppression,
32 | boolean writableStackTrace)
33 | {
34 | super(message, cause, enableSuppression, writableStackTrace);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-commons/src/main/java/org/gengine/content/hash/ContentHashWorker.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.hash;
2 |
3 | import java.util.List;
4 |
5 | import org.gengine.content.ContentIOException;
6 | import org.gengine.content.ContentReference;
7 | import org.gengine.content.ContentWorkResult;
8 | import org.gengine.content.ContentWorker;
9 |
10 | /**
11 | * Defines the methods responsible for doing the work of hash computation of content references
12 | *
13 | */
14 | public interface ContentHashWorker extends ContentWorker
15 | {
16 | public static final String HASH_ALGORITHM_MD5 = "MD5";
17 | public static final String HASH_ALGORITHM_SHA_256 = "SHA-256";
18 | public static final String HASH_ALGORITHM_SHA_512 = "SHA-512";
19 |
20 | public static final String RESULT_DETAIL_HEX_ENCODED_VALUE = "HEX_ENCODED_VALUE";
21 |
22 | /**
23 | * Generates a hash value for the given content reference using the given algorithm
24 | *
25 | * @param sources
26 | * @param hashAlgorithm
27 | * @return the results with hex encoded hash values
28 | * @throws Exception
29 | */
30 | public List generateHashes(
31 | List sources,
32 | String hashAlgorithm) throws ContentIOException, InterruptedException, ContentHashException;
33 |
34 | /**
35 | * Determines whether or not the given hash algorithm is supported
36 | * by the implementation.
37 | *
38 | * @param hashAlgorithm
39 | * @return true if the algorithm is supported
40 | */
41 | public boolean isAlgorithmSupported(String hashAlgorithm);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-component/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | This forms the basis of a content hash component which acts as a
6 | `MessageConsumer` to process `HashRequest` objects and sends
7 | `HashReply` objects to a specified `MessageProducer`.
8 |
9 | No assumptions are made as to how those Java object messages are routed
10 | to or from the hash component.
11 |
12 | A `ContentHashNodeWorker` performs the actual work of computing
13 | the hash value.
14 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-component/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-hash
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-hash-component
12 |
13 |
14 |
15 | org.gengine
16 | gengine-hash-commons
17 | ${project.version}
18 |
19 |
20 | org.gengine
21 | gengine-hash-messaging
22 | ${project.version}
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-component/src/main/java/org/gengine/content/hash/BaseContentHashComponent.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.hash;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.commons.logging.Log;
6 | import org.apache.commons.logging.LogFactory;
7 | import org.gengine.content.AbstractComponent;
8 | import org.gengine.content.ContentWorkResult;
9 | import org.gengine.content.hash.HashReply;
10 | import org.gengine.content.hash.HashRequest;
11 | import org.gengine.messaging.MessageProducer;
12 |
13 | /**
14 | * A base implementation of a hash node which receives messages, uses a {@link ContentHashWorker}
15 | * to perform the hash computation, then uses a {@link MessageProducer} to send the reply.
16 | *
17 | */
18 | public class BaseContentHashComponent extends AbstractComponent
19 | {
20 | private static final Log logger = LogFactory.getLog(BaseContentHashComponent.class);
21 |
22 | protected void onReceiveImpl(Object message)
23 | {
24 | HashRequest request = (HashRequest) message;
25 | if (logger.isDebugEnabled())
26 | {
27 | logger.info("Processing hash requestId=" + request.getRequestId());
28 | }
29 | try
30 | {
31 |
32 | List results = worker.generateHashes(
33 | request.getSourceContentReferences(),
34 | request.getHashAlgorithm());
35 |
36 | HashReply reply = new HashReply(request);
37 | reply.setResults(results);
38 |
39 | if (logger.isDebugEnabled())
40 | {
41 | logger.debug("Sending reply");
42 | }
43 | messageProducer.send(reply, request.getReplyTo());
44 | }
45 | catch (Exception e)
46 | {
47 | logger.error(e.getMessage(), e);
48 | // TODO send error reply
49 | }
50 | }
51 |
52 | public Class> getConsumingMessageBodyClass()
53 | {
54 | return HashRequest.class;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-messaging/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | Contains the basic definitions of `HashRequest` and `HashReply`
6 | objects to be sent to content hash nodes.
7 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-messaging/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-hash
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-hash-messaging
12 |
13 |
14 |
15 | org.gengine
16 | gengine-messaging-commons
17 | ${project.version}
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-messaging/src/main/java/org/gengine/content/hash/HashReply.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.hash;
2 |
3 | import org.gengine.content.AbstractContentReply;
4 | import org.gengine.messaging.Request;
5 |
6 | /**
7 | * Represents a reply from a content hasher on the status of a hash request.
8 | *
9 | */
10 | public class HashReply extends AbstractContentReply
11 | {
12 |
13 | public HashReply()
14 | {
15 | super();
16 | }
17 |
18 | public HashReply(Request> request)
19 | {
20 | super(request);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-messaging/src/main/java/org/gengine/content/hash/HashRequest.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.hash;
2 |
3 | import java.util.List;
4 |
5 | import org.gengine.content.AbstractContentRequest;
6 | import org.gengine.content.ContentReference;
7 | import org.gengine.messaging.Request;
8 |
9 | /**
10 | * Represents a request for content hash
11 | *
12 | */
13 | public class HashRequest extends AbstractContentRequest implements Request
14 | {
15 | private String hashAlgorithm;
16 |
17 | public HashRequest()
18 | {
19 | super();
20 | }
21 |
22 | public HashRequest(List sourceContentReferences, String hashAlgorithm)
23 | {
24 | super();
25 | setSourceContentReferences(sourceContentReferences);
26 | this.hashAlgorithm = hashAlgorithm;
27 | }
28 |
29 | /**
30 | * Gets the hash algorithm to be used
31 | *
32 | * @return the hash algorithm
33 | */
34 | public String getHashAlgorithm()
35 | {
36 | return hashAlgorithm;
37 | }
38 |
39 | /**
40 | * Sets hash algorithm to be used
41 | *
42 | * @param hashAlgorithm
43 | */
44 | public void setHashAlgorithm(String hashAlgorithm)
45 | {
46 | this.hashAlgorithm = hashAlgorithm;
47 | }
48 |
49 | @Override
50 | public Class getReplyClass()
51 | {
52 | return HashReply.class;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-worker-javase/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | A Java SE implementation which computes a hash
6 | of File objects.
7 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-worker-javase/src/main/java/org/gengine/content/hash/javase/JavaSeContentHashWorker.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content.hash.javase;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.math.BigInteger;
6 | import java.security.MessageDigest;
7 | import java.security.NoSuchAlgorithmException;
8 |
9 | import org.gengine.content.ContentIOException;
10 | import org.gengine.content.hash.AbstractContentHashWorker;
11 | import org.gengine.content.hash.ContentHashException;
12 |
13 | /**
14 | * A Java SE implementation of a content hash node worker
15 | *
16 | */
17 | public class JavaSeContentHashWorker extends AbstractContentHashWorker
18 | {
19 | private static final int BUFFER_SIZE = 8*1024;
20 |
21 | @Override
22 | public String generateHashInternal(InputStream source, String hashAlgorithm) throws ContentIOException, InterruptedException, ContentHashException
23 | {
24 | if (source == null || hashAlgorithm == null) {
25 | throw new IllegalArgumentException("source and hashAlgorithm must not be null");
26 | }
27 | try
28 | {
29 | MessageDigest messageDigest = MessageDigest.getInstance(hashAlgorithm);
30 |
31 | byte[] buffer = new byte[BUFFER_SIZE];
32 |
33 | int bytesRead = 0;
34 | while( (bytesRead = source.read(buffer)) > 0) {
35 | messageDigest.update(buffer, 0, bytesRead);
36 | }
37 |
38 | return encodeHex(messageDigest.digest());
39 | }
40 | catch (IOException e)
41 | {
42 | throw new ContentIOException("Could not read content for hashing", e);
43 | }
44 | catch (NoSuchAlgorithmException e)
45 | {
46 | throw new ContentHashException(e);
47 | }
48 | finally
49 | {
50 | try
51 | {
52 | source.close();
53 | }
54 | catch (IOException e)
55 | {
56 | }
57 | }
58 | }
59 |
60 | /**
61 | * Performs a hex encoding of the given byte array
62 | *
63 | * @param byteArray
64 | * @return the hex encoded value
65 | */
66 | protected String encodeHex(byte[] byteArray)
67 | {
68 | BigInteger integer = new BigInteger(1, byteArray);
69 | return integer.toString(16);
70 | }
71 |
72 | @Override
73 | public boolean isAlgorithmSupported(String hashAlgorithm)
74 | {
75 | try
76 | {
77 | MessageDigest.getInstance(hashAlgorithm);
78 | return true;
79 | }
80 | catch (NoSuchAlgorithmException e)
81 | {
82 | return false;
83 | }
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/gengine-hash/gengine-hash-worker-javase/src/main/resources/org/gengine/content/hash/javase/JavaSeContentHashWorker.properties:
--------------------------------------------------------------------------------
1 | name=Gengine JavaSE Content Hash Worker
2 | version=${project.version}
3 |
--------------------------------------------------------------------------------
/gengine-hash/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-parent
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-hash
12 | pom
13 |
14 |
15 | gengine-hash-commons
16 | gengine-hash-messaging
17 | gengine-hash-worker-javase
18 | gengine-hash-component
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gengine-health-commons/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | Interfaces and implementations to monitor the health of different components in a system involving
6 | heartbeats and `ComponentUnavailableExceptions`.
7 |
--------------------------------------------------------------------------------
/gengine-health-commons/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-parent
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-health-commons
12 |
13 |
14 |
15 | org.gengine
16 | gengine-commons
17 | ${project.version}
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gengine-health-commons/src/main/java/org/gengine/health/ComponentUnavailableAction.java:
--------------------------------------------------------------------------------
1 | package org.gengine.health;
2 |
3 | /**
4 | * Defines actions to be taken when a service's dependent component is unavailable.
5 | *
6 | */
7 | public interface ComponentUnavailableAction
8 | {
9 |
10 | /**
11 | * Executes the action using the given exception
12 | *
13 | * @param e the exception
14 | */
15 | public void execute(Throwable e);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/gengine-health-commons/src/main/java/org/gengine/health/ComponentUnavailableActionTerminate.java:
--------------------------------------------------------------------------------
1 | package org.gengine.health;
2 |
3 | import org.apache.commons.logging.Log;
4 | import org.apache.commons.logging.LogFactory;
5 |
6 | /**
7 | * ComponentUnavailableAction which terminates the JVM with the specified exit code, not to be used lightly.
8 | *
9 | */
10 | public class ComponentUnavailableActionTerminate implements ComponentUnavailableAction
11 | {
12 | private static final Log logger = LogFactory.getLog(ComponentUnavailableActionTerminate.class);
13 |
14 | private static final Integer DEFAULT_EXIT_STATUS_CODE = new Integer(1);
15 |
16 | @Override
17 | public void execute(Throwable e)
18 | {
19 | logger.fatal("Terminating due to " + e.getClass().getSimpleName() + ": " + e.getMessage());
20 | Integer statusCode = null;
21 | if (e instanceof ComponentUnavailableException)
22 | {
23 | statusCode = ((ComponentUnavailableException) e).getExitStatusCode();
24 | }
25 | if (statusCode == null)
26 | {
27 | statusCode = DEFAULT_EXIT_STATUS_CODE;
28 | }
29 | System.exit(statusCode);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/gengine-health-commons/src/main/java/org/gengine/health/ComponentUnavailableException.java:
--------------------------------------------------------------------------------
1 | package org.gengine.health;
2 |
3 | /**
4 | * Thrown when a dependent component such as a database or other service is unavailable.
5 | *
6 | */
7 | public class ComponentUnavailableException extends RuntimeException
8 | {
9 |
10 | private static final long serialVersionUID = 4814912374901612569L;
11 |
12 | public ComponentUnavailableException()
13 | {
14 | }
15 |
16 | public ComponentUnavailableException(String message)
17 | {
18 | super(message);
19 | }
20 |
21 | public ComponentUnavailableException(Throwable cause)
22 | {
23 | super(cause);
24 | }
25 |
26 | public ComponentUnavailableException(String message, Throwable cause)
27 | {
28 | super(message, cause);
29 | }
30 |
31 | public ComponentUnavailableException(String message, Throwable cause, boolean enableSuppression,
32 | boolean writableStackTrace)
33 | {
34 | super(message, cause, enableSuppression, writableStackTrace);
35 | }
36 |
37 | public Integer getExitStatusCode()
38 | {
39 | return 1;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/gengine-health-commons/src/main/java/org/gengine/health/ComponentUnavailableExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package org.gengine.health;
2 |
3 | import java.util.Map;
4 |
5 | import org.apache.commons.logging.Log;
6 | import org.apache.commons.logging.LogFactory;
7 |
8 | /**
9 | * Determines the {@link ComponentUnavailableAction} to execute when a
10 | * {@link ComponentUnavailableException} is thrown
11 | *
12 | */
13 | public class ComponentUnavailableExceptionHandler
14 | {
15 | private static final Log logger = LogFactory.getLog(ComponentUnavailableExceptionHandler.class);
16 |
17 | private Map policies;
18 |
19 | /**
20 | * A map of ComponentUnavailableException canonical class names to the
21 | * ComponentUnavailableAction that should be executed.
22 | *
23 | * @param policies
24 | */
25 | public void setPolicies(Map policies)
26 | {
27 | this.policies = policies;
28 | }
29 |
30 | /**
31 | * Determines the ComponentUnavailableAction to execute based on the given exception
32 | * and executes it.
33 | *
34 | * @param e
35 | */
36 | public void handle(Throwable e)
37 | {
38 | if (e == null)
39 | {
40 | return;
41 | }
42 | String actionKey = e.getClass().getCanonicalName();
43 | if (policies == null || !policies.containsKey(actionKey))
44 | {
45 | logger.error("Received " + actionKey +
46 | " but no corresponding action registered: " + e.getMessage(), e);
47 | }
48 | else
49 | {
50 | policies.get(actionKey).execute(e);
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/gengine-health-commons/src/main/java/org/gengine/health/heartbeat/Heart.java:
--------------------------------------------------------------------------------
1 | package org.gengine.health.heartbeat;
2 |
3 | /**
4 | * Defines the object responsible for producing {@link Heartbeat}s
5 | * which let services monitor health of other services in the system.
6 | *
7 | */
8 | public interface Heart
9 | {
10 | /**
11 | * Starts the repeated sending of {@link Heartbeat} messages
12 | * for health monitoring
13 | */
14 | public void start();
15 |
16 | /**
17 | * Stops the repeated sending of {@link Heartbeat} messages
18 | * for health monitoring
19 | */
20 | public void stop();
21 |
22 | /**
23 | * Returns a single {@link Heartbeat} object without sending
24 | * via messaging
25 | *
26 | * @return the heartbeat object
27 | */
28 | public Heartbeat beat();
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/gengine-health-commons/src/main/java/org/gengine/health/heartbeat/HeartbeatDao.java:
--------------------------------------------------------------------------------
1 | package org.gengine.health.heartbeat;
2 |
3 | /**
4 | * Defines the persistence of a heartbeat. Implementations might
5 | * be a log, database, or in-memory queue.
6 | *
7 | */
8 | public interface HeartbeatDao
9 | {
10 |
11 | /**
12 | * Persists the heartbeat.
13 | *
14 | * @param heartbeat
15 | */
16 | public void record(Heartbeat heartbeat);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/gengine-health-commons/src/main/java/org/gengine/health/heartbeat/HeartbeatMonitor.java:
--------------------------------------------------------------------------------
1 | package org.gengine.health.heartbeat;
2 |
3 | /**
4 | * Defines an object responsible for listening for the heartbeat.
5 | * Implementations may utilize a {@link HeartbeatDao} to persist the data.
6 | *
7 | */
8 | public interface HeartbeatMonitor
9 | {
10 |
11 | /**
12 | * Called when a {@link Heartbeat} message is routed to the
13 | * monitor.
14 | *
15 | * @param message
16 | */
17 | public void onReceive(Object message);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-amqp-direct/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | A Qpid-based AMQP endpoint which can serve as both a `MessageProducer` and
6 | contains a message listener which accepts messages then unmarshals and
7 | passes them to a specified `MessageConsumer`.
8 |
9 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-amqp-direct/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-messaging
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-messaging-amqp-direct
12 |
13 |
14 | 0.26
15 |
16 |
17 |
18 |
19 | org.gengine
20 | gengine-messaging-commons
21 | ${project.version}
22 |
23 |
24 | org.apache.qpid
25 | qpid-amqp-1-0-client
26 | ${dependency.qpid.version}
27 |
28 |
29 | org.apache.qpid
30 | qpid-amqp-1-0-common
31 | ${dependency.qpid.version}
32 |
33 |
34 | org.apache.qpid
35 | qpid-amqp-1-0-client-jms
36 | ${dependency.qpid.version}
37 |
38 |
39 | org.apache.geronimo.specs
40 | geronimo-jms_1.1_spec
41 | 1.1.1
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-benchmark/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | A simple benchmark that produces and consumes messages on a single AMQP endpoint
6 | and measures the throughput.
7 |
8 | Usage
9 | =====
10 |
11 | First build the jar via Maven:
12 |
13 | mvn clean package
14 |
15 | either from this project.
16 |
17 | Start an AMQP broker. See the `messaging-broker-activemq` project.
18 |
19 | The single jar with dependencies should be launched with a parameter of the
20 | brokerUrl and the number of messages to test, i.e. (replace 0.X-SNAPSHOT with appropriate version):
21 |
22 | java -jar target/gengine-messaging-benchmark-0.X-SNAPSHOT-jar-with-dependencies.jar 'tcp://localhost:61616' 10000
23 |
24 | You should see a message indicating that the test is sending messages and the final statistics.
25 |
26 | Advanced Usage
27 | ==============
28 |
29 | Note: In the examples below, replace 0.X-SNAPSHOT with appropriate version.
30 |
31 | You can optionally specify the queue or topic you wish to use in the command line:
32 |
33 | java -jar target/gengine-messaging-benchmark-0.X-SNAPSHOT-jar-with-dependencies.jar 'tcp://localhost:61616' 100 'queue:foo'
34 | java -jar target/gengine-messaging-benchmark-0.X-SNAPSHOT-jar-with-dependencies.jar 'tcp://localhost:61616' 100 'topic:bar.foo'
35 |
36 | You can run just the producer of messages with the `product-only` option:
37 |
38 | java -jar target/gengine-messaging-benchmark-0.X-SNAPSHOT-jar-with-dependencies.jar 'tcp://localhost:61616' 100 'topic:bar.foo' produce-only
39 |
40 | You can run just the consumer of messages with the `consume-only` option, shown with a durable subscriber expecting 100 messages:
41 |
42 | java -jar target/gengine-messaging-benchmark-0.X-SNAPSHOT-jar-with-dependencies.jar 'tcp://localhost:61616' 100 'topic:bar.foo?clientId=1&durableSubscriptionName=bar1' consume-only
43 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-benchmark/src/main/java/org/gengine/messaging/benchmark/BenchmarkConsumer.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging.benchmark;
2 |
3 | import org.apache.commons.logging.Log;
4 | import org.apache.commons.logging.LogFactory;
5 | import org.gengine.messaging.MessageConsumer;
6 |
7 | /**
8 | * Consumer of {@link BenchmarkMessage}s which maintains a count of messages received.
9 | *
10 | */
11 | public class BenchmarkConsumer implements MessageConsumer
12 | {
13 | private static final Log logger = LogFactory.getLog(BenchmarkConsumer.class);
14 |
15 | protected int logAfterNumMessages = 1000;
16 | protected int messageCount = 0;
17 |
18 | public void setLogAfterNumMessages(int logAfterNumMessages)
19 | {
20 | this.logAfterNumMessages = logAfterNumMessages;
21 | }
22 |
23 | @Override
24 | public void onReceive(Object message)
25 | {
26 | if (logger.isTraceEnabled())
27 | {
28 | logger.trace("Receiving message, current messageCount=" + messageCount + "...");
29 | }
30 | validateMessage(message);
31 |
32 | messageCount++;
33 |
34 | if (messageCount > 0 && messageCount % logAfterNumMessages == 0)
35 | {
36 | logger.debug("Received " + messageCount + " messages...");
37 | }
38 | else
39 | {
40 | if (logger.isTraceEnabled())
41 | {
42 | logger.trace("Received " + messageCount + " messages...");
43 | }
44 | }
45 | }
46 |
47 | protected void validateMessage(Object message)
48 | {
49 | if (message == null || ((BenchmarkMessage) message).getValue() == null ||
50 | !((BenchmarkMessage) message).getValue().equals(BenchmarkMessage.getDefaultValue()))
51 | {
52 | throw new IllegalArgumentException("Could not verify message");
53 | }
54 | }
55 |
56 | @Override
57 | public Class> getConsumingMessageBodyClass()
58 | {
59 | return BenchmarkMessage.class;
60 | }
61 |
62 | public int getMessageCount()
63 | {
64 | return messageCount;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-benchmark/src/main/java/org/gengine/messaging/benchmark/BootstrapArguments.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging.benchmark;
2 |
3 | public class BootstrapArguments
4 | {
5 | public String brokerUrl;
6 | public String brokerUsername;
7 | public String brokerPassword;
8 | public int numMessages;
9 | public String endpointSend;
10 | public String endpointReceive;
11 | public boolean runProducer = true;
12 | public boolean runConsumer = true;
13 | public int numSections = 100; // see also BenchmarkMessage
14 | }
15 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-benchmark/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # Set root logger level to error
2 | log4j.rootLogger=error, Console
3 |
4 | ###### Console appender definition #######
5 |
6 | # All outputs currently set to be a ConsoleAppender.
7 | log4j.appender.Console=org.apache.log4j.ConsoleAppender
8 | log4j.appender.Console.layout=org.apache.log4j.PatternLayout
9 |
10 | # use log4j NDC to replace %x with tenant domain / username
11 | log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %x %-5p [%c{1}] %m%n
12 | #log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %x %-5p [%c{3}] [%t] %m%n
13 | #log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
14 |
15 | log4j.logger.org.gengine=debug
16 | #log4j.logger.org.gengine.messaging.benchmark=trace
17 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-camel/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | Apache Camel `MessageProducer` and `RequestReplyMessageProducer` implementations.
6 |
7 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-camel/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-messaging
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-messaging-camel
12 |
13 |
14 | 1.7.35
15 |
16 |
17 |
18 |
19 | org.gengine
20 | gengine-messaging-commons
21 | ${project.version}
22 |
23 |
24 | org.gengine
25 | gengine-health-commons
26 | ${project.version}
27 |
28 |
29 | org.apache.camel
30 | camel-core
31 | ${dependency.camel.version}
32 |
33 |
34 | org.apache.camel
35 | camel-jackson
36 | ${dependency.camel.version}
37 |
38 |
39 | org.slf4j
40 | slf4j-api
41 | ${dependency.sl4j.version}
42 |
43 |
44 | org.apache.camel
45 | camel-test
46 | test
47 | ${dependency.camel.version}
48 |
49 |
50 | org.apache.maven
51 | maven-artifact
52 | 3.6.3
53 | test
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-camel/src/main/java/org/gengine/health/camel/ExceptionProcessor.java:
--------------------------------------------------------------------------------
1 | package org.gengine.health.camel;
2 |
3 | import org.apache.camel.Exchange;
4 | import org.apache.camel.Processor;
5 | import org.gengine.health.ComponentUnavailableExceptionHandler;
6 |
7 | /**
8 | * Camel Processor and standard bean which provide methods to pass the exception
9 | * to the specified handler.
10 | *
11 | */
12 | public class ExceptionProcessor implements Processor
13 | {
14 | private ComponentUnavailableExceptionHandler handler;
15 |
16 | public void setHandler(ComponentUnavailableExceptionHandler handler)
17 | {
18 | this.handler = handler;
19 | }
20 |
21 | @Override
22 | public void process(Exchange exchange) throws Exception
23 | {
24 | Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
25 | handler.handle(cause);
26 | }
27 |
28 | public void onReceive(Object body)
29 | {
30 | // Handler can only deal with Throwables
31 | if (body instanceof Throwable)
32 | {
33 | handler.handle((Throwable) body);
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-camel/src/main/java/org/gengine/health/camel/HeartbeatMonitorImpl.java:
--------------------------------------------------------------------------------
1 | package org.gengine.health.camel;
2 |
3 | import org.apache.camel.Handler;
4 | import org.apache.commons.logging.Log;
5 | import org.apache.commons.logging.LogFactory;
6 | import org.gengine.health.heartbeat.Heartbeat;
7 | import org.gengine.health.heartbeat.HeartbeatDao;
8 | import org.gengine.health.heartbeat.HeartbeatMonitor;
9 |
10 | /**
11 | * HeartbeatMonitor implementation which uses Camel to route {@link Heartbeat}
12 | * messages.
13 | *
14 | */
15 | public class HeartbeatMonitorImpl implements HeartbeatMonitor
16 | {
17 | private static final Log logger = LogFactory.getLog(HeartbeatMonitorImpl.class);
18 |
19 | private HeartbeatDao heartbeatDao;
20 |
21 | /**
22 | * Sets the DAO used to persist heartbeats.
23 | *
24 | * @param heartbeatDao
25 | */
26 | public void setHeartbeatDao(HeartbeatDao heartbeatDao)
27 | {
28 | this.heartbeatDao = heartbeatDao;
29 | }
30 |
31 | @Override
32 | @Handler
33 | public void onReceive(Object message)
34 | {
35 | if (!(message instanceof Heartbeat))
36 | {
37 | logger.warn("Heartbeat message expected but received: " + message.toString());
38 | return;
39 | }
40 | heartbeatDao.record((Heartbeat) message);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-camel/src/test/java/org/gengine/messaging/camel/dataformat/SimplePojo.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging.camel.dataformat;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class SimplePojo {
7 | public enum EnumValue {
8 | VALUE_1, VALUE_2
9 | }
10 |
11 | private String field1;
12 | private Integer field2;
13 | private EnumValue field3;
14 | private Map, String> field4;
15 | private Map field5;
16 |
17 | // Constructor
18 | public SimplePojo(String field1, Integer field2, EnumValue field3) {
19 | this.field1 = field1;
20 | this.field2 = field2;
21 | this.field3 = field3;
22 | }
23 |
24 | // Getters and setters for field1, field2, and field3
25 | public String getField1() {
26 | return field1;
27 | }
28 |
29 | public void setField1(String field1) {
30 | this.field1 = field1;
31 | }
32 |
33 | public Integer getField2() {
34 | return field2;
35 | }
36 |
37 | public void setField2(Integer field2) {
38 | this.field2 = field2;
39 | }
40 |
41 | public EnumValue getField3() {
42 | return field3;
43 | }
44 |
45 | public void setField3(EnumValue field3) {
46 | this.field3 = field3;
47 | }
48 |
49 | // Getters and setters for field4
50 | public Map, String> getField4() {
51 | return field4;
52 | }
53 |
54 | public void setField4(Map, String> field4) {
55 | this.field4 = field4;
56 | }
57 |
58 | // Getters and setters for field5
59 | public Map getField5() {
60 | return field5;
61 | }
62 |
63 | public void setField5(Map field5) {
64 | this.field5 = field5;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/README.md:
--------------------------------------------------------------------------------
1 |
2 | Overview
3 | ========
4 |
5 | Defines generic `MessageConsumer` and `MessageProducer` interfaces which process
6 | and send Java object messages and contains a Jackson-based JSON marshaller.
7 |
8 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.gengine
6 | gengine-messaging
7 | 0.13-SNAPSHOT
8 | ../pom.xml
9 |
10 |
11 | gengine-messaging-commons
12 |
13 |
14 |
15 | org.gengine
16 | gengine-commons
17 | ${project.version}
18 |
19 |
20 | com.fasterxml.jackson.core
21 | jackson-databind
22 | ${dependency.jackson-databind.version}
23 |
24 |
25 | com.fasterxml.jackson.module
26 | jackson-module-jaxb-annotations
27 | ${dependency.jackson.version}
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/content/AbstractContentReply.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content;
2 |
3 | import java.util.List;
4 |
5 | import org.gengine.messaging.AbstractReply;
6 | import org.gengine.messaging.Request;
7 |
8 | /**
9 | * Base implementation of a content reply
10 | *
11 | */
12 | public abstract class AbstractContentReply extends AbstractReply implements ContentReply
13 | {
14 | private List results;
15 |
16 | public AbstractContentReply()
17 | {
18 | super();
19 | }
20 |
21 | public AbstractContentReply(Request> request)
22 | {
23 | super(request);
24 | }
25 |
26 | public List getResults()
27 | {
28 | return results;
29 | }
30 |
31 | public void setResults(List results)
32 | {
33 | this.results = results;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/content/AbstractContentRequest.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content;
2 |
3 | import java.util.List;
4 |
5 | import org.gengine.content.ContentReference;
6 | import org.gengine.messaging.AbstractRequest;
7 |
8 | /**
9 | * Represents a request for some operation on content sources.
10 | *
11 | */
12 | public abstract class AbstractContentRequest extends AbstractRequest
13 | {
14 | private List sourceContentReferences;
15 |
16 | public AbstractContentRequest()
17 | {
18 | super();
19 | }
20 |
21 | /**
22 | * Gets the source content reference objects
23 | *
24 | * @return source content references
25 | */
26 | public List getSourceContentReferences()
27 | {
28 | return sourceContentReferences;
29 | }
30 |
31 | /**
32 | * Sets the source content reference objects
33 | *
34 | * @param sourceContentReference
35 | */
36 | public void setSourceContentReferences(List sourceContentReferences)
37 | {
38 | this.sourceContentReferences = sourceContentReferences;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/content/Component.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content;
2 |
3 | import org.gengine.messaging.MessageConsumer;
4 |
5 | /**
6 | * Defines a component which is a consumer of request for content action messages,
7 | * delegates that work to a worker, and sends a reply with the results.
8 | *
9 | */
10 | public interface Component extends MessageConsumer
11 | {
12 | /**
13 | * Gets the name of the component, useful for health checks.
14 | *
15 | * @return the component name
16 | */
17 | public String getName();
18 |
19 | /**
20 | * Determines whether or not the worker is available.
21 | *
22 | * @return true if the worker is available
23 | * @see {@link ContentWorker#isAvailable()}
24 | */
25 | public boolean isWorkerAvailable();
26 |
27 | /**
28 | * Gets a string returning name and version information
29 | *
30 | * @return the version string
31 | * @see {@link ContentWorker#getVersionString()}
32 | */
33 | public String getWorkerVersionString();
34 |
35 |
36 | /**
37 | * Gets a string returning detailed version information such as JVM
38 | * or command line application's version output
39 | *
40 | * @return the version string
41 | * @see {@link ContentWorker#getVersionDetailsString()}
42 | */
43 | public String getWorkerVersionDetailsString();
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/content/ContentReply.java:
--------------------------------------------------------------------------------
1 | package org.gengine.content;
2 |
3 | import java.util.List;
4 |
5 | import org.gengine.messaging.Reply;
6 |
7 | public interface ContentReply extends Reply
8 | {
9 |
10 | /**
11 | * Gets the results of the content operation.
12 | *
13 | * @return the results
14 | */
15 | public List getResults();
16 | }
17 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/messaging/AbstractReply.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging;
2 |
3 | /**
4 | * Base implementation of a reply.
5 | *
6 | */
7 | public abstract class AbstractReply implements Reply
8 | {
9 | private String requestId;
10 |
11 | public AbstractReply() {
12 | super();
13 | }
14 |
15 | public AbstractReply(Request> request)
16 | {
17 | super();
18 | this.requestId = request.getRequestId();
19 | }
20 |
21 | /**
22 | * Gets the UUID for the original hash request
23 | *
24 | * @return the hash request ID
25 | */
26 | public String getRequestId()
27 | {
28 | return requestId;
29 | }
30 |
31 | /**
32 | * Sets the UUID for the original hash request
33 | *
34 | * @param requestId
35 | */
36 | public void setRequestId(String requestId)
37 | {
38 | this.requestId = requestId;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/messaging/AbstractRequest.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging;
2 |
3 | import java.util.UUID;
4 |
5 | /**
6 | * Represents a generic messaging request
7 | *
8 | */
9 | public abstract class AbstractRequest
10 | {
11 | private final String requestId;
12 | private String replyQueueName;
13 |
14 | public AbstractRequest()
15 | {
16 | super();
17 | this.requestId = UUID.randomUUID().toString();
18 | }
19 |
20 | /**
21 | * Gets the generated UUID for the transformation request
22 | *
23 | * @return the request ID
24 | */
25 | public String getRequestId()
26 | {
27 | return requestId;
28 | }
29 |
30 | /**
31 | * Gets the optional overriding reply to queue replies should be sent to
32 | *
33 | * @return the optional override reply to queue
34 | */
35 | public String getReplyTo()
36 | {
37 | return replyQueueName;
38 | }
39 |
40 | /**
41 | * Sets the optional overriding reply to queue replies should be sent to
42 | *
43 | * @param replyQueueName
44 | */
45 | public void setReplyTo(String replyQueueName)
46 | {
47 | this.replyQueueName = replyQueueName;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/messaging/LoggingDeadLetterQueue.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging;
2 |
3 | import org.apache.commons.logging.Log;
4 | import org.apache.commons.logging.LogFactory;
5 |
6 | /**
7 | * Endpoint which simply logs dead letter messages
8 | *
9 | */
10 | public class LoggingDeadLetterQueue
11 | {
12 | private static final Log logger = LogFactory.getLog(LoggingDeadLetterQueue.class);
13 |
14 | public void onReceive(Object message)
15 | {
16 | if (logger.isDebugEnabled() && message != null)
17 | {
18 | logger.debug("Received:\n\n" + message.toString() + "\n\n");
19 | }
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/messaging/MessageConsumer.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging;
2 |
3 | /**
4 | * Defines methods for handling messages. A separate message listener is
5 | * responsible for pulling messages off a queue and passing them to the consumer.
6 | *
7 | */
8 | public interface MessageConsumer
9 | {
10 |
11 | /**
12 | * Performs any processing required upon receiving the given POJO message
13 | *
14 | * @param message
15 | */
16 | public void onReceive(Object message);
17 |
18 | /**
19 | * The class of POJO messages expected
20 | *
21 | * @return the POJO message class
22 | */
23 | public Class> getConsumingMessageBodyClass();
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/messaging/MessageProducer.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Defines methods for sending message objects to a queue.
7 | *
8 | */
9 | public interface MessageProducer
10 | {
11 |
12 | /**
13 | * Send the given POJO message to the default queue for the producer
14 | *
15 | * @param message
16 | * @throws MessagingException
17 | */
18 | public void send(Object message) throws MessagingException;
19 |
20 | /**
21 | * Send the given POJO message to the default queue for the producer with the given headers
22 | *
23 | * @param message
24 | * @param headers
25 | * @throws MessagingException
26 | */
27 | public void send(Object message, Map headers) throws MessagingException;
28 |
29 | /**
30 | * Send the given POJO message to the given queue
31 | *
32 | * @param message
33 | * @param queueName
34 | * @throws MessagingException
35 | */
36 | public void send(Object message, String queueName) throws MessagingException;
37 |
38 | /**
39 | * Send the given POJO message to the given queue with the given headers
40 | *
41 | * @param message
42 | * @param queueName
43 | * @param headers
44 | * @throws MessagingException
45 | */
46 | public void send(Object message, String queueName, Map headers) throws MessagingException;
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/messaging/MessagingException.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging;
2 |
3 | import org.gengine.error.GengineRuntimeException;
4 |
5 | /**
6 | * Exception thrown when a message is unable to be processed.
7 | *
8 | */
9 | public class MessagingException extends GengineRuntimeException
10 | {
11 | private static final long serialVersionUID = 8192266871339806688L;
12 |
13 | public MessagingException(String message)
14 | {
15 | super(message);
16 | }
17 |
18 | public MessagingException(String message, Throwable cause)
19 | {
20 | super(message, cause);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/messaging/Reply.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging;
2 |
3 | /**
4 | * Defines a reply message for a specific {@link Request} message
5 | *
6 | */
7 | public interface Reply
8 | {
9 |
10 | /**
11 | * The correlating request ID for the reply.
12 | *
13 | * Note that this is unlikely to be the same value as the
14 | * 'native' correlation ID used by a particular messaging transport.
15 | *
16 | * @return the request correlation ID
17 | */
18 | public String getRequestId();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/gengine-messaging/gengine-messaging-commons/src/main/java/org/gengine/messaging/Request.java:
--------------------------------------------------------------------------------
1 | package org.gengine.messaging;
2 |
3 | /**
4 | * Defines a request message where a {@link Reply} is expected
5 | *
6 | * @param