Skip to content

Commit 7065cc0

Browse files
committed
Added Receiver interface
Added an interface to group all receiver interfaces used in Metafacture. This allows to make the template argument to Sender more specific.
1 parent a84bdc5 commit 7065cc0

18 files changed

+94
-64
lines changed

src/main/java/org/culturegraph/mf/flux/parser/Flow.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.culturegraph.mf.exceptions.FluxParseException;
2424
import org.culturegraph.mf.framework.LifeCycle;
2525
import org.culturegraph.mf.framework.ObjectReceiver;
26+
import org.culturegraph.mf.framework.Receiver;
2627
import org.culturegraph.mf.framework.Sender;
2728
import org.culturegraph.mf.framework.Tee;
2829
import org.culturegraph.mf.stream.source.StdInOpener;
@@ -44,7 +45,7 @@ final class Flow {
4445
private boolean joinLooseEnds;
4546

4647
@SuppressWarnings({ "unchecked", "rawtypes" })
47-
public void addElement(final LifeCycle nextElement) {
48+
public void addElement(final Receiver nextElement) {
4849
if(element==null){
4950
setStart((ObjectReceiver<? extends Object>) nextElement);
5051
return;
@@ -53,7 +54,7 @@ public void addElement(final LifeCycle nextElement) {
5354
final Sender sender = (Sender) element;
5455
if (joinLooseEnds) {
5556
teeStack.pop();
56-
for (LifeCycle looseEnd : looseEndsStack.pop()) {
57+
for (final LifeCycle looseEnd : looseEndsStack.pop()) {
5758
if (looseEnd instanceof Tee) {
5859
((Tee) looseEnd).addReceiver(nextElement);
5960
} else {
@@ -115,7 +116,7 @@ public void close() {
115116
start.closeStream();
116117
}
117118

118-
public LifeCycle getFirst() {
119+
public Receiver getFirst() {
119120
return start;
120121
}
121122
}

src/main/java/org/culturegraph/mf/flux/parser/FluxProgramm.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import org.culturegraph.mf.exceptions.FluxParseException;
3131
import org.culturegraph.mf.flux.HelpPrinter;
32-
import org.culturegraph.mf.framework.LifeCycle;
32+
import org.culturegraph.mf.framework.Receiver;
3333
import org.culturegraph.mf.util.ResourceUtil;
3434
import org.culturegraph.mf.util.reflection.ObjectFactory;
3535

@@ -39,7 +39,7 @@
3939
*/
4040
public final class FluxProgramm {
4141

42-
private static final ObjectFactory<LifeCycle> COMMAND_FACTORY = new ObjectFactory<LifeCycle>();
42+
private static final ObjectFactory<Receiver> COMMAND_FACTORY = new ObjectFactory<Receiver>();
4343
private static final String PROPERTIES_LOCATION = "flux-commands.properties";
4444

4545
static {
@@ -48,9 +48,9 @@ public final class FluxProgramm {
4848
.getResources(PROPERTIES_LOCATION);
4949
while (enumeration.hasMoreElements()) {
5050
final URL url = enumeration.nextElement();
51-
COMMAND_FACTORY.loadClassesFromMap(ResourceUtil.loadProperties(url), LifeCycle.class);
51+
COMMAND_FACTORY.loadClassesFromMap(ResourceUtil.loadProperties(url), Receiver.class);
5252
}
53-
} catch (IOException e) {
53+
} catch (final IOException e) {
5454
throw new FluxParseException("unable to load properties.", e);
5555
}
5656
}
@@ -60,15 +60,15 @@ public final class FluxProgramm {
6060
private final Map<String, Wormhole> wormholeNameMapping = new HashMap<String, Wormhole>();
6161
private final Map<Flow, Wormhole> wormholeInFlowMapping = new Hashtable<Flow, Wormhole>();
6262

63-
private static LifeCycle createElement(final String name, final Map<String, String> namedArgs,
63+
private static Receiver createElement(final String name, final Map<String, String> namedArgs,
6464
final List<Object> cArgs) {
6565

66-
final LifeCycle newElement;
66+
final Receiver newElement;
6767
if (COMMAND_FACTORY.containsKey(name)) {
6868
newElement = COMMAND_FACTORY.newInstance(name, namedArgs, cArgs.toArray());
6969

7070
} else {
71-
newElement = ObjectFactory.newInstance(ObjectFactory.loadClass(name, LifeCycle.class), cArgs.toArray());
71+
newElement = ObjectFactory.newInstance(ObjectFactory.loadClass(name, Receiver.class), cArgs.toArray());
7272
ObjectFactory.applySetters(newElement, namedArgs);
7373
}
7474
return newElement;
@@ -136,20 +136,20 @@ protected void nextFlow() {
136136

137137
protected void compile() {
138138

139-
for (Wormhole wormhole : wormholeNameMapping.values()) {
139+
for (final Wormhole wormhole : wormholeNameMapping.values()) {
140140
if (wormhole.getOut() == null) {
141141
throw new FluxParseException("Wormhole " + wormhole.getName() + " is going nowhere");
142142
}
143143

144-
for (Flow flow : wormhole.getIns()) {
144+
for (final Flow flow : wormhole.getIns()) {
145145

146146
flow.addElement(wormhole.getOut().getFirst());
147147
}
148148
}
149149
}
150150

151151
public void start() {
152-
for (Flow flow : initialFlows) {
152+
for (final Flow flow : initialFlows) {
153153
flow.start();
154154
if (!wormholeInFlowMapping.containsKey(flow)) {
155155
flow.close();
@@ -197,7 +197,7 @@ public void finished(final Flow flow) {
197197
insReady.remove(flow);
198198
insFinished.add(flow);
199199
if (insReady.isEmpty()) {
200-
for (Flow finished : insFinished) {
200+
for (final Flow finished : insFinished) {
201201
finished.close();
202202
}
203203
}

src/main/java/org/culturegraph/mf/framework/DefaultObjectPipe.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.culturegraph.mf.framework;
1717

1818
/**
19-
* Default implementation for {@link ObjectPipe}s which simply
19+
* Default implementation for {@link ObjectPipe}s which simply
2020
* does nothing.
2121
*
2222
* @param <T> object type that this module processes
@@ -25,19 +25,19 @@
2525
* @author Christoph Böhme
2626
*
2727
*/
28-
public class DefaultObjectPipe<T, R extends LifeCycle>
28+
public class DefaultObjectPipe<T, R extends Receiver>
2929
extends DefaultSender<R> implements ObjectPipe<T, R> {
3030

3131
// CHECKSTYLE OFF: StrictDuplicateCode
3232
// Code duplication in DefaultObjectPipe and DefaultObjectReceiver
33-
// cannot be avoided. DefaultObjectPipe combines the logic
33+
// cannot be avoided. DefaultObjectPipe combines the logic
3434
// from DefaultSender and DefaultObjectReceiver but can only
3535
// have one of these classes as its base class. Hence, the
3636
// logic from the second one must be duplicated here.
3737

3838
@Override
3939
public void process(final T obj) {
40-
// Default implementation does nothing
40+
// Default implementation does nothing
4141
}
4242

4343
// CHECKSTYLE ON: StrictDuplicateCode

src/main/java/org/culturegraph/mf/framework/DefaultSender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @author Christoph Böhme
3131
*
3232
*/
33-
public class DefaultSender<T extends LifeCycle> implements Sender<T> {
33+
public class DefaultSender<T extends Receiver> implements Sender<T> {
3434

3535
private T receiver;
3636
private boolean isClosed;

src/main/java/org/culturegraph/mf/framework/DefaultStreamPipe.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
package org.culturegraph.mf.framework;
1717

1818
/**
19-
* Default implementation for {@link StreamPipe}s which simply
19+
* Default implementation for {@link StreamPipe}s which simply
2020
* does nothing.
2121
*
2222
* @param <R> receiver type of the downstream receiver
2323
*
2424
* @author Markus Michael Geipel, Christoph Böhme
2525
*
2626
*/
27-
public class DefaultStreamPipe<R extends LifeCycle>
27+
public class DefaultStreamPipe<R extends Receiver>
2828
extends DefaultSender<R> implements StreamPipe<R> {
2929

3030
// CHECKSTYLE OFF: StrictDuplicateCode
3131
// Code duplication in DefaultStreamPipe and DefaultStreamReceiver
32-
// cannot be avoided. DefaultStreamPipe combines the logic
32+
// cannot be avoided. DefaultStreamPipe combines the logic
3333
// from DefaultSender and DefaultStreamReceiver but can only
3434
// have one of these classes as its base class. Hence, the
3535
// logic from the second one must be duplicated here.

src/main/java/org/culturegraph/mf/framework/DefaultTee.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @author Christoph Böhme
2929
*/
30-
public class DefaultTee<T extends LifeCycle> implements Tee<T> {
30+
public class DefaultTee<T extends Receiver> implements Tee<T> {
3131

3232
private final List<T> receivers = new ArrayList<T>();
3333

@@ -72,15 +72,15 @@ public final Tee<T> clearReceivers() {
7272
@Override
7373
public final void resetStream() {
7474
onResetStream();
75-
for (T receiver : receivers) {
75+
for (final T receiver : receivers) {
7676
receiver.resetStream();
7777
}
7878
}
7979

8080
@Override
8181
public final void closeStream() {
8282
onCloseStream();
83-
for (T receiver : receivers) {
83+
for (final T receiver : receivers) {
8484
receiver.closeStream();
8585
}
8686
}
@@ -92,37 +92,37 @@ public final void closeStream() {
9292
* receivers.
9393
*/
9494
protected void onChangeReceivers() {
95-
// Default implementation does nothing
95+
// Default implementation does nothing
9696
}
9797

9898
/**
9999
* Invoked when the {@code resetStream()} method is called.
100-
* Override this method to perform a reset of the module.
100+
* Override this method to perform a reset of the module.
101101
*
102-
* Do not call the {@code resetStream()} method of the next modules downstream.
103-
* This is handled by the implementation of {@code resetStream()} in
102+
* Do not call the {@code resetStream()} method of the next modules downstream.
103+
* This is handled by the implementation of {@code resetStream()} in
104104
* {@code DefaultTee}.
105105
*
106106
* {@code onResetStream()} is called before {@code DefaultTee} calls the
107107
* {@code resetStream()} method of the downstream modules.
108108
*/
109109
protected void onResetStream() {
110-
// Default implementation does nothing
110+
// Default implementation does nothing
111111
}
112112

113113
/**
114-
* Invoked when the {@code closeStream()} method is called. Override
115-
* this method to close any resources used by the module.
114+
* Invoked when the {@code closeStream()} method is called. Override
115+
* this method to close any resources used by the module.
116116
*
117-
* Do not call the {@code closeStream()} method of the next modules
118-
* downstream. This is handled by the implementation of
117+
* Do not call the {@code closeStream()} method of the next modules
118+
* downstream. This is handled by the implementation of
119119
* {@code closeStream()} in {@code DefaultTee}.
120120
*
121-
* {@code onCloseStream()} is called before {@code DefaultTee} calls
121+
* {@code onCloseStream()} is called before {@code DefaultTee} calls
122122
* the {@code closeStream()} method of the downstream modules.
123123
*/
124124
protected void onCloseStream() {
125-
// Default implementation does nothing
125+
// Default implementation does nothing
126126
}
127127

128128
/**

src/main/java/org/culturegraph/mf/framework/DefaultXmlPipe.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@
2424
import org.xml.sax.SAXParseException;
2525

2626
/**
27-
* Default implementation for {@link XmlPipe}s which simply
27+
* Default implementation for {@link XmlPipe}s which simply
2828
* does nothing.
2929
*
3030
* @param <R> receiver type of the downstream module
3131
*
3232
* @author Christoph Böhme
3333
*
3434
*/
35-
public class DefaultXmlPipe <R extends LifeCycle>
35+
public class DefaultXmlPipe <R extends Receiver>
3636
extends DefaultSender<R> implements XmlPipe<R> {
3737

3838
// CHECKSTYLE OFF: StrictDuplicateCode
3939
// Code duplication in DefaultXmlPipe and DefaultXmlReceiver
40-
// cannot be avoided. DefaultXmlPipe combines the logic
40+
// cannot be avoided. DefaultXmlPipe combines the logic
4141
// from DefaultSender and DefaultXmlReceiver but can only
4242
// have one of these classes as its base class. Hence, the
4343
// logic from the second one must be duplicated here.
4444

4545
@Override
4646
public void setDocumentLocator(final Locator locator) {
47-
// Default implementation does nothing
47+
// Default implementation does nothing
4848
}
4949

5050
@Override
@@ -168,7 +168,7 @@ public void endCDATA() throws SAXException {
168168
}
169169

170170
@Override
171-
public void comment(final char[] chars, final int start, final int length)
171+
public void comment(final char[] chars, final int start, final int length)
172172
throws SAXException {
173173
// Default implementation does nothing
174174
}

src/main/java/org/culturegraph/mf/framework/ObjectPipe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
* @author Christoph Böhme
2929
*
3030
*/
31-
public interface ObjectPipe<T, R extends LifeCycle> extends ObjectReceiver<T>, Sender<R> {
31+
public interface ObjectPipe<T, R extends Receiver> extends ObjectReceiver<T>, Sender<R> {
3232
// Just a combination of sender and receiver
3333
}

src/main/java/org/culturegraph/mf/framework/ObjectReceiver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
* @author Christoph Böhme
2727
*
2828
*/
29-
public interface ObjectReceiver<T> extends LifeCycle {
29+
public interface ObjectReceiver<T> extends Receiver {
3030

3131
/**
32-
* This method is called by upstream modules to trigger the
32+
* This method is called by upstream modules to trigger the
3333
* processing of {@code obj}.
3434
*
3535
* @param obj the object to be processed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2014 Christoph Böhme
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.culturegraph.mf.framework;
17+
18+
/**
19+
* A common base for all receiver interfaces.
20+
*
21+
* @author Christoph Böhme
22+
*
23+
*/
24+
public interface Receiver extends LifeCycle {
25+
// This interface servces only as a common
26+
// base for all receiver interfaces.
27+
}

0 commit comments

Comments
 (0)