|
| 1 | +/** |
| 2 | + * |
| 3 | + */ |
| 4 | +package org.culturegraph.mf.stream.pipe; |
| 5 | + |
| 6 | +import org.culturegraph.mf.framework.DefaultStreamPipe; |
| 7 | +import org.culturegraph.mf.framework.StreamReceiver; |
| 8 | +import org.culturegraph.mf.framework.annotations.Description; |
| 9 | +import org.culturegraph.mf.framework.annotations.In; |
| 10 | +import org.culturegraph.mf.framework.annotations.Out; |
| 11 | +import org.slf4j.Logger; |
| 12 | +import org.slf4j.LoggerFactory; |
| 13 | + |
| 14 | +/** |
| 15 | + * @author schaeferd |
| 16 | + * |
| 17 | + */ |
| 18 | +@Description("passes streams events through and catches exceptions.") |
| 19 | +@In(StreamReceiver.class) |
| 20 | +@Out(StreamReceiver.class) |
| 21 | +public final class StreamExceptionCatcher extends |
| 22 | + DefaultStreamPipe<StreamReceiver> { |
| 23 | + |
| 24 | + private static final Logger LOG = LoggerFactory.getLogger(StreamExceptionCatcher.class); |
| 25 | + private static final String MSG_PATTERN = "{}{}"; |
| 26 | + |
| 27 | + private final String logPrefix; |
| 28 | + |
| 29 | + public StreamExceptionCatcher() { |
| 30 | + this(""); |
| 31 | + } |
| 32 | + |
| 33 | + public StreamExceptionCatcher(final String logPrefix) { |
| 34 | + super(); |
| 35 | + this.logPrefix = logPrefix; |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + @Override |
| 40 | + public void startRecord(final String identifier) { |
| 41 | + try { |
| 42 | + getReceiver().startRecord(identifier); |
| 43 | + |
| 44 | + } catch(final Exception e) { |
| 45 | + // NO CHECKSTYLE IllegalCatch FOR -1 LINES: |
| 46 | + // This module is supposed to intercept _all_ exceptions |
| 47 | + // thrown by downstream modules. Hence, we have to catch |
| 48 | + // Exception. |
| 49 | + LOG.error(MSG_PATTERN, logPrefix, "StartRecord" + identifier); |
| 50 | + LOG.error(MSG_PATTERN, logPrefix, e); |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void endRecord() { |
| 58 | + try { |
| 59 | + getReceiver().endRecord(); |
| 60 | + |
| 61 | + } catch(final Exception e) { |
| 62 | + // NO CHECKSTYLE IllegalCatch FOR -1 LINES: |
| 63 | + // This module is supposed to intercept _all_ exceptions |
| 64 | + // thrown by downstream modules. Hence, we have to catch |
| 65 | + // Exception. |
| 66 | + LOG.error(MSG_PATTERN, logPrefix, "endRecord"); |
| 67 | + LOG.error(MSG_PATTERN, logPrefix, e); |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + |
| 74 | + @Override |
| 75 | + public void startEntity(final String name) { |
| 76 | + try { |
| 77 | + getReceiver().startEntity(name); |
| 78 | + |
| 79 | + } catch(final Exception e) { |
| 80 | + // NO CHECKSTYLE IllegalCatch FOR -1 LINES: |
| 81 | + // This module is supposed to intercept _all_ exceptions |
| 82 | + // thrown by downstream modules. Hence, we have to catch |
| 83 | + // Exception. |
| 84 | + LOG.error(MSG_PATTERN, logPrefix, "startEntity" + name); |
| 85 | + LOG.error(MSG_PATTERN, logPrefix, e); |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | + } |
| 90 | + @Override |
| 91 | + public void endEntity() { |
| 92 | + try { |
| 93 | + getReceiver().endEntity(); |
| 94 | + |
| 95 | + } catch(final Exception e) { |
| 96 | + // NO CHECKSTYLE IllegalCatch FOR -1 LINES: |
| 97 | + // This module is supposed to intercept _all_ exceptions |
| 98 | + // thrown by downstream modules. Hence, we have to catch |
| 99 | + // Exception. |
| 100 | + LOG.error(MSG_PATTERN, logPrefix, "endEntity"); |
| 101 | + LOG.error(MSG_PATTERN, logPrefix, e); |
| 102 | + } |
| 103 | + |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public void literal(final String name, final String value) { |
| 109 | + try { |
| 110 | + getReceiver().literal(name, value); |
| 111 | + |
| 112 | + } catch(final Exception e) { |
| 113 | + // NO CHECKSTYLE IllegalCatch FOR -1 LINES: |
| 114 | + // This module is supposed to intercept _all_ exceptions |
| 115 | + // thrown by downstream modules. Hence, we have to catch |
| 116 | + // Exception. |
| 117 | + LOG.error(MSG_PATTERN, logPrefix, "literal " + name +" " + value); |
| 118 | + LOG.error(MSG_PATTERN, logPrefix, e); |
| 119 | + } |
| 120 | + |
| 121 | + |
| 122 | + } |
| 123 | + |
| 124 | +} |
0 commit comments