Peaberry Stuart McCulloch.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Do you really get class loaders? Jevgeni Kabanov Founder & CTO of ZeroTurnaround.
Java Web User Group Impala Framework Update Modular class loaders and OSGi Phil Zoio London December 2, 2008.
C15: Design Patterns Gamma,Helm,Johnson,Vlissides (GOF)
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics.
Bridge The decoupling of abstraction and implementation.
Iterators Chapter 7. Chapter Contents What is an Iterator? A Basic Iterator Visits every item in a collection Knows if it has visited all items Doesn’t.
Spring Dynamic Modules. Startlocation: Documentation: /1.2.1/reference/html/
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
© 2008 by Mark Melvin; made available under the EPL v1.0 | March 13 th, 2008 | ON Semiconductor Creating Your Own Extension Points (It's Easier Than You.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Introduction to Java Prepared by: Ahmed Hefny. Outline Classes Access Levels Member Initialization Inheritance and Polymorphism Interfaces Inner Classes.
50.003: Elements of Software Construction Week 8 Composing Thread-safe Objects.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
Effective Java: Generics Last Updated: Spring 2009.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Tu sca ny 1 Extending The Tuscany Java SCA Runtime 21 August 2006.
OSGi in action BlueDavy
Apache Synapse The small print
What’s new in Kentico CMS 5.0 Michal Neuwirth Product Manager Kentico Software.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
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.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
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.
Java 5 Part 2 CSE301 University of Sunderland Harry Erwin, PhD.
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
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.
Coming up: Inheritance
Bulding a Modular Application with Coherence David Whitmarsh Independent Contractor Technical Architect Investment Banks
问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Impala A dynamic module framework for Java web development Phil Zoio Realsolve Solutions Devoxx 12 December, 2008.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Introduction to OSGi +ActorFrame Surya Bahadur Kathayat
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
JavaOne 2010 Patterns for Modularity Anton Epple, Eppleton IT Consulting Jaroslav Tulach, NetBeans Team, Oracle, Prague Zoran Sevarac, Faculty of Organizational.
EECE 310: Software Engineering
A&AI Component Diagram
Section 9: Design Patterns
Section 13 - Integrating with Third Party Tools
MPCS – Advanced java Programming
Overall Architecture and Component Model
Inheritance and Polymorphism
Magento Technical Guidelines Eugene Shakhsuvarov, Software Magento
How to be a Good Developer
Functional Programming with Java
Software Engineering Lecture 7 - Design Patterns
null, true, and false are also reserved.
Embracing Java 9 and beyond with Eclipse JDT
Java Programming Language
CSE 1030: Data Structure Mark Shtern.
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Iteration Abstraction
Role Models and Lifecycles in IoT and their Impact on the W3C WoT Thing Description Michele Blank.
JavaScript Reserved Words
Structural Patterns: Adapter and Bridge
7. Decorator SE2811 Software Component Design
Lecture 15: Inheritance II
Designing For Testability
Plug-In Architecture Pattern
GoF Patterns Ch. 26.
Threads and concurrency / Safety
Presentation transcript:

peaberry Stuart McCulloch

Today's menu Origin of peaberry OSGi-fying Guice Service providers Service registry abstraction Blending services & extensions Future ideas

patched Guice to support service “auto-binding” Origin Began as lab project at community site @Inject @OSGiService("(Currency=GBP)") StockQuote quote; new annotations patched Guice to support service “auto-binding” @OSGiService(...) StockQuote quote; // magically added for you bind(StockQuote.class)...

Auto-binding introduced too much magic so... Simplification Auto-binding introduced too much magic so... @Inject @OSGiService("(Currency=GBP)") StockQuote quote; NO new annotations service bindings now explicit, just like pure Guice aim to be a true extension to Guice – no patches!

& Squeezing Guice into a bundle Guice now has OSGi metadata thanks to BND Guice's type-safety meant no major classloading issues ... but AOP proxies initially didn't work in OSGi AOP proxies need to see client types & internal AOP support types

com.google.inject.internal.* Bridge class loader Don't want to expose AOP internals (repackaged CGLIB) A class loader B class loader com.google.inject.internal.* parent parent Guice class loader bridge A bridge B loadClass loadClass proxy proxy proxy proxy proxy so load proxy classes using “bridge” class loaders

Bridge class loader (2) No dependency on OSGi ! – only used when needed weak cache of bridge classloaders allows re-use ... as well as eager unloading of proxy classes BUT cannot apply bridging to package-private types as not visible from other classloaders

:( :) Why peaberry? Guice can now be used in OSGi – so what's missing? no support for dynamic OSGi services! each injector uses immutable set of explicit bindings :( so ... new Injector on every service change? :) or ... Provider<T> that returns dynamic proxies?

Service Provider @Inject StockQuote quote; quote.price(“JAVA”); p r o x y get @Inject StockQuote quote; K P P K P injector K P p r o x y Service Registry get price quote.price(“JAVA”); RealQuote unget

Fluent API helps you get the right service Provider<T> Service binding Fluent API helps you get the right service Provider<T> @Inject A bestService; bind(A.class).toProvider(service(A.class).single()); @Inject Iterable<A> allServices; // each element is a proxy bind(iterable(A.class)).toProvider(service(A.class).multiple()); * import static org.ops4j.peaberry.Peaberry.service; import static org.ops4j.peaberry.util.TypeLiterals.iterable;

Service binding (2) So is that it? s:

So is that it? ... no, you can also Service binding (2) So is that it? ... no, you can also service(A.class).filter(/* apply a filter */)... service(A.class).in(/* query a specific registry */)... service(A.class).out(/* watch for service changes */)... service(A.class).decoratedWith(/* apply decoration */)... each stage of the builder creates an immutable copy which means you can share and re-use builders

Pluggable API – integrate all kinds of service registries Service Registry Pluggable API – integrate all kinds of service registries public interface ServiceRegistry { <T> Iterable<Import<T>> lookup(Class<T> clazz, AttributeFilter filter); <T> void watch(Class<T> clazz, AttributeFilter filter, ServiceWatcher<? super T> watcher); } simple, allows lazinesszzz, no dependency on OSGi service filters not just limited to LDAP strings public interface AttributeFilter { boolean matches(Map<String, ?> attributes); } but we do provide an LDAP adapter (among others)

Tracking service use is very important ! public interface Import<T> { T get(); // may throw unchecked ServiceUnavailableException Map<String, ?> attributes(); void unget(); boolean available(); } can easily apply deco ation to imported services public interface ImportDecorator<S> { <T extends S> Import<T> decorate(Import<T> service); } to change dynamic behaviour (e.g. sticky services)

Single services wrap iterables to look like single imports Concurrent Import Single services wrap iterables to look like single imports public synchronized T get() { count++; if (null == service) { final Iterator<Import<T>> i = services.iterator(); if (i.hasNext()) { service = i.next(); instance = service.get(); } return instance; public synchronized void unget() { if (0 == --count && null != service) { final Import<T> temp = service; instance = null; service = null; temp.unget(); avoids thread-locals, provides basic service affinity

Export What's the opposite of a imported service? hint

Can alter/remove exported instance, update attributes public interface Export<T> { void put(T instance); void attributes(Map<String, ?> attributes); void unput(); } watchers can receive imports and (re-)export them public interface ServiceWatcher<S> { <T extends S> Export<T> add(Import<T> service); } but wait, isn't a registry a bit like a watcher?

Service Registry (revisited) Yes, and exports are also related to imports public interface ServiceRegistry extends ServiceWatcher<Object> { // etc... public interface Export<T> extends Import<T> { // etc... which leads to interesting possibilities ... // like pushing services from one registry to another for (Import<A> i : extensionRegistry.lookup(A.class, null)) { serviceRegistry.add(i); } but you don't have to use the raw API to export

Service binding (revisited) Exported service handles can be injected @Inject Export<A> exportedService; bind(export(A.class)).toProvider(service(aImpl).export()); can defer publishing a service by passing in null bind(export(A.class)).toProvider(service((A)null).export()); otherwise published when export handle is created * import static org.ops4j.peaberry.Peaberry.service; import static org.ops4j.peaberry.util.TypeLiterals.export;

Eclipse extensions Eclipse has its own registry for plug-in extensions this is like another service registry, but less dynamic so ... how can we map the service class to an instance? take inspiration from Eclipse Riena, use bean mapping ! unless its a compatible executable extension OR we're looking up IconfigurationElement class

Same approach as Riena for mapping bean types Mapping extensions Same approach as Riena for mapping bean types But use @ExtensionBean to configure point id @ExtensionBean("examples.menu.items") public interface Item { String getLabel(); @MapName("label") String toString(); @MapContent String getContent(); } Use @MapName, @MapContent from peaberry or Riena

GuiceExtensionFactory, similar approach as Spring Injecting extensions GuiceExtensionFactory, similar approach as Spring <extension point="org.eclipse.ui.views"> <view name="Message" allowMultiple="true" icon="icons/sample2.gif" class="example.ViewImpl" id="example.view" /> </extension> becomes <extension point="org.eclipse.ui.views"> <view name="Message" allowMultiple="true" icon="icons/sample2.gif" class="org.ops4j.peaberry.eclipse.GuiceExtensionFactory:example.ViewImpl" id="example.view" /> </extension> <extension point="org.ops4j.peaberry.eclipse.modules"> <module class="example.ViewModule" />

Blending services and extensions peaberry 1.1-rc2 lets you combine registries binder.install(osgiModule(context, eclipseRegistry())); service proxies will then query both OSGi and Clients can continue to use the same injection points @Inject StockQuote quote; YOU can choose where the service comes from or even whether to use a dynamic service at all !

coming soon: lifecycles, configuration support Summary Guice can now be used in OSGi peaberry adds dynamic services to Guice model easy to switch between services and non-services can mix'n'match different service registries ... like OSGi services and Eclipse extensions coming soon: lifecycles, configuration support

Questions?