Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call LineRecorder receiver's closeStream() (#433) #435

Merged
merged 1 commit into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package org.metafacture.strings;

import org.metafacture.framework.FluxCommand;
import org.metafacture.framework.ObjectPipe;
import org.metafacture.framework.ObjectReceiver;
import org.metafacture.framework.annotations.Description;
import org.metafacture.framework.annotations.In;
import org.metafacture.framework.annotations.Out;
import org.metafacture.framework.helpers.DefaultObjectPipe;

/**
* Collects strings and emits them as records when a line matches the pattern.
Expand All @@ -34,7 +34,7 @@
@In(String.class)
@Out(String.class)
@FluxCommand("lines-to-records")
public final class LineRecorder implements ObjectPipe<String, ObjectReceiver<String>> {
public final class LineRecorder extends DefaultObjectPipe<String, ObjectReceiver<String>> {

private static final int SB_CAPACITY = 4096 * 7;
// empty line is the default
Expand Down Expand Up @@ -70,34 +70,16 @@ record = new StringBuilder(SB_CAPACITY);
}
}

private boolean isClosed() {
return isClosed;
}

@Override
public void resetStream() {
record = new StringBuilder(SB_CAPACITY);
}

@Override
public void closeStream() {
getReceiver().process(record.toString());
isClosed = true;
protected void onCloseStream() {
if (record.length() > 0) {
getReceiver().process(record.toString());
}
}

@Override
public <R extends ObjectReceiver<String>> R setReceiver(final R newReceiver) {
receiver = newReceiver;
return newReceiver;
}

/**
* Returns a reference to the downstream module.
*
* @return reference to the downstream module
*/
protected ObjectReceiver<String> getReceiver() {
return receiver;
public void onResetStream() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I think this should be protected.

record = new StringBuilder(SB_CAPACITY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void shouldEmitLastRecordWithoutRecordMarkerWhenClosingStream() {
LINE_SEPARATOR +
RECORD3_PART2 +
LINE_SEPARATOR);
ordered.verify(receiver).closeStream();
ordered.verifyNoMoreInteractions();
}

Expand Down