Skip to content

Commit 59ff596

Browse files
committed
catches stream exception
1 parent a84bdc5 commit 59ff596

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
}

src/main/resources/flux-commands.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ filter-strings org.culturegraph.mf.stream.pipe.StringFilter
9494
draw-uniform-sample org.culturegraph.mf.stream.pipe.UniformSampler
9595

9696
catch-object-exception org.culturegraph.mf.stream.pipe.ObjectExceptionCatcher
97+
catch-stream-exception org.culturegraph.mf.stream.pipe.StreamExceptionCatcher
9798

9899
normalize-utf8 org.culturegraph.mf.stream.pipe.Utf8Normalizer
99100

0 commit comments

Comments
 (0)