Modular Applications and the Lookup API Tim Boudreau Senior Staff Engineer Sun Microsystems.

Slides:



Advertisements
Similar presentations
Goals Give you a feeling of what Eclipse is.
Advertisements

Apache Axis2 - OSGi Integration in WSO2 Carbon Platform
Notes to the presenter. I would like to thank Jim Waldo, Jon Bostrom, and Dennis Govoni. They helped me put this presentation together for the field.
Eclipse Architecture Dwight Deugo Nesa Matic
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of Creating Eclipse plug-ins.
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
Java Beans Component Technology Integrated, Visual Development Environments Reusable Platform-Independent Modular.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Component-Based Software Engineering Introduction to Java Beans Paul Krause and Sotiris Moschoyiannis.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
OSGi.
Session 1 - Introduction and Data Access Layer
Eric Keller, Evan Green Princeton University PRESTO /22/08 Virtualizing the Data Plane Through Source Code Merging.
ANSTO E-Science workshop Romain Quilici University of Sydney CIMA CIMA Instrument Remote Control Instrument Remote Control Integration with GridSphere.
CHEF II / Sakai Architecture. CHEF II Changes uPortal replaces Jetspeed –jsr 168 portlet, servlet compliant Spring replaces Turbine component framework.
XML Registries Source: Java TM API for XML Registries Specification.
Comparing JavaBeans and OSGi Towards an Integration of Two Complementary Component Models HUMBERTO CERVANTES JEAN-MARIE FAVRE 09/02.
Shannon Hastings Multiscale Computing Laboratory Department of Biomedical Informatics.
Plug-In Architecture Pattern. Problem The functionality of a system needs to be extended after the software is shipped The set of possible post-shipment.
GWT Development with Activities and Places
Introduction to Java Beans CIS 421 Web-based Java Programming.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
Architecture View Models A model is a complete, simplified description of a system from a particular perspective or viewpoint. There is no single view.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Plug-in Architectures Presented by Truc Nguyen. What’s a plug-in? “a type of program that tightly integrates with a larger application to add a special.
Lorenz: Visitor Beans: An Aspect-Oriented Pattern Aspect-oriented pattern: describes a solution to a tangling problem in a particular context.
Introduction to business component technologies. Component definitions Szyperski: A software component is a unit of composition with contractually specified.
ETICS All Hands meeting B ologna, October , 2006 WP4 Test and Metrics Plugin Framework (WP4) (WP4) Eva TAKACS.
Plug-In Architecture Pattern. Problem The functionality of a system needs to be extended after the software is shipped The set of possible post-shipment.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Modular Applications and the Lookup API Geertjan Wielenga NetBeans Team.
Data Objects & Editors Tim Boudreau Senior Staff Engineer Sun Microsystems.
Modular Applications and the Lookup API David Štrupl Sun Microsystems.
System FileSystem Everything is a Stream. What is it? General registry of configuration data.
The Holmes Platform and Applications
Object Oriented Programming in
Java Interview Questions
MVC in NetBeans and other modular applications Jaroslav Tulach.
Nodes and Explorer David Strupl Staff Engineer Sun Microsystems.
Goals Give you a feeling of what Eclipse is.
Course Outcomes of Object Oriented Modeling Design (17630,C604)
University of Central Florida COP 3330 Object Oriented Programming
Chapter 1 Introduction to Computers, Programs, and Java
Tomcat Celsina Bignoli
Self Healing and Dynamic Construction Framework:
Cross Platform Development using Software Matrix
Nodes and Explorer NetBeans ~ JavaBeans Tim Boudreau
Java Beans Sagun Dhakhwa.
An In-Depth Look at the Autodesk® AutoCAD® App Autoloader Module
OpenOffice.org API Plugin for NetBeans- a look under the hood
Contributing to Open Source Projects
University of Central Florida COP 3330 Object Oriented Programming
Introduction Enosis Learning.
Introduction Enosis Learning.
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Present by Andie Saizan, MCP
ESIS Consulting LLC (C) ESIS Consulting LLC. All rights reserved
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Could Jiro™ Extend the Jini™ Pattern Lanuguage?
(Computer fundamental Lab)
Java Remote Method Invocation
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2018
Plug-In Architecture Pattern
Presentation transcript:

Modular Applications and the Lookup API Tim Boudreau Senior Staff Engineer Sun Microsystems

The Need for Modular Applications ● Applications get more complex ● Assembled from pieces ● Developed by distributed teams ● Components have complex dependencies ● Good architecture – Know your dependencies – Manage your dependencies

The Entropy of Software ● Version 1.0 is cleanly designed...

The Entropy of Software ● Version a few expedient hacks...we'll clean those up in 2.0

The Entropy of Software ● Version oops...but...it works!

The Entropy of Software ● Version Help! Whenever I fix one bug, I create two more!

The Entropy of Software ● Version 4.0 is cleanly designed. It's a complete rewrite. It was a year late, but it works...

The Entropy of Software ● Version does this look familiar?....

The Entropy of Software ● TO BE CONTINUED....

Types of Library ● Simple library – one impl, put it on classpath and use ● Reference Impl + Vendor Impl – You trust that the Vendor impl conforms to the spec ● Modular Library – the API is separate from the implementation – Multiple implementations possible – Spec conformance is enforced by design – API must find its implementation – You need a registry of things

Modular Applications ● Discover their components at runtime ● May add/remove/reload components at runtime ● Must satisfy dependencies between components ● Have API contracts between components ● Run inside a runtime container

What is a NetBeans Module ● It is just a JAR file – no magic – Has some special manifest entries to describe it to NetBeans – Editable in the Project Properties dialog for module projects ● Distributed in an NBM file – Basically a signed JAR file – Contains metadata about the module – May contain 3 rd party JARs or anything else that needs to be on the system

NetBeans Module Manifest Manifest-Version: 1.0 Ant-Version: Apache Ant Created-By: 1.5.0_14-b03 (Sun Microsystems Inc.) OpenIDE-Module-Public-Packages: - OpenIDE-Module-Module-Dependencies: org.netbeans.api.java/1,... OpenIDE-Module-Java-Dependencies: Java > 1.5 OpenIDE-Module-Build-Version: OpenIDE-Module-Specification-Version: OpenIDE-Module: org.netbeans.modules.java.editor/1 OpenIDE-Module-Implementation-Version: 4 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/editor/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/java/editor/JavaEditorModule.class OpenIDE-Module-Layer: org/netbeans/modules/java/editor/resources/layer.xml OpenIDE-Module-Requires: org.openide.modules.ModuleFormat1 AutoUpdate-Show-In-Client: false

Modular Runtime Containers Must ● Ensure dependencies are satisfied – Including requiring > version n of a module ● Not allow illegal dependencies ● Allow legal dependencies ● Instantiate components of the system at runtime ● Provide service registration/discovery facility

What is a NetBeans Module ● It is just a JAR file – no magic – Has some special manifest entries to describe it to NetBeans ● Distributed in an NBM file – Basically a signed JAR file – Contains metadata about the module – May contain 3 rd party JARs or anything else that needs to be on the system

Enforcing Module Dependencies

Use an Existing Runtime Container Rest In Peace, Home-made Frameworks

Class Loader Partitioning

Module Dependencies

Provides/Requires Tokens ● API can be in one module, implementation in another ● API module can include a requires token in its manifest OpenIDE-Module-Requires: Spellchecker ● Implementation module includes a provides token in its manifest OpenIDE-Module-Provides: Spellchecker ● Modules needing the API only install if requirement is satisfied

Modular Libraries and Discovery

Discovery and Dependencies ? So how will the SpellChecker API find its implementation?

The Java Extension Mechanism ● In JDK since 1.3 ● Easy with JDK 6's ServiceLoader.load() ● Declarative registration – No startup penalty ● Plain-text file in META- INF/services – Name is interface – Content is FQN of implementation

Other Solutions ● Global static singleton – why that's bad – Why that's bad: ● Can never be garbage collected ● Locked in to one implementation ● Setter injection – why that's bad: – Can be changed later by foreign code – A modular application may contain modules the original author did not write – Introduces state – threading and synchronization issues – “Push” model where we should be using a “pull” model ● String-based registry (JNDI, etc.) - why that's bad: – Not type-safe

Lookup – NetBeans Solution ● Small, NetBeans independent library – Part of NetBeans org-openide-util.jar ● org.openide.util.Lookup ● Works with any version of Java (unlike JDK's ServiceLoader) ● A Lookup is dynamic – Can fire changes ● A Lookup is instantiable – You can make one and use it ● Lookups are composable – ProxyLookup can combine and switch between other lookups and fire changes

A Lookup is a place ● A space objects swim into and out of ● You can observe when specific types of object appear and disappear ● You can get a collection all of the instances of a type in a Lookup

The Default Lookup – A global registry ● Global Lookup Patterns – Pseudo-singletons: StatusDisplayer x = Lookup.getDefault().lookup ( StatusDisplayer.class ); ● Better memory management: The singleton can be garbage collected if nothing references it – Global services Collection c = Lookup.getDefault().lookupAll( ProjectFactory.class );

Lookup: Service discovery and more

Can Contain >1 instance of a type ● It's not just for singletons ● Requesting multiple objects is easy: Collection c = Lookup.getDefault().lookupAll(A.class);

Lookup.Result – Keeping A Query Result

Tracking Changes in a Lookup

Listening To A Lookup.Result ● Why do that? – Default Lookup: ● Detect when a module is uninstalled/installed that provides something you are interested in – Some object that owns a lookup ● Detect when the set of its “capabilities” change

Listening for Changes Lookup.Result r = someLookup.lookupResult ( SomeClass.class ); r.addLookupListener (new LookupListener() { public void resultChanged (LookupEvent e) { //handler code here } });

So...What's So Special About This? ? What if objects had Lookups? What if Lookups could proxy each other?

Example: NetBeans Project API ● Associates a directory on disk with a Lookup ● Defines interfaces that may be in that Lookup public interface Project extends Lookup.Provider { FileObject getProjectDirectory(); Lookup getLookup(); }

Example: Selection in NetBeans ● Each main window tab has its own Lookup – Some tabs show Nodes, which also have Lookups, and proxy the selected Node's Lookup ● A utility Lookup proxies the Lookup of whatever window tab has focus – What is “to proxy”? Lookup lkp = Utilities.actionsGlobalContext();

Example: Selection in NetBeans Demo

Creating Your Own Lookup – when? ● When do you want to do this? Common cases: – You are implementing a Project ● The Lookup provides objects that let code interact with the project – You are writing a TopComponent (logical window) ● The Lookup provides its selection – You are writing a Node ● The Node's Lookup contents determine what actions will be enabled, what is shown in the Navigator, etc. – You are creating an API that other modules can inject objects into ● Your API classes can be final but still be extensible

Creating Your Own Lookup - How? ● A Lookup that never changes – org.openide.util.lookup.Lookups ● A utility class that provides some convenient Lookup implementations ● You set the contents once and it stays this way forever Lookup lkp = Lookups.fixed ( obj1, obj2, obj3 ); Lookup lkp = Lookups.singleton( onlyObject );

Creating Your Own Lookup - How? ● AbstractLookup – lookup subclass – org.openide.util.lookup.AbstractLookup – Driven by an InstanceContent object – You can add/remove/set the contents on the fly ● Appropriate changes will be fired to listeners InstanceContent content = new InstanceContent(); Lookup lkp = new AbstractLookup ( content ); content.set ( obj1, obj2, obj3 ); content.remove ( obj3 );

Creating Your Own Lookup - How? ● ProxyLookup – Merge multiple lookups together ● A lookup that proxies a bunch of other lookups – Can change which lookups are merged together on the fly ● And appropriate events will be fired Lookup lkp = new ProxyLookup ( otherLookup1, otherLookup2, otherLookup3 );

ProxyLookup

Useful Utility Implementations ● AbstractLookup + InstanceContent – Lookup whose contents you can manage ● Lookups.singleton( Object ) - one item Lookup ● Lookups.fixed( Object... ) - unchanging Lookup ● Lookups.exclude ( Lookup, Class... ); ● ProxyLookup ( Lookup... otherLookups ) - compose multiple lookups

Named Global Lookups ● New in NetBeans 6 ● Many “global” lookups – Lookup myOwnRegistry = Lookups.forPath(“my/registry/path”); ● Standalone – META-INF/namedservices/my/registry/path ● Integrated with System File System

Conclusion ● Lookup is used pervasively throughout NetBeans APIs ● It is used for – Declaratively registered global services ● Instantiation on demand – reduce startup time ● Separation of API and implementation – One module can provide an API – Another module provides the implementation – Selection context – action enablement & more – Simplifying general-purpose APIs (such as Project) ● It is one of the most important APIs to learn

References ● Lookup Javadoc: util/org/openide/util/Lookup.html ● Get the library $NB_HOME/platform8/lib/org-openide-util.jar ● Article – ● FAQ

Questions & Answers Q&A