|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 |
| -package org.culturegraph.mf.stream.pipe; |
17 |
| - |
18 |
| -import org.culturegraph.mf.framework.DefaultObjectPipe; |
19 |
| -import org.culturegraph.mf.framework.ObjectReceiver; |
20 |
| -import org.culturegraph.mf.framework.annotations.Description; |
21 |
| -import org.culturegraph.mf.framework.annotations.In; |
22 |
| -import org.culturegraph.mf.framework.annotations.Out; |
23 |
| -import org.slf4j.Logger; |
24 |
| -import org.slf4j.LoggerFactory; |
25 |
| - |
26 |
| - |
27 |
| -/** |
28 |
| - * Wraps the call to the process method of the downstream module |
29 |
| - * in a try catch block with Exception as the catch-block's |
30 |
| - * argument type. This module is supposed to stop any exception |
31 |
| - * from downstream modules to travel further upstream. If an |
32 |
| - * exception is caught, a log message with log level "error" is |
33 |
| - * written. |
34 |
| - * |
35 |
| - * @param <T> object type |
36 |
| - * |
37 |
| - * @author Christoph Böhme |
38 |
| - */ |
39 |
| -@Description("passes objects through and catches exceptions.") |
40 |
| -@In(Object.class) |
41 |
| -@Out(Object.class) |
42 |
| -public final class ObjectExceptionCatcher<T> extends |
43 |
| - DefaultObjectPipe<T, ObjectReceiver<T>> { |
44 |
| - |
45 |
| - private static final Logger LOG = LoggerFactory.getLogger(ObjectExceptionCatcher.class); |
46 |
| - private static final String MSG_PATTERN = "{}{}"; |
47 |
| - |
48 |
| - private final String logPrefix; |
49 |
| - |
50 |
| - public ObjectExceptionCatcher() { |
51 |
| - this(""); |
52 |
| - } |
53 |
| - |
54 |
| - public ObjectExceptionCatcher(final String logPrefix) { |
55 |
| - super(); |
56 |
| - this.logPrefix = logPrefix; |
57 |
| - } |
58 |
| - |
59 |
| - @Override |
60 |
| - public void process(final T obj) { |
61 |
| - try { |
62 |
| - getReceiver().process(obj); |
63 |
| - } catch(final Exception e) { // NO CHECKSTYLE: IllegalCatch |
64 |
| - // This module is supposed to intercept _all_ exceptions |
65 |
| - // thrown by downstream modules. Hence, we have to catch |
66 |
| - // Exception. |
67 |
| - LOG.error(MSG_PATTERN, logPrefix, obj); |
68 |
| - LOG.error(MSG_PATTERN, logPrefix, e); |
69 |
| - } |
70 |
| - } |
71 |
| - |
72 |
| -} |
| 16 | +package org.culturegraph.mf.stream.pipe; |
| 17 | + |
| 18 | +import org.culturegraph.mf.framework.DefaultObjectPipe; |
| 19 | +import org.culturegraph.mf.framework.ObjectReceiver; |
| 20 | +import org.culturegraph.mf.framework.annotations.Description; |
| 21 | +import org.culturegraph.mf.framework.annotations.In; |
| 22 | +import org.culturegraph.mf.framework.annotations.Out; |
| 23 | +import org.slf4j.Logger; |
| 24 | +import org.slf4j.LoggerFactory; |
| 25 | + |
| 26 | + |
| 27 | +/** |
| 28 | + * Wraps the call to the process method of the downstream module |
| 29 | + * in a try catch block with Exception as the catch-block's |
| 30 | + * argument type. This module is supposed to stop any exception |
| 31 | + * from downstream modules to travel further upstream. If an |
| 32 | + * exception is caught, a log message with log level "error" is |
| 33 | + * written. |
| 34 | + * |
| 35 | + * @param <T> object type |
| 36 | + * |
| 37 | + * @author Christoph Böhme |
| 38 | + */ |
| 39 | +@Description("passes objects through and catches exceptions.") |
| 40 | +@In(Object.class) |
| 41 | +@Out(Object.class) |
| 42 | +public final class ObjectExceptionCatcher<T> extends |
| 43 | + DefaultObjectPipe<T, ObjectReceiver<T>> { |
| 44 | + |
| 45 | + private static final Logger LOG = LoggerFactory.getLogger(ObjectExceptionCatcher.class); |
| 46 | + private static final String MSG_PATTERN = "{}{}"; |
| 47 | + |
| 48 | + private final String logPrefix; |
| 49 | + |
| 50 | + public ObjectExceptionCatcher() { |
| 51 | + this(""); |
| 52 | + } |
| 53 | + |
| 54 | + public ObjectExceptionCatcher(final String logPrefix) { |
| 55 | + super(); |
| 56 | + this.logPrefix = logPrefix; |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public void process(final T obj) { |
| 61 | + try { |
| 62 | + getReceiver().process(obj); |
| 63 | + } catch(final Exception e) { |
| 64 | + // NO CHECKSTYLE IllegalCatch FOR -1 LINES: |
| 65 | + // This module is supposed to intercept _all_ exceptions |
| 66 | + // thrown by downstream modules. Hence, we have to catch |
| 67 | + // Exception. |
| 68 | + LOG.error(MSG_PATTERN, logPrefix, obj); |
| 69 | + LOG.error(MSG_PATTERN, logPrefix, e); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments