package org.superemail.connector;
// other imports...
public interface EmailConsumer {
public void receiveEmail(Properties headers, String body);
}
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 {
}
}
ActivationSpec
, we'll cover that later.EmailConsumer
interface and configure the Connector'sEmailAccountInfo
JavaBean which is done via the activation-config
tag of the ejb-jar.xml or via @ActivationConfigProperty
annotations 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!
}
}
MessageListener
interface and an ActivationConfig
JavaBean, the MDB implements the interface and configures the JavaBean via the loosely-typed @ActivationConfigProperty
.- Metadata is loosely typed in the bean code
- Only class-level metadata is allowed, not method-level
- Requiring an interface can limit expressiveness
package org.superemail.connector;
@Target(TYPE)
@Retention(RUNTIME)
@javax.resource.annotation.ActivationSpec
public @interface EmailAccountInfo {
String address();
}
@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!
}
}
@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!
}
}
@MessageDriven
anymore. Instead we can do this:import javax.annotation.ManagedBean;
@ManagedBean
@EmailAccountInfo(address = "dblevins@apache.org")
public static class EmailBean {
// ....
}
@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
.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