// Path: src/main/java/io/cdap/plugin/salesforce/authenticator/AuthenticatorCredentials.java
// public class AuthenticatorCredentials implements Serializable {
// 
//   private final OAuthInfo oAuthInfo;
//   private final String username;
//   private final String password;
//   private final String consumerKey;
//   private final String consumerSecret;
//   private final String loginUrl;
// 
//   public AuthenticatorCredentials(OAuthInfo oAuthInfo) {
//     this(Objects.requireNonNull(oAuthInfo), null, null, null, null, null);
//   }
// 
//   public AuthenticatorCredentials(String username, String password,
//                                   String consumerKey, String consumerSecret, String loginUrl) {
//     this(null, Objects.requireNonNull(username), Objects.requireNonNull(password), Objects.requireNonNull(consumerKey),
//          Objects.requireNonNull(consumerSecret), Objects.requireNonNull(loginUrl));
//   }
// 
//   private AuthenticatorCredentials(@Nullable OAuthInfo oAuthInfo,
//                                    @Nullable String username,
//                                    @Nullable String password,
//                                    @Nullable String consumerKey,
//                                    @Nullable String consumerSecret,
//                                    @Nullable String loginUrl) {
//     this.oAuthInfo = oAuthInfo;
//     this.username = username;
//     this.password = password;
//     this.consumerKey = consumerKey;
//     this.consumerSecret = consumerSecret;
//     this.loginUrl = loginUrl;
//   }
// 
//   @Nullable
//   public OAuthInfo getOAuthInfo() {
//     return oAuthInfo;
//   }
// 
//   @Nullable
//   public String getUsername() {
//     return username;
//   }
// 
//   @Nullable
//   public String getPassword() {
//     return password;
//   }
// 
//   @Nullable
//   public String getConsumerKey() {
//     return consumerKey;
//   }
// 
//   @Nullable
//   public String getConsumerSecret() {
//     return consumerSecret;
//   }
// 
//   @Nullable
//   public String getLoginUrl() {
//     return loginUrl;
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (o == null || getClass() != o.getClass()) {
//       return false;
//     }
// 
//     AuthenticatorCredentials that = (AuthenticatorCredentials) o;
// 
//     return Objects.equals(username, that.username) &&
//       Objects.equals(password, that.password) &&
//       Objects.equals(consumerKey, that.consumerKey) &&
//       Objects.equals(consumerSecret, that.consumerSecret) &&
//       Objects.equals(loginUrl, that.loginUrl);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hash(username, password, consumerKey, consumerSecret, loginUrl);
//   }
// }


import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.cdap.plugin.salesforce.authenticator.AuthenticatorCredentials;
import org.apache.spark.storage.StorageLevel;
import org.apache.spark.streaming.receiver.Receiver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
/*
 * Copyright 2019 Google Inc. All Rights Reserved.
 *
 * Licensed 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 io.cdap.plugin.salesforce.plugin.source.streaming;



/**
 * Implementation of Spark receiver to receive Salesforce push topic events
 */
public class SalesforceReceiver extends Receiver<String> {
  private static final Logger LOG = LoggerFactory.getLogger(SalesforceReceiver.class);
  private static final String RECEIVER_THREAD_NAME = "salesforce_streaming_api_listener";
  // every x seconds thread wakes up and checks if stream is not yet stopped
  private static final long GET_MESSAGE_TIMEOUT_SECONDS = 2;

// Path: src/main/java/io/cdap/plugin/salesforce/authenticator/AuthenticatorCredentials.java
// public class AuthenticatorCredentials implements Serializable {
// 
//   private final OAuthInfo oAuthInfo;
//   private final String username;
//   private final String password;
//   private final String consumerKey;
//   private final String consumerSecret;
//   private final String loginUrl;
// 
//   public AuthenticatorCredentials(OAuthInfo oAuthInfo) {
//     this(Objects.requireNonNull(oAuthInfo), null, null, null, null, null);
//   }
// 
//   public AuthenticatorCredentials(String username, String password,
//                                   String consumerKey, String consumerSecret, String loginUrl) {
//     this(null, Objects.requireNonNull(username), Objects.requireNonNull(password), Objects.requireNonNull(consumerKey),
//          Objects.requireNonNull(consumerSecret), Objects.requireNonNull(loginUrl));
//   }
// 
//   private AuthenticatorCredentials(@Nullable OAuthInfo oAuthInfo,
//                                    @Nullable String username,
//                                    @Nullable String password,
//                                    @Nullable String consumerKey,
//                                    @Nullable String consumerSecret,
//                                    @Nullable String loginUrl) {
//     this.oAuthInfo = oAuthInfo;
//     this.username = username;
//     this.password = password;
//     this.consumerKey = consumerKey;
//     this.consumerSecret = consumerSecret;
//     this.loginUrl = loginUrl;
//   }
// 
//   @Nullable
//   public OAuthInfo getOAuthInfo() {
//     return oAuthInfo;
//   }
// 
//   @Nullable
//   public String getUsername() {
//     return username;
//   }
// 
//   @Nullable
//   public String getPassword() {
//     return password;
//   }
// 
//   @Nullable
//   public String getConsumerKey() {
//     return consumerKey;
//   }
// 
//   @Nullable
//   public String getConsumerSecret() {
//     return consumerSecret;
//   }
// 
//   @Nullable
//   public String getLoginUrl() {
//     return loginUrl;
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (o == null || getClass() != o.getClass()) {
//       return false;
//     }
// 
//     AuthenticatorCredentials that = (AuthenticatorCredentials) o;
// 
//     return Objects.equals(username, that.username) &&
//       Objects.equals(password, that.password) &&
//       Objects.equals(consumerKey, that.consumerKey) &&
//       Objects.equals(consumerSecret, that.consumerSecret) &&
//       Objects.equals(loginUrl, that.loginUrl);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hash(username, password, consumerKey, consumerSecret, loginUrl);
//   }
// }


// Path: src/main/java/io/cdap/plugin/salesforce/plugin/source/streaming/SalesforceReceiver.java
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.cdap.plugin.salesforce.authenticator.AuthenticatorCredentials;
import org.apache.spark.storage.StorageLevel;
import org.apache.spark.streaming.receiver.Receiver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

/*
 * Copyright 2019 Google Inc. All Rights Reserved.
 *
 * Licensed 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 io.cdap.plugin.salesforce.plugin.source.streaming;



/**
 * Implementation of Spark receiver to receive Salesforce push topic events
 */
public class SalesforceReceiver extends Receiver<String> {
  private static final Logger LOG = LoggerFactory.getLogger(SalesforceReceiver.class);
  private static final String RECEIVER_THREAD_NAME = "salesforce_streaming_api_listener";
  // every x seconds thread wakes up and checks if stream is not yet stopped
  private static final long GET_MESSAGE_TIMEOUT_SECONDS = 2;

  private final AuthenticatorCredentials credentials;