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




224 comments:

«Oldest   ‹Older   201 – 224 of 224
ritikangt4u said...

Saket Call Girls | 9999965857 | Book Escorts in Saket at Hotels

saket escorts $$$$$$
mahipalpur escorts $$$$$$
nagar escorts $$$$$$
karol bagh escorts $$$$$$
dwarka escorts $$$$$$

ritikangt4u said...

Saket Call Girls | 9999965857 | Book Escorts in Saket at Hotels

mahipalpur escorts $$$$$$
saket escorts $$$$$$
nagar escorts $$$$$$

EscortsServiceLebanon said...

Would you like to book one of our ladies for a trade fair tour? No problem. Our ladies are professional and have very good manners. An overview of the fair dates in Lebanon this year and next year can be found here. Not far from the fair you will also find a variety of hotels and accommodation. An overview of hotels in Lebanon can be found on booking.com. Let yourself be accompanied by a charming lady, enjoy the day with her and then let it end in a romantic and pleasant atmosphere. You do not want to wake up alone in the morning? Then ask us about the possibilities of an overnight booking. We speak the availability of ladies and give you immediate feedback. We are always ready to fulfill all your wishes.
escort Lebanon, escort in Lebanon, escorts in Lebanon, escorts Lebanon, Lebanon escort, Lebanon escorts, escort Beirut, escort in Beirut, escorts Beirut, Beirut escort, Beirut escorts, Lebanon escort, escort in Lebanon, escort in Lebanon, escorts in Lebanon, escorts Lebanon, escort Beirut, escort in Beirut, escorts Beirut, Beirut escort, Beirut escorts

Unknown said...

Choose High Profile Call Girls in Delhi with Photos, Contact us at 9899900591, to book Top Model Escorts in Delhi. India's VIP Independent Delhi Escorts.

http://www.monarathi.in/ $$$$
http://www.monarathi.in/gallery.html $$$$
http://www.monarathi.in/services.html $$$$
http://www.monarathi.in/fees.html $$$$
http://www.monarathi.in/contactus.html $$$$
http://www.monarathi.in/escorts-service-aerocity.html $$$$
http://www.monarathi.in/escorts-service-chanakyapuri.html $$$$
http://www.monarathi.in/escorts-service-chandni-chowk.html $$$$
http://www.monarathi.in/escorts-service-chhatarpur.html $$$$
http://www.monarathi.in/escorts-service-connaught-place.html $$$$

bookyourgf said...

juhu escorts###
vakola escorts###
vile-parle escorts###
wadala escorts###
kalyan escorts###

reeyakapoor said...

russian call girls chennai $$$
independent chennai escorts $$$
tambaram escorts $$$
kolathur escorts $$$
guindy escorts $$$
ambattur escorts $$$

Lebanon Escort Services said...

Sensual massages are characterized as energizing massages, but at the same time enveloping. Clients who request a sensual Body to Body Massage escort Lebanon seek the best, and professional erotic masseuses are able to offer it to them. Why keep going to a conventional massage when you can go much further? Sensual massages will let your imagination run wild. Erotic massage will allow you to unlock all your emotions and get rid of their negative feelings, reaching a state of absolute peace, relaxation and tranquility. In addition, they will help you balance your mind and body, making you gain more confidence in yourself and increasing your self-esteem to levels that are not imaginary.
Letting yourself be carried away by the tactile sensations will make the sensuality increase in leaps and bounds and the sensibility will get to the surface with every movement made by the masseuse. Sensual massage can become the tool you need to achieve greater self-awareness of all corners of your body, eliminating all kinds of blockages and increasing the vital energy of your body.

escort Lebanon, escort in Lebanon, escorts in Lebanon, escorts Lebanon, Lebanon escort, Lebanon escorts, escort Beirut, escort in Beirut, escorts Beirut, Beirut escort, Beirut escorts, Lebanon escort, escort in Lebanon, escort in Lebanon, escorts in Lebanon, escorts Lebanon, escort Beirut, escort in Beirut, escorts Beirut, Beirut escort, Beirut escorts

Divya Dutta said...

We can assure our clients to receive the dependable, sophisticated and stunning escort service in Jaipur from our end. You will find escorts who understand this to look after the consumers and provide services gratifying.
Nainital Escorts service
Delhi Escorts
Jaipur Call Girls
Goa Escort
Jaipur Escorts
Goa Escorts
Dehradun Escorts
Nainital Escorts
Escorts in Jaipur
Ramnagar escorts

Divya Dutta said...

They well prepared to meet people and visit new places and find out the destination. The escorts in Goa are excellent in the subject of providing in personal services. In call providers want customers to come and meet the girl.
Nainital escorts
Escorts in Goa
Jaipur Call Girls
Jodhpur Escorts
Dehradun Escorts
Goa Escorts
Jaipur Escorts
Ramnagar Escorts
Dehradun Escorts

Kurtkoy said...

Enjoy your nights with hot and sizzling kurtkoylari model call girls in Bangalore.

http://www.kurtkoyescortlari.com/

Miss Kanishka said...

Mskanishka offers Independent Bangalore Escorts Services to elite clients at affordable rates. Call and fun with hot and sizzling Bangalore Escorts.
visit Bangalore Escorts
visit Bangalore Escorts Service
visit Independent Bangalore Escorts
visit Bangalore Call girls
visit Escorts Agency Bangalore

kumari komal said...

vasant kunj Escorts for Gathering, Private & Get-togethers. Our Premium, Excellent and High-Class vasant kunj escorts will satisfy your dreams. An organization that offers Outcall benefits in all vasant kunj zones. Additionally, we offer modest vasant kunj escorts . Book now

ashram escorts ##
sarita vihar escorts ##
new friends colony escorts ##
okhla escorts ##
katwaria sarai escorts ##
kalkaji escorts ##

Megha Patil said...

The Ultimate Hyderabad Escorts Service Provider with a large number of high-class profiles. Hire the real Independent Escorts in Hyderabad with us.
http://www.surveensaniya.com/hyderabad-escorts.html

Hyderabad Escorts Service

Hyderabad Escorts Agency

Independent Hyderabad Escorts

Hyderabad Escorts Girl

Hyderabad Female Escorts

Escorts in Hyderabad

Escorts Service in Hyderabad

Call Girl Service in Hyderabad

Call Girl Services in Hyderabad

http://www.meghnamathur.co.in/bangalore-escorts.html

Bangalore Escorts Service

Bangalore Escorts Agency

Independent Bangalore Escorts

Hyderabad Escorts

Hyderabad Escort

Hyderabad Escorts Service

Hyderabad Escorts Agency

Independent Raipur Escorts

http://www.meghapatil.com/

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Mumbai Escorts Girl

Mumbai Female Escorts

Escorts in Mumbai

Escorts Service in Mumbai

Call Girl Service in Mumbai

Call Girl Services in Mumbai

http://www.meghapatil.com/hyderabad-escorts.html

Hyderabad Escorts Service

Hyderabad Escorts Agency

Independent Hyderabad Escorts

Mumbai Escorts Service

Mumbai Escorts Agency

Independent Mumbai Escorts

Mumbai Escorts Girl

Mumbai Female Escorts

Escorts in Mumbai

Megha Patil said...

Call make your evening and night much colorful with our independent Hyderabad escorts girls because we always know they will satisfy you from top to bottom.

http://www.tinaoberoi.com/

Hyderabad Escorts Service

Hyderabad Escorts Agency

Independent Hyderabad Escorts

Hyderabad Escorts Girl

Escorts in Hyderabad

Escorts Service in Hyderabad

Call Girl Service in Hyderabad

Escorts Service in Bangalore

http://www.meghnamathur.co.in/

Hyderabad Escorts Service

Hyderabad Escorts Agency

Independent Hyderabad Escorts

Hyderabad Escorts Girl

Escorts in Hyderabad

Escorts Service in Hyderabad

Call Girl Service in Hyderabad

http://www.nidhiverma.co.in/

Hyderabad Escorts Service

Hyderabad Escorts Agency

Independent Hyderabad Escorts

Hyderabad Escorts Girl

Escorts in Hyderabad

Escorts Service in Hyderabad

Call Girl Services in Hyderabad

http://www.monikabansal.co.in/

Hyderabad Escorts Service

Hyderabad Escorts Agency

Independent Hyderabad Escorts

Hyderabad Escorts Girl

Escorts in Hyderabad

Escorts Service in Hyderabad

Call Girl Service in Hyderabad

Call Girl Services in Hyderabad

Call Girl Services in Hyderabad

Bangalore Call Girl

Hyderabad Escorts Girl

Hyderabad Female Escorts

Escorts in Hyderabad

Escorts Service in Hyderabad

Call Girl Service in Hyderabad

http://www.surveensaniya.com/

Kurtkoy said...

the provider of bangalore escorts girls in afford cheap rate in kurtkoyescotlari.
to collection of high profile and sexy girls.
Bangalore escorts

modelsvila said...

Delhi Escorts Service available for bookings 9711199171 , Fulfill your sexual dream with Independent Call Girls Delhi, You can Hire Models vila Call Girls in Delhi for hotels and beaches. Fulfill your wish and find Independent Call Girls in Delhi.

escorts in pragati vihar $$$
call girls in safdarjung $$$
shakti nagar escorts $$$
call girls subzi mandi $$$
wazir nagar escorts $$$
call girls chand nagar $$$
call girls aerocity $$$

hot-escorts said...

Thanks for posting nice article. Kajal Sexena Offering teen and naughty Independent Escorts Girl in Bangalore.
visit Bangalore Escort
visit Escorts in Bangalore
visit Independent Bangalore Escorts
visit Bangalore Escort service
visit Female Bangalore Escorts
visit Independent Bangalore Escort girls

Independent Bangalore escorts said...

Fantastic and Modern High profile Bangalore escorts are available at cheap price 24*7. You can find your sizzling partners according to your choice. Just make a call at - 7022789089.
Bangalore escorts services
Independent Bangalore escorts
Bangalore escorts agency
female Bangalore escorts
Bangalore Call girls
Call girls in Bangalore
Escorts agency in Bangalore

Escortgirl elite said...

Bangalore escorts are the independent young call girls who like fun more than Money. They like's to invest energy with customer instead of having intercourse. Call now-8123770473.
vipcanadaescorts.com

sathyaramesh said...

Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
SEO Training in Chennai
JAVA Training in Chennai
Big Data Training in Chennai
Selenium Training in Chennai
German Classes in chennai
PHP Training in Chennai
PHP Training in Anna Nagar

ghaziabadqueen said...

Ghaziabad Call Girls are the finest choice for High Class Services. book our Russian Call girls 24*7. Call 9873940964 for Hire Independent Escort Girl for fun.


indirapuram escorts $$$
vaishali escorts $$$
ramprastha escorts $$$
shalimar garden escorts $$$
krishna vihar escorts $$$
pratap vihar escorts $$$

ansha khan said...

Bangalore Escorts,Dating Sexy FemaleI have energy for everything, which means the man in the way is going to keep up with me after a while.

Bangalore escorts

prestige packer said...

Prestige packers and movers are best packers and movers in Thane. Shuffling from one place to another is easy and manageable with the help of expert packers and movers in Thane, and it is beneficial to save significant cost on making arrangements solely. Hiring a certified and reputed shifting contractor will return real value for your investment. https://www.prestigepackersandmover.co.in/packers-movers-in-thane/

ankit polyweave said...

Ankitech brand hospital furniture have rich looks, inventive plans and utility, aside from normal hospital furniture straight forwardly identified with patients and human services suppliers. We do manufacture and supply all type of best hospital furniture like hospital beds, medical furniture, ICU Bed, Fowler bed, semi Fowler bed. https://ankitech.in/hospital-furniture/

«Oldest ‹Older   201 – 224 of 224   Newer› Newest»