590 likes | 1k Views
JavaSpaces ™. Nati Shalom Natis@gigaspaces.com CTO GigaSpaces Technologies. Goals. Introduction to JavaSpaces™ technology and it’s functions and usage within the Java Services Framework. Learning Objectives. As a result of this presentation, you will be able to:
E N D
JavaSpaces ™ Nati Shalom Natis@gigaspaces.com CTO GigaSpaces Technologies
Goals Introduction to JavaSpaces™ technology and it’s functions and usage within the Java Services Framework.
Learning Objectives • As a result of this presentation, you will be able to: • Understand the Space Concept • Know more about Java Services Architecture • Learn about JavaSpaces™ simplicity and strength • Figure out the position of JavaSpaces™ in the overall Java Architecture
Speaker’s Qualifications • Nati Shalom is a C.T.O and Co Founder of GigaSpaces a Software Company that specializes in Performance & Scalability of Distributed application using Distributed Shared Memory & JavaSpaces™. • Nati Shalom have a vast experience in distributed computing technologies such as CORBA, JINI , Web Services , J2EE • Nati Shalom is active in various technological forums such as GRID consortium, SUN/JINI group , I.JUG • Nati Shalom is managing the I.JUG Web Services track. • Nati Shalom speaks frequently on those topics in conferences and technical courses
Agenda • What Is A Space • What Is JavaSpaces™ • JavaSpaces™ Benefits • Programming with JavaSpaces™ • The Service Oriented Architecture (SOA) • JINI Service Platform • Summary & References
What is a space: • Write • Writing an object into a shared pool memory • Read • Reading and object from a shared pool memory • Take • Reading and Deleting an object from a shared pool memory • Notify • Setting and Receiving notifications of changes made within the shared pool memory A Network service for Sharing and Exchanging information between distributed services: Small & Powerful API
Agenda • What Is A Space • What Is JavaSpaces™ • JavaSpaces™ Benefits • Programming with JavaSpaces™ • The Service Oriented Architecture (SOA) • JINI Service Platform • Summary & References
What Is JavaSpaces? • Distributed Shared Memory • A Jini ™ Service • Transactionally Secure • Astonishingly Simple • Based on “tuple-spaces” (see David Gelernter’s Linda system)
JavaSpaces Benefits • Boost the performance of the Distributed Applications: • Distributed Caching • Parallel Processing • Batching of remote calls. • Provides a generic solution for addressing the scalability and high availability of the distributed applications. • Hides the complexity of the distributed world: • Anonymity between applications • Uncoupled communication • Programs can communicate through time or space • Vast savings in design and development time
JavaSpaces Concepts • High-level communications between Java program • SIMPLE: only a few operations to learn • EXPRESSIVE: a large number of computing problems can be solved
Agenda • What Is A Space • What Is JavaSpaces™ • JavaSpaces™ Benefits • Programming with JavaSpaces™ • The Service Oriented Architecture (SOA) • JINI Service Platform • Summary & References
JavaSpaces Programs • Processes are decoupled from one another • Indirect interaction through one or more spaces
Matching Entries • A template is used to match entries in a space • The template is simply an entry of the type to be matched • Fields of the entry are used for matching • Non-assigned fields are wildcards
Entries • Entries are collections of typed objects • Must implement net.jini.core.entry.Entry • Fields can be any Serializable Java ™ object • Fields must be public to be matchable • Entry needs no-arg constructor
Example Entry • This shows a minimal entry: package hello; import net.jini.core.entry.Entry; public class Message implements Entry { public String content; public Message() { } } Must Implements Entry interface Entry Filed need to be public Must include a constructor
Accessing a Space • Jini is used to locate a space • Sun’s implementation identifies spaces by name. • GigaSpaces identifies spaces by name , container , persistency • Convenience method from GigaSpaces: • SpaceFinder.find(jini://*/*/spaceName);
Space Operations • Very small number of operations are defined on a space • The three fundamental operations are: • Write • Read • Take
Write Operation • Writes an entry to a space
Write Operation • Instantiate an Entry • Set its fields as necessary • Write the entry to the space Message msg = new Message(); msg.content = "Hello World"; JavaSpace space = (JavaSpace)SpaceFinder.find( args[0] ); space.write(msg, null, Lease.FOREVER);
Read Operation • Reads an entry from a space • Copy of object is returned • Original remains in space
Read Operation • Build a template • Read a matching entry from the space Message template = new Message(); Message result = (Message)space.read(template, null, Long.MAX_VALUE);
Take Operation • Takes an entry from a space • Matched entry is removed from space
Take Operation • Build a template • Take a matching entry from the space Message template = new Message(); Message result = (Message)space.take(template, null, Long.MAX_VALUE);
Snapshot Operation • The snapshot operation is used for performance optimization • It generates an image of the Entry. • This image usually saves the serialization overhead. Message template = new Message(); Entry snapshot = space.snapshot(template) Message result = (Message)space.read( snapshot, null, Long.MAX_VALUE);
The Notify Operation • The space implements the JINI RemoteEvents pattern • Clients can register for events on write operation using the notify method. • The notify callback should implement a RemoteEventListener
Notify Operation (Cont) • Registering for notifications // Register a notification template = space.snapshot(new Message()); EventRegistration reg = space.notify( template, null, //TX SpaceEventListener() , // The listener 60000 , // Lease null); // handbag System.out.println( "Notification registered. Registration id: " + reg.getID() + “Sequence number: " + reg.getSequenceNumber());
The Notify Operation (Cont) • RMI Event Listener public class SpaceEventListener extends UnicastRemoteObject implements RemoteEventListener { public SpaceEventListener() throws java.rmi.RemoteException{} public void notify(net.jini.core.event.RemoteEvent theEvent) throws net.jini.core.event.UnknownEventException, java.rmi.RemoteException { System.out.println("\nGot event from space:"); System.out.println("Event Source: " + theEvent.getSource()); System.out.println("Event Id: " + theEvent.getID()); } }
Other Space Operations • ReadIfExists() • Non-blocking read • takeIfExists() • Non-blocking take
Clustered Space A network of cooperating spaces with single, virtual, interface Replication Manages the distribution of work between the cluster spaces Fail-Over Manages the process of transparent re-routing in case of failure during an active session Load Balancing Enables partial or full replication between groups of spaces. Clustering Models With JavaSpaces
Agenda • What Is A Space • What Is JavaSpaces™ • JavaSpaces™ Benefits • Programming with JavaSpaces™ • The Service Oriented Architecture (SOA) • JINI Service Platform • Summary & References
What’s Missing ? Data sharing between services Activities synchronized between services Data collaboration between services Optimal Performance Component Oriented Service Oriented Application Composite Application Becomes… A B C Components A B C Services The Service Oriented Approach
The Space itself is A SERVICE that provides Shared Memory Capabilities. Services allocate space dynamically. Unique Benefits: Performance Distributed Caching Parallel Processing Virtualization Collaboration Synchronization Personalization Session Sharing Single Sign On Using JavaSpaces™ as a Shared Address Space between services Composite Application Distributed Shared Memory Service A B C Services
Enterprise Service Bus “In 2002, a new form of infrastructure that combines Web services, messaging, basic transformation and content-based routing came to market. These low-cost, application-server-neutral enterprise service buses (ESBs) are well suited to be the backbones for SOAs and basic ENSs.” Source: “From Enterprise Network to Enterprise Nervous System” Massimo Pezzini, 10–12 March 2003
Why Now? (Cont) • Network vs. computer performance • Computer speed doubles every 18 months • Network speed doubles every 9 months • Difference = order of magnitude per 5 years • 1986 to 2000 • Computers: x 500 • Networks: x 340,000 • 2001 to 2010 • Computers: x 60 • Networks: x 4000 Moore’s Law vs. storage improvements vs. optical improvements. Graph from Scientific American (Jan-2001).
Agenda • What Is A Space • What Is JavaSpaces™ • JavaSpaces™ Benefits • Programming with JavaSpaces™ • The Service Oriented Architecture (SOA) • JINI Service Platform • Summary & References
Step 2: Finding a Service Lookup Service Client
JoinManager & DiscoveryManager • Locating services can be done using the utility classes of ``Discovery Management'‘ • The JoinManager uses the DiscoveryManager for locating an LUS. • It than register the service with each LUS. • The JoinManager provides two constructors: • No serviceId – This constructor should be used in the first time the service has been registered. • With serviceId - This constructor should be used after the service had been assigned atleast once a service id.
Example:Joining A Service with all LUS • JoinManager joinMgr = null; • try { • LookupDiscoveryManager mgr = • new LookupDiscoveryManager(LookupDiscovery.ALL_GROUPS, • null /* unicast locators */, • null /* DiscoveryListener */); • joinMgr = new JoinManager(new FileClassifierImpl(), /* service */ • null /* attr sets */, • this /* ServiceIDListener*/, • mgr /* DiscoveryManagement */, • new LeaseRenewalManager()); • } • catch(Exception e) {..}
ServiceDiscoveryManager • The class ServiceDiscoveryManager is only available in Jini 1.1. It performs client-side functions similar to that of JoinManager for services, and simplifies the tasks of finding services
ServiceDiscoveryManager Goals • The ServiceDiscoveryManager was designed to assist clients with the following tasks: • A client may wish to use a service immediately or later • A client may want to use multiple services • A client will want to find services by their interface, but may also want to apply additional criteria, such as being a ``fast enough'' printer • A client may just wish to use a service if it is available at the time of request, but alternatively may want to be informed of new services becoming available and respond to this new availability (for example, a service browser)
The ServiceDiscoveryManger Interface • public class ServiceDiscoveryManager { • public ServiceDiscoveryManager(DiscoveryManagement discoveryMgr, LeaseRenewalManager leaseMgr) throws IOException; • LookupCache createLookupCache(ServiceTemplate tmpl, ServiceItemFilter filter, ServiceDiscoveryListener listener); • ServiceItem[] lookup(ServiceTemplate tmpl, int maxMatches, ServiceItemFilter filter); • ServiceItem lookup(ServiceTemplate tmpl, ServiceItemFilter filter); ServiceItem lookup(ServiceTemplate tmpl, ServiceItemFilter filter, long wait); • ServiceItem[] lookup(ServiceTemplate tmpl, int minMaxMatch, int maxMatches, ServiceItemFilter filter, long wait); • void terminate(); • }
Finding a Service Immediately • try { • LookupDiscoveryManager mgr = new LookupDiscoveryManager(LookupDiscovery.ALL_GROUPS, • null /* unicast locators */, • null /* DiscoveryListener */); • clientMgr = new ServiceDiscoveryManager(mgr, • new LeaseRenewalManager()); • } catch(…) {.. } • Class [] classes = new Class[] {FileClassifier.class}; • ServiceTemplate template = new ServiceTemplate(null, classes, null); • ServiceItem item = null; • // Try to find the service, blocking till timeout if necessary • try { • item = clientMgr.lookup(template, • null, /* no filter */ • WAITFOR /* timeout */); • } catch(..) {..}
The Details: Programming using Leases,Events, and Transactions
Why Distributed Leasing? • Problem: • Partial failure in distributed systems can lead to unchecked resource consumption • Traditional solution: system administration • Error-prone • Costly • Only happens when it’s too late
Distributed Leasing in Jini™ • Protocol for managing resources using a renewable, duration-based model • Contract between objects • Resources can be shared or private • Provides a method of managing resources in an environment where network failures can, and do, occur
What are Leases? • Time-based grants of resources or services • Loose contracts between grantor and holder • Negotiated for a set period of time • Can be shared or exclusive