InMemoryLeaseManager Class
- java.
lang. Object - ILeaseManager
- com.
microsoft. azure. eventprocessorhost. InMemoryLeaseManager
- com.
public class InMemoryLeaseManager implements ILeaseManager
Constructor Summary
Constructor | Description | |
---|---|---|
InMemoryLeaseManager() |
Method Summary
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Boolean> |
acquireLease(CompleteLease lease)
Acquire the lease on the desired partition for this EventProcessorHost. Note that it is legal to acquire a lease that is currently owned by another host, which is called "stealing". Lease-stealing is how partitions are redistributed when additional hosts are started. The existing Azure Storage implementation can experience races between two host instances attempting to acquire or steal the lease at the same time. To avoid situations where two host instances both believe that they own the lease, acquisition can fail non-exceptionally by returning false and should do so when there is any doubt the worst that can happen is that no host instance owns the lease for a short time. This is qualitatively different from, for example, the underlying store throwing an access exception, which is an error and should complete exceptionally. |
CompletableFuture<Void> |
createAllLeasesIfNotExists(List<String> partitionIds)
Create in the store a lease for each of the given partitions, if it does not exist. Do nothing for any lease which exists in the store already. |
CompletableFuture<Void> |
createLeaseStoreIfNotExists()
Create the lease store if it does not exist, do nothing if it does exist. |
CompletableFuture<Void> |
deleteLease(CompleteLease lease)
Delete the lease info for a partition from the store. If there is no stored lease for the given partition, that is treated as success. |
CompletableFuture<Void> |
deleteLeaseStore()
Deletes the lease store. |
CompletableFuture<List<Base |
getAllLeases()
Returns lightweight BaseLease for all leases, which includes name of owning host and whether lease is expired. An implementation is free to return CompleteLease or its own class derived from CompleteLease, but it is important that getAllLeases run as fast as possible. If it is faster to obtain only the information required for a BaseLease, we heavily recommend doing that. |
CompletableFuture<Complete |
getLease(String partitionId)
Returns the lease info for the given partition.. |
int |
getLeaseDurationInMilliseconds()
The lease duration is mostly internal to the lease manager implementation but may be needed by other parts of the event processor host. |
void | initialize(HostContext hostContext) |
CompletableFuture<Boolean> |
leaseStoreExists()
Does the lease store exist? The returned CompletableFuture completes with true if the checkpoint store exists or false if it does not. It completes exceptionally on error. |
void | notifyOnSteal(String expectedOwner, String partitionId, Callable<?> notifier) |
CompletableFuture<Void> |
releaseLease(CompleteLease lease)
Give up a lease currently held by this host. If the lease has expired or been taken by another host, releasing it is unnecessary but will succeed since the intent has been fulfilled. |
CompletableFuture<Boolean> |
renewLease(CompleteLease lease)
Renew a lease currently held by this host instance. If the lease has been taken by another host instance (either stolen or after expiration) or explicitly released, renewLease must return false. With the Azure Storage-based implementation, it IS possible to renew an expired lease that has not been taken by another host, so your implementation can allow that or not, whichever is convenient. If it does not, renewLease should return false. |
void | setLatency(long milliseconds) |
CompletableFuture<Boolean> |
updateLease(CompleteLease lease)
Update the store with the information in the provided lease. It is necessary to currently hold a lease in order to update it. If the lease has been stolen, or expired, or released, it cannot be updated. Lease manager implementations should renew the lease before performing the update to avoid lease expiration during the process. |
Constructor Details
InMemoryLeaseManager
public InMemoryLeaseManager()
Method Details
acquireLease
public CompletableFuture
Acquire the lease on the desired partition for this EventProcessorHost.
Note that it is legal to acquire a lease that is currently owned by another host, which is called "stealing". Lease-stealing is how partitions are redistributed when additional hosts are started.
The existing Azure Storage implementation can experience races between two host instances attempting to acquire or steal the lease at the same time. To avoid situations where two host instances both believe that they own the lease, acquisition can fail non-exceptionally by returning false and should do so when there is any doubt the worst that can happen is that no host instance owns the lease for a short time. This is qualitatively different from, for example, the underlying store throwing an access exception, which is an error and should complete exceptionally.
Overrides:
InMemoryLeaseManager.acquireLease(CompleteLease lease)Parameters:
Returns:
createAllLeasesIfNotExists
public CompletableFuture
Create in the store a lease for each of the given partitions, if it does not exist. Do nothing for any lease which exists in the store already.
Overrides:
InMemoryLeaseManager.createAllLeasesIfNotExists(List<String> partitionIds)Parameters:
Returns:
createLeaseStoreIfNotExists
public CompletableFuture
Create the lease store if it does not exist, do nothing if it does exist.
Overrides:
InMemoryLeaseManager.createLeaseStoreIfNotExists()Returns:
deleteLease
public CompletableFuture
Delete the lease info for a partition from the store. If there is no stored lease for the given partition, that is treated as success.
Overrides:
InMemoryLeaseManager.deleteLease(CompleteLease lease)Parameters:
Returns:
deleteLeaseStore
public CompletableFuture
Deletes the lease store.
Overrides:
InMemoryLeaseManager.deleteLeaseStore()Returns:
getAllLeases
public CompletableFuture> getAllLeases()
Returns lightweight BaseLease for all leases, which includes name of owning host and whether lease is expired. An implementation is free to return CompleteLease or its own class derived from CompleteLease, but it is important that getAllLeases run as fast as possible. If it is faster to obtain only the information required for a BaseLease, we heavily recommend doing that.
Overrides:
InMemoryLeaseManager.getAllLeases()Returns:
getLease
public CompletableFuture
Returns the lease info for the given partition..
Overrides:
InMemoryLeaseManager.getLease(String partitionId)Parameters:
Returns:
getLeaseDurationInMilliseconds
public int getLeaseDurationInMilliseconds()
The lease duration is mostly internal to the lease manager implementation but may be needed by other parts of the event processor host.
Overrides:
InMemoryLeaseManager.getLeaseDurationInMilliseconds()Returns:
initialize
public void initialize(HostContext hostContext)
Parameters:
leaseStoreExists
public CompletableFuture
Does the lease store exist?
The returned CompletableFuture completes with true if the checkpoint store exists or false if it does not. It completes exceptionally on error.
Overrides:
InMemoryLeaseManager.leaseStoreExists()Returns:
notifyOnSteal
public void notifyOnSteal(String expectedOwner, String partitionId, Callable notifier)
Parameters:
releaseLease
public CompletableFuture
Give up a lease currently held by this host.
If the lease has expired or been taken by another host, releasing it is unnecessary but will succeed since the intent has been fulfilled.
Overrides:
InMemoryLeaseManager.releaseLease(CompleteLease lease)Parameters:
Returns:
renewLease
public CompletableFuture
Renew a lease currently held by this host instance.
If the lease has been taken by another host instance (either stolen or after expiration) or explicitly released, renewLease must return false. With the Azure Storage-based implementation, it IS possible to renew an expired lease that has not been taken by another host, so your implementation can allow that or not, whichever is convenient. If it does not, renewLease should return false.
Overrides:
InMemoryLeaseManager.renewLease(CompleteLease lease)Parameters:
Returns:
setLatency
public void setLatency(long milliseconds)
Parameters:
updateLease
public CompletableFuture
Update the store with the information in the provided lease.
It is necessary to currently hold a lease in order to update it. If the lease has been stolen, or expired, or released, it cannot be updated. Lease manager implementations should renew the lease before performing the update to avoid lease expiration during the process.
Overrides:
InMemoryLeaseManager.updateLease(CompleteLease lease)Parameters:
Returns:
Applies to
Azure SDK for Java