Friday, October 1, 2010

EJB.next Connector/Bean API : JAX-RS and beyond

It isn't commonly known that MessageDrivenBeans (MDBs) are not directly tied to the Java Message Service (JMS). In fact, they are tied to the Java EE Connector Architecture. It's even less commonly known that MDBs are not necessarily asynchronous. It's really the Connector that drives the communication style.
Overall, it is a very cool model that does allow for some pretty impressive and standard extension to any compliant Java EE platform. It is, however, incredibly underused. With a few changes to the model, it could be made to support even things like JAX-RS. Let's break it down.
The touchpoints between the Connector and the MDB are the ActivationSpec/ActivationConfig and the MessageListener interface. Using a fictitious "Email" Connector idea, let's see how this looks.
EmailConsumer (MessageListener) interface*
package org.superemail.connector;

// other imports...
    
public interface EmailConsumer {
    public void receiveEmail(Properties headers, String body);
}
EmailAccountInfo (ActivationSpec) class
package org.superemail.connector;
    
/**
 * This class is basically an old-style JavaBean with get/set for each property
 */
public class EmailAccountInfo implements javax.resource.spi.ActivationSpec {

    private String address;

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void validate() throws InvalidPropertyException {
    }
}
That's it for the Connector (aside from the Connector itself). I have left out a little detail on the ActivationSpec, we'll cover that later.
Now for the MDB's side of things. The MDB needs to implement the Connector's EmailConsumer interface and configure the Connector'sEmailAccountInfo JavaBean which is done via the activation-config tag of the ejb-jar.xml or via @ActivationConfigPropertyannotations in the @MessageDriven declaration.
@MessageDriven(activationConfig = 
        {@ActivationConfigProperty(
                propertyName = "address", 
                propertyValue = "dblevins@apache.org")
        })
public class EmailBean implements EmailConsumer {

    @PostConstruct
    public void init() {
    }

    public void receiveEmail(Properties headers, String body) {
        // do your thing!
    }
}
Done. Those are the basics. The Connector supplies a MessageListener interface and an ActivationConfig JavaBean, the MDB implements the interface and configures the JavaBean via the loosely-typed @ActivationConfigProperty.
There are a few things that prevent this model from reaching its true potential:
  • Metadata is loosely typed in the bean code
  • Only class-level metadata is allowed, not method-level
  • Requiring an interface can limit expressiveness
Let's see how life might look if we eliminate the JavaBean and allow the Connector to instead supply an annotation.
package org.superemail.connector;
    
@Target(TYPE)
@Retention(RUNTIME)
@javax.resource.annotation.ActivationSpec
public @interface EmailAccountInfo {
    String address();
}
Side Note: The original javax.resource.spi.ActivationSpec interface has a 'validate()' method on it to validate the JavaBean. A clear update to that part of the API would be to instead use the Bean Validation API.
Which gives us a bean that might look like this:
@MessageDriven
@EmailAccountInfo(address = "dblevins@apache.org")
public static class EmailBean implements EmailConsumer {

    @PostConstruct
    public void init() {
    }

    public void receiveEmail(Properties headers, String body) {
        // do your thing!
    }
}
Now we're getting somewhere!
Ok, let's get rid of that message listener interface and image our Email Connector uses a very JAX-RS inspired API for consuming emails. If you know a little JAX-RS you'll see where I'm going with this.
@MessageDriven
@EmailAccountInfo(address = "dblevins@apache.org")
public static class EmailBean {

    @PostConstruct
    public void init() {
    }

    @Deliver @Header("Subject: {subject}")
    public void receiveEmail(@HeaderParam("subject") String subject, @Body String body) {
        // do your thing!
    }
}
Pretty neat, huh?
Side note: For the rare few of you that speak Connector implementation, instead of giving your Resource Adapter a MessageEndpoint that is a proxy that only implements the MessageListener interface and the standard MessageEndpoint interface, the Container would instead give you an @LocalBean proxy that also implements MessageEndpoint. If you're thinking that an API like that would be great to use... imagine with the above changes you could make that API ... and use it in any compliant Java EE platform. Maybe even submit your own JSR if you came up with something great.
Truthfully speaking, it's the Connector who controls the lifecycle of the bean (MDB). The Connector API already allows for the Connector to say to the Container, "create me a bean" and "destroy this bean". So really, we don't need @MessageDriven anymore. Instead we can do this:
import javax.annotation.ManagedBean;

@ManagedBean
@EmailAccountInfo(address = "dblevins@apache.org")
public static class EmailBean {
 // ....
}
That's a little more modern and perhaps a bit clearer.
At this point, we have a generic API to hook arbitrary "Connectors" up to arbitrary "Beans" that are managed by a container. Were this the case when JAX-RS was created, they wouldn't have had to put so much effort into duplicating all the services that people who have managed beans expect: injection of resources, lifecycle callbacks, interceptors.
Summary: A few improvements to the expressiveness of the metadata passed between a Bean and its Connector could kick the MDB/Connector model into the mainstream as was the intention of the API from the beginning. New specifications could be created based on this model and be introduced incrementally as they are developed and needed.
The impact of fully opening up the Bean metadata to the Connector is quite deep and wide and likely not something that will scream at you immediately. Ask yourself, could something like the new EJB 3.1 @Schedule API have been done with a Connector/Bean model like this? To some extent probably it could. Certainly there already existed a few Quartz Connectors out there prior to the introduction of @Schedule.
Take a moment to daydream. What kind of Connectors could you create with this model?


UPDATE - Feb 7th, 2013

Save this proposal.  Without more voices it will be delayed till Java EE 8.  Let's not wait 4 years!  Take action and celebrate the Java Community Process openness by showing your support for including this in Java EE 7.  Act now.

VOTE AND COMMENT HERE http://java.net/jira/browse/EJB_SPEC-60




47 comments:

lightguardjp said...

Could something like @Connector or something be used instead of @ManagedBean? Seems like you should be able to do something like this with CDI

Garima Chopra said...

Chennai Escorts
Escorts in Chennai
Chennai Escorts Service
Chennai Escorts Agency
Independent Escorts in Chennai
Chennai call girls
Call girls in Chennai

Ranjana Mehta said...

Chennai Escorts
Independent Escorts in Chennai
Chennai Escorts Service
Chennai Escorts Agency
Escorts in Chennai
Chennai Escort
Chennai Call Girl
Call Girl in Chennai

Era Sharma said...

Hi guys you are discuss with Independent Mumbai escorts girl Era Sharma for your dating and satisfaction, I am fully verified top class escorts in Mumbai.

http://www.erasharma.com

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://www.pinklipslady.com/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://www.riyadubey.com/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

Independent Mumbai Escorts

">Independent Mumbai Escort

">Escorts in Mumbai

http://www.virginmumbaiqueens.com/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

Escorts Beirut Lebanon said...

Escorts in Beirut - Hello gentleman welcome to Beirut Escorts in Lebanon agency for hiring top class models for incall and outcall service.

Read More

Escorts Beirut Lebanon said...

Escorts in Beirut - Beirut Escorts offering independent escort services in Lebanon provide real genuine Escort Service anytime in Beirut and Lebanon are also there.

Click More

Escorts Beirut Lebanon said...

Escort in Lebanon - If you are planning to enjoy with Beirut and Lebanon Escort then comes with our escort models and make your happy dating.

Learn More

Escorts Beirut Lebanon said...

Escort in Beirut - Independent Beirut Escort Lebanon services to fulfill all your sensual desires. Sexy escorts model are available 24*7 for romantic relationship.

Know More

Escorts Beirut Lebanon said...

Lebanon Escorts - Exclusive Beirut Escorts Lebanon Service. VIP escort girls, review or search by price range. And incall outcall service.

Visit Our Site

Escorts Beirut Lebanon said...

Beirut Escorts - Call on +961 70 033 596 | Lebanon Escort Beirut Service, We are always popular and provide you best female escorts on your choices.

Website

Escorts Beirut Lebanon said...

Escort Lebanon - We provide all types of female Beirut Escort Lebanon including sexy escorts, model escorts and independent escorts agency.

Site

Escorts Beirut Lebanon said...

Beirut Escort - The most lovable Independent Beirut Escort Lebanon provide you best escorts service in Beirut and the most beautiful escort agency. Book Now.

Info

Soniya Mathur said...

Chennai Escorts
Escorts in Chennai
Chennai Escorts Service
Chennai Escorts Agency
Independent Escorts in Chennai
Chennai call girls
Call girls in Chennai

爸爸 x said...

20170619 junda
oakley sunglasses sale
cheap jerseys wholesale
burberry outlet sale
cheap ray ban sunglasses
adidas uk store
michael kors outlet clearance
cheap nba jerseys
true religion outlet
ray ban sunglasses
nike air max 90

Sanaya Seth said...

One of the most breathtakingly sensuous kajalaggarwaal tumblr escorts, who only likes men that have a class and are prudent.

If you ever wanted most exciting and fulfilling simpygrewal hatenablog escorts, your one stop solution to satisfy all your sexual desires.

If there is any high class gentleman looking for some exciting and mushy love making then he should definitely contact mydreamangels bravesites escorts.

There is not just a single service which is given one but so many various other kinds of services are offered at mydreamangels zohosites escorts.

Sharon Sandy said...

great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
Web Design Development Company
Web design Company in Chennai
Web development Company in Chennai

Anika Mehta said...

Ahmedabad Escorts
Independent Escorts in Ahmedabad
Escorts in Ahmedabad
Ahmedabad Escorts Service
Ahmedabad Escorts Agency
Female Escorts in Ahmedabad
Call Girls in Ahmedabad

john stany said...


I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.

Android App Development Company

isabella jacob said...

it is really amazing...thanks for sharing....provide more useful information...
Mobile app development company

louis philip said...

Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every blog.. i am expecting more updated posts from your hands.
Fitness SMS
Salon SMS
Investor Relation SMS

Arohi Mishra said...

Russian Escorts in Delhi
Russian Escorts
Delhi Escorts
Independent Russian Escorts in Delhi
Escorts in Delhi
Russian Escorts Service
Russian Escorts Agency

Kangana Ready said...

Chennai Escorts
Independent Escorts in Chennai
Chennai Escorts Service
Chennai Escorts Agency
Escorts in Chennai
Chennai Escort
Female Escorts in Chennai
Call Girl in Chennai

john stany said...


Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every blog.i am expecting more updated posts from your hands.
iOS App Development Company

Habib Malik said...

Sarkari Naukri
OBC Bank Recruitment 2018

Bhavna Kaur said...

Chennai Escorts
Escorts in Chennai
Chennai Escorts Service
Chennai Escorts Agency
Independent Escorts in Chennai
Chennai call girls
Chennai Escort

louis philip said...

I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

Fitness SMS
Fitness Text
Salon SMS
Salon Text
Investor Relation SMS
Investor Relation Text

Kavya Patel said...

Ahmedabad Escorts
Independent Escorts in Ahmedabad
Ahmedabad Escorts Service
Ahmedabad Escorts Agency
Call Girls in Ahmedabad
Female Escorts in Ahmedabad

Hiral Sharma said...

Reliable Independent Mumbai Escorts Girl Model in Between your Living City, so you can connect with us any time According Suitable your date, time and place. Thanks.

http://www.taajmumbaiescorts.com/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://www.missdaina.com/">

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://garimachopra.com/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://www.hiralsharma.com/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://taajmumbaiescort.blogspot.in/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://riyadubey.co.in/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

Habib Malik said...

AP SSC Time Table 2018
AP Intermediate Time Table 2018
Goa SSC Date Sheet 2018
Goa Board HSSC Date Sheet 2018

Priya Rana said...

Kolkata Escorts
Independent Escorts in Kolkata
Kolkata Escorts Service
Kolkata Escorts Agency
Escorts in Kolkata
Russian Escorts in Kolkata
Call Girl in Kolkata

Danish Ahmed said...

Thanks for sharing this article, now you can check your cut off marks by following below given links

rajasthan post office gds result 2017

north eastern post office gds result 2017

karnataka post office gds result 2017

punjab post office gds result 2017

uttarakhand post office gds result 2017

Priya Chauhan said...

Kolkata Escorts
Independent Escorts in Kolkata
Kolkata Escorts Service
Kolkata Escorts Agency
Escorts in Kolkata
Russian Escorts in Kolkata
Call Girl in Kolkata

Danish Ahmed said...

Thanks for sharing this article, now you can check your Time table & Date sheet 2017 by following below given links

ap ssc time table 2017

assam hslc date sheet 2017

bihar board 10th date sheet 2017

cbse board 10th date sheet 2017

ch board 10th date sheet 2017


Taniya Arora said...

Good post. Appreciate your deliver greater to share this informative article
that useful! For a nice and looking for manuals of this nature for the way
too much time.
Call Girls in Faridabad |

http://www.callgirlsoncall.in/Faridabad

Nidhi Mehta said...

Kolkata Escorts
Independent Escorts in Kolkata
Kolkata Escorts Service
Kolkata Escorts Agency
Call Girl in Kolkata
Escorts in Kolkata
Russian Escorts in Kolkata

Danish Ahmed said...

Thanks for sharing this article, now you can also check your Admit card & Recuritment 2017 by following below given links...

police si admit card 2017

gpsc medical officer admit card 2017

tamilnadu teacher recuritment 2017

bihar police constable recuritment 2017

gujarat high court recruitment 2017

Komal Aggarwal said...

Kolkata Escorts
Escorts in Kolkata
Kolkata Escorts Service
Independent Escorts in Kolkata
Kolkata Escorts Agency
Kolkata Escort
Call Girls in Kolkata
Russian Escorts in Kolkata

Priya Thakur said...

Chennai Escorts
Independent Escorts in Chennai
Chennai Escorts Service
Chennai Escorts Agency
Escorts in Chennai
Russian Escorts in Chennai
Call Girl in Chennai

Ankara Sharma said...

Chennai Escorts
Independent Escorts in Chennai
Chennai Escorts Service
Escorts in Chennai
Chennai Escorts Agency

friv 10 said...


gracias por la detallada información. Friv 2019 Gry Friv 2018 Juegos Friv 3 Gracias por compartir sus ideas con nosotros. Gry Friv 3 Jeux De Friv Gracias por vuestras reacciones a las transmisiones que os han hecho. Friv 2019 Juegos Friv 2019 Acogemos con agrado los comentarios de los lectores

Sweata Oberoi said...

Chennai Escorts
Independent Escorts in Chennai
Chennai Escorts Service
Call Girl in Chennai
Chennai Escorts Agency
Escorts in Chennai
Russian Escorts in Chennai

louis philip said...

Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
Texting API
Text message marketing
Digital Mobile Marketing
Sms API
Sms marketing

Priya Ghosh said...

Ahmedabad Escorts
Ahmedabad Escort
Independent Escorts in Ahmedabad
Escorts in Ahmedabad
Ahmedabad Escorts Service
Ahmedabad Escorts Agency
Ahmedabad Call Girls

Hiral Sharma said...

Riya Dubey offer high profile Independent Mumbai Escorts Girl at shameful rates. Hire hot & Sexy Independent Escorts in Mumbai for erotic fun.

http://www.taajmumbaiescorts.com/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://www.missdaina.com/">

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://garimachopra.com/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://www.hiralsharma.com/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://taajmumbaiescort.blogspot.in/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

http://riyadubey.co.in/

Mumbai Escorts

Mumbai Escort

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Independent Mumbai Escort

Escorts in Mumbai

Riya Pillai said...

Chennai Escorts
Chennai Escort
Independent Escorts in Chennai
Escorts in Chennai
Chennai Escorts Service
Chennai Escorts Agency
Chennai Call Girls
Coimbatore Escorts

Jesica Night said...

Welcome to escorts in Jaipur, in our escorts agency collection Indian, Russian and Punjabi model, age lime is 21 to 35. All girl is related to different - Jaipur Escort | Escort in jaipur

chandigarhcallgirls said...

Break out everyday elation of regular existence and natural jollity. Verify out some element radiant and out of the crate. Pick out a loose Independent Chandigarh escorts committed to supplying best sexual satisfaction, real man or girl care and ideal panacea in your each excitement and exceptional nature.
Chandigarh independent escorts
Independent escorts in Chandigarh
Chandigarh vip escort
Chandigarh female escorts
Chandigarh female escort
vip escorts in Chandigarh
female escorts in Chandigarh
Chandigarh Call Girls