Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.bazaarvoice.emodb.event.owner;
import com.bazaarvoice.curator.recipes.leader.LeaderService;
import com.bazaarvoice.emodb.common.dropwizard.leader.LeaderServiceTask;
import com.bazaarvoice.emodb.common.dropwizard.lifecycle.ServiceFailureListener;
import com.bazaarvoice.ostrich.HostDiscovery;
import com.bazaarvoice.ostrich.ServiceEndPoint;
import com.bazaarvoice.ostrich.partition.ConsistentHashPartitionFilter;
import com.bazaarvoice.ostrich.partition.PartitionFilter;
import com.codahale.metrics.MetricRegistry;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.net.HostAndPort;
import com.google.common.util.concurrent.Service;
import org.apache.curator.framework.CuratorFramework;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.time.Duration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import static java.util.Objects.requireNonNull;
/**
* A group of services that should only run when the current server is considered the owner of the specified object.
*
* This uses the Ostrich consistent hashing algorithm to determine which objects this server should attempt to own,
* and a ZooKeeper leader election to ensure that it the exclusive owner of the object.
*/
public class OstrichOwnerGroup implements OwnerGroup {
private static final Logger _log = LoggerFactory.getLogger(OstrichOwnerGroup.class);
private final String _group;
private final OstrichOwnerFactory _factory;
private final LoadingCache> _leaderMap;
private final CuratorFramework _curator;
private final HostDiscovery _hostDiscovery;
private final HostDiscovery.EndPointListener _endPointListener;
private final String _selfId;
private final LeaderServiceTask _dropwizardTask;
private final PartitionFilter _partitionFilter = new ConsistentHashPartitionFilter();
private final boolean _expireWhenInactive;
private final MetricRegistry _metricRegistry;
public OstrichOwnerGroup(String group,
OstrichOwnerFactory factory,
@Nullable Duration expireWhenInactive,
CuratorFramework curator,
HostDiscovery hostDiscovery,
HostAndPort self,
LeaderServiceTask dropwizardTask,
MetricRegistry metricRegistry) {
_group = requireNonNull(group, "group");
_factory = requireNonNull(factory, "factory");
_curator = requireNonNull(curator, "curator");
_hostDiscovery = requireNonNull(hostDiscovery, "hostDiscovery");
_selfId = requireNonNull(self, "self").toString();
_dropwizardTask = requireNonNull(dropwizardTask, "dropwizardTask");
_expireWhenInactive = (expireWhenInactive != null);
_metricRegistry = metricRegistry;
// Build a cache of name -> leader service, used to track which objects this server is responsible for.
CacheBuilder