Last active
January 5, 2019 11:34
-
-
Save cschneider/2828a1ce83975a6ee176a1587075a69d to your computer and use it in GitHub Desktop.
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
/* | |
* Licensed to the Apache Software Foundation (ASF) under one | |
* or more contributor license agreements. See the NOTICE file | |
* distributed with this work for additional information | |
* regarding copyright ownership. The SF licenses this file | |
* to you under the Apache License, Version 2.0 (the | |
* "License"); you may not use this file except in compliance | |
* with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, | |
* software distributed under the License is distributed on an | |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
* KIND, either express or implied. See the License for the | |
* specific language governing permissions and limitations under the License. | |
*/ | |
package org.apache.aries.events.api; | |
import static java.util.Objects.requireNonNull; | |
import java.util.function.Consumer; | |
import javax.annotation.ParametersAreNonnullByDefault; | |
@ParametersAreNonnullByDefault | |
public final class SubscribeRequestBuilder { | |
private SubscribeRequest subscribeRequest; | |
private SubscribeRequestBuilder(SubscribeRequest subscribeRequest) { | |
this.subscribeRequest = subscribeRequest; | |
} | |
public static SubscribeRequestBuilder to(String topic, Consumer<Received> callback) { | |
return new SubscribeRequestBuilder(new SubscribeRequest(topic, callback)); | |
} | |
public SubscribeRequestBuilder startAt(Position position) { | |
this.subscribeRequest.position = position; | |
return this; | |
} | |
public SubscribeRequestBuilder seek(Seek seek) { | |
this.subscribeRequest.seek = requireNonNull(seek, "Seek must not be null"); | |
return this; | |
} | |
public SubscribeRequest build() { | |
return subscribeRequest; | |
} | |
public static class SubscribeRequest { | |
private final String topic; | |
private final Consumer<Received> callback; | |
private Position position; | |
private Seek seek = Seek.latest; | |
private SubscribeRequest(String topic, Consumer<Received> callback) { | |
this.topic = topic; | |
this.callback = callback; | |
} | |
public String getTopic() { | |
return topic; | |
} | |
public Position getPosition() { | |
return position; | |
} | |
public Seek getSeek() { | |
return seek; | |
} | |
public Consumer<Received> getCallback() { | |
return callback; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment