OW2 UTILITIESThe Swiss Army Knife Of OW2 Projects          Guillaume SauthierOW2 Annual Conference 2012, 27-29 November, O...
OW2 UtilitiesOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris                     www.ow2.org               ...
GenesisOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris                     www.ow2.org                     ...
A LITTLE BIT OF HISTORY•Was born in 2006 inside the OW2 EasyBeans project•Used in JOnAS, CAROL, CMI, EasyBeans, Shelbie, J...
ModulesOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris                     www.ow2.org                     ...
QUITE BASIC STUFF•I18n and Logger                                 • Simple Java/Xml mapper (read your                     ...
ANNOTATION PROCESSOR•Traverse Class, Method and Field declaration    • Support inheritance•Call interested AnnotationHandl...
EVENT SYSTEM•On steroid topic notification system                // Simple asynchronous listener                           ...
// Create a Dispatcher                                      EVENT SYSTEMEventDispatcher dispatcher = new EventDispatcher()...
POOL                                          public static void main(String[] args) throws Exception {                   ...
SUBSTITUTION•Extract variables declaration from String  • ‘Hello ${speaker.name} !’          DefaultSubstitutionEngine eng...
ARCHIVE•Uniform API for resource consumption•Supporting (out of the box)              public interface IArchive {         ...
BUNDLES, BUNDLES,                                  BUNDLES•Around 20 common libraries wrapped as Bundles • commons-{collec...
ContributionsOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris                     www.ow2.org               ...
ANONYMOUS QUOTES           http://gitorious.ow2.org/ow2-utilities                                 http://utilities.ow2.org...
QuestionsOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris                     www.ow2.org                   ...
utilities.ow2.org    guillaume.sauthier@peergreen.com                @sauthiegOW2 Annual Conference 2012, 27-29 November, ...
RESOURCES•http://www.flickr.com/photos/emagic/56206868/          OW2 Annual Conference 2012, 27-29 November, Orange Labs, P...
Upcoming SlideShare
Loading in...5
×

Ow2 Utilities, OW2con'12, Paris

169

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
169
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ow2 Utilities, OW2con'12, Paris

  1. 1. OW2 UTILITIESThe Swiss Army Knife Of OW2 Projects Guillaume SauthierOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 1
  2. 2. OW2 UtilitiesOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 2
  3. 3. GenesisOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 3
  4. 4. A LITTLE BIT OF HISTORY•Was born in 2006 inside the OW2 EasyBeans project•Used in JOnAS, CAROL, CMI, EasyBeans, Shelbie, JASMINe for years•Extracted as a separate maven project in 2008•More than 35 releases up to today !•Proposed as top level OW2 project in 2012•We’re here now :) OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 4
  5. 5. ModulesOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 5
  6. 6. QUITE BASIC STUFF•I18n and Logger • Simple Java/Xml mapper (read your Xml configuration files) • Internationalized loggers, Java 5 style •Base64•Xml parsing • Encode, decode • Obtain a DocumentParser, extract values from Elements (trimmed, •File/URL conversion Properties, default values, ...) •Classloader aware•Xml Config ObjectInputStream OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 6
  7. 7. ANNOTATION PROCESSOR•Traverse Class, Method and Field declaration • Support inheritance•Call interested AnnotationHandler(s) public class SampleAnnotationHandler extends AbstractAnnotationHandler { public boolean isSupported(Class<? extends Annotation> clazz) { return clazz.equals(Hello.class); } @OverrideIAnnotationProcessor processor = new DefaultAnnotationProcessor(); public void process(Annotation annotation, Class<?> clazz, Object target)processor.addAnnotationHandler(new SampleAnnotationHandler()); throws ProcessorException {processor.addAnnotationHandler(/* as many handler as you want */); System.out.printf("Type %s is annotated with @%s(%s)",processor.process(/* some instance */); clazz, annotation.annotationType().getSimpleName() ((Hello) annotation).name()); } } OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 7
  8. 8. EVENT SYSTEM•On steroid topic notification system // Simple asynchronous listener IEventListener listener = new IEventListener() { public void handle(IEvent event) { // Do your own casting here • Hierarchical, multi-threaded } System.out.printf("Received Event %s", event); public EventPriority getPriority() {•Dispatcher fires event on a topic return EventPriority.ASYNC_HIGH; } public boolean accept(IEvent event) { return true; } };•Listeners receive events matching a topic pattern • Declares a priority (SYNC, ASYNC) OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 8
  9. 9. // Create a Dispatcher EVENT SYSTEMEventDispatcher dispatcher = new EventDispatcher();dispatcher.setNbWorkers(3); // Listen to all Event published in /result/**dispatcher.start(); eventService.registerListener(listener, "/result/.*"); // Topic registrationeventService.registerDispatcher("/result/success", dispatcher); Dispatchers Loose Coupling Event Listeners Event Source(s) Asynchronous Consumer(s) /a/b /a /c Event Service // Dispatch an Event dispatcher.dispatch(new MyEvent("/result/.*")); OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 9
  10. 10. POOL public static void main(String[] args) throws Exception { PoolFactory<Pooled, Long> poolFactory = new PooledFactory();•Simple Pooling API JPool<Pooled,Long> pool = new JPool<Pooled, Long>(poolFactory); pool.start(); Pooled one = pool.get(); Pooled two = pool.get(); • Pool size, waiters, timeout Pooled three = pool.get(); Pooled four = pool.get(); // Will block until timeout or a release } • Thread-safe private static final class PooledFactory implements PoolFactory<Pooled, Long> { public Pooled create(Long clue) throws PoolException { return new Pooled(clue);•Basic implementation } public boolean isMatching(Pooled instance, Long clue) { return instance.id == clue; } public void remove(Pooled instance) { // Destroy instance } • Synchronous public boolean validate(Pooled instance, PoolEntryStatistics stats) { } return true; }•Advanced implementation @Pool(min = 1, max = 3) private static class Pooled { long id; public Pooled(Long clue) { id = clue; } • Asynchronous, composable } OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 10
  11. 11. SUBSTITUTION•Extract variables declaration from String • ‘Hello ${speaker.name} !’ DefaultSubstitutionEngine engine = new DefaultSubstitutionEngine(); ChainedResolver chain = new ChainedResolver(); chain.getResolvers().add(new SpeakerResolver());•PropertyResolvers chain.getResolvers().add(new DateResolver());engine.setResolver(chain); engine.substitute("Hello ${speaker.name} ! -- ${date}"); public class SpeakerResolver implements IPropertyResolver { public String resolve(String expression) { return "speaker.name".equals(expression) ? "Guillaume" : null; • Provides value for expression } } public class DateResolver implements IPropertyResolver { public String resolve(String expression) { • Composable } } return "date".equals(expression) ? (new Date()).toString() : null; • Support recursion (variables in variable) OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 11
  12. 12. ARCHIVE•Uniform API for resource consumption•Supporting (out of the box) public interface IArchive { String getName(); URL getURL() throws ArchiveException; • Directory URL getResource(String resourceName) throws ArchiveException; Iterator<URL> getResources() throws ArchiveException; • Jar Iterator<URL> getResources(String resourceName) throws ArchiveException; Iterator<String> getEntries() throws ArchiveException; • OSGi Bundle boolean close(); IArchiveMetadata getMetadata(); }•Extensible OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 12
  13. 13. BUNDLES, BUNDLES, BUNDLES•Around 20 common libraries wrapped as Bundles • commons-{collections, logging, modeler}, javassist, jaxb2-ri, jgroups, jsch, opencsv, weld, zookeeper, bouncycastle, ... • Correct exported packages version, verified imports•All other modules are OSGi Bundles • Versioned API, content exported OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 13
  14. 14. ContributionsOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 14
  15. 15. ANONYMOUS QUOTES http://gitorious.ow2.org/ow2-utilities http://utilities.ow2.org http://bamboo.ow2.org/browse/UTIL http://jira.ow2.org/browse/UTIL OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 15
  16. 16. QuestionsOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 16
  17. 17. utilities.ow2.org guillaume.sauthier@peergreen.com @sauthiegOW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 17
  18. 18. RESOURCES•http://www.flickr.com/photos/emagic/56206868/ OW2 Annual Conference 2012, 27-29 November, Orange Labs, Paris www.ow2.org 18
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×