Skip to content
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

New signature for HystrixObservableCollapser #261

Merged
merged 2 commits into from
May 6, 2014
Merged

New signature for HystrixObservableCollapser #261

merged 2 commits into from
May 6, 2014

Conversation

benjchristensen
Copy link
Contributor

Replacing mapResponseToRequests with functional style selectors and allowing streaming response from Observable.

Intent is for a collapser implementation like this:

public class BookmarkCommand extends HystrixObservableCollapser<Integer, Bookmark, Bookmark, Video> {

    private final Video video;

    public BookmarkCommand(Video video) {
        this.video = video;
    }

    @Override
    public Video getRequestArgument() {
        return video;
    }

    @Override
    protected HystrixObservableCommand<Bookmark> createCommand(Collection<CollapsedRequest<Bookmark, Video>> requests) {
        List<Video> videos = new ArrayList<>();
        for (CollapsedRequest<Bookmark, Video> r : requests) {
            videos.add(r.getArgument());
        }
        return new BookmarksCommand(videos);
    }

    protected void onMissingResponse(CollapsedRequest<Bookmark, Video> r) {
        // would normally send a default instead of failing here
        r.setException(new Exception("No bookmark"));
    }

    @Override
    protected Func1<Bookmark, Integer> getBatchReturnTypeKeySelector() {
        return new Func1<Bookmark, Integer>() {

            @Override
            public Integer call(Bookmark b) {
                return b.getVideoId();
            }

        };
    }

    @Override
    protected Func1<Video, Integer> getRequestArgumentKeySelector() {
        return new Func1<Video, Integer>() {

            @Override
            public Integer call(Video v) {
                return v.getId();
            }

        };
    }

    @Override
    protected Func1<Bookmark, Bookmark> getBatchReturnTypeToResponseTypeMapper() {
        return new Func1<Bookmark, Bookmark>() {

            @Override
            public Bookmark call(Bookmark b) {
                return b;
            }

        };
    }

}

Replacing mapResponseToRequests with functional style selectors and allowing streaming response from Observable.
benjchristensen added a commit that referenced this pull request May 6, 2014
New signature for HystrixObservableCollapser
@benjchristensen benjchristensen merged commit 5212caa into Netflix:master May 6, 2014
@benjchristensen benjchristensen deleted the observable-collapser branch May 6, 2014 03:45
@cloudbees-pull-request-builder

Hystrix-pull-requests #131 ABORTED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants