Package com.netflix.eureka.lease
Class Lease<T>
- java.lang.Object
-
- com.netflix.eureka.lease.Lease<T>
-
public class Lease<T> extends java.lang.ObjectDescribes a time-based availability of aLease. Purpose is to avoid accumulation of instances inAbstractInstanceRegistryas result of ungraceful shutdowns that is not uncommon in AWS environments. If a lease elapses without renewals, it will eventually expire consequently marking the associatedLeasefor immediate eviction - this is similar to an explicit cancellation except that there is no communication between theLeaseandLeaseManager.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_DURATION_IN_SECS
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancels the lease by updating the eviction time.longgetEvictionTimestamp()Gets the milliseconds since epoch when the lease was evicted.TgetHolder()Returns the holder of the lease.longgetLastRenewalTimestamp()Gets the milliseconds since epoch when the lease was last renewed.longgetRegistrationTimestamp()Gets the milliseconds since epoch when the lease was registered.longgetServiceUpTimestamp()Gets the milliseconds since epoch when the service for the lease was marked as up.booleanisExpired()Checks if the lease of a givenInstanceInfohas expired or not.booleanisExpired(long additionalLeaseMs)Checks if the lease of a givenInstanceInfohas expired or not.voidrenew()Renew the lease, use renewal duration if it was specified by the associatedLeaseduring registration, otherwise default duration isDEFAULT_DURATION_IN_SECS.voidserviceUp()Mark the service as up.voidsetServiceUpTimestamp(long serviceUpTimestamp)Set the leases service UP timestamp.
-
-
-
Field Detail
-
DEFAULT_DURATION_IN_SECS
public static final int DEFAULT_DURATION_IN_SECS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Lease
public Lease(T r, int durationInSecs)
-
-
Method Detail
-
renew
public void renew()
Renew the lease, use renewal duration if it was specified by the associatedLeaseduring registration, otherwise default duration isDEFAULT_DURATION_IN_SECS.
-
cancel
public void cancel()
Cancels the lease by updating the eviction time.
-
serviceUp
public void serviceUp()
Mark the service as up. This will only take affect the first time called, subsequent calls will be ignored.
-
setServiceUpTimestamp
public void setServiceUpTimestamp(long serviceUpTimestamp)
Set the leases service UP timestamp.
-
isExpired
public boolean isExpired()
Checks if the lease of a givenInstanceInfohas expired or not.
-
isExpired
public boolean isExpired(long additionalLeaseMs)
Checks if the lease of a givenInstanceInfohas expired or not. Note that due to renew() doing the 'wrong" thing and setting lastUpdateTimestamp to +duration more than what it should be, the expiry will actually be 2 * duration. This is a minor bug and should only affect instances that ungracefully shutdown. Due to possible wide ranging impact to existing usage, this will not be fixed.- Parameters:
additionalLeaseMs- any additional lease time to add to the lease evaluation in ms.
-
getRegistrationTimestamp
public long getRegistrationTimestamp()
Gets the milliseconds since epoch when the lease was registered.- Returns:
- the milliseconds since epoch when the lease was registered.
-
getLastRenewalTimestamp
public long getLastRenewalTimestamp()
Gets the milliseconds since epoch when the lease was last renewed. Note that the value returned here is actually not the last lease renewal time but the renewal + duration.- Returns:
- the milliseconds since epoch when the lease was last renewed.
-
getEvictionTimestamp
public long getEvictionTimestamp()
Gets the milliseconds since epoch when the lease was evicted.- Returns:
- the milliseconds since epoch when the lease was evicted.
-
getServiceUpTimestamp
public long getServiceUpTimestamp()
Gets the milliseconds since epoch when the service for the lease was marked as up.- Returns:
- the milliseconds since epoch when the service for the lease was marked as up.
-
getHolder
public T getHolder()
Returns the holder of the lease.
-
-