-
Notifications
You must be signed in to change notification settings - Fork 23
Added consumer classes #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22b8519
Added consumer classes
chillaq 42e03ce
polish
chillaq da05139
Merge branch 'rbs-fetchers' into rbs-consumer
chillaq f9abc5d
deleted RBS storage producer
chillaq 815c9f3
Merge branch 'rbs-consumer' of https://github.com/splitio/java-client…
chillaq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
95 changes: 95 additions & 0 deletions
95
.../java/io/split/storages/pluggable/adapters/UserCustomRuleBasedSegmentAdapterConsumer.java
This file contains hidden or 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,95 @@ | ||
| package io.split.storages.pluggable.adapters; | ||
|
|
||
| import io.split.client.dtos.RuleBasedSegment; | ||
| import io.split.client.utils.Json; | ||
| import io.split.engine.experiments.ParsedRuleBasedSegment; | ||
| import io.split.engine.experiments.RuleBasedSegmentParser; | ||
| import io.split.storages.RuleBasedSegmentCacheConsumer; | ||
| import io.split.storages.pluggable.domain.PrefixAdapter; | ||
| import io.split.storages.pluggable.domain.UserStorageWrapper; | ||
| import io.split.storages.pluggable.utils.Helper; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import pluggable.CustomStorageWrapper; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| public class UserCustomRuleBasedSegmentAdapterConsumer implements RuleBasedSegmentCacheConsumer { | ||
|
|
||
| private static final Logger _log = LoggerFactory.getLogger(UserCustomRuleBasedSegmentAdapterConsumer.class); | ||
|
|
||
| private final RuleBasedSegmentParser _ruleBasedSegmentParser; | ||
| private final UserStorageWrapper _userStorageWrapper; | ||
|
|
||
| public UserCustomRuleBasedSegmentAdapterConsumer(CustomStorageWrapper customStorageWrapper) { | ||
| _ruleBasedSegmentParser = new RuleBasedSegmentParser(); | ||
| _userStorageWrapper = new UserStorageWrapper(checkNotNull(customStorageWrapper)); | ||
| } | ||
|
|
||
| @Override | ||
| public long getChangeNumber() { | ||
| String wrapperResponse = _userStorageWrapper.get(PrefixAdapter.buildRuleBasedSegmentChangeNumber()); | ||
| return Helper.responseToLong(wrapperResponse, -1L); | ||
| } | ||
|
|
||
| @Override | ||
| public ParsedRuleBasedSegment get(String name) { | ||
| String wrapperResponse = _userStorageWrapper.get(PrefixAdapter.buildRuleBasedSegmentKey(name)); | ||
| if(wrapperResponse == null) { | ||
| return null; | ||
| } | ||
| RuleBasedSegment ruleBasedSegment = Json.fromJson(wrapperResponse, RuleBasedSegment.class); | ||
| if(ruleBasedSegment == null) { | ||
| _log.warn("Could not parse RuleBasedSegment."); | ||
| return null; | ||
| } | ||
| return _ruleBasedSegmentParser.parse(ruleBasedSegment); | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<ParsedRuleBasedSegment> getAll() { | ||
| Set<String> keys = _userStorageWrapper.getKeysByPrefix(PrefixAdapter.buildGetAllRuleBasedSegment()); | ||
| if(keys == null) { | ||
| return new ArrayList<>(); | ||
| } | ||
| List<String> wrapperResponse = _userStorageWrapper.getMany(new ArrayList<>(keys)); | ||
| if(wrapperResponse == null) { | ||
| return new ArrayList<>(); | ||
| } | ||
| return stringsToParsedRuleBasedSegments(wrapperResponse); | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> ruleBasedSegmentNames() { | ||
| Set<String> ruleBasedSegmentNamesWithPrefix = _userStorageWrapper.getKeysByPrefix(PrefixAdapter.buildGetAllRuleBasedSegment()); | ||
| ruleBasedSegmentNamesWithPrefix = ruleBasedSegmentNamesWithPrefix.stream(). | ||
| map(key -> key.replace(PrefixAdapter.buildRuleBasedSegmentsPrefix(), "")). | ||
| collect(Collectors.toSet()); | ||
| return new ArrayList<>(ruleBasedSegmentNamesWithPrefix); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> getSegments() { | ||
| return getAll().stream() | ||
| .flatMap(parsedRuleBasedSegment -> parsedRuleBasedSegment. | ||
| getSegmentsNames().stream()).collect(Collectors.toSet()); | ||
| } | ||
|
|
||
| private List<ParsedRuleBasedSegment> stringsToParsedRuleBasedSegments(List<String> elements) { | ||
| List<ParsedRuleBasedSegment> result = new ArrayList<>(); | ||
| for(String s : elements) { | ||
| if(s != null) { | ||
| result.add(_ruleBasedSegmentParser.parse(Json.fromJson(s, RuleBasedSegment.class))); | ||
| continue; | ||
| } | ||
| result.add(null); | ||
| } | ||
| return result; | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
.../java/io/split/storages/pluggable/adapters/UserCustomRuleBasedSegmentAdapterProducer.java
chillaq marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or 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,57 @@ | ||
| package io.split.storages.pluggable.adapters; | ||
|
|
||
| import io.split.client.dtos.RuleBasedSegment; | ||
| import io.split.client.utils.Json; | ||
| import io.split.engine.experiments.ParsedRuleBasedSegment; | ||
| import io.split.storages.RuleBasedSegmentCacheProducer; | ||
| import io.split.storages.pluggable.domain.PrefixAdapter; | ||
| import io.split.storages.pluggable.domain.UserStorageWrapper; | ||
| import io.split.storages.pluggable.utils.Helper; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import pluggable.CustomStorageWrapper; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| public class UserCustomRuleBasedSegmentAdapterProducer implements RuleBasedSegmentCacheProducer { | ||
|
|
||
| private static final Logger _log = LoggerFactory.getLogger(UserCustomRuleBasedSegmentAdapterProducer.class); | ||
|
|
||
| private final UserStorageWrapper _userStorageWrapper; | ||
|
|
||
| public UserCustomRuleBasedSegmentAdapterProducer(CustomStorageWrapper customStorageWrapper) { | ||
| _userStorageWrapper = new UserStorageWrapper(checkNotNull(customStorageWrapper)); | ||
| } | ||
|
|
||
| @Override | ||
| public long getChangeNumber() { | ||
| String wrapperResponse = _userStorageWrapper.get(PrefixAdapter.buildRuleBasedSegmentChangeNumber()); | ||
| return Helper.responseToLong(wrapperResponse, -1L); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean remove(String ruleBasedSegmentName) { | ||
| // NoOp | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void setChangeNumber(long changeNumber) { | ||
| //NoOp | ||
| } | ||
|
|
||
| @Override | ||
| public void update(List<ParsedRuleBasedSegment> toAdd, List<String> toRemove, long changeNumber) { | ||
| //NoOp | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> getSegments() { | ||
| //NoOp | ||
| return new HashSet<>(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.