1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package com.att.nsa.mr.client.impl;
24 import java.io.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.io.OutputStream;
27 import java.net.MalformedURLException;
29 import java.net.URISyntaxException;
30 import java.util.Collection;
31 import java.util.HashMap;
32 import java.util.LinkedList;
33 import java.util.List;
35 import java.util.Properties;
36 import java.util.concurrent.LinkedBlockingQueue;
37 import java.util.concurrent.ScheduledThreadPoolExecutor;
38 import java.util.concurrent.TimeUnit;
39 import java.util.zip.GZIPOutputStream;
41 import javax.ws.rs.core.MultivaluedMap;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
46 import org.apache.http.HttpException;
47 import org.apache.http.HttpStatus;
48 import org.json.JSONArray;
49 import org.json.JSONObject;
50 import org.json.JSONTokener;
52 import com.att.aft.dme2.api.DME2Client;
53 import com.att.aft.dme2.api.DME2Exception;
54 import com.att.nsa.mr.client.HostSelector;
55 import com.att.nsa.mr.client.MRBatchingPublisher;
56 import com.att.nsa.mr.client.response.MRPublisherResponse;
57 import com.att.nsa.mr.test.clients.ProtocolTypeConstants;
59 public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingPublisher {
60 private static final Logger logger = LoggerFactory.getLogger(MRSimplerBatchPublisher.class);
62 public static class Builder {
66 public Builder againstUrls(Collection<String> baseUrls) {
71 public Builder onTopic(String topic) {
76 public Builder batchTo(int maxBatchSize, long maxBatchAgeMs) {
77 fMaxBatchSize = maxBatchSize;
78 fMaxBatchAgeMs = maxBatchAgeMs;
82 public Builder compress(boolean compress) {
87 public Builder httpThreadTime(int threadOccuranceTime) {
88 this.threadOccuranceTime = threadOccuranceTime;
92 public Builder allowSelfSignedCertificates(boolean allowSelfSignedCerts) {
93 fAllowSelfSignedCerts = allowSelfSignedCerts;
97 public Builder withResponse(boolean withResponse) {
98 fWithResponse = withResponse;
102 public MRSimplerBatchPublisher build() {
103 if (!fWithResponse) {
105 return new MRSimplerBatchPublisher(fUrls, fTopic, fMaxBatchSize, fMaxBatchAgeMs, fCompress,
106 fAllowSelfSignedCerts, threadOccuranceTime);
107 } catch (MalformedURLException e) {
108 throw new RuntimeException(e);
112 return new MRSimplerBatchPublisher(fUrls, fTopic, fMaxBatchSize, fMaxBatchAgeMs, fCompress,
113 fAllowSelfSignedCerts, fMaxBatchSize);
114 } catch (MalformedURLException e) {
115 throw new RuntimeException(e);
121 private Collection<String> fUrls;
122 private String fTopic;
123 private int fMaxBatchSize = 100;
124 private long fMaxBatchAgeMs = 1000;
125 private boolean fCompress = false;
126 private int threadOccuranceTime = 50;
127 private boolean fAllowSelfSignedCerts = false;
128 private boolean fWithResponse = false;
133 public int send(String partition, String msg) {
134 return send(new message(partition, msg));
138 public int send(String msg) {
139 return send(new message(null, msg));
143 public int send(message msg) {
144 final LinkedList<message> list = new LinkedList<message>();
150 public synchronized int send(Collection<message> msgs) {
152 throw new IllegalStateException("The publisher was closed.");
155 for (message userMsg : msgs) {
156 fPending.add(new TimestampedMessage(userMsg));
158 return getPendingMessageCount();
162 public synchronized int getPendingMessageCount() {
163 return fPending.size();
167 public void close() {
169 final List<message> remains = close(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
170 if (remains.size() > 0) {
171 getLog().warn("Closing publisher with " + remains.size() + " messages unsent. "
172 + "Consider using MRBatchingPublisher.close( long timeout, TimeUnit timeoutUnits ) to recapture unsent messages on close.");
174 } catch (InterruptedException e) {
175 getLog().warn("Possible message loss. " + e.getMessage(), e);
176 } catch (IOException e) {
177 getLog().warn("Possible message loss. " + e.getMessage(), e);
182 public List<message> close(long time, TimeUnit unit) throws IOException, InterruptedException {
183 synchronized (this) {
186 // stop the background sender
187 fExec.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
188 fExec.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
192 final long now = Clock.now();
193 final long waitInMs = TimeUnit.MILLISECONDS.convert(time, unit);
194 final long timeoutAtMs = now + waitInMs;
196 while (Clock.now() < timeoutAtMs && getPendingMessageCount() > 0) {
201 synchronized (this) {
202 final LinkedList<message> result = new LinkedList<message>();
203 fPending.drainTo(result);
209 * Possibly send a batch to the MR server. This is called by the background
210 * thread and the close() method
214 private synchronized void send(boolean force) {
215 if (force || shouldSendNow()) {
217 getLog().warn("Send failed, " + fPending.size() + " message to send.");
219 // note the time for back-off
220 fDontSendUntilMs = sfWaitAfterError + Clock.now();
225 private synchronized boolean shouldSendNow() {
226 boolean shouldSend = false;
227 if (fPending.size() > 0) {
228 final long nowMs = Clock.now();
230 shouldSend = (fPending.size() >= fMaxBatchSize);
232 final long sendAtMs = fPending.peek().timestamp + fMaxBatchAgeMs;
233 shouldSend = sendAtMs <= nowMs;
236 // however, wait after an error
237 shouldSend = shouldSend && nowMs >= fDontSendUntilMs;
243 * Method to parse published JSON Objects and Arrays
247 private JSONArray parseJSON() {
248 JSONArray jsonArray = new JSONArray();
249 for (TimestampedMessage m : fPending) {
250 JSONTokener jsonTokener = new JSONTokener(m.fMsg);
251 JSONObject jsonObject = null;
252 JSONArray tempjsonArray = null;
253 final char firstChar = jsonTokener.next();
255 if ('[' == firstChar) {
256 tempjsonArray = new JSONArray(jsonTokener);
257 if (null != tempjsonArray) {
258 for (int i = 0; i < tempjsonArray.length(); i++) {
259 jsonArray.put(tempjsonArray.getJSONObject(i));
263 jsonObject = new JSONObject(jsonTokener);
264 jsonArray.put(jsonObject);
271 private synchronized boolean sendBatch() {
272 // it's possible for this call to be made with an empty list. in this
273 // case, just return.
274 if (fPending.size() < 1) {
278 final long nowMs = Clock.now();
280 host = this.fHostSelector.selectBaseHost();
282 final String httpurl = MRConstants.makeUrl(host, fTopic, props.getProperty("Protocol"),
283 props.getProperty("partition"));
287 * final String contentType = fCompress ?
288 * MRFormat.CAMBRIA_ZIP.toString () : MRFormat.CAMBRIA.toString () ;
291 final ByteArrayOutputStream baseStream = new ByteArrayOutputStream();
292 OutputStream os = baseStream;
293 final String contentType = props.getProperty("contenttype");
294 if (contentType.equalsIgnoreCase("application/json")) {
295 JSONArray jsonArray = parseJSON();
296 os.write(jsonArray.toString().getBytes());
299 } else if (contentType.equalsIgnoreCase("text/plain")) {
300 for (TimestampedMessage m : fPending) {
301 os.write(m.fMsg.getBytes());
305 } else if (contentType.equalsIgnoreCase("application/cambria")
306 || (contentType.equalsIgnoreCase("application/cambria-zip"))) {
307 if (contentType.equalsIgnoreCase("application/cambria-zip")) {
308 os = new GZIPOutputStream(baseStream);
310 for (TimestampedMessage m : fPending) {
312 os.write(("" + m.fPartition.length()).getBytes());
314 os.write(("" + m.fMsg.length()).getBytes());
316 os.write(m.fPartition.getBytes());
317 os.write(m.fMsg.getBytes());
322 for (TimestampedMessage m : fPending) {
323 os.write(m.fMsg.getBytes());
329 final long startMs = Clock.now();
330 if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(protocolFlag)) {
335 getLog().info("sending " + fPending.size() + " msgs to " + url + subContextPath + ". Oldest: "
336 + (nowMs - fPending.peek().timestamp) + " ms");
337 sender.setPayload(os.toString());
338 String dmeResponse = sender.sendAndWait(5000L);
340 final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + dmeResponse.toString();
341 getLog().info(logLine);
346 if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
347 getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
348 + (nowMs - fPending.peek().timestamp) + " ms");
349 final JSONObject result = postAuth(httpurl, baseStream.toByteArray(), contentType, authKey, authDate,
350 username, password, protocolFlag);
351 // Here we are checking for error response. If HTTP status
352 // code is not within the http success response code
353 // then we consider this as error and return false
354 if (result.getInt("status") < 200 || result.getInt("status") > 299) {
357 final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString();
358 getLog().info(logLine);
363 if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) {
364 getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
365 + (nowMs - fPending.peek().timestamp) + " ms");
366 final JSONObject result = post(httpurl, baseStream.toByteArray(), contentType, username, password,
369 // Here we are checking for error response. If HTTP status
370 // code is not within the http success response code
371 // then we consider this as error and return false
372 if (result.getInt("status") < 200 || result.getInt("status") > 299) {
375 final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString();
376 getLog().info(logLine);
380 } catch (IllegalArgumentException x) {
381 getLog().warn(x.getMessage(), x);
382 } catch (IOException x) {
383 getLog().warn(x.getMessage(), x);
384 } catch (HttpException x) {
385 getLog().warn(x.getMessage(), x);
386 } catch (Exception x) {
387 getLog().warn(x.getMessage(), x);
392 public synchronized MRPublisherResponse sendBatchWithResponse() {
393 // it's possible for this call to be made with an empty list. in this
394 // case, just return.
395 if (fPending.size() < 1) {
396 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
397 pubResponse.setResponseMessage("No Messages to send");
401 final long nowMs = Clock.now();
403 host = this.fHostSelector.selectBaseHost();
405 final String httpurl = MRConstants.makeUrl(host, fTopic, props.getProperty("Protocol"),
406 props.getProperty("partition"));
407 OutputStream os = null;
410 final ByteArrayOutputStream baseStream = new ByteArrayOutputStream();
412 final String contentType = props.getProperty("contenttype");
413 if (contentType.equalsIgnoreCase("application/json")) {
414 JSONArray jsonArray = parseJSON();
415 os.write(jsonArray.toString().getBytes());
416 } else if (contentType.equalsIgnoreCase("text/plain")) {
417 for (TimestampedMessage m : fPending) {
418 os.write(m.fMsg.getBytes());
421 } else if (contentType.equalsIgnoreCase("application/cambria")
422 || (contentType.equalsIgnoreCase("application/cambria-zip"))) {
423 if (contentType.equalsIgnoreCase("application/cambria-zip")) {
424 os = new GZIPOutputStream(baseStream);
426 for (TimestampedMessage m : fPending) {
428 os.write(("" + m.fPartition.length()).getBytes());
430 os.write(("" + m.fMsg.length()).getBytes());
432 os.write(m.fPartition.getBytes());
433 os.write(m.fMsg.getBytes());
438 for (TimestampedMessage m : fPending) {
439 os.write(m.fMsg.getBytes());
444 final long startMs = Clock.now();
445 if (ProtocolTypeConstants.DME2.getValue().equalsIgnoreCase(protocolFlag)) {
451 getLog().info("sending " + fPending.size() + " msgs to " + url + subContextPath + ". Oldest: "
452 + (nowMs - fPending.peek().timestamp) + " ms");
453 sender.setPayload(os.toString());
455 String dmeResponse = sender.sendAndWait(5000L);
457 pubResponse = createMRPublisherResponse(dmeResponse, pubResponse);
459 if (Integer.valueOf(pubResponse.getResponseCode()) < 200
460 || Integer.valueOf(pubResponse.getResponseCode()) > 299) {
464 final String logLine = String.valueOf((Clock.now() - startMs)) + dmeResponse.toString();
465 getLog().info(logLine);
468 } catch (DME2Exception x) {
469 getLog().warn(x.getMessage(), x);
470 pubResponse.setResponseCode(x.getErrorCode());
471 pubResponse.setResponseMessage(x.getErrorMessage());
472 } catch (URISyntaxException x) {
474 getLog().warn(x.getMessage(), x);
475 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
476 pubResponse.setResponseMessage(x.getMessage());
477 } catch (Exception x) {
479 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
480 pubResponse.setResponseMessage(x.getMessage());
481 logger.error("exception: ", x);
488 if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
489 getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
490 + (nowMs - fPending.peek().timestamp) + " ms");
491 final String result = postAuthwithResponse(httpurl, baseStream.toByteArray(), contentType, authKey,
492 authDate, username, password, protocolFlag);
493 // Here we are checking for error response. If HTTP status
494 // code is not within the http success response code
495 // then we consider this as error and return false
497 pubResponse = createMRPublisherResponse(result, pubResponse);
499 if (Integer.valueOf(pubResponse.getResponseCode()) < 200
500 || Integer.valueOf(pubResponse.getResponseCode()) > 299) {
505 final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString();
506 getLog().info(logLine);
511 if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) {
512 getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
513 + (nowMs - fPending.peek().timestamp) + " ms");
514 final String result = postWithResponse(httpurl, baseStream.toByteArray(), contentType, username,
515 password, protocolFlag);
517 // Here we are checking for error response. If HTTP status
518 // code is not within the http success response code
519 // then we consider this as error and return false
520 pubResponse = createMRPublisherResponse(result, pubResponse);
522 if (Integer.valueOf(pubResponse.getResponseCode()) < 200
523 || Integer.valueOf(pubResponse.getResponseCode()) > 299) {
528 final String logLine = String.valueOf((Clock.now() - startMs));
529 getLog().info(logLine);
533 } catch (IllegalArgumentException x) {
534 getLog().warn(x.getMessage(), x);
535 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
536 pubResponse.setResponseMessage(x.getMessage());
538 } catch (IOException x) {
539 getLog().warn(x.getMessage(), x);
540 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
541 pubResponse.setResponseMessage(x.getMessage());
543 } catch (HttpException x) {
544 getLog().warn(x.getMessage(), x);
545 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
546 pubResponse.setResponseMessage(x.getMessage());
548 } catch (Exception x) {
549 getLog().warn(x.getMessage(), x);
551 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
552 pubResponse.setResponseMessage(x.getMessage());
557 if (fPending.size() > 0) {
558 getLog().warn("Send failed, " + fPending.size() + " message to send.");
559 pubResponse.setPendingMsgs(fPending.size());
564 } catch (Exception x) {
565 getLog().warn(x.getMessage(), x);
566 pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
567 pubResponse.setResponseMessage("Error in closing Output Stream");
575 private MRPublisherResponse createMRPublisherResponse(String reply, MRPublisherResponse mrPubResponse) {
577 if (reply.isEmpty()) {
579 mrPubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
580 mrPubResponse.setResponseMessage("Please verify the Producer properties");
581 } else if (reply.startsWith("{")) {
582 JSONObject jObject = new JSONObject(reply);
583 if (jObject.has("message") && jObject.has("status")) {
584 String message = jObject.getString("message");
585 if (null != message) {
586 mrPubResponse.setResponseMessage(message);
588 mrPubResponse.setResponseCode(Integer.toString(jObject.getInt("status")));
590 mrPubResponse.setResponseCode(String.valueOf(HttpStatus.SC_OK));
591 mrPubResponse.setResponseMessage(reply);
593 } else if (reply.startsWith("<")) {
594 String responseCode = getHTTPErrorResponseCode(reply);
595 if (responseCode.contains("403")) {
596 responseCode = "403";
598 mrPubResponse.setResponseCode(responseCode);
599 mrPubResponse.setResponseMessage(getHTTPErrorResponseMessage(reply));
602 return mrPubResponse;
605 private final String fTopic;
606 private final int fMaxBatchSize;
607 private final long fMaxBatchAgeMs;
608 private final boolean fCompress;
609 private int threadOccuranceTime;
610 private boolean fClosed;
611 private String username;
612 private String password;
616 private HostSelector fHostSelector = null;
618 private final LinkedBlockingQueue<TimestampedMessage> fPending;
619 private long fDontSendUntilMs;
620 private final ScheduledThreadPoolExecutor fExec;
622 private String latitude;
623 private String longitude;
624 private String version;
625 private String serviceName;
627 private String partner;
628 private String routeOffer;
629 private String subContextPath;
630 private String protocol;
631 private String methodType;
633 private String dmeuser;
634 private String dmepassword;
635 private String contentType;
636 private static final long sfWaitAfterError = 10000;
637 private HashMap<String, String> DMETimeOuts;
638 private DME2Client sender;
639 public String protocolFlag = ProtocolTypeConstants.DME2.getValue();
640 private String authKey;
641 private String authDate;
642 private String handlers;
643 private Properties props;
644 public static String routerFilePath;
645 protected static final Map<String, String> headers = new HashMap<String, String>();
646 public static MultivaluedMap<String, Object> headersMap;
648 private MRPublisherResponse pubResponse;
650 public MRPublisherResponse getPubResponse() {
654 public void setPubResponse(MRPublisherResponse pubResponse) {
655 this.pubResponse = pubResponse;
658 public static String getRouterFilePath() {
659 return routerFilePath;
662 public static void setRouterFilePath(String routerFilePath) {
663 MRSimplerBatchPublisher.routerFilePath = routerFilePath;
666 public Properties getProps() {
670 public void setProps(Properties props) {
674 public String getProtocolFlag() {
678 public void setProtocolFlag(String protocolFlag) {
679 this.protocolFlag = protocolFlag;
682 private void DME2Configue() throws Exception {
686 * FileReader reader = new FileReader(new File (producerFilePath));
687 * Properties props = new Properties(); props.load(reader);
689 latitude = props.getProperty("Latitude");
690 longitude = props.getProperty("Longitude");
691 version = props.getProperty("Version");
692 serviceName = props.getProperty("ServiceName");
693 env = props.getProperty("Environment");
694 partner = props.getProperty("Partner");
695 routeOffer = props.getProperty("routeOffer");
696 subContextPath = props.getProperty("SubContextPath") + fTopic;
698 * if(props.getProperty("partition")!=null &&
699 * !props.getProperty("partition").equalsIgnoreCase("")){
700 * subContextPath=subContextPath+"?partitionKey="+props.getProperty(
703 protocol = props.getProperty("Protocol");
704 methodType = props.getProperty("MethodType");
705 dmeuser = props.getProperty("username");
706 dmepassword = props.getProperty("password");
707 contentType = props.getProperty("contenttype");
708 handlers = props.getProperty("sessionstickinessrequired");
709 routerFilePath = props.getProperty("DME2preferredRouterFilePath");
712 * Changes to DME2Client url to use Partner for auto failover
713 * between data centers When Partner value is not provided use the
714 * routeOffer value for auto failover within a cluster
717 String partitionKey = props.getProperty("partition");
719 if (partner != null && !partner.isEmpty()) {
720 url = protocol + "://" + serviceName + "?version=" + version + "&envContext=" + env + "&partner="
722 if (partitionKey != null && !partitionKey.equalsIgnoreCase("")) {
723 url = url + "&partitionKey=" + partitionKey;
725 } else if (routeOffer != null && !routeOffer.isEmpty()) {
726 url = protocol + "://" + serviceName + "?version=" + version + "&envContext=" + env + "&routeoffer="
728 if (partitionKey != null && !partitionKey.equalsIgnoreCase("")) {
729 url = url + "&partitionKey=" + partitionKey;
733 DMETimeOuts = new HashMap<String, String>();
734 DMETimeOuts.put("AFT_DME2_EP_READ_TIMEOUT_MS", props.getProperty("AFT_DME2_EP_READ_TIMEOUT_MS"));
735 DMETimeOuts.put("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", props.getProperty("AFT_DME2_ROUNDTRIP_TIMEOUT_MS"));
736 DMETimeOuts.put("AFT_DME2_EP_CONN_TIMEOUT", props.getProperty("AFT_DME2_EP_CONN_TIMEOUT"));
737 DMETimeOuts.put("Content-Type", contentType);
738 System.setProperty("AFT_LATITUDE", latitude);
739 System.setProperty("AFT_LONGITUDE", longitude);
740 System.setProperty("AFT_ENVIRONMENT", props.getProperty("AFT_ENVIRONMENT"));
741 // System.setProperty("DME2.DEBUG", "true");
744 // System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS",
745 // "SSLv3,TLSv1,TLSv1.1");
746 System.setProperty("AFT_DME2_CLIENT_SSL_INCLUDE_PROTOCOLS", "TLSv1.1,TLSv1.2");
747 System.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", "false");
748 System.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", "changeit");
752 sender = new DME2Client(new URI(url), 5000L);
754 sender.setAllowAllHttpReturnCodes(true);
755 sender.setMethod(methodType);
756 sender.setSubContext(subContextPath);
757 sender.setCredentials(dmeuser, dmepassword);
758 sender.setHeaders(DMETimeOuts);
759 if (handlers.equalsIgnoreCase("yes")) {
760 sender.addHeader("AFT_DME2_EXCHANGE_REQUEST_HANDLERS",
761 props.getProperty("AFT_DME2_EXCHANGE_REQUEST_HANDLERS"));
762 sender.addHeader("AFT_DME2_EXCHANGE_REPLY_HANDLERS",
763 props.getProperty("AFT_DME2_EXCHANGE_REPLY_HANDLERS"));
764 sender.addHeader("AFT_DME2_REQ_TRACE_ON", props.getProperty("AFT_DME2_REQ_TRACE_ON"));
766 sender.addHeader("AFT_DME2_EXCHANGE_REPLY_HANDLERS", "com.att.nsa.mr.dme.client.HeaderReplyHandler");
768 } catch (DME2Exception x) {
769 getLog().warn(x.getMessage(), x);
770 throw new DME2Exception(x.getErrorCode(), x.getErrorMessage());
771 } catch (URISyntaxException x) {
773 getLog().warn(x.getMessage(), x);
774 throw new URISyntaxException(url, x.getMessage());
775 } catch (Exception x) {
777 getLog().warn(x.getMessage(), x);
778 throw new Exception(x.getMessage());
782 private MRSimplerBatchPublisher(Collection<String> hosts, String topic, int maxBatchSize, long maxBatchAgeMs,
783 boolean compress) throws MalformedURLException {
786 if (topic == null || topic.length() < 1) {
787 throw new IllegalArgumentException("A topic must be provided.");
790 fHostSelector = new HostSelector(hosts, null);
793 fMaxBatchSize = maxBatchSize;
794 fMaxBatchAgeMs = maxBatchAgeMs;
795 fCompress = compress;
797 fPending = new LinkedBlockingQueue<TimestampedMessage>();
798 fDontSendUntilMs = 0;
799 fExec = new ScheduledThreadPoolExecutor(1);
800 pubResponse = new MRPublisherResponse();
804 private MRSimplerBatchPublisher(Collection<String> hosts, String topic, int maxBatchSize, long maxBatchAgeMs,
805 boolean compress, boolean allowSelfSignedCerts, int httpThreadOccurnace) throws MalformedURLException {
808 if (topic == null || topic.length() < 1) {
809 throw new IllegalArgumentException("A topic must be provided.");
812 fHostSelector = new HostSelector(hosts, null);
815 fMaxBatchSize = maxBatchSize;
816 fMaxBatchAgeMs = maxBatchAgeMs;
817 fCompress = compress;
818 threadOccuranceTime = httpThreadOccurnace;
819 fPending = new LinkedBlockingQueue<TimestampedMessage>();
820 fDontSendUntilMs = 0;
821 fExec = new ScheduledThreadPoolExecutor(1);
822 fExec.scheduleAtFixedRate(new Runnable() {
827 }, 100, threadOccuranceTime, TimeUnit.MILLISECONDS);
830 private static class TimestampedMessage extends message {
831 public TimestampedMessage(message m) {
833 timestamp = Clock.now();
836 public final long timestamp;
839 public String getUsername() {
843 public void setUsername(String username) {
844 this.username = username;
847 public String getPassword() {
851 public void setPassword(String password) {
852 this.password = password;
855 public String getHost() {
859 public void setHost(String host) {
863 public String getContentType() {
867 public void setContentType(String contentType) {
868 this.contentType = contentType;
871 public String getAuthKey() {
875 public void setAuthKey(String authKey) {
876 this.authKey = authKey;
879 public String getAuthDate() {
883 public void setAuthDate(String authDate) {
884 this.authDate = authDate;