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




425 comments:

«Oldest   ‹Older   401 – 425 of 425
anjli said...

Female Escorts in Agra
Escorts in Agra
Call Girls in Agra
Escorts Service in Agra
Hi Profile Call Girls in Agra
Russian Escorts in Agra
Russian Escorts in Gurgaon
Escorts Service in Gurgaon
Call Girls in Gurgaon
Russian Call Girls in Gurgaon
Escorts Near Sahara Mall 
Escorts Service in Gurgaon
Gurgaon Call Girls 
Housewife Escorts in Gurgaon 
Independent Escorts in Gurgaon 
Russian Call Girls in Gurgaon 
Russian Escorts in Gurgaon 
Punjabi escorts in Gurgaon

gowsalya said...

This is very good content you share on this blog. it's very informative and provide me future related information.
msbi online training

Unknown said...

Bangalore Elite Models are the ladies of flawless love, passionate desires and classy sensual pleasures. These girls are hot, stunning and extremely sexy. What people love is meeting exclusive girls so here what we have for you.
Bangalore Escorts
Escorts in Bangalore
Bangalore Escorts Services
Bangalore Escorts Agency
Bangalore Call Girls

Danny Escorts said...

It's an incredible chance to give up depleting and fuckin sexual positions and experience intercourse which will underneath your cerebrum. Our creative and energetic Bangalore Escorts Services will pass on you in a dozing issue of warmth. Their various strategies to serving their figure in different groupings are simply grand. Here are an immense number of different mating positions that accept an unimaginable activity truly coming to fruition of coupling dumbfounding. We give our organizations in different terms of closeness in different terms of charges and range.
So people get ready to experience astounding and unprecedented sex.

Bangalore Escorts
Bangalore Escort
Bangalore Escorts Services
Escorts in Bangalore
Escort in Bangalore
Call Girl in Bangalore
Bangalore Call Girl
Bangalore Escorts
Bangalore Escort
Bangalore Escorts Services
Escorts in Bangalore
Escort in Bangalore
Call Girl in Bangalore
Bangalore Call Girl

shwetakaur said...

Book Your Sexy Call Girl in Noida | Find Hot Girls online Booking Open at:- http://shwetakaur.in/ India's no.1 escort agency. Full Satisfied customers we have. check reviews.
call girls chittaranjan park

call girls crossings republik

call girls daryaganj

call girls dasna

call girls defence colony

call girls delhi cantt

Call Girls in Noida

call girls dhaula kuan

anjli said...

Escorts Service in Faridabad
Call Girls in Faridabad
Russian Escorts in Faridabad
Foreigner Escorts in Faridabad
Foreigner Call Girls in Faridabad
Russian Call Girls in Faridabad
Independent Escorts in Faridabad
Housewife Escorts in faridabad
Housewife Call Girls in faridabad
Hi Profile Escorts in Faridabad
Escorts in Surajkund
Call Girls in Surajkund
Escorts Service in Aerocity
Call Girls in Aerocity
Russian Call Girls in Aerocity
Foreigner Call Girls in Aerocity

shrutiescorts said...

saraswati vihar escorts ☺☺
shalimar bagh escorts ☺☺
gagan vihar escorts ☺☺
surajmal vihar escorts ☺☺
vaishali escorts ☺☺

Manaliescortvilla said...

We offer high class female independent escorts in Manali, the best Manali escorts agency at Neha Rajput are available 24/7. Sizzling girls for initiating romantic.
Manali Escorts
Manali Call Girls
Escorts In Manali
Call Girls In Manali

Manaliescortvilla said...

We offer high class female independent escorts in Manali, the best Manali escorts agency at Neha Rajput are available 24/7. Sizzling girls for initiating romantic.
Manali Escorts $
Manali Call Girls$
Escorts In Manali$
Call Girls In Manali $

Bangalore escorts said...

Independent escort in Bangalore
escort service in Bangalore
Female escort in Bangalore
Escort female in Bangalore
Escort girl in Bangalore
Call girl in Bangalore


https://www.callgirlsingurgaongirls.com/ said...

Gurgaon sexy call girls are here to serve that promise to you, there is no need to go anywhere to get beautiful girls, they are available here in Gurgaon and ready to entertain you get the best pleasure of life. If you are the type that has a lot of fantasy in sex and pleasure then these Gurgaon call girls are ready to give you that in any way that will please you. They can get wild in bed with you and can also make you feel much more alive than never before.

Call Girls in Gurgaon
Call Girls in Gurgaon
sikanderpur
sushant-lok
call-girls-in-gurgaon
call-girls-delhi
gurgaon-call-girls
blog
high-profile-call-girls-in-gurgaon
blog
sikanderpur-call-girls
call-girls-huda-city-center
college-call-girls-gurgaon
sexy-call-girl-gurgaon
call-center-girls-escort
iffco-chock-call-girls
sikandarpur-hiprofile-escorts
call-girls-sikanderpur-gurgaon
bus-stand-escorts-call-girls
call-girls-gurgaon
call-girls-mg-road
hudacity-centre-call-girls
high-profile-call-girls-in-gurgaon
escorts-service-in-gurgaon-with-sexy-call-girls
best-call-service-in-gurgaon
gurgaon-call-girls-service
russian-escorts-sikanderpu
best-call-girls-gurgaon

https://www.callgirlsingurgaongirls.com/ said...

STARRY AND SATISFYING NIGHTS WITH RISHIKESH ESCORTS

FLAWLESS BEAUTY WITH MOUTH WATERING BOOBS
Yes, we all want a flawless beauty and that’s precisely what we are giving you. You will get what you see. Mature beauties or a young woman with the right curves – you will get anything that you require. Everyone has specific needs when it comes to how the woman should look. All the women in our list are sexy in every way! They will make sure you have a fantastic time in garhwali area of Uttarakhand.

Of course she will Rock your bed, but she will also blow your mind with her impressive personality. We take special care of our client’s needs. With too many fake escort agencies in the market, we just want you to spend your money at the right place. We share genuine photos of the desirable women in our list. Showcasing fake photos off the Internet is certainly not our style.
Call us @ Phone Number :- +91 0000000000

Rishikesh call girls
call girls in haridwar
call girls in rishikesh
call girls in dehradun
call girls in gurgaon
call girls in agra
need help
call girls in dwarka
Call girls in Dwarka
services

For whatsup Number Open this website

https://www.callgirlsingurgaongirls.com/ said...

A warm welcome to our website ( http://callgirlsnoida.in ), we have top quality of girls with the full-on experience to provide call girls in Saket. We are supplying our beautiful call girls in Saket from the last Seven years, and we know how to serve with your emotions. Our escorts in Saket is ready to deliver the best service all the time with extra energy. We have a variety of variety in our Saket call girls, and Escorts in Saket will melt your heart. Our escorts are ready to remove all the stress from your daily routine life.


FIND ESCORTS IN DELHI, NCR, NOIDA
Escorts in noida
Call girls sector 51
Call girls Ghaziabad
Call girls Saket
Call girls Kirti nagar
call-girls-gurgaon/
call-girls-in-gurugram/
haridwar-escort-call-girl/#
call-girls-dehradun/
haridwar-escort-call-girl/
rishikesh-escort-call-girl/

SEARCH ESCORTS IN DELHI GHAZIABAD
Call girls Laxmi Nagar
Call girls Indirapuram
Call girls Nirman Vihar
Call girls Mayur Vihar

LOOKING FOR ESCORTS IN GURGAON
Escorts in Aerocity
Call girls in Gurgaon
Call girls Greater Noida

FIND SEX QUEENS IN RAJISTHAN
Call girls in Jaipur
Call girls in Bhilwara
Call girls in Ajmer
Call girls in Sri Ganganagar

VIP HIGH PROFILE GIRLS IN UTTRAKHAND
Call girls in Haridwar, Haridwar call girls, Call girls Haridwar
Call girls in Rishikesh, Call girls Rishikesh
How to sex with call girls

Manaliescortvilla said...

Hello Guys My Name Is Megha Sharma i am Gorgeous busty blonde or a slim tall statuesque brunette model, the great choice of Dwarka escorts and call girls to full fill all your desires and fantasies.
Dwarka Escorts
Dwarka Call Girls
Escorts In Dwarka
Call Girls In Dwarka

Aerocity escorts said...

Aerocity escorts
Independent escorts in Aerocity
escort in Aerocity
escorts service in Aerocity

Aerocity escorts said...

Aerocity escorts
Independent escorts in Aerocity
escort in Aerocity
escorts service in Aerocity

Kiruthiprabha said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging..
Oracle DBA Online Training

Jiya Verma said...

You may also impart your fantasies and cravings since I wish to produce companions before the end of the time. I truly like to present my sensual service people who fully disturb from existence. Jaipur escorts never assists of the types of men.
Jaipur escorts
Jaipur Call Girls
Ajmer escorts

Female Escorts in Delhi - 9990343797 said...

Russian Escorts in Gurgaon
Escorts Service in Gurgaon
Call Girls in Gurgaon
Russian Call Girls in Gurgaon
Foreigner Escorts in Gurgaon
Foreigner Call Girls in Gurgaon
Housewife Escorts in Gurgaon
Housewife Call Girls in Gurgaon
Hi Profile Escorts in Gurgaon
Hi Profile Call Girls in Gurgaon
Independent Escorts in Gurgaon
Independent Call Girls in Gurgaon
Escorts Service in Faridabad
Call Girls in Faridabad
Russian Escorts in Faridabad
Russian Call Girls in Faridabad
Foreigner Escorts in Faridabad
Foreigner Call Girls in Faridabad
Housewife Escorts in Faridabad
Housewife Call Girls in Faridabad
Hi Profile Escorts in Faridabad
Hi Profile Call Girls in Faridabad
Independent Escorts in Faridabad
Independent Call Girls in Faridabad


Unknown said...



Escorts Service in Delhi
Call Girls in Delhi
Russian Escorts in Delhi 
Russian Call Girls in Delhi
Foreigner Escorts in Delhi 
Foreigner Call Girls in Delhi 
Housewife Escorts in Delhi
Housewife Call Girls in Delhi
Hi Profile Escorts in Delhi
Hi Profile Call Girls in Delhi
Independent Escorts in Delhi
Independent Call Girls in Delhi
Escorts Service in Surajkund
Call Girls in Surajkund
Russian Escorts in Surajkund 
Russian Call Girls in Surajkund
Foreigner Escorts in Surajkund 
Foreigner Call Girls in Surajkund 
Housewife Escorts in Surajkund
Housewife Call Girls in Surajkund
Hi Profile Escorts in Surajkund
Hi Profile Call Girls in Surajkund
Independent Escorts in Surajkund
Independent Call Girls in Surajkund

riyaaggarwal said...

Noida call girls Service for 100% fully satisfaction. Our young n expert girls are available 24x7. call us on :-9873940964. visit my website:-
chanakyapuri escorts

connaught place escorts

defence colony escorts

dhaula kuan escorts

dwarka escorts

east of kailash escorts

greater kailash escorts

hauz khas escorts

janakpuri escorts

Unknown said...

Nehru Place Escorts Service | Independent Escort Nehru Place

independent escorts service dwarka||||||
independent escorts service hauz khas||||||
independent escorts service lajpat nagar ||||||
independent escorts service connaught place ||||||
independent escorts service saket||||||

sunitaahuja said...

Book Noida Escorts Service to fulfill all your secret desires with hot female Call Girls in Noida. Dial 9873940964 and book VIP Escorts in Noida Hotels.

call girls manesar ####
call girls mayur vihar ####
call girls meera bagh ####
call girls mehrauli ####
call girls mg road ####
call girls model town ####

Danny Escorts said...

Norton antivirus gives bolster against infections and spam. It shields and expels infections from your PC. Norton antivirus remains on a main position among best antivirus programming suppliers.Antivirus support
Antivirus support Number
Antivirus support Customer care
Norton Antivirus support
Norton Antivirus support Number
Norton Antivirus support Customer care
Mcafee Antivirus support
Mcafee Antivirus support
Mcafee Antivirus support
AVG Antivirus support
AVG Antivirus support Number
AVG Antivirus support Customer care
Avast Antivirus support
Avast Antivirus support Number
Avast Antivirus support Customer care

PUJA said...

Aerocity Escorts service
Russian Escorts in Hotels in Aerocity
Charges of Escorts in Aerocity
Escorts Job in Delhi
Russian Escorts in Aerocity
Call Girls Services in Aerocity
Female Escort in Aerocity
Foreigner Escorts in Aerocity
Housewife Escorts in Delhi
Russian Escorts in Mahipalpur
Russian Escorts in Paharganj, Delhi

«Oldest ‹Older   401 – 425 of 425   Newer› Newest»