Why Spaghetti Is Not Tasty: Architecting Full-Scale Swing Apps Jasper Potts SwingTeam Sun Microsystems Inc http://jasperpotts.com TS-3316 2007 JavaOne SM Conference | Session TS-3316 |
The Goals What you will take away from this session A understanding of some of the key issues of building large desktop Java™ applications. Why you need to think about these problems early on and some ways to tackle them. 2 2007 JavaOne SM Conference | Session TS-3316 |
My Background • Working on Swing Team at Sun • Nimbus Look and Feel • Synth • Metal & Ocean • JTable • Creator of Xerto Imagery • Worked on large Swing Applications for: Banking, GIS and Image Processing 3 2007 JavaOne SM Conference | Session TS-3316 |
The Start • How did I end up standing here talking to you today? 4 2007 JavaOne SM Conference | Session TS-3316 |
Agenda Basics Modularity Wiring Communication Conclusion Q & A 5 2007 JavaOne SM Conference | Session TS-3316 |
Setting the Scene • So you have a idea of what to build • Time to make a prototype 6 2007 JavaOne SM Conference | Session TS-3316 |
Setting the Scene • Lets look at some common architectures 7 2007 JavaOne SM Conference | Session TS-3316 |
Passing Everything Around MainPanel Editor Frame Quit Action Paste Action Save Action Copy Action 8 2007 JavaOne SM Conference | Session TS-3316 |
Static or Singleton Core MainPanel Editor Frame Application Core Quit Action Paste Action Save Action Copy Action 9 2007 JavaOne SM Conference | Session TS-3316 |
Static or Singleton Core Application Core 10 2007 JavaOne SM Conference | Session TS-3316 |
Pass the Core Around MainPanel Editor Frame Application Core Quit Action Paste Action Save Action Copy Action 11 2007 JavaOne SM Conference | Session TS-3316 |
Pass the Core Around Big Application MainPanel MainPanel Editor Frame Editor Frame Application Application Core Core Paste Action Quit Action Paste Action Quit Action Save Action Copy Action Save Action Copy Action 12 2007 JavaOne SM Conference | Session TS-3316 |
Applications Sizes How to draw the lines • When is a application small, medium, large? • Let’s look at some example applications 13 2007 JavaOne SM Conference | Session TS-3316 |
Application Sizes: Old UK Maps 14 2007 JavaOne SM Conference | Session TS-3316 |
Application Sizes: Aerith 15 2007 JavaOne SM Conference | Session TS-3316 |
Application Sizes: JEdit 16 2007 JavaOne SM Conference | Session TS-3316 |
Application Sizes: JAlbum 17 2007 JavaOne SM Conference | Session TS-3316 |
Application Sizes: Xerto Imagery 18 2007 JavaOne SM Conference | Session TS-3316 |
Application Sizes: NetBeans™ Software 19 2007 JavaOne SM Conference | Session TS-3316 |
Application Sizes Source: Simple line count of Java,XML,MF,C,CPP,H files including comments and excluding test code. 20 2007 JavaOne SM Conference | Session TS-3316 |
Application Size Breakdown 50,000 Source: Simple line count of Java,XML,MF,C,CPP,H files including comments and excluding test code. 21 2007 JavaOne SM Conference | Session TS-3316 |
SPAR - A Swing Rich Client Platform • At a point Imagery got to big for a simple model • I did a lot of research and put together the best technologies of the time • The SPAR framework was born 22 2007 JavaOne SM Conference | Session TS-3316 |
Agenda Basics Modularity Wiring Communication Conclusion Q & A 23 2007 JavaOne SM Conference | Session TS-3316 |
Modularity • The idea of breaking an application down into manageable modules is well known. • It has been tackled in the server space by frameworks like: Java Platform, Enterprise Edition (Java EE platform) • The main form modularity takes in desktop applications is plugin frameworks. 24 2007 JavaOne SM Conference | Session TS-3316 |
Modularity: Solutions • Today • OSGi [Java Specification Request (JSR) 291] ● Eclipse Equinox ● Knopperfish • NetBeans™ Platform • Platonos • JPF • In the next generation Java SE Platform • JSR 277: Java Module System • JSR 294: Improved Modularity Support in the Java Programming Language 25 2007 JavaOne SM Conference | Session TS-3316 |
Modularity: Platonos http://platonos.sourceforge.net • Small light weight plugin framework • Not as fully featured as OSGi etc but smaller and simpler to understand. • Could be a good choice for medium sized applications • Currently on Version 1.0 version 2 in the works • Good support on the mailing lists 26 2007 JavaOne SM Conference | Session TS-3316 |
Modularity: JPF http://jpf.sourceforge.net/ • Another light-weight plug-in framework • Derivation from Eclipse plug-in framework before it went OSGi • Not one I have had personal experience with but looks like there are people using it for serious applications • Recent releases of 1.0.1 and 1.5.0 on 03/07/2007 27 2007 JavaOne SM Conference | Session TS-3316 |
Modularity: NetBeans Platform http://platform.netbeans.org • Robust well proven framework • Many applications out there using it • Good tool support ● New Book on NetBeans Platform Rich Client Programming: Plugging into the NetBeans™ Platform (ISBN: 0132354802) 28 2007 JavaOne SM Conference | Session TS-3316 |
Modularity: OSGi http://www.osgi.org • Huge industry support for the specification • Widely used in many industries such as: cars, cell(mobile) phones, industrial automation, building automation, PDAs, servers, and of course desktop applications with Eclipse and its RCP apps. • Has good support for native code in plugins • Links: • There is a good presentation on Spring and OSGi that covers the basics of OSGi http://www.bejug.org/confluenceBeJUG/display/PARLEYS/Spring%20OSGi • A good reference to OSGi API is the official spec: http://osgi.org/osgi_technology/download_specs.asp The Eclipse OSGi implementation: http://www.eclipse.org/equinox/ • 29 2007 JavaOne SM Conference | Session TS-3316 |
Modularity: JSR 277 and 294 Offer first-class modularity, packaging and deployment support in the next generation Java SE platform. • JSR-294 (superpackage) • Defines linguistic unit of modularity • Information hiding and separate compilation • JSR-277 (Java Module System) • Defines deployment unit of modularity • Versioning scheme, new distribution format, repository, and runtime support • In the future, existing frameworks like OSGi and NetBeans software will be able to be take advantages of these new core functionality. 30 2007 JavaOne SM Conference | Session TS-3316 |
Modularity in the Spar Framework • Provides modularity though plugins • Uses Eclipse OSGi implementation as its engine • In OSGi a plugin is called a Bundle • What is a Bundle: • Basically a bundle is just a Jar file with some extra attributes in its manifest file 31 2007 JavaOne SM Conference | Session TS-3316 |
Modularity: A OSGi Bundle Manifest Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SPAR UI Bundle-SymbolicName: com.xerto.spar.ui; singleton:=true Bundle-Version: 1.0.0 Bundle-Vendor: XERTO Bundle-Activator: com.xerto.spar.ui.internal.SparUiActivator Export-Package: com.xerto.spar.ui, com.xerto.spar.ui.actions, … Require-Bundle: org.eclipse.core.runtime, com.xerto.spar Bundle-Classpath: ., swing-worker.jar Eclipse-AutoStart: false Spar-Runlevel: 10 32 2007 JavaOne SM Conference | Session TS-3316 |
Modularity: So what does this give you • Simple self contained building block • Forces you to think about contracts(links) • Separate public API from any implementation • Makes it easy to breakdown work • Defined dependencies • Simple start-up ordering 33 2007 JavaOne SM Conference | Session TS-3316 |
Agenda Basics Modularity Wiring Communication Conclusion Q & A 34 2007 JavaOne SM Conference | Session TS-3316 |
Wiring How do you connect all these plugins together • Three types of connections: • First is Class Exports • Plugin ‘A’ exports a public API that is used by plugin ‘B’ • Example: ‘A’ contains some Swing components like a Image Viewer Panel which ‘B’ is then using in its UI 35 2007 JavaOne SM Conference | Session TS-3316 |
Wiring: Class Exports How does one plugin use another plugin’s classes • Class exports are provided by the core of OSGi • Plugin ‘A’ who provides the class needs export that classes package in its manifest: Bundle-Name: Plugin A Bundle-SymbolicName: com.abc.A; singleton:=true Export-Package: com.abc.components.imagepanel • Plugin ‘B: needs to depend on ‘A’ in its manifest: Bundle-Name: Plugin B Bundle-SymbolicName: com.abc.B; singleton:=true Require-Bundle: com.abc.A 36 2007 JavaOne SM Conference | Session TS-3316 |
Wiring: Class Exports import com.abc.components.imagepanel.ImagePanel; public class ExmpleB { private ImagePanel ip = new ImagePanel(); … } 37 2007 JavaOne SM Conference | Session TS-3316 |
Recommend
More recommend