Skip to content

New signature for HystrixObservableCollapser #261

Merged
merged 2 commits into from May 6, 2014

2 participants

@benjchristensen

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;
            }

        };
    }

}
Ben Christensen added some commits May 5, 2014
Ben Christensen New signature for HystrixObservableCollapser
Replacing mapResponseToRequests with functional style selectors and allowing streaming response from Observable.
d1204e1
Ben Christensen Javadoc for new HystrixObservableCollapser methods 6bdb273
@benjchristensen benjchristensen merged commit 5212caa into Netflix:master May 6, 2014
@benjchristensen benjchristensen deleted the unknown repository branch May 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.