aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/dmaap/mr/client/MRClientBuilders.java6
-rw-r--r--src/main/java/org/onap/dmaap/mr/client/MRClientFactory.java41
-rw-r--r--src/main/java/org/onap/dmaap/mr/client/impl/MRConsumerImpl.java111
3 files changed, 125 insertions, 33 deletions
diff --git a/src/main/java/org/onap/dmaap/mr/client/MRClientBuilders.java b/src/main/java/org/onap/dmaap/mr/client/MRClientBuilders.java
index abf3736..8936bea 100644
--- a/src/main/java/org/onap/dmaap/mr/client/MRClientBuilders.java
+++ b/src/main/java/org/onap/dmaap/mr/client/MRClientBuilders.java
@@ -163,7 +163,11 @@ public class MRClientBuilders
if ( sfConsumerMock != null ) return sfConsumerMock;
try {
- return new MRConsumerImpl ( fHosts, fTopic, fGroup, fId, fTimeoutMs, fLimit, fFilter, fApiKey, fApiSecret );
+ return new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(fHosts)
+ .setTopic(fTopic).setConsumerGroup(fGroup).setConsumerId(fId)
+ .setTimeoutMs(fTimeoutMs).setLimit(fLimit).setFilter(fFilter)
+ .setApiKey_username(fApiKey).setApiSecret_password(fApiSecret)
+ .createMRConsumerImpl();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
diff --git a/src/main/java/org/onap/dmaap/mr/client/MRClientFactory.java b/src/main/java/org/onap/dmaap/mr/client/MRClientFactory.java
index 84885d3..e5ea48e 100644
--- a/src/main/java/org/onap/dmaap/mr/client/MRClientFactory.java
+++ b/src/main/java/org/onap/dmaap/mr/client/MRClientFactory.java
@@ -34,9 +34,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.TreeSet;
import java.util.UUID;
-
import javax.ws.rs.core.MultivaluedMap;
-
import org.onap.dmaap.mr.client.impl.MRConsumerImpl;
import org.onap.dmaap.mr.client.impl.MRMetaClient;
import org.onap.dmaap.mr.client.impl.MRSimplerBatchPublisher;
@@ -254,8 +252,11 @@ public class MRClientFactory {
if (MRClientBuilders.sfConsumerMock != null)
return MRClientBuilders.sfConsumerMock;
try {
- return new MRConsumerImpl(hostSet, topic, consumerGroup, consumerId, timeoutMs, limit, filter, apiKey,
- apiSecret);
+ return new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hostSet).setTopic(topic)
+ .setConsumerGroup(consumerGroup).setConsumerId(consumerId)
+ .setTimeoutMs(timeoutMs).setLimit(limit).setFilter(filter)
+ .setApiKey_username(apiKey).setApiSecret_password(apiSecret)
+ .createMRConsumerImpl();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
@@ -597,7 +598,11 @@ public class MRClientFactory {
MRConsumerImpl sub;
try {
- sub = new MRConsumerImpl(MRConsumerImpl.stringToList(host), topic, group, id, i, j, null, null, null);
+ sub = new MRConsumerImpl.MRConsumerImplBuilder()
+ .setHostPart(MRConsumerImpl.stringToList(host)).setTopic(topic)
+ .setConsumerGroup(group).setConsumerId(id).setTimeoutMs(i).setLimit(j)
+ .setFilter(null).setApiKey_username(null).setApiSecret_password(null)
+ .createMRConsumerImpl();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
@@ -615,7 +620,11 @@ public class MRClientFactory {
MRConsumerImpl sub;
try {
- sub = new MRConsumerImpl(MRConsumerImpl.stringToList(host), topic, group, id, i, j, null, null, null);
+ sub = new MRConsumerImpl.MRConsumerImplBuilder()
+ .setHostPart(MRConsumerImpl.stringToList(host)).setTopic(topic)
+ .setConsumerGroup(group).setConsumerId(id).setTimeoutMs(i).setLimit(j)
+ .setFilter(null).setApiKey_username(null).setApiSecret_password(null)
+ .createMRConsumerImpl();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
@@ -655,17 +664,25 @@ public class MRClientFactory {
group = props.getProperty("group");
MRConsumerImpl sub = null;
if (props.getProperty(TRANSPORT_TYPE).equalsIgnoreCase(ProtocolTypeConstants.AUTH_KEY.getValue())) {
- sub = new MRConsumerImpl(MRConsumerImpl.stringToList(props.getProperty("host")), props.getProperty(TOPIC),
- group, props.getProperty("id"), timeout, limit, props.getProperty("filter"),
- props.getProperty(AUTH_KEY), props.getProperty(AUTH_DATE));
+ sub = new MRConsumerImpl.MRConsumerImplBuilder()
+ .setHostPart(MRConsumerImpl.stringToList(props.getProperty("host")))
+ .setTopic(props.getProperty(TOPIC)).setConsumerGroup(group)
+ .setConsumerId(props.getProperty("id")).setTimeoutMs(timeout).setLimit(limit)
+ .setFilter(props.getProperty("filter"))
+ .setApiKey_username(props.getProperty(AUTH_KEY))
+ .setApiSecret_password(props.getProperty(AUTH_DATE)).createMRConsumerImpl();
sub.setAuthKey(props.getProperty(AUTH_KEY));
sub.setAuthDate(props.getProperty(AUTH_DATE));
sub.setUsername(props.getProperty(USERNAME));
sub.setPassword(props.getProperty(PASSWORD));
} else {
- sub = new MRConsumerImpl(MRConsumerImpl.stringToList(props.getProperty("host")), props.getProperty(TOPIC),
- group, props.getProperty("id"), timeout, limit, props.getProperty("filter"),
- props.getProperty(USERNAME), props.getProperty(PASSWORD));
+ sub = new MRConsumerImpl.MRConsumerImplBuilder()
+ .setHostPart(MRConsumerImpl.stringToList(props.getProperty("host")))
+ .setTopic(props.getProperty(TOPIC)).setConsumerGroup(group)
+ .setConsumerId(props.getProperty("id")).setTimeoutMs(timeout).setLimit(limit)
+ .setFilter(props.getProperty("filter"))
+ .setApiKey_username(props.getProperty(USERNAME))
+ .setApiSecret_password(props.getProperty(PASSWORD)).createMRConsumerImpl();
sub.setUsername(props.getProperty(USERNAME));
sub.setPassword(props.getProperty(PASSWORD));
}
diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/MRConsumerImpl.java b/src/main/java/org/onap/dmaap/mr/client/impl/MRConsumerImpl.java
index d224bdf..73840be 100644
--- a/src/main/java/org/onap/dmaap/mr/client/impl/MRConsumerImpl.java
+++ b/src/main/java/org/onap/dmaap/mr/client/impl/MRConsumerImpl.java
@@ -83,26 +83,97 @@ public class MRConsumerImpl extends MRBaseClient implements MRConsumer {
private long dme2ReplyHandlerTimeoutMs;
private long longPollingMs;
- public MRConsumerImpl(Collection<String> hostPart, final String topic, final String consumerGroup,
- final String consumerId, int timeoutMs, int limit, String filter, String apiKey_username,
- String apiSecret_password) throws MalformedURLException {
- this(hostPart, topic, consumerGroup, consumerId, timeoutMs, limit, filter, apiKey_username, apiSecret_password,
- false);
- }
-
- public MRConsumerImpl(Collection<String> hostPart, final String topic, final String consumerGroup,
- final String consumerId, int timeoutMs, int limit, String filter, String apiKey, String apiSecret,
- boolean allowSelfSignedCerts) throws MalformedURLException {
- super(hostPart, topic + "::" + consumerGroup + "::" + consumerId);
-
- fTopic = topic;
- fGroup = consumerGroup;
- fId = consumerId;
- fTimeoutMs = timeoutMs;
- fLimit = limit;
- fFilter = filter;
-
- fHostSelector = new HostSelector(hostPart);
+ public MRConsumerImpl(MRConsumerImplBuilder builder) throws MalformedURLException {
+ super(builder.hostPart,
+ builder.topic + "::" + builder.consumerGroup + "::" + builder.consumerId);
+
+ fTopic = builder.topic;
+ fGroup = builder.consumerGroup;
+ fId = builder.consumerId;
+ fTimeoutMs = builder.timeoutMs;
+ fLimit = builder.limit;
+ fFilter = builder.filter;
+
+ fHostSelector = new HostSelector(builder.hostPart);
+ }
+
+ public static class MRConsumerImplBuilder {
+ private Collection<String> hostPart;
+ private String topic;
+ private String consumerGroup;
+ private String consumerId;
+ private int timeoutMs;
+ private int limit;
+ private String filter;
+ private String apiKey_username;
+ private String apiSecret_password;
+ private String apiKey;
+ private String apiSecret;
+ private boolean allowSelfSignedCerts = false;
+
+ public MRConsumerImplBuilder setHostPart(Collection<String> hostPart) {
+ this.hostPart = hostPart;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setTopic(String topic) {
+ this.topic = topic;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setConsumerGroup(String consumerGroup) {
+ this.consumerGroup = consumerGroup;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setConsumerId(String consumerId) {
+ this.consumerId = consumerId;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setTimeoutMs(int timeoutMs) {
+ this.timeoutMs = timeoutMs;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setLimit(int limit) {
+ this.limit = limit;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setFilter(String filter) {
+ this.filter = filter;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setApiKey_username(String apiKey_username) {
+ this.apiKey_username = apiKey_username;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setApiSecret_password(String apiSecret_password) {
+ this.apiSecret_password = apiSecret_password;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setApiSecret(String apiSecret) {
+ this.apiSecret = apiSecret;
+ return this;
+ }
+
+ public MRConsumerImplBuilder setAllowSelfSignedCerts(boolean allowSelfSignedCerts) {
+ this.allowSelfSignedCerts = allowSelfSignedCerts;
+ return this;
+ }
+
+ public MRConsumerImpl createMRConsumerImpl() throws MalformedURLException {
+ return new MRConsumerImpl(this);
+ }
}
@Override