com.azure.cosmos.implementation.changefeed.epkversion.PartitionSupervisorFactoryImpl Maven / Gradle / Ivy
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.cosmos.implementation.changefeed.epkversion;
import com.azure.cosmos.implementation.changefeed.ChangeFeedObserver;
import com.azure.cosmos.implementation.changefeed.ChangeFeedObserverFactory;
import com.azure.cosmos.implementation.changefeed.Lease;
import com.azure.cosmos.implementation.changefeed.LeaseManager;
import com.azure.cosmos.implementation.changefeed.LeaseRenewer;
import com.azure.cosmos.implementation.changefeed.PartitionSupervisor;
import com.azure.cosmos.implementation.changefeed.PartitionSupervisorFactory;
import com.azure.cosmos.models.ChangeFeedProcessorOptions;
import reactor.core.scheduler.Scheduler;
import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;
/**
* Implementation for the partition supervisor factory.
*/
class PartitionSupervisorFactoryImpl implements PartitionSupervisorFactory {
private final ChangeFeedObserverFactory observerFactory;
private final LeaseManager leaseManager;
private final ChangeFeedProcessorOptions changeFeedProcessorOptions;
private final PartitionProcessorFactory partitionProcessorFactory;
private final Scheduler scheduler;
private final Class partitionProcessItemType;
public PartitionSupervisorFactoryImpl(
ChangeFeedObserverFactory observerFactory,
LeaseManager leaseManager,
PartitionProcessorFactory partitionProcessorFactory,
ChangeFeedProcessorOptions options,
Scheduler scheduler,
Class partitionProcessItemType) {
checkNotNull(observerFactory, "Argument 'observerFactory' can not be null");
checkNotNull(leaseManager, "Argument 'leaseManager' can not be null");
checkNotNull(options, "Argument 'options' can not be null");
checkNotNull(partitionProcessorFactory, "Argument 'partitionProcessorFactory' can not be null");
checkNotNull(partitionProcessItemType, "Argument 'partitionProcessItemType' can not be null");
this.observerFactory = observerFactory;
this.leaseManager = leaseManager;
this.changeFeedProcessorOptions = options;
this.partitionProcessorFactory = partitionProcessorFactory;
this.scheduler = scheduler;
this.partitionProcessItemType = partitionProcessItemType;
}
@Override
public PartitionSupervisor create(Lease lease) {
checkNotNull(lease, "Argument 'lease' can not be null");
ChangeFeedObserver changeFeedObserver = this.observerFactory.createObserver();
PartitionProcessor processor = this.partitionProcessorFactory.create(lease, changeFeedObserver, this.partitionProcessItemType);
LeaseRenewer renewer = new LeaseRenewerImpl(lease, this.leaseManager, this.changeFeedProcessorOptions.getLeaseRenewInterval());
return new PartitionSupervisorImpl<>(lease, changeFeedObserver, processor, renewer, this.scheduler);
}
}