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
@@ -0,0 +1,27 @@
/*
* Copyright (C) Sportradar AG. See LICENSE for full license governing this code
*/

package com.sportradar.unifiedodds.sdk.entities;

import com.sportradar.utils.Urn;
import java.util.Date;

/**
* Defines methods used to access data of a change
*/
public interface Change {
/**
* Returns the {@link Urn} instance specifying the sport event
*
* @return - the {@link Urn} instance specifying the sport event
*/
Urn getSportEventId();

/**
* Returns the {@link Date} instance specifying the last update time
*
* @return - the {@link Date} instance specifying the last update time
*/
Date getUpdateTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,7 @@

package com.sportradar.unifiedodds.sdk.entities;

import com.sportradar.utils.Urn;
import java.util.Date;

/**
* Defines methods used to access data of a fixture change
*/
public interface FixtureChange {
/**
* Returns the {@link Urn} instance specifying the sport event
*
* @return - the {@link Urn} instance specifying the sport event
*/
Urn getSportEventId();

/**
* Returns the {@link Date} instance specifying the last update time
*
* @return - the {@link Date} instance specifying the last update time
*/
Date getUpdateTime();
}
public interface FixtureChange extends Change {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,7 @@

package com.sportradar.unifiedodds.sdk.entities;

import com.sportradar.utils.Urn;
import java.util.Date;

/**
* Defines methods used to access data of a result change
*/
public interface ResultChange {
/**
* Returns the {@link Urn} instance specifying the sport event
*
* @return - the {@link Urn} instance specifying the sport event
*/
Urn getSportEventId();

/**
* Returns the {@link Date} instance specifying the last update time
*
* @return - the {@link Date} instance specifying the last update time
*/
Date getUpdateTime();
}
public interface ResultChange extends Change {}
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ private Map<HomeAway, String> provideHomeAway(SapiSportEvent se) {
return null;
}

Map<HomeAway, String> result = new HashMap<>(2);
Map<HomeAway, String> result = new EnumMap<>(HomeAway.class);
result.put(HomeAway.Home, home.getId());
result.put(HomeAway.Away, away.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class CompetitorCiImpl implements CompetitorCi, ExportableCacheItem {
) {
this(id, dataRouterManager, defaultLocale, exceptionHandlingStrategy);
if (data != null && data.getPlayers() != null && !data.getPlayers().getPlayer().isEmpty()) {
this.lastTimeCompetitorProfileIsFetched = Calendar.getInstance().getTime();
this.lastTimeCompetitorProfileIsFetched = new Date();
if (cultureCompetitorProfileFetched == null) {
this.cultureCompetitorProfileFetched = Collections.synchronizedList(new ArrayList<>());
}
Expand All @@ -215,7 +215,7 @@ class CompetitorCiImpl implements CompetitorCi, ExportableCacheItem {
) {
this(id, dataRouterManager, defaultLocale, exceptionHandlingStrategy);
if (data != null && data.getPlayers() != null && !data.getPlayers().getPlayer().isEmpty()) {
this.lastTimeCompetitorProfileIsFetched = Calendar.getInstance().getTime();
this.lastTimeCompetitorProfileIsFetched = new Date();
if (cultureCompetitorProfileFetched == null) {
this.cultureCompetitorProfileFetched = Collections.synchronizedList(new ArrayList<>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.inject.Inject;
import com.sportradar.unifiedodds.sdk.EventChangeListener;
import com.sportradar.unifiedodds.sdk.LoggerDefinitions;
import com.sportradar.unifiedodds.sdk.entities.Change;
import com.sportradar.unifiedodds.sdk.entities.FixtureChange;
import com.sportradar.unifiedodds.sdk.entities.ResultChange;
import com.sportradar.unifiedodds.sdk.entities.SportEvent;
Expand Down Expand Up @@ -62,6 +63,9 @@ public EventUpdate(Urn id, Date updated, SportEvent sportEvent, boolean isFixtur
private static final Logger clientInteractionLogger = LoggerFactory.getLogger(
LoggerDefinitions.UfSdkClientInteractionLog.class
);
private static final Comparator<Change> BY_UPDATE_TIME = Comparator.comparing(change ->
change.getUpdateTime().getTime()
);
private final SdkInternalConfiguration configuration;
private final SportDataProviderImpl sportDataProvider;
private final SportEventCache sportEventCache;
Expand Down Expand Up @@ -330,11 +334,7 @@ private void fetchFixtures() {
}

if (changes != null) {
changes =
changes
.stream()
.sorted(Comparator.comparing(c -> c.getUpdateTime().getTime()))
.collect(Collectors.toList());
changes = changes.stream().sorted(BY_UPDATE_TIME).collect(Collectors.toList());
}

for (FixtureChange fixtureChange : changes) {
Expand Down Expand Up @@ -413,11 +413,7 @@ private void fetchResults() {
}

if (changes != null) {
changes =
changes
.stream()
.sorted(Comparator.comparing(c -> c.getUpdateTime().getTime()))
.collect(Collectors.toList());
changes = changes.stream().sorted(BY_UPDATE_TIME).collect(Collectors.toList());
}

for (ResultChange resultChange : changes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ public String toString() {
return "PeriodStatisticsImpl{}";
}

String teamStatisticsResult = "";
for (TeamStatisticsDto teamStatistics : stats.getTeamStatisticDtos()) {
teamStatisticsResult += " | " + teamStatistics.toString();
}
if (teamStatisticsResult.length() > 3) {
teamStatisticsResult = teamStatisticsResult.substring(3);
}
String teamStatisticsResult = stats
.getTeamStatisticDtos()
.stream()
.map(TeamStatisticsDto::toString)
.collect(Collectors.joining(" | "));

return (
"PeriodStatisticsImpl{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Urn getSportId() {
public String getMarketId() {
StringBuilder sb = new StringBuilder(String.valueOf(marketTypeId));
if (marketSubTypeId != null) {
sb.append(":").append(getMarketSubTypeId());
sb.append(':').append(getMarketSubTypeId());
}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ static AbstractMap.SimpleImmutableEntry<String, List<String>> parseDescriptor(St

List<String> expressions = new ArrayList<>();
for (int currentIndex = 0; currentIndex < descriptor.length(); currentIndex++) {
int startIndex = descriptor.indexOf("{", currentIndex);
int endIndex = descriptor.indexOf("}", currentIndex);
int startIndex = descriptor.indexOf('{', currentIndex);
int endIndex = descriptor.indexOf('}', currentIndex);

if (startIndex < 0 && endIndex < 0) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,29 +604,31 @@ static class StatusMessage {

@Override
public String toString() {
StringBuilder sb = new StringBuilder("An error occurred while generating the name for event=[")
.append(sportEvent)
.append("], market=[");
String specifierString = marketSpecifiers == null
? "null"
: marketSpecifiers
.entrySet()
.stream()
.map(e -> "{" + e.getKey() + "}={" + e.getValue() + "}")
.collect(Collectors.joining("|"));
sb.append(" MarketId=").append(marketId);
sb.append(" Specifiers=[").append(specifierString).append("]");

StringBuilder sb = new StringBuilder(200)
.append("An error occurred while generating the name for event=[")
.append(sportEvent)
.append("], market=[ MarketId=")
.append(marketId)
.append(" Specifiers=[")
.append(specifierString)
.append(']');

if (outcomeId != null) {
sb.append(" OutcomeId=").append(outcomeId);
}

sb.append("]");

sb.append(" Locale=").append(locales);
sb.append("] Locale=").append(locales);

if (outcomeName != null) {
sb.append(" Retrieved nameDescriptor=[").append(outcomeName).append("]");
sb.append(" Retrieved nameDescriptor=[").append(outcomeName).append(']');
}

sb.append("]. Additional message: ").append(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,10 @@ public void handleRecovery(Recoverable recoverable) {
MDC.setContextMap(sdkMdcContextDescription);
long now = timeUtils.now();

StringBuilder notificationString = new StringBuilder(
"Connection reestablished. Last valid producers alive(w\\s=1 && producer up) messages received: "
);
StringBuilder notificationString = new StringBuilder(200)
.append(
"Connection reestablished. Last valid producers alive(w\\s=1 && producer up) messages received: "
);
for (ProducerInfo pi : perProducerInfo.values()) {
if (pi.isDisabled()) continue;

Expand All @@ -418,7 +419,7 @@ public void handleRecovery(Recoverable recoverable) {
} else {
secondsAgo = -99;
}
notificationString.append("(").append(pi).append(":").append(secondsAgo).append(")");
notificationString.append('(').append(pi).append(':').append(secondsAgo).append(')');
}
notificationString.append(
" seconds ago. Recovery will be initiated when the Alive messages start to process."
Expand Down Expand Up @@ -668,19 +669,19 @@ private static void updateLogStringBuilders(
) {
long systemInactivityInterval = now - pi.getLastSystemAliveReceivedTimestamp();
heartBeatBuilder
.append("(")
.append('(')
.append(pi)
.append(":")
.append(':')
.append(systemInactivityInterval / 1000)
.append(")");
.append(')');

statusBuilder.append("(").append(pi);
statusBuilder.append('(').append(pi);
long lastMessageReceivedAgo = 0;
if (pi.getLastMessageReceivedTimestamp() != 0) {
lastMessageReceivedAgo =
TimeUnit.SECONDS.convert(now - pi.getLastMessageReceivedTimestamp(), TimeUnit.MILLISECONDS);
}
statusBuilder.append(":").append(lastMessageReceivedAgo);
statusBuilder.append(':').append(lastMessageReceivedAgo);

long lastMessageProcessingDelay = 0;
if (pi.getLastProcessedMessageGenTimestamp() != 0) {
Expand All @@ -690,9 +691,7 @@ private static void updateLogStringBuilders(
TimeUnit.MILLISECONDS
);
}
statusBuilder.append(":").append(lastMessageProcessingDelay);

statusBuilder.append(":");
statusBuilder.append(':').append(lastMessageProcessingDelay).append(':');
if (!pi.isFlaggedDown()) {
statusBuilder.append("UP");
} else {
Expand All @@ -707,7 +706,7 @@ private static void updateLogStringBuilders(
}
statusBuilder.append(", RecoveryState=").append(pi.getRecoveryState());
}
statusBuilder.append(")");
statusBuilder.append(')');
}

private void performProducerRecovery(ProducerInfo pi) {
Expand Down Expand Up @@ -1245,11 +1244,11 @@ private String createInitiateRecoveryUrl() {
reqBuilder.append("recovery/initiate_request?");

if (fromTimestamp != 0) {
reqBuilder.append("after=").append(fromTimestamp).append("&");
reqBuilder.append("after=").append(fromTimestamp).append('&');
}

if (config.getSdkNodeId() != null) {
reqBuilder.append("node_id=").append(config.getSdkNodeId()).append("&");
reqBuilder.append("node_id=").append(config.getSdkNodeId()).append('&');
}

reqBuilder.append("request_id=").append(recoveryId);
Expand Down
38 changes: 9 additions & 29 deletions sdk-core/src/main/java/com/sportradar/utils/SdkHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,66 +304,46 @@ public static String stringSetToString(Set<String> set) {
if (set == null || set.isEmpty()) {
return null;
}
String result = "";
for (String key : set) {
result += "," + key;
}
if (result.length() > 1) {
result = result.substring(1);
}
return result;
return String.join(",", set);
}

public static String integerSetToString(Set<Integer> set) {
if (set == null || set.isEmpty()) {
return null;
}
String result = "";
for (int key : set) {
result += "," + key;
}
if (result.length() > 1) {
result = result.substring(1);
}
return result;
return set.stream().map(String::valueOf).collect(Collectors.joining(","));
}

public static String dictionaryToString(Map<String, String> dict) {
if (dict == null || dict.isEmpty()) {
return null;
}
String result = null;
for (String key : dict.keySet()) {
result += "," + key + "=" + dict.get(key);
StringBuilder result = new StringBuilder();
for (Map.Entry<String, String> entry : dict.entrySet()) {
result.append(',').append(entry.getKey()).append('=').append(entry.getValue());
}
return result;
return result.toString();
}

public static String specifierListToString(List<Specifier> specifiers) {
if (specifiers == null || specifiers.isEmpty()) {
return null;
}
String result = specifiers
.stream()
.map(n -> String.valueOf(n))
.collect(Collectors.joining("|", "{", "}"));
return result;
return specifiers.stream().map(String::valueOf).collect(Collectors.joining("|", "{", "}"));
}

public static String specifierKeyListToString(List<Specifier> specifiers) {
if (specifiers == null || specifiers.isEmpty()) {
return null;
}
String result = specifiers.stream().map(n -> n.getName()).collect(Collectors.joining("|", "{", "}"));
return result;
return specifiers.stream().map(Specifier::getName).collect(Collectors.joining("|", "{", "}"));
}

public static String localeListToString(List<Locale> locales) {
if (locales == null || locales.isEmpty()) {
return null;
}
String result = locales.stream().map(Locale::getLanguage).collect(Collectors.joining(", "));
return result;
return locales.stream().map(Locale::getLanguage).collect(Collectors.joining(", "));
}

public static boolean checkCauseReason(Throwable cause, String message) {
Expand Down