Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
with:
fetch-depth: 0

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'temurin'
cache: maven

- name: Build/Test & SonarCloud Scan
run: mvn -B clean verify -Pcoverage,sonar -Dsonar.login=${{ secrets.SONAR_TOKEN }}
run: mvn -B clean verify -Pcoverage,sonar -Dsonar.token=${{ secrets.SONAR_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.github.switcherapi</groupId>
<artifactId>switcher-client</artifactId>
<packaging>jar</packaging>
<version>1.4.4</version>
<version>1.4.5-SNAPSHOT</version>

<name>Switcher Client</name>
<description>Switcher Client SDK for working with Switcher API</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ public class SnapshotCallback {
* @param version of the new snapshot
*/
public void onSnapshotUpdate(long version) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Snapshot updated: %s", version));
}
logger.debug("Snapshot updated: {}", version);
}

/**
Expand All @@ -24,8 +22,6 @@ public void onSnapshotUpdate(long version) {
* @param e Exception
*/
public void onSnapshotUpdateError(Exception e) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Failed to update snapshot: %s", e.getMessage()));
}
logger.debug("Failed to update snapshot: {}", e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ private static void initExecutorService() {
* @throws SwitcherKeyNotFoundException in case the key was not properly loaded
*/
public static Switcher getSwitcher(String key, boolean keepEntries) {
if (logger.isDebugEnabled())
logger.debug(String.format("key: %s - keepEntries: %s", key, keepEntries));
logger.debug("key: {} - keepEntries: {}", key, keepEntries);

if (!switchers.containsKey(key))
throw new SwitcherKeyNotFoundException(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,23 @@ public abstract class SwitcherExecutor {

protected boolean checkSnapshotVersion(ClientRemote clientRemote, final Domain domain) {
final String environment = SwitcherContextBase.contextStr(ContextKey.ENVIRONMENT);

if (logger.isDebugEnabled()) {
logger.debug(String.format("verifying snapshot version - environment: %s", environment));
}
logger.debug("verifying snapshot version - environment: {}", environment);

return clientRemote.checkSnapshotVersion(domain.getVersion());
}

protected Domain initializeSnapshotFromAPI(ClientRemote clientRemote) {
final String environment = SwitcherContextBase.contextStr(ContextKey.ENVIRONMENT);
logger.debug("initializing snapshot from API - environment: {}", environment);

if (logger.isDebugEnabled()) {
logger.debug(String.format("initializing snapshot from API - environment: %s", environment));
}

try {
final Snapshot snapshot = clientRemote.resolveSnapshot();
final String snapshotLocation = SwitcherContextBase.contextStr(ContextKey.SNAPSHOT_LOCATION);

if (snapshotLocation != null) {
SnapshotLoader.saveSnapshot(snapshot, snapshotLocation, environment);
}

return snapshot.getDomain();
} catch (SwitcherRemoteException | SwitcherSnapshotWriteException e) {
logger.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ public class AsyncSwitcher implements Runnable {
*/
public synchronized void execute(final Switcher switcher) {
this.switcher = switcher;

if (logger.isDebugEnabled())
logger.debug(String.format("nextRun: %s - currentTimeMillis: %s", nextRun,
System.currentTimeMillis()));
logger.debug("nextRun: {} - currentTimeMillis: {}", nextRun, System.currentTimeMillis());

if (nextRun < System.currentTimeMillis()) {
if (logger.isDebugEnabled())
logger.debug("Running AsyncSwitcher");
logger.debug("Running AsyncSwitcher");

this.nextRun = System.currentTimeMillis() + switcher.delay;
new Thread(this, AsyncSwitcher.class.getName()).start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public ClientWSImpl() {

@Override
public CriteriaResponse executeCriteriaService(final Switcher switcher, final String token) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("switcher: %s", switcher));
}
logger.debug("switcher: {}", switcher);

final String url = SwitcherContextBase.contextStr(ContextKey.URL);
final WebTarget myResource = client.target(String.format(CRITERIA_URL, url))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,8 @@ public CriteriaResponse executeCriteria(final Switcher switcher, final Domain do
*/
private CriteriaResponse processOperation(final Strategy[] configStrategies, final List<Entry> input,
final Switcher switcher) {

if (logger.isDebugEnabled()) {
logger.debug(String.format("configStrategies: %s", Arrays.toString(configStrategies)));
logger.debug(String.format("input: %s",
Arrays.toString(input != null ? input.toArray() : ArrayUtils.EMPTY_STRING_ARRAY)));
}
logger.debug("configStrategies: {}", () -> Arrays.toString(configStrategies));
logger.debug("input: {}", () -> Arrays.toString(input != null ? input.toArray() : ArrayUtils.EMPTY_STRING_ARRAY));

boolean result;
for (final Strategy strategy : configStrategies) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,13 @@ public void init() {

@Override
public CriteriaResponse executeCriteria(final Switcher switcher) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("switcher: %s", switcher));
}

logger.debug("switcher: {}", switcher);
final CriteriaResponse response = ClientLocalService.getInstance().executeCriteria(switcher, this.domain);

if (logger.isDebugEnabled()) {
logger.debug(String.format("[Offline] response: %s", response));
}
logger.debug("[Offline] response: {}", response);

return response;
}


@Override
public boolean checkSnapshotVersion() {
return super.checkSnapshotVersion(this.clientRemote, this.domain);
Expand All @@ -89,9 +82,7 @@ public void updateSnapshot() {

@Override
public void checkSwitchers(final Set<String> switchers) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("switchers: %s", switchers));
}
logger.debug("switchers: {}", switchers);

final List<String> response = ClientLocalService.getInstance().checkSwitchers(switchers, this.domain);
if (!response.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,11 @@ public SwitcherRemoteService() {

@Override
public CriteriaResponse executeCriteria(final Switcher switcher) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("switcher: %s", switcher));
}
logger.debug("switcher: {}", switcher);

try {
final CriteriaResponse response = this.clientRemote.executeCriteria(switcher);

if (logger.isDebugEnabled()) {
logger.debug(String.format("[Online] response: %s", response));
}
logger.debug("[Online] response: {}", response);

return response;
} catch (final SwitcherRemoteException e) {
Expand All @@ -59,9 +54,7 @@ private CriteriaResponse executeSilentCriteria(final Switcher switcher,
final SwitcherRemoteException e) {
if (StringUtils.isNotBlank(SwitcherContextBase.contextStr(ContextKey.SILENT_MODE))) {
CriteriaResponse response = this.switcherOffline.executeCriteria(switcher);
if (logger.isDebugEnabled()) {
logger.debug(String.format("[Silent] response: %s", response));
}
logger.debug("[Silent] response: {}", response);

return response;
} else {
Expand All @@ -87,9 +80,7 @@ public void updateSnapshot() {

@Override
public void checkSwitchers(final Set<String> switchers) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("switchers: %s", switchers));
}
logger.debug("switchers: {}", switchers);

final SwitchersCheck response = this.clientRemote.checkSwitchers(switchers);
if (response.getNotFound() != null && response.getNotFound().length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ public abstract class Validator {

protected static final Logger logger = LogManager.getLogger(Validator.class);

public static final String DEBUG_SWITCHER_INPUT = "switcherInput: %s";
public static final String DEBUG_STRATEGY = "strategy: %s";
public static final String DEBUG_SWITCHER_INPUT = "switcherInput: {}";
public static final String DEBUG_STRATEGY = "strategy: {}";

public boolean execute(final Strategy strategy, final Entry switcherInput)
throws SwitcherException {

if (logger.isDebugEnabled()) {
logger.debug(String.format(DEBUG_STRATEGY, strategy));
logger.debug(String.format(DEBUG_SWITCHER_INPUT, switcherInput));
}

logger.debug(DEBUG_STRATEGY, strategy);
logger.debug(DEBUG_SWITCHER_INPUT, switcherInput);
return process(strategy, switcherInput);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public class SnapshotEventHandler {
private static final Logger logger = LogManager.getLogger(SnapshotEventHandler.class);

public void onSuccess() {
if (logger.isDebugEnabled()) {
logger.debug("Snapshot has been changed");
}
logger.debug("Snapshot has been changed");
}

public void onError(SwitcherException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public class SwitcherUtils {

private static final Logger logger = LogManager.getLogger(SwitcherUtils.class);

private static final String LOG_DATE = "date: %s";
private static final String LOG_DATE = "date: {}";

private static final String LOG_TME = "time: %s";
private static final String LOG_TME = "time: {}";

private static final String LOG_ADDVALUE = "addValue: %s";
private static final String LOG_ADDVALUE = "addValue: {}";

/**
* [0] = s (seconds) [1] = m (minutes) [2] = h (hours) [3] = d (days)
Expand All @@ -59,10 +59,8 @@ private SwitcherUtils() {}

public static Date addTimeDuration(final String addValue, final Date date)
throws SwitcherInvalidDateTimeArgumentException {
if (logger.isDebugEnabled()) {
logger.debug(String.format(LOG_ADDVALUE, addValue));
logger.debug(String.format(LOG_DATE, date));
}
logger.debug(LOG_ADDVALUE, addValue);
logger.debug(LOG_DATE, date);

if (addValue.endsWith(DURATION[0])) {
return DateUtils.addSeconds(date, Integer.parseInt(addValue.replace(DURATION[0], StringUtils.EMPTY)));
Expand All @@ -78,9 +76,7 @@ public static Date addTimeDuration(final String addValue, final Date date)
}

public static long getMillis(final String time) {
if (logger.isDebugEnabled()) {
logger.debug(String.format(LOG_TME, time));
}
logger.debug(LOG_TME, time);

if (time.endsWith(DURATION[0])) {
return (long) (Double.parseDouble(time.replace(DURATION[0], StringUtils.EMPTY)) * 1000L);
Expand All @@ -92,19 +88,15 @@ public static long getMillis(final String time) {
}

public static String getFullDate(final String date) {
if (logger.isDebugEnabled()) {
logger.debug(String.format(LOG_DATE, date));
}
logger.debug(LOG_DATE, date);

final String time = RegExUtils.removePattern(date, FULL_DATE_REGEX).trim();
return getFullTime(date, time);
}

public static String getFullTime(final String date, final String time) {
if (logger.isDebugEnabled()) {
logger.debug(String.format(LOG_DATE, date));
logger.debug(String.format(LOG_TME, time));
}
logger.debug(LOG_DATE, date);
logger.debug(LOG_TME, time);

if (StringUtils.isBlank(time)) {
return String.format("%s 00:00:00", date);
Expand Down