Skip to content
Open
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 @@ -27,9 +27,9 @@
import de.ii.xtraplatform.features.sql.domain.SqlClient;
import de.ii.xtraplatform.features.sql.domain.SqlConnector;
import de.ii.xtraplatform.features.sql.domain.SqlDbmsPgis;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection; // NOPMD
import java.sql.SQLException; // NOPMD
import java.sql.Statement; // NOPMD
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -78,6 +78,7 @@
*/
@Singleton
@AutoBind
@SuppressWarnings("PMD.DoNotUseThreads")
public class FeatureChangesPgListener implements FeatureQueriesExtension {

private static final Logger LOGGER = LoggerFactory.getLogger(FeatureChangesPgListener.class);
Expand Down Expand Up @@ -105,9 +106,11 @@ public boolean isSupported(
return false;
}
if (!((FeatureProviderSqlData) data).getDatasetChanges().isModeTrigger()) {
LOGGER.warn(
"Feature provider with id '{}' does not support change listeners: datasetChanges.mode is not 'TRIGGER'",
data.getId());
if (LOGGER.isWarnEnabled()) {
LOGGER.warn(
"Feature provider with id '{}' does not support change listeners: datasetChanges.mode is not 'TRIGGER'",
data.getId());
}
return false;
}

Expand All @@ -122,15 +125,10 @@ public void on(
Optional<FeatureChangesPgConfiguration> configuration =
getConfiguration(provider.getData().getExtensions());

if (configuration.isPresent()) {
if (configuration.isPresent() && hook == LIFECYCLE_HOOK.STARTED) {
SqlClient sqlClient = ((SqlConnector) connector).getSqlClient();

switch (hook) {
case STARTED:
subscribe(
provider, configuration.get(), sqlClient::getConnection, sqlClient::getNotifications);
break;
}
subscribe(
provider, configuration.get(), sqlClient::getConnection, sqlClient::getNotifications);
}
}

Expand Down Expand Up @@ -211,7 +209,9 @@ private void poll(String provider, FeatureChanges featureChangeHandler) {
private void poll(
String provider, FeatureChanges featureChangeHandler, Subscription subscription) {
if (!subscription.isConnected()) {
LOGGER.debug("Lost connection to retrieve feature changes for {}", subscription.getLabel());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Lost connection to retrieve feature changes for {}", subscription.getLabel());
}
subscriptions.get(provider).remove(subscription.getChannel());
subscribe(provider, subscription);

Expand Down Expand Up @@ -250,8 +250,9 @@ private List<Subscription> getSubscriptions(
includes.forEach(
include -> {
if (types.stream()
.map(FeatureSchema::getName)
.noneMatch(type -> Objects.equals(type, include))) {
.map(FeatureSchema::getName)
.noneMatch(type -> Objects.equals(type, include))
&& LOGGER.isWarnEnabled()) {
LOGGER.warn("Change listener: unknown type '{}' in listenForTypes", include);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
@Value.Immutable
public interface Notification {

Splitter SPLITTER = Splitter.on(",").trimResults();

static Notification from(String featureType, String payload) {
return ImmutableNotification.builder().featureType(featureType).payload(payload).build();
}
Expand Down Expand Up @@ -55,22 +57,22 @@ default FeatureChange asFeatureChange() {
.build();
}

Splitter SPLITTER = Splitter.on(",").trimResults();

private static List<String> parseFeatureId(String featureId) {
if (featureId.isEmpty() || featureId.equalsIgnoreCase("NULL")) return ImmutableList.of();
if (featureId.isEmpty() || "NULL".equalsIgnoreCase(featureId)) {
return ImmutableList.of();
}

return ImmutableList.of(featureId);
}

private static Optional<Interval> parseInterval(List<String> interval) {
if (interval.get(0).isEmpty()) {
// no instant or interval, ignore
} else if (interval.get(1).isEmpty()) {
if (interval.get(1).isEmpty()) {
// an instant
try {
Instant instant = parseTimestamp(interval.get(0));
if (Objects.nonNull(instant)) return Optional.of(Interval.of(instant, instant));
if (Objects.nonNull(instant)) {
return Optional.of(Interval.of(instant, instant));
}
} catch (Exception e) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import com.google.common.base.Strings;
import de.ii.xtraplatform.base.domain.util.Tuple;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Connection; // NOPMD
import java.sql.SQLException; // NOPMD
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
Expand Down
Loading