Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lili Shtorper Nava Vaisman

Similar presentations


Presentation on theme: "Lili Shtorper Nava Vaisman"— Presentation transcript:

1 Lili Shtorper Nava Vaisman
In Depth: Leasing Lili Shtorper Nava Vaisman 5/4/2019 Cahpter 10

2 Overview Reliability and self-healing The leasing paradigm
Using relative time Batching leases for performance The low-level leasing interfaces Convenience classes for building lease consumers A leasing service Guidelines for implementing leasing 5/4/2019 Cahpter 10

3 Reliability in Distributed Systems
Any system, distributed or not, will never be completely reliable. The challenge is to design distributed systems using concepts that promote reliability wherever possible, acknowledge the inevitability of failures, and provide a way for the system itself to clean up from failures. 5/4/2019 Cahpter 10

4 Self-Healing and Evolvability
The distributed system should do its own clean up – if a system is disconnected from the network, and to reduce human intervention to the minimum. This is almost impossible to upgrade all components of a distributed system at the same time. One must be able to evolve or upgrade the system on a component-by-component basis – rather than upgrading the entire system as a whole. 5/4/2019 Cahpter 10

5 Leasing as a Solution Leasing is Jini is an attempt to address the issues we’ve just covered. Jini uses one central concept – access to resources is leased to consumers, rather than granted to them perpetuity – as a way to acknowledge that systems fail. 5/4/2019 Cahpter 10

6 The Leasing Approach The primary idea behind leasing is that it requires a continued proof-of-interest on the part of the lease holder if it is to continue holding some resources. If the lease holder fails to demonstrate interest, then the lease expires and the resource is released. The resource that the lease grants access to can be essentially anything. The core Jini services use lease to grant access to event and lookup service registrations. The failure of a lease holder to demonstrate proof-of-interest may be because the holder is honestly no longer interested in the resource, or because he has crashed or became disconnected from the network. 5/4/2019 Cahpter 10

7 The Leasing Approach (cont.)
By granting a lease, the system guarantees that failures will be detected, and when will they be detected – if a lease is granted for 10 minutes, then 10 minutes is the longest window during which unnoticed failure may exist. Leases provides a way to for a distributed to automatically clean up after failed components. A component that fails won’t have the opportunity to free up its resources. Leasing guarantees that irrelevant data will simply be forgotten when leases expire. We can say that the system is self-healing in face of failures of resource holders. 5/4/2019 Cahpter 10

8 The Leasing Approach (cont.)
The fact that a service that does not renew its lease is forgotten from the system provides a way to evolve components of a distributed software system in isolation. When a service is cleaned up after its lease expire, you know that the entire service and any trace of it has been removed from the Jini community. Now you are free to run a different version of the same service, with different implementations, and plug into all the same communities of which the original service was a member. 5/4/2019 Cahpter 10

9 Issues in Leasing – Relative versus Absolute Time
Jini leases are specified using a desired lease duration, rather than an explicit lease expiration time. Relative time – a resource consumer requests a lease for a duration (an hour…). Time required to send the message to renew the lease – you should request leases large enough that the time required to send a renewal message will be in the noise. Most leases will be on the order of five to ten minutes. 5/4/2019 Cahpter 10

10 Issues in Leasing – Lease Negotiation
Leases in Jini are negotiated. The grantor has the final say on the lease that is offered. A lease requestor asks for a lease of a given duration, and the grantor replies with the actual duration, which may be the requested value, zero (denying the lease), or any value in between. The grantor returns the lease, the receiver effectively holds it. 5/4/2019 Cahpter 10

11 Issues in Leasing – Leasing Done by Third Parties
Leases could be acquired by third parties on behalf of the resource consumer. That means that the task of providing proof-of-interest can be delegated to an external entity. Resource consumers can delegate all or most of the mechanics of leasing to someone else. Such a strategy may be a requirement in situations where services are running on computationally-impoverished devices that may not have the power,connectivity or bandwidth to handle the chores of leasing. Problems with third-party leasing arise from the separation between the consumer holding the resource, and the third-party in charge of providing proof-of-interest. 5/4/2019 Cahpter 10

12 Building Lease Consumers
Lease consumers – services and applications who hold leases on some resource in another service. Basic leasing interfaces – renew and cancel leasing. Lookup service registrations are leased – the process of registering a service causes a lease to be returned. Event registrations are leased, asking for notifications returns a lease. A leases is created by the provider of the lease. 5/4/2019 Cahpter 10

13 The Lease Interface 5/4/2019 Cahpter 10 package net.jini.lease;
Import java.rmi.RemoteException; public interface Lease { longFOREVER = Long.MAX_VALUE; long ANY = -1; int DURATION = 1; int ABSOLUTE = 2; long getExpiration(); void cancel() throws UnknownLeaseException, RemoteException; void renew() throws LeaseDeniedException, UnknownLeaseException, void setSerialFormat (int format); int getSerialFormat(); LeaseMap createLeaseMap(long duration); boolean canBatch(lease lease); } 5/4/2019 Cahpter 10

14 The Lease Interface (cont.)
The Lease object that is returned to a caller is used to manage the lease. The lease object held by the consumer is a proxy that’s used to communicate with a lease grantor. The grantor maintains the actual resource and any information it uses to track the status of leases. Lease grantors decide how they will communicate with the Lease proxy, this is why the Lease is an interface and not a class. Invoking the remote methods on the lease object causes messages to travel to the lease grantor. FOREVER - the requestor wishes a lease granted in perpetuity. ANY – a lease of any duration. 5/4/2019 Cahpter 10

15 The Lease Interface (cont.)
grantor Local user Private Protocol Resources lease Leasing Status info 5/4/2019 Cahpter 10

16 Determining When a Lease Expires, Canceling and renewing a Lease
getExpiration() returns the expiration time of the lease. The return value is a long, representing the number of milliseconds since January 1 ,1970. It returns the absolute time, you can call System.currentTimeMillis() to check the current clock against the returned value. Cancel() – cancels the lease represented by the Lease object. A lease that was canceled has the same effect as a lease that expired. Renew() - renew an already granted lease. The parameter is the duration in milliseconds. If the lease is renewed, the specified duration will be the new lease duration. If the grantor decides to deny the request, the LeaseDeniedException is raised. 5/4/2019 Cahpter 10

17 Ensuring That Leases are Serialized Correctly
Leases are serialized when: they are transmitted across machines or when a service needs to record its persistent state. Services may “checkpoint” themselves, so that they could recover from a crash. They may write the Lease object to a persistent storage. When a Lease is transmitted between two machines via serialization, make sure that the expiration time is sent as a duration. When storing Leases for later use in the same machine, we write the expiration time in absolute times. 5/4/2019 Cahpter 10

18 Ensuring That Leases are Serialized Correctly (cont.)
This is done using the setSerialForm() and getSerialForm() methods. The two constants DURATION and ABSOLUTE are used as arguments setSerialForm() to and are returned from getSerialForm() . DURATION: time should be expressed as duration. This is the default. ABSOUTE: the expiration time should be represented as an absolute time. 5/4/2019 Cahpter 10

19 Batching Leases for Performance
A number of leases can be batched together in a data structure called a LeaseMap, and can all be renewed or canceled at the same time. LeaseMap are designed to group together all the Lease object that originated from the same lease grantor. 5/4/2019 Cahpter 10

20 Batching Leases for Performance (cont.)
canBatch() – used to determine whether an object from a particular Lease implementation can be batched with another Lease object. createLeaseMap() – creates a new LeaseMap object, initialized to contain the Lease instance that the method was called on. The arguments for this method associate a duration in milliseconds with the Lease object. Whenever the Leases in the LeaseMap are all renewed together, this is the value requested for the duration of the Lease. 5/4/2019 Cahpter 10

21 The LeaseMap Interface
package net.jini.lease; import java.rmi.RemoteException; public interface LeaseMap extends java.util.Map { boolean canContainKey(Object key); void renewAll() throws LeaseMapExeption, RemoteException; void cancelAll() throws LeaseMapExeption, } 5/4/2019 Cahpter 10

22 The LeaseMap Interface (cont.)
A Map is much like a hash table. Since LeaseMap extends Map, all the usual Map methods for adding and removing key-value pairs from the object are available here. The keys are the Lease objects, and the values are the desired duration, represented as objects of the Long class. When trying to add a Lease that cannot be batched with the rest of the Leases in the LeaseMap, an IllegalArgumentExcecption is raised. cancelAll()/renewAll() – attempt to cancel/renew all Leases in the LeaseMap. If the operation failed for a certain Lease, it is dropped from the LeaseMap.a LeaseMapException is raised, and it contains all the Leases that were dropped. 5/4/2019 Cahpter 10

23 Higher-Level APIs for Lease Consumers
The com.sun.jini.lease package defines a handful a class that are ready-to-use for lease management. The LeaseRenewalManager is a class that can manage the renewal for whole sets of lease. You create a LeaseRenewalManager and give it leases to manage. Whenever you pass it a lease, you also tell it how long the lease shold be held. At any point in the future, you can tell the LeaseRenewalManager to extend the expiration time on the lease, remove lease from the set of managed leases, or cancel the lease. The LeaseRenewalManager will continue renewing the lease until the times expires, or you tell the manager to drop the lease. 5/4/2019 Cahpter 10

24 Higher-Level APIs for Lease Consumers (cont.)
If a lease cannot be renewed by the LeaseRenewalManager, it will call out a listener that can decide what to do with the dropped lease. You can have different listeners for different leases. Lease listeners should implement the LeaseListener interface, which includes only the method notify(), which receives a LeaseRenewalEvent whenever a lease expires. 5/4/2019 Cahpter 10

25 LeaseRenewalManager package com.sun.jini.leases;
import net.jini.core.lease.Lease; import net.jini.core.lease.UnknownLeaseException; import java.rmi.RemoteException; public class LeaseRenewalManager { public LeaseRenewalManager(); public LeaseRenewalManager (Lease lease, long expiration, LeaseListener listener); public void cancel(Lease lease) throws UnknownLeaseException, RemoteException; 5/4/2019 Cahpter 10

26 LeaseRenewalManager (cont.)
public void clear(); public long getExpiration(Lease lease); public void remove(Lease lease) throws UnknownLeaseException; public void renewFor(Lease lease, long duration, LeaseListener listener); public void renewUntil(Lease lease, long expiration, public void setExpiration(Lease lease, long expiration) throws UnknownLeaseException; } 5/4/2019 Cahpter 10

27 LeaseListener package com.sun.jini.lease;
import java.util.EventListener; public interface LeaseListener extends EventListener { public void notify(LeaseRenewalEvent ev); } 5/4/2019 Cahpter 10

28 LeaseRenewalEvent package com.sun.jini.lease;
import java.util.EventObject; import net.jini.core.lease.Lease; public class LeaseRenewalEvent extends EventObject { // public Exception getException(); public long getExpiration(); public Lease getLease(); } 5/4/2019 Cahpter 10

29 Leasing Strategies Service Architecture Leasing strategy
Always-active back-end process written in Java. Back-end process handles lease renewal for service proxy. Always-active back-end process not written in Java. An external “wrapper” process manages Jini participation and lease renewal. This wrapper can do leasing itself internally, or can delegate it to an external leasing service. Rarely-active back-end process. Either wake up the back-end process periodically to handle lease renewals,or refer to an external leasing delegate. 5/4/2019 Cahpter 10

30 Leasing Strategies (cont.)
Service Architecture Leasing strategy Device with embedded JVM The device handles lease renewal for the service proxy. Device without embedded JVM Create an external wrapper for the device that runs on a nearby computer; this wrapper may refer to an external leasing service for lease renewal. Proxy-only Create an external wrapper for the proxy; this wrapper may stay running to do lease management, or may refer to an external leasing service for lease renewal. 5/4/2019 Cahpter 10


Download ppt "Lili Shtorper Nava Vaisman"

Similar presentations


Ads by Google