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

SolaceIO.Read: Make sure the messageReceiver is always initialized. #32964

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -71,36 +71,39 @@ public UnboundedSolaceReader(UnboundedSolaceSource<T> currentSource) {

@Override
public boolean start() {
populateSession();
populateMessageConsumer();
getOrInitializeSessionService();
getOrInitializeMessageReceiver();
return advance();
}

public void populateSession() {
public SessionService getOrInitializeSessionService() {
if (sessionService == null) {
sessionService = getCurrentSource().getSessionServiceFactory().create();
}
if (sessionService.isClosed()) {
checkNotNull(sessionService).connect();
SessionService service = checkNotNull(sessionService);
if (service.isClosed()) {
service.connect();
}
return service;
}

private void populateMessageConsumer() {
private MessageReceiver getOrInitializeMessageReceiver() {
if (messageReceiver == null) {
messageReceiver = checkNotNull(sessionService).createReceiver();
messageReceiver = getOrInitializeSessionService().createReceiver();
messageReceiver.start();
}
MessageReceiver receiver = checkNotNull(messageReceiver);
if (receiver.isClosed()) {
receiver.start();
}
return receiver;
}

@Override
public boolean advance() {
BytesXMLMessage receivedXmlMessage;
try {
receivedXmlMessage = checkNotNull(messageReceiver).receive();
receivedXmlMessage = getOrInitializeMessageReceiver().receive();
} catch (IOException e) {
LOG.warn("SolaceIO.Read: Exception when pulling messages from the broker.", e);
return false;
Expand All @@ -119,13 +122,15 @@ public boolean advance() {
@Override
public void close() {
active.set(false);
checkNotNull(sessionService).close();
if (sessionService != null && !sessionService.isClosed()) {
checkNotNull(sessionService).close();
}
}

@Override
public Instant getWatermark() {
// should be only used by a test receiver
if (checkNotNull(messageReceiver).isEOF()) {
// should be only used by a test receiver in unit/integration tests
if (getOrInitializeMessageReceiver().isEOF()) {
return BoundedWindow.TIMESTAMP_MAX_VALUE;
}
return watermarkPolicy.getWatermark();
Expand Down
Loading