All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.target.edge.client.ondevice.OnDeviceDecisioningServicesManager Maven / Gradle / Ivy

There is a newer version: 2.6.1
Show newest version
/*
 * Copyright 2021 Adobe. All rights reserved.
 * This file is licensed 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 REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package com.adobe.target.edge.client.ondevice;

import com.adobe.target.edge.client.ClientConfig;
import com.adobe.target.edge.client.service.NotificationService;
import com.adobe.target.edge.client.service.TargetService;
import java.util.HashMap;
import java.util.Map;

public class OnDeviceDecisioningServicesManager {

  public static class OnDeviceDecisioningServices {
    private NotificationService notificationService;
    private RuleLoader ruleLoader;
    private ClusterLocator clusterLocator;

    private void setNotificationDeliveryService(NotificationService notificationService) {
      this.notificationService = notificationService;
    }

    private void setRuleLoader(RuleLoader ruleLoader) {
      this.ruleLoader = ruleLoader;
    }

    private void setClusterLocator(ClusterLocator clusterLocator) {
      this.clusterLocator = clusterLocator;
    }

    public NotificationService getNotificationDeliveryService() {
      return notificationService;
    }

    public RuleLoader getRuleLoader() {
      return ruleLoader;
    }

    public ClusterLocator getClusterLocator() {
      return clusterLocator;
    }
  }

  private static final OnDeviceDecisioningServicesManager sInstance =
      new OnDeviceDecisioningServicesManager();

  private final Map servicesMap = new HashMap<>();

  public static OnDeviceDecisioningServicesManager getInstance() {
    return sInstance;
  }

  public OnDeviceDecisioningServices getServices(
      ClientConfig clientConfig, TargetService targetService) {
    String serviceKey = clientConfig.getClient();
    OnDeviceDecisioningServices services = servicesMap.get(serviceKey);
    if (services != null) {
      return services;
    }
    synchronized (servicesMap) {
      services = servicesMap.get(serviceKey);
      if (services != null) {
        return services;
      }
      services = new OnDeviceDecisioningServices();
      ClusterLocator clusterLocator = new ClusterLocator();
      services.setNotificationDeliveryService(
          new NotificationService(targetService, clientConfig, clusterLocator));
      services.setRuleLoader(new DefaultRuleLoader());
      services.setClusterLocator(clusterLocator);
      servicesMap.put(serviceKey, services);
      return services;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy