-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new config fileResource and refactor localhost
- Loading branch information
1 parent
d439f75
commit f95cd7e
Showing
17 changed files
with
261 additions
and
68 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
client/src/main/java/io/split/client/JsonFileLocalhostSplitChangeFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.split.client; | ||
|
||
import com.google.gson.stream.JsonReader; | ||
import io.split.client.dtos.SplitChange; | ||
import io.split.client.utils.Json; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class JsonFileLocalhostSplitChangeFetcher extends JsonLocalhostSplitChangeFetcher { | ||
|
||
private static final Logger _log = LoggerFactory.getLogger(JsonFileLocalhostSplitChangeFetcher.class); | ||
private final File _file; | ||
|
||
|
||
public JsonFileLocalhostSplitChangeFetcher(String filePath) { | ||
_file = new File(filePath); | ||
super.lastHash = new byte[0]; | ||
} | ||
|
||
@Override | ||
public JsonReader readFile() { | ||
try { | ||
return new JsonReader(new FileReader("_file")); | ||
} catch (FileNotFoundException f) { | ||
_log.warn(String.format("There was no file named %s found. " + | ||
"We created a split client that returns default treatments for all feature flags for all of your users. " + | ||
"If you wish to return a specific treatment for a feature flag, enter the name of that feature flag name and " + | ||
"treatment name separated by whitespace in %s; one pair per line. Empty lines or lines starting with '#' are " + | ||
"considered comments", | ||
getFilePath(), getFilePath()), f); | ||
throw new IllegalStateException("Problem fetching splitChanges: " + f.getMessage(), f); | ||
} | ||
} | ||
|
||
@Override | ||
public String getFilePath() { | ||
return _file.getPath(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
client/src/main/java/io/split/client/JsonResourceLocalhostSplitChangeFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.split.client; | ||
|
||
import com.google.gson.stream.JsonReader; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
|
||
public class JsonResourceLocalhostSplitChangeFetcher extends JsonLocalhostSplitChangeFetcher { | ||
private static final Logger _log = LoggerFactory.getLogger(JsonResourceLocalhostSplitChangeFetcher.class); | ||
private final String _fileName; | ||
|
||
public JsonResourceLocalhostSplitChangeFetcher(String fileName) { | ||
_fileName = fileName; | ||
super.lastHash = new byte[0]; | ||
} | ||
|
||
@Override | ||
public JsonReader readFile() { | ||
try { | ||
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(_fileName); | ||
BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); | ||
JsonReader jsonReader = new JsonReader(streamReader); | ||
return jsonReader; | ||
} catch (Exception e){ | ||
_log.warn(String.format("Problem to fetch split change using the file %s", | ||
_fileName), e); | ||
throw new IllegalStateException("Problem fetching splitChanges: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getFilePath() { | ||
return _fileName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
client/src/main/java/io/split/client/YamlFileLocalhostSplitChangeFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.split.client; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.yaml.snakeyaml.Yaml; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class YamlFileLocalhostSplitChangeFetcher extends YamlLocalhostSplitChangeFetcher{ | ||
|
||
private static final Logger _log = LoggerFactory.getLogger(YamlFileLocalhostSplitChangeFetcher.class); | ||
private final File _splitFile; | ||
|
||
public YamlFileLocalhostSplitChangeFetcher(String fileName) { | ||
_splitFile = new File(fileName); | ||
} | ||
|
||
@Override | ||
public List<Map<String, Map<String, Object>>> readFile() { | ||
try { | ||
Yaml yaml = new Yaml(); | ||
return yaml.load(new FileReader(_splitFile)); | ||
} catch (FileNotFoundException f) { | ||
_log.warn(String.format("There was no file named %s found. We created a split client that returns default treatments " + | ||
"for all feature flags for all of your users. If you wish to return a specific treatment for a feature flag, " + | ||
"enter the name of that feature flag name and treatment name separated by whitespace in %s; one pair per line. " + | ||
"Empty lines or lines starting with '#' are considered comments", | ||
_splitFile.getPath(), _splitFile.getPath()), f); | ||
throw new IllegalStateException("Problem fetching splitChanges: " + f.getMessage(), f); | ||
} catch (Exception e) { | ||
_log.warn(String.format("Problem to fetch split change using the file %s", | ||
_splitFile.getPath()), e); | ||
throw new IllegalStateException("Problem fetching splitChanges: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getFilePath() { | ||
return _splitFile.getPath(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
client/src/main/java/io/split/client/YamlResourceLocalhostSplitChangeFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.split.client; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.yaml.snakeyaml.Yaml; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class YamlResourceLocalhostSplitChangeFetcher extends YamlLocalhostSplitChangeFetcher { | ||
private static final Logger _log = LoggerFactory.getLogger(YamlFileLocalhostSplitChangeFetcher.class); | ||
private final String _fileName; | ||
|
||
public YamlResourceLocalhostSplitChangeFetcher(String fileName) { | ||
_fileName = fileName; | ||
} | ||
@Override | ||
public List<Map<String, Map<String, Object>>> readFile() { | ||
try { | ||
Yaml yaml = new Yaml(); | ||
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(_fileName); | ||
return yaml.load(inputStream); | ||
} catch (Exception e) { | ||
_log.warn(String.format("Problem to fetch split change using the file %s", | ||
_fileName), e); | ||
throw new IllegalStateException("Problem fetching splitChanges: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getFilePath() { | ||
return _fileName; | ||
} | ||
} |
Oops, something went wrong.