Transcript Jini

CS 603
Jini
April 10, 2002
What is Jini?
Java Middleware
•
Tools to construct federation
– Multiple devices, each with Java Virtual Machine
– Multiple services
•
•
Uses (doesn’t replace) Java RMI
Adds infrastructure to support distribution
– Registration
– Lookup
– Security
Service
• Basic “unit” of JINI system
– Members provide services
– Federate to share access to services
• Services combined to accomplish tasks
• Communicate using service protocol
– Initial set defined
– Add more on the fly
Infrastructure:
Key Components
• RMI
– Basic communication model
• Distributed Security System
– Integrated with RMI
– Extends JVM security model
• Discovery/join protocol
– How to register and advertise services
• Lookup services
– Returns object implementing service (really a local
proxy)
Programming Model
• Lookup
• Leasing
– Extends Java reference with notion of time
• Events
– Extends JavaBeans event model
– Adds third-party transfer, delivery and
timeliness guarantees, possibility of delay
• Transaction Interfaces
Jini Component Categories
• Infrastructure – Base features
• Programming Model – How you use them
• Services – What you build
Java / Jini Comparison
Lookup Service
• Describes functionality
• Describes interface
• Lookup is a service
– Can be referenced in another lookup service
– Also register lookup with non-Jini naming
• Registering
– Discovery protocol: Find a lookup service
– Join protocol: Register with the lookup
service
Registration
Sample Server
public class SendHelloServer implements
DiscoveryListener {
protected LeaseRenewalManager leaseManager
= new LeaseRenewalManager();
public static void main(String argv[]) {
new SendHelloServer();
// keep server running to allow time for locator
// discovery and keep re-registering the lease
Thread.currentThread().sleep(Lease.FOREVER);
}
public SendHello() {
LookupDiscovery discover = null;
// Prepare for discovery - empty here
// Discover a lookup service
// This uses the asynchronous multicast protocol,
// which calls back into the discovered() method
discover = new LookupDiscovery(
LookupDiscovery.ALL_GROUPS);
discover.addDiscoveryListener(this);
}
public void discovered(DiscoveryEvent evt) {
ServiceRegistrar registrar = evt.getRegistrars()[0];
// At this point we have discovered a lookup service
// Create information about a service
ServiceItem item = new ServiceItem(null, new
SendHelloImpl(), null);
// Export a service
ServiceRegistration reg = registrar.register(item,
Lease.FOREVER);
// Renew leasing
leaseManager.renewUntil(reg.getLease(), Lease.FOREVER,
this);
}
} // SendHelloServer
Invocation
Sample Client
public class Hello {
public static void main(String
argv[ ]) { new Hello(); }
public Hello() {
LookupLocator lookup = null;
ServiceRegistrar registrar = null;
FileClassifier classifier = null;
// Prepare for discovery
lookup = new LookupLocator(
"jini://www.simple_stuff.com");
// Discover a lookup service
// This uses the synchronous
unicast protocol
registrar = lookup.getRegistrar();
// Prepare a template for lookup
search
Class[ ] classes = new Class[ ]
{SendHello.class};
ServiceTemplate template = new
ServiceTemplate(
null, classes, null);
// Lookup a service
sender = (SendHello)
registrar.lookup(template);
// Call the service
System.out.println(
sender.SendHello());
}
} // Hello
Security
• Principal: Authenticated user making
request
• Access control list: What principals can
use a service
• JVM security mechanisms ensure services
don’t compromise local machine
Leasing
• Lease: Right to access a service
– Guarantees access for specified time period
• Negotiated as part of service protocol
• Allows freeing resource by either end,
without explicit negotiation
– Fault tolerance
• Exclusive vs. Non-exclusive
– Exclusive: Non-shared resource
– Non-exclusive: Allows sharing resource
Transactions
• Operations can be wrapped in transaction
– What is done in transaction is up to operation
– Notion of what “commit” or “abort” means isn’t
specified
Abort may even change state of system!
• Jini provides two-phase commit protocol
– Secure, fault tolerant commit / abort
– No semantics enforced by Jini
Events
•
•
•
•
Notification system
Object must support/define events
Other objects can register for notification
Jini handles communication / reliability
issues