mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
Java code style
This commit is contained in:
parent
3b778f4711
commit
96721b863b
@ -32,7 +32,8 @@ public class PollingToggleRepository implements ToggleRepository {
|
|||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
TIMER.setRemoveOnCancelPolicy(true);
|
TIMER.setRemoveOnCancelPolicy(true);
|
||||||
@ -43,7 +44,7 @@ public class PollingToggleRepository implements ToggleRepository {
|
|||||||
private Map<String, Toggle> togglesCache;
|
private Map<String, Toggle> togglesCache;
|
||||||
|
|
||||||
|
|
||||||
public PollingToggleRepository(final ToggleRepository toggleRepository, final int pollIntervalSeconds){
|
public PollingToggleRepository(final ToggleRepository toggleRepository, final int pollIntervalSeconds) {
|
||||||
this.toggleRepository = toggleRepository;
|
this.toggleRepository = toggleRepository;
|
||||||
this.pollIntervalSeconds = pollIntervalSeconds;
|
this.pollIntervalSeconds = pollIntervalSeconds;
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ public class PollingToggleRepository implements ToggleRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Toggle getToggle(final String name){
|
public final Toggle getToggle(final String name) {
|
||||||
return togglesCache.get(name);
|
return togglesCache.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ public class PollingToggleRepository implements ToggleRepository {
|
|||||||
try {
|
try {
|
||||||
Map<String, Toggle> freshToggleMap = new HashMap<>();
|
Map<String, Toggle> freshToggleMap = new HashMap<>();
|
||||||
|
|
||||||
for(Toggle toggle : fetchToggles()) {
|
for (Toggle toggle : fetchToggles()) {
|
||||||
freshToggleMap.put(toggle.getName(), toggle);
|
freshToggleMap.put(toggle.getName(), toggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ public class PollingToggleRepository implements ToggleRepository {
|
|||||||
storeRepoAsTempFile(JsonToggleParser.toJsonString(toggles));
|
storeRepoAsTempFile(JsonToggleParser.toJsonString(toggles));
|
||||||
return toggles;
|
return toggles;
|
||||||
} catch (ToggleException ex) {
|
} catch (ToggleException ex) {
|
||||||
if(togglesCache.isEmpty()) {
|
if (togglesCache.isEmpty()) {
|
||||||
return loadFromTempFile();
|
return loadFromTempFile();
|
||||||
}
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
@ -108,11 +109,11 @@ public class PollingToggleRepository implements ToggleRepository {
|
|||||||
|
|
||||||
private Collection<Toggle> loadFromTempFile() throws ToggleException {
|
private Collection<Toggle> loadFromTempFile() throws ToggleException {
|
||||||
LOG.info("Unleash will try to load feature toggle states from temporary backup");
|
LOG.info("Unleash will try to load feature toggle states from temporary backup");
|
||||||
try(FileReader reader = new FileReader(pathToTmpBackupFile())) {
|
try (FileReader reader = new FileReader(pathToTmpBackupFile())) {
|
||||||
BufferedReader br = new BufferedReader(reader);
|
BufferedReader br = new BufferedReader(reader);
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
String line;
|
String line;
|
||||||
while((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
builder.append(line);
|
builder.append(line);
|
||||||
}
|
}
|
||||||
return JsonToggleParser.fromJson(builder.toString());
|
return JsonToggleParser.fromJson(builder.toString());
|
||||||
@ -123,7 +124,7 @@ public class PollingToggleRepository implements ToggleRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void storeRepoAsTempFile(final String serverResponse) {
|
private void storeRepoAsTempFile(final String serverResponse) {
|
||||||
try(FileWriter writer = new FileWriter(pathToTmpBackupFile())) {
|
try (FileWriter writer = new FileWriter(pathToTmpBackupFile())) {
|
||||||
writer.write(serverResponse);
|
writer.write(serverResponse);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user