/** Create an SOA Databus client for forwarding non-partition-aware clients to the right server. */ @Provides @Singleton @PartitionAwareClient SubjectDatabus provideSubjectDatabusClient(MultiThreadedServiceFactory<SubjectDatabus> serviceFactory, @DatabusHostDiscovery HostDiscovery hostDiscovery, SubjectDatabus localSubjectDatabus, @SelfHostAndPort HostAndPort self, MetricRegistry metricRegistry, HealthCheckRegistry healthCheckRegistry) { SubjectDatabus client = ServicePoolBuilder.create(SubjectDatabus.class) .withHostDiscovery(hostDiscovery) .withServiceFactory( new PartitionAwareServiceFactory<>(SubjectDatabus.class, serviceFactory, localSubjectDatabus, self, healthCheckRegistry, metricRegistry)) .withMetricRegistry(metricRegistry) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS)); _environment.lifecycle().manage(new ManagedServicePoolProxy(client)); return client; }
@Provides @Singleton @AllCompactionControlSources public List<CompactionControlSource> getAllCompactionControlSources(@LocalCompactionControl CompactionControlSource localCompactionControlSource, @ServerCluster String serverCluster, Client client, DataCenters dataCenters, @CompControlApiKey String compControlApiKey, HealthCheckRegistry healthCheckRegistry, MetricRegistry metrics) { List<CompactionControlSource> compactionControlSources = Lists.newArrayList(); for (DataCenter dataCenter : dataCenters.getAll()) { MultiThreadedServiceFactory<CompactionControlSource> clientFactory = new CompactionControlClientFactory(serverCluster, new JerseyEmoClient(client), compControlApiKey); if (dataCenter.equals(dataCenters.getSelf())) { compactionControlSources.add(localCompactionControlSource); } else { ServiceEndPoint endPoint = new ServiceEndPointBuilder() .withServiceName(clientFactory.getServiceName()) .withId(dataCenter.getName()) .withPayload(new PayloadBuilder() .withUrl(dataCenter.getServiceUri().resolve(DataStoreClient.SERVICE_PATH)) .withAdminUrl(dataCenter.getAdminUri()) .toString()) .build(); compactionControlSources.add(ServicePoolBuilder.create(CompactionControlSource.class) .withHostDiscovery(new FixedHostDiscovery(endPoint)) .withServiceFactory(clientFactory) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .withMetricRegistry(metrics) .buildProxy(new ExponentialBackoffRetry(30, 1, 10, TimeUnit.SECONDS))); } } return compactionControlSources; }
/** Create an SOA DedupQueue client for forwarding non-partition-aware clients to the right server. */ @Provides @Singleton @PartitionAwareClient DedupQueueServiceAuthenticator provideDedupQueueClient(MultiThreadedServiceFactory<AuthDedupQueueService> serviceFactory, @DedupQueueHostDiscovery HostDiscovery hostDiscovery, DedupQueueService databus, @SelfHostAndPort HostAndPort self, HealthCheckRegistry healthCheckRegistry, MetricRegistry metricRegistry) { AuthDedupQueueService client = ServicePoolBuilder.create(AuthDedupQueueService.class) .withHostDiscovery(hostDiscovery) .withServiceFactory(new PartitionAwareServiceFactory<>( AuthDedupQueueService.class, serviceFactory, new TrustedDedupQueueService(databus), self, healthCheckRegistry, metricRegistry)) .withMetricRegistry(_environment.metrics()) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS)); _environment.lifecycle().manage(new ManagedServicePoolProxy(client)); return DedupQueueServiceAuthenticator.proxied(client); } }
.withHostDiscovery(new ZooKeeperHostDiscovery(curator, serviceFactory.getServiceName(), metrics)) .withMetricRegistry(metrics) .withCachingPolicy(cachingPolicy) .build();
/** Create an SOA QueueService client for forwarding non-partition-aware clients to the right server. */ @Provides @Singleton @PartitionAwareClient QueueServiceAuthenticator provideQueueClient(QueueService queueService, Client jerseyClient, @SelfHostAndPort HostAndPort self, @Global CuratorFramework curator, MetricRegistry metricRegistry, HealthCheckRegistry healthCheckRegistry) { MultiThreadedServiceFactory<AuthQueueService> serviceFactory = new PartitionAwareServiceFactory<>( AuthQueueService.class, QueueClientFactory.forClusterAndHttpClient(_configuration.getCluster(), jerseyClient), new TrustedQueueService(queueService), self, healthCheckRegistry, metricRegistry); AuthQueueService client = ServicePoolBuilder.create(AuthQueueService.class) .withHostDiscovery(new ZooKeeperHostDiscovery(curator, serviceFactory.getServiceName(), metricRegistry)) .withServiceFactory(serviceFactory) .withMetricRegistry(metricRegistry) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS)); _environment.lifecycle().manage(new ManagedServicePoolProxy(client)); return QueueServiceAuthenticator.proxied(client); }
.withHostDiscovery(new ZooKeeperHostDiscovery(curator, serviceFactory.getServiceName(), metrics)) .withMetricRegistry(metrics) .withCachingPolicy(cachingPolicy) .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS));
.withHostDiscovery(hostDiscovery) .withServiceFactory(dataStoreFactory) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .withMetricRegistry(metricRegistry) .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS));
.withHostDiscovery(hostDiscovery) .withServiceFactory(dataStoreFactory) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .withMetricRegistry(metricRegistry) .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS));
.withHostDiscovery(new ZooKeeperHostDiscovery(curator, serviceFactory.getServiceName(), metrics)) .withMetricRegistry(metrics) .withCachingPolicy(cachingPolicy) .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS));
/** Creates a ReplicationSource proxy to the remote data center. */ private ReplicationSource newRemoteReplicationSource(DataCenter dataCenter) { MultiThreadedServiceFactory<ReplicationSource> clientFactory = new ReplicationClientFactory(_jerseyClient) .usingApiKey(_replicationApiKey); ServiceEndPoint endPoint = new ServiceEndPointBuilder() .withServiceName(clientFactory.getServiceName()) .withId(dataCenter.getName()) .withPayload(new PayloadBuilder() .withUrl(dataCenter.getServiceUri().resolve(ReplicationClient.SERVICE_PATH)) .withAdminUrl(dataCenter.getAdminUri()) .toString()) .build(); return ServicePoolBuilder.create(ReplicationSource.class) .withHostDiscovery(new FixedHostDiscovery(endPoint)) .withServiceFactory(clientFactory) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .withHealthCheckExecutor(_healthCheckExecutor) .withMetricRegistry(_metrics) .buildProxy(new ExponentialBackoffRetry(30, 1, 10, TimeUnit.SECONDS)); } }
/** Creates a ReplicationSource proxy to the remote data center. */ private ReplicationSource newRemoteReplicationSource(DataCenter dataCenter) { MultiThreadedServiceFactory<ReplicationSource> clientFactory = new ReplicationClientFactory(_jerseyClient) .usingApiKey(_replicationApiKey); ServiceEndPoint endPoint = new ServiceEndPointBuilder() .withServiceName(clientFactory.getServiceName()) .withId(dataCenter.getName()) .withPayload(new PayloadBuilder() .withUrl(dataCenter.getServiceUri().resolve(ReplicationClient.SERVICE_PATH)) .withAdminUrl(dataCenter.getAdminUri()) .toString()) .build(); return ServicePoolBuilder.create(ReplicationSource.class) .withHostDiscovery(new FixedHostDiscovery(endPoint)) .withServiceFactory(clientFactory) .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy()) .withHealthCheckExecutor(_healthCheckExecutor) .withMetricRegistry(_metrics) .buildProxy(new ExponentialBackoffRetry(30, 1, 10, TimeUnit.SECONDS)); } }