SlideShare a Scribd company logo
1 of 46
Download to read offline
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Java EE Connectors
The Secret Weapon Reloaded
Jonathan Gallimore
Tomitribe
David Blevins
Tomitribe
.JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Inbound Connectors
(aka MDBs)
.JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Dispelling Myths
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Which Statements are Always True?
• MDBs are for JMS
• MDBs must be asynchronous
• A MessageListener interface has one method which returns ‘void’
• MDBs are pooled
• MDBs are stateless
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
The Truth
• MDBs are actually “Connector Driven Beans”
• MDBs are not asynchronous or synchronous
• Connectors are asynchronous or synchronous
• A MessageListener interface may:
• have any number of methods
• have any return type
• MDBs are not pooled, stateful or stateless
• The Connector has that choice
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
The Promise
• Infinite Extensibility
• Push CommunicaLon
• To any server
• From anywhere
• Support any protocol
• OpLonal transacLon guarantees
.JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Did it deliver?
.JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Technically, yes
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
What Spoiled It?
• JMS legacy confused and misleading
• Pigeonholed thinking
• SpecificaLon too large
• Outbound Connectors are very complex
• No strong second use-case
• Crippled configuraLon
• EffecLvely a typeless map
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
JMS MDB in Java EE 7
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
User manual required…
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Loosely typed
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Poor targeNng
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
StaNc interface
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
So 2004....
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Learning from JAX-RS
• No interfaces
• Fluid method signatures
• AnnotaLon-based configuraLon
• Strongly Typed
• Self-documenLng
• Targeted
• Class-level
• Method-level
• Parameter-level
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
2 Simple Changes
• Give Connector the full Bean Class
• Hello, AnnotaLons!
• Modern Expressive API design
• Allow Connector to invoke Any Bean Method
• Bean Developer gains full freedom
• APIs people would actually use and enjoy
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Oh yeah.
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Beyond JMS
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Tutorial
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
WriNng an Inbound Connector
• ResourceAdapter
• MessageListener API
• AcLvaLonSpec
• ra.xml
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
CreaNng the resource adapter
• Implement javax.resource.spi.ResourceAdapter
• provide metadata with @Connector
• Implement start() and stop() methods
• perform the connector’s logic (sockets, threads, etc)
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
CreaNng the resource adapter
@Connector(description = "Twitter Resource Adapter",
displayName = "Twitter Resource Adapter",
eisType = "Twitter Resource Adapter", version = "1.0")

public class TwitterResourceAdapter implements ResourceAdapter, StatusChangeListener {



private TwitterStreamingClient client;



public void start(final BootstrapContext bootstrapContext)
throws ResourceAdapterInternalException {

client = new TwitterStreamingClient(this, consumerKey, consumerSecret,
accessToken, accessTokenSecret);

try {

client.run();

} catch (InterruptedException | ControlStreamException | IOException e) {

// TODO: custom error handling
}

}



public void stop() {

client.stop();

}
}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Configuring the resource adapter
• ConfiguraLon can be provided using fields on the
ResourceAdapter implementaLon
• Values can be provided in ra.xml, or through app server specific
configuraLon mechanisms
• TomEE uses system properLes
• e.g. twi]er-connector-rar-0.1RA.consumerKey = <consumer key>
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Configuring the resource adapter
@Connector(description = "Twitter Resource Adapter",
displayName = "Twitter Resource Adapter",
eisType = "Twitter Resource Adapter", version = "1.0")

public class TwitterResourceAdapter implements ResourceAdapter, StatusChangeListener {

@ConfigProperty

@NotNull

private String consumerKey;



@ConfigProperty

@NotNull

private String consumerSecret;
}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Registering the MDB
• ResourceAdapter.endpointAcLvaLon(), store
• AcLvaLonSpec
• MessageEndpoint
• bean class
• ResourceAdapter. endpointDeacLvaLon() , remove
• AcLvaLonSpec
• MessageEndpoint.release()
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Registering the MDB
public void endpointActivation(final MessageEndpointFactory messageEndpointFactory,
final ActivationSpec activationSpec) throws ResourceException {

final TwitterActivationSpec twitterActivationSpec = (TwitterActivationSpec)
activationSpec;

final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null);



final Class<?> endpointClass = twitterActivationSpec.getBeanClass() != null ?
twitterActivationSpec

.getBeanClass() : messageEndpointFactory.getEndpointClass();



final EndpointTarget target = new EndpointTarget(messageEndpoint, endpointClass);

targets.put(twitterActivationSpec, target);

}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Invoking the MDB
• Can be done at any Lme in the connector
• Call Method.invoke() with the MessageEndpoint as the object
reference
• Wrap with messageEndpoint.beforeDelivery() and
messageEndpoint.aeerDelivery()
public void invokeEndpoints() {

try {

messageEndpoint.beforeDelivery(method);

final Object[] values = … // values to pass in as parameters

method.invoke(messageEndpoint, values);

} finally {

messageEndpoint.afterDelivery();

}
}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Packaging the connector
• Typically delivered in a .rar file
• Installed in the container
• Or part of an EAR file
• Package connector API files separately from the implementaLon
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Sounds like a lot…
• Help is here!
• Connector starter projects
• h]ps://github.com/tomitribe/connector-starter-project
• h]ps://github.com/tomitribe/connector-starter-project-with-security
• h]ps://github.com/tomitribe/connector-starter-project-inbound
• h]ps://github.com/tomitribe/connector-starter-project-outbound
• Examples
• h]ps://tomitribe.io/projects/cha]erbox
• h]ps://tomitribe.io/projects/sheldon
.JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Sample Connectors
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Example: IMAP & Twi[er
• Inbound connector with threads to carry out the actual work
• Uses reflecLon with annotaLons to filter messages for different
methods on the MDB
• Note - no @AcLvaLonConfig
• Strongly typed method parameters
• JAX-RS style parameters (modelled on @Path / @PathParam)
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Advanced Inbound
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
WorkManager
• Connectors provide a WorkManager
• Manages a configurable number of threads
• Submijng work can be blocking or non-blocking
• Work object is essenLally like a Runnable
@Connector(description = “My Connector")

public class MyResourceAdapter implements ResourceAdapter {



public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {

workManager = bootstrapContext.getWorkManager();

}

public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {

workManager.scheduleWork(new Work() {



@Override

public void run() {
// TODO: do some work here

}

});

}
}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Security
• Invoke a MDB in the context of an authenLcated user
• Create a class that extends SecurityContext
public class WorkSecurityContext extends SecurityContext {



@Override

public void setupSecurityContext(final CallbackHandler handler,
final Subject executionSubject, final Subject serviceSubject) {


List<Callback> callbacks = new ArrayList<Callback>();



final PasswordValidationCallback pvc = new PasswordValidationCallback(executionSubject, username,
password.toCharArray());


callbacks.add(pvc);



Callback callbackArray[] = new Callback[callbacks.size()];

try {

handler.handle(callbacks.toArray(callbackArray));

} catch (UnsupportedCallbackException e) {

// handle this
}



this.authenticated = pvc.getResult();

}

}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Security conNnued
• Add custom SecurityContext to Work Object
• The server will process the callbacks and run the work as the
required principal
public class AuthenticateWork implements Work, WorkContextProvider {



private final WorkSecurityContext securityContext = new WorkSecurityContext();



@Override

public void run() {

// do work here

}



@Override

public List<WorkContext> getWorkContexts() {

return Collections.singletonList((WorkContext) securityContext);

}

}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Example: Sheldon
• Inbound connector
• Demonstrates security and work
• SSH session uses CREST to call @Commands on MDBs
• Easy to add commands
@MessageDriven(name = "Echo")

public class UserBean implements CommandListener {



@Command

public String echo(final String input) {

return input;

}

}
.JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Outbound Connectors
(harder)
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
CreaNng an Outbound connector
• API
• ConnecLonFactory
• ConnecLon
• ImplementaLon
• ManagedConnecLonFactory
• ConnecLonFactoryImpl
• ManagedConnecLon
• ConnecLonImpl
• Complex, but mostly boilerplate for simple cases
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
ConnecNonFactory
• ApplicaLon component interacts with the ConnecLonFactory and ConnecLon
• ManagedConnecLonFactory and ManagedConnecLon hide complexiLes from
the applicaLon
public class XMPPManagedConnectionFactory implements ManagedConnectionFactory, ResourceAdapterAssociation {



public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException {

return new XMPPConnectionFactoryImpl(this, cxManager);

}



public Object createConnectionFactory() throws ResourceException {

throw new ResourceException("This resource adapter doesn't support non-managed environments");

}



public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {

return new XMPPManagedConnection(this);

}



public ManagedConnection matchManagedConnections(Set connectionSet,

Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {

ManagedConnection result = null;

Iterator it = connectionSet.iterator();

while (result == null && it.hasNext()) {

ManagedConnection mc = (ManagedConnection) it.next();

if (mc instanceof XMPPManagedConnection) {

result = mc;

}



}

return result;

}
}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
ConnecNonFactory conNnued
• ConnecLon factory calls the ConnecLonManager to obtain a connecLon from
the ManagedConnecLonFactory
public class XMPPConnectionFactoryImpl implements XMPPConnectionFactory {

private static final long serialVersionUID = 1L;



private Reference reference;

private XMPPManagedConnectionFactory mcf;

private ConnectionManager connectionManager;



public XMPPConnectionFactoryImpl(XMPPManagedConnectionFactory mcf, ConnectionManager cxManager) {

this.mcf = mcf;

this.connectionManager = cxManager;

}



@Override

public XMPPConnection getConnection() throws ResourceException {

log.finest("getConnection()");

return (XMPPConnection) connectionManager.allocateConnection(mcf, null);

}
}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
ConnecNon
• ManagedConnecLonFactory creates ManagedConnecLon objects
• Add methods to the connecLon implementaLon to call the external
service
public class XMPPManagedConnection implements ManagedConnection {



private XMPPManagedConnectionFactory mcf;

private List<ConnectionEventListener> listeners;

private XMPPConnectionImpl connection;



public XMPPManagedConnection(XMPPManagedConnectionFactory mcf) {

this.mcf = mcf;

this.logwriter = null;

this.listeners = Collections.synchronizedList(new ArrayList<ConnectionEventListener>(1));

this.connection = null;

}



public Object getConnection(Subject subject,

ConnectionRequestInfo cxRequestInfo) throws ResourceException {

log.finest("getConnection()");

connection = new XMPPConnectionImpl(this, mcf);

return connection;

}
public void sendMessage(String recipient, String message) throws MessageException {

log.finest("sendMessage()");



final XMPPResourceAdapter resourceAdapter = (XMPPResourceAdapter) mcf.getResourceAdapter();

resourceAdapter.sendXMPPMessage(recipient, message);

}
}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Using a connecNon
• Use @Resource to inject the connecLon factory into a managed
component
• Obtain a connecLon from the connecLon factory and use it
• Do not forget to close the connecLon when you have finished
@MessageDriven(name = "Chat")

public class ChatBean implements XMPPMessageListener {



@Resource

private XMPPConnectionFactory cf;



@MessageText("echo {message:.*$}")

public void echo(@SenderParam final String sender, @MessageTextParam("message") final String message)
throws Exception {

final XMPPConnection connection = cf.getConnection();

connection.sendMessage(sender, message);

connection.close();

}
}
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Example: XMPP
• Bi-direcLonal connector
• Incoming messages call MDBs
• ApplicaLon components can use the ConnecLonFactory to send
messages
• MDB uses the ConnecLonFactory to create an “interacLve bot”
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Want more?
• Examples
• h]ps://tomitribe.io/projects/cha]erbox
• h]ps://github.com/tomitribe/connector-starter-project
• Standardized Extension-Building in Java EE with CDI and JCA
[CON2385], Jason Porter, Oct 28th, 4.30pm, Parc 55 Mission
JavaOne
@jongallimore @dblevins @tomitribe#Connectors
Thank You!
Jonathan Gallimore
Tomitribe
David Blevins
Tomitribe

More Related Content

What's hot

比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesomeAndrew Hull
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play FrameworkKnoldus Inc.
 
Top 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaTop 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaEdureka!
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScriptLilia Sfaxi
 
React in Native Apps - Meetup React - 20150409
React in Native Apps - Meetup React - 20150409React in Native Apps - Meetup React - 20150409
React in Native Apps - Meetup React - 20150409Minko3D
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database ConnectivityRanjan Kumar
 
Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Hsuan Fu Lien
 
React for Dummies
React for DummiesReact for Dummies
React for DummiesMitch Chen
 
Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring Sunil kumar Mohanty
 
Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)njbartlett
 
Large-Scale JavaScript Development
Large-Scale JavaScript DevelopmentLarge-Scale JavaScript Development
Large-Scale JavaScript DevelopmentAddy Osmani
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOCCarl Lu
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developersYakov Fain
 

What's hot (20)

Angular beans
Angular beansAngular beans
Angular beans
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
Doc abap
Doc abapDoc abap
Doc abap
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
 
COScheduler
COSchedulerCOScheduler
COScheduler
 
Top 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaTop 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | Edureka
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
React in Native Apps - Meetup React - 20150409
React in Native Apps - Meetup React - 20150409React in Native Apps - Meetup React - 20150409
React in Native Apps - Meetup React - 20150409
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
 
Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring
 
Angular 2 introduction
Angular 2 introductionAngular 2 introduction
Angular 2 introduction
 
Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)Introduction to OSGi (Tokyo JUG)
Introduction to OSGi (Tokyo JUG)
 
Large-Scale JavaScript Development
Large-Scale JavaScript DevelopmentLarge-Scale JavaScript Development
Large-Scale JavaScript Development
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOC
 
Java EE 6 & Spring: A Lover's Quarrel
Java EE 6 & Spring: A Lover's QuarrelJava EE 6 & Spring: A Lover's Quarrel
Java EE 6 & Spring: A Lover's Quarrel
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 

Viewers also liked

عرض تقديمي
عرض تقديميعرض تقديمي
عرض تقديميcoach2010
 
Beslenme bozukluklari
Beslenme bozukluklariBeslenme bozukluklari
Beslenme bozukluklariNevzat Bilgin
 
خاص عشان الموقع
خاص عشان الموقعخاص عشان الموقع
خاص عشان الموقعcoach2010
 
عرض سيد للمقدمة المصورة
عرض سيد للمقدمة المصورةعرض سيد للمقدمة المصورة
عرض سيد للمقدمة المصورةcoach2010
 
مكونات جسم الانسان
مكونات جسم الانسانمكونات جسم الانسان
مكونات جسم الانسانcoach2010
 

Viewers also liked (7)

NAMERA
NAMERANAMERA
NAMERA
 
عرض تقديمي
عرض تقديميعرض تقديمي
عرض تقديمي
 
Beslenme bozukluklari
Beslenme bozukluklariBeslenme bozukluklari
Beslenme bozukluklari
 
REVOLUCIJA
REVOLUCIJAREVOLUCIJA
REVOLUCIJA
 
خاص عشان الموقع
خاص عشان الموقعخاص عشان الموقع
خاص عشان الموقع
 
عرض سيد للمقدمة المصورة
عرض سيد للمقدمة المصورةعرض سيد للمقدمة المصورة
عرض سيد للمقدمة المصورة
 
مكونات جسم الانسان
مكونات جسم الانسانمكونات جسم الانسان
مكونات جسم الانسان
 

Similar to 2015 JavaOne Java EE Connectors - The Secret Weapon Reloaded

MicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java PlatformMicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java PlatformMike Croft
 
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineDroidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineJavier de Pedro López
 
Java EE changes design pattern implementation: JavaDays Kiev 2015
Java EE changes design pattern implementation: JavaDays Kiev 2015Java EE changes design pattern implementation: JavaDays Kiev 2015
Java EE changes design pattern implementation: JavaDays Kiev 2015Alex Theedom
 
Devoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementationDevoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementationAlex Theedom
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)David Coulter
 
Cleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsCleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsDebora Gomez Bertoli
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptTJ Stalcup
 
Java APIs - the missing manual
Java APIs - the missing manualJava APIs - the missing manual
Java APIs - the missing manualHendrik Ebbers
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EEAlexis Hassler
 
Java days Lviv 2015
Java days Lviv 2015Java days Lviv 2015
Java days Lviv 2015Alex Theedom
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileKonstantin Loginov
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Deliverymasoodjan
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)Thinkful
 
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?Paco van Beckhoven
 
JUDCON India 2014 Java EE 7 talk
JUDCON India 2014 Java EE 7 talkJUDCON India 2014 Java EE 7 talk
JUDCON India 2014 Java EE 7 talkVijay Nair
 
BPM-3 Advanced Workflow Deep Dive
BPM-3 Advanced Workflow Deep DiveBPM-3 Advanced Workflow Deep Dive
BPM-3 Advanced Workflow Deep DiveAlfresco Software
 
Re-architecting the designer-developer workflow
Re-architecting the designer-developer workflowRe-architecting the designer-developer workflow
Re-architecting the designer-developer workflowRichard Lord
 

Similar to 2015 JavaOne Java EE Connectors - The Secret Weapon Reloaded (20)

MicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java PlatformMicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
 
Droidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offlineDroidcon ES '16 - How to fail going offline
Droidcon ES '16 - How to fail going offline
 
Java EE changes design pattern implementation: JavaDays Kiev 2015
Java EE changes design pattern implementation: JavaDays Kiev 2015Java EE changes design pattern implementation: JavaDays Kiev 2015
Java EE changes design pattern implementation: JavaDays Kiev 2015
 
Devoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementationDevoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementation
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
Linq
LinqLinq
Linq
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)
 
Cleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsCleaning your architecture with android architecture components
Cleaning your architecture with android architecture components
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
 
Java APIs - the missing manual
Java APIs - the missing manualJava APIs - the missing manual
Java APIs - the missing manual
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
 
Java days Lviv 2015
Java days Lviv 2015Java days Lviv 2015
Java days Lviv 2015
 
Mobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve MobileMobile Developers Talks: Delve Mobile
Mobile Developers Talks: Delve Mobile
 
WOdka
WOdkaWOdka
WOdka
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Delivery
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
 
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
 
JUDCON India 2014 Java EE 7 talk
JUDCON India 2014 Java EE 7 talkJUDCON India 2014 Java EE 7 talk
JUDCON India 2014 Java EE 7 talk
 
BPM-3 Advanced Workflow Deep Dive
BPM-3 Advanced Workflow Deep DiveBPM-3 Advanced Workflow Deep Dive
BPM-3 Advanced Workflow Deep Dive
 
Re-architecting the designer-developer workflow
Re-architecting the designer-developer workflowRe-architecting the designer-developer workflow
Re-architecting the designer-developer workflow
 

Recently uploaded

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Recently uploaded (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

2015 JavaOne Java EE Connectors - The Secret Weapon Reloaded

  • 1. JavaOne @jongallimore @dblevins @tomitribe#Connectors Java EE Connectors The Secret Weapon Reloaded Jonathan Gallimore Tomitribe David Blevins Tomitribe
  • 4. JavaOne @jongallimore @dblevins @tomitribe#Connectors Which Statements are Always True? • MDBs are for JMS • MDBs must be asynchronous • A MessageListener interface has one method which returns ‘void’ • MDBs are pooled • MDBs are stateless
  • 5. JavaOne @jongallimore @dblevins @tomitribe#Connectors The Truth • MDBs are actually “Connector Driven Beans” • MDBs are not asynchronous or synchronous • Connectors are asynchronous or synchronous • A MessageListener interface may: • have any number of methods • have any return type • MDBs are not pooled, stateful or stateless • The Connector has that choice
  • 6. JavaOne @jongallimore @dblevins @tomitribe#Connectors The Promise • Infinite Extensibility • Push CommunicaLon • To any server • From anywhere • Support any protocol • OpLonal transacLon guarantees
  • 9. JavaOne @jongallimore @dblevins @tomitribe#Connectors What Spoiled It? • JMS legacy confused and misleading • Pigeonholed thinking • SpecificaLon too large • Outbound Connectors are very complex • No strong second use-case • Crippled configuraLon • EffecLvely a typeless map
  • 16. JavaOne @jongallimore @dblevins @tomitribe#Connectors Learning from JAX-RS • No interfaces • Fluid method signatures • AnnotaLon-based configuraLon • Strongly Typed • Self-documenLng • Targeted • Class-level • Method-level • Parameter-level
  • 17. JavaOne @jongallimore @dblevins @tomitribe#Connectors 2 Simple Changes • Give Connector the full Bean Class • Hello, AnnotaLons! • Modern Expressive API design • Allow Connector to invoke Any Bean Method • Bean Developer gains full freedom • APIs people would actually use and enjoy
  • 21. JavaOne @jongallimore @dblevins @tomitribe#Connectors WriNng an Inbound Connector • ResourceAdapter • MessageListener API • AcLvaLonSpec • ra.xml
  • 22. JavaOne @jongallimore @dblevins @tomitribe#Connectors CreaNng the resource adapter • Implement javax.resource.spi.ResourceAdapter • provide metadata with @Connector • Implement start() and stop() methods • perform the connector’s logic (sockets, threads, etc)
  • 23. JavaOne @jongallimore @dblevins @tomitribe#Connectors CreaNng the resource adapter @Connector(description = "Twitter Resource Adapter", displayName = "Twitter Resource Adapter", eisType = "Twitter Resource Adapter", version = "1.0")
 public class TwitterResourceAdapter implements ResourceAdapter, StatusChangeListener {
 
 private TwitterStreamingClient client;
 
 public void start(final BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
 client = new TwitterStreamingClient(this, consumerKey, consumerSecret, accessToken, accessTokenSecret);
 try {
 client.run();
 } catch (InterruptedException | ControlStreamException | IOException e) {
 // TODO: custom error handling }
 }
 
 public void stop() {
 client.stop();
 } }
  • 24. JavaOne @jongallimore @dblevins @tomitribe#Connectors Configuring the resource adapter • ConfiguraLon can be provided using fields on the ResourceAdapter implementaLon • Values can be provided in ra.xml, or through app server specific configuraLon mechanisms • TomEE uses system properLes • e.g. twi]er-connector-rar-0.1RA.consumerKey = <consumer key>
  • 25. JavaOne @jongallimore @dblevins @tomitribe#Connectors Configuring the resource adapter @Connector(description = "Twitter Resource Adapter", displayName = "Twitter Resource Adapter", eisType = "Twitter Resource Adapter", version = "1.0")
 public class TwitterResourceAdapter implements ResourceAdapter, StatusChangeListener {
 @ConfigProperty
 @NotNull
 private String consumerKey;
 
 @ConfigProperty
 @NotNull
 private String consumerSecret; }
  • 26. JavaOne @jongallimore @dblevins @tomitribe#Connectors Registering the MDB • ResourceAdapter.endpointAcLvaLon(), store • AcLvaLonSpec • MessageEndpoint • bean class • ResourceAdapter. endpointDeacLvaLon() , remove • AcLvaLonSpec • MessageEndpoint.release()
  • 27. JavaOne @jongallimore @dblevins @tomitribe#Connectors Registering the MDB public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
 final TwitterActivationSpec twitterActivationSpec = (TwitterActivationSpec) activationSpec;
 final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null);
 
 final Class<?> endpointClass = twitterActivationSpec.getBeanClass() != null ? twitterActivationSpec
 .getBeanClass() : messageEndpointFactory.getEndpointClass();
 
 final EndpointTarget target = new EndpointTarget(messageEndpoint, endpointClass);
 targets.put(twitterActivationSpec, target);
 }
  • 28. JavaOne @jongallimore @dblevins @tomitribe#Connectors Invoking the MDB • Can be done at any Lme in the connector • Call Method.invoke() with the MessageEndpoint as the object reference • Wrap with messageEndpoint.beforeDelivery() and messageEndpoint.aeerDelivery() public void invokeEndpoints() {
 try {
 messageEndpoint.beforeDelivery(method);
 final Object[] values = … // values to pass in as parameters
 method.invoke(messageEndpoint, values);
 } finally {
 messageEndpoint.afterDelivery();
 } }
  • 29. JavaOne @jongallimore @dblevins @tomitribe#Connectors Packaging the connector • Typically delivered in a .rar file • Installed in the container • Or part of an EAR file • Package connector API files separately from the implementaLon
  • 30. JavaOne @jongallimore @dblevins @tomitribe#Connectors Sounds like a lot… • Help is here! • Connector starter projects • h]ps://github.com/tomitribe/connector-starter-project • h]ps://github.com/tomitribe/connector-starter-project-with-security • h]ps://github.com/tomitribe/connector-starter-project-inbound • h]ps://github.com/tomitribe/connector-starter-project-outbound • Examples • h]ps://tomitribe.io/projects/cha]erbox • h]ps://tomitribe.io/projects/sheldon
  • 32. JavaOne @jongallimore @dblevins @tomitribe#Connectors Example: IMAP & Twi[er • Inbound connector with threads to carry out the actual work • Uses reflecLon with annotaLons to filter messages for different methods on the MDB • Note - no @AcLvaLonConfig • Strongly typed method parameters • JAX-RS style parameters (modelled on @Path / @PathParam)
  • 34. JavaOne @jongallimore @dblevins @tomitribe#Connectors WorkManager • Connectors provide a WorkManager • Manages a configurable number of threads • Submijng work can be blocking or non-blocking • Work object is essenLally like a Runnable @Connector(description = “My Connector")
 public class MyResourceAdapter implements ResourceAdapter {
 
 public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
 workManager = bootstrapContext.getWorkManager();
 }
 public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
 workManager.scheduleWork(new Work() {
 
 @Override
 public void run() { // TODO: do some work here
 }
 });
 } }
  • 35. JavaOne @jongallimore @dblevins @tomitribe#Connectors Security • Invoke a MDB in the context of an authenLcated user • Create a class that extends SecurityContext public class WorkSecurityContext extends SecurityContext {
 
 @Override
 public void setupSecurityContext(final CallbackHandler handler, final Subject executionSubject, final Subject serviceSubject) { 
 List<Callback> callbacks = new ArrayList<Callback>();
 
 final PasswordValidationCallback pvc = new PasswordValidationCallback(executionSubject, username, password.toCharArray()); 
 callbacks.add(pvc);
 
 Callback callbackArray[] = new Callback[callbacks.size()];
 try {
 handler.handle(callbacks.toArray(callbackArray));
 } catch (UnsupportedCallbackException e) {
 // handle this }
 
 this.authenticated = pvc.getResult();
 }
 }
  • 36. JavaOne @jongallimore @dblevins @tomitribe#Connectors Security conNnued • Add custom SecurityContext to Work Object • The server will process the callbacks and run the work as the required principal public class AuthenticateWork implements Work, WorkContextProvider {
 
 private final WorkSecurityContext securityContext = new WorkSecurityContext();
 
 @Override
 public void run() {
 // do work here
 }
 
 @Override
 public List<WorkContext> getWorkContexts() {
 return Collections.singletonList((WorkContext) securityContext);
 }
 }
  • 37. JavaOne @jongallimore @dblevins @tomitribe#Connectors Example: Sheldon • Inbound connector • Demonstrates security and work • SSH session uses CREST to call @Commands on MDBs • Easy to add commands @MessageDriven(name = "Echo")
 public class UserBean implements CommandListener {
 
 @Command
 public String echo(final String input) {
 return input;
 }
 }
  • 39. JavaOne @jongallimore @dblevins @tomitribe#Connectors CreaNng an Outbound connector • API • ConnecLonFactory • ConnecLon • ImplementaLon • ManagedConnecLonFactory • ConnecLonFactoryImpl • ManagedConnecLon • ConnecLonImpl • Complex, but mostly boilerplate for simple cases
  • 40. JavaOne @jongallimore @dblevins @tomitribe#Connectors ConnecNonFactory • ApplicaLon component interacts with the ConnecLonFactory and ConnecLon • ManagedConnecLonFactory and ManagedConnecLon hide complexiLes from the applicaLon public class XMPPManagedConnectionFactory implements ManagedConnectionFactory, ResourceAdapterAssociation {
 
 public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException {
 return new XMPPConnectionFactoryImpl(this, cxManager);
 }
 
 public Object createConnectionFactory() throws ResourceException {
 throw new ResourceException("This resource adapter doesn't support non-managed environments");
 }
 
 public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
 return new XMPPManagedConnection(this);
 }
 
 public ManagedConnection matchManagedConnections(Set connectionSet,
 Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
 ManagedConnection result = null;
 Iterator it = connectionSet.iterator();
 while (result == null && it.hasNext()) {
 ManagedConnection mc = (ManagedConnection) it.next();
 if (mc instanceof XMPPManagedConnection) {
 result = mc;
 }
 
 }
 return result;
 } }
  • 41. JavaOne @jongallimore @dblevins @tomitribe#Connectors ConnecNonFactory conNnued • ConnecLon factory calls the ConnecLonManager to obtain a connecLon from the ManagedConnecLonFactory public class XMPPConnectionFactoryImpl implements XMPPConnectionFactory {
 private static final long serialVersionUID = 1L;
 
 private Reference reference;
 private XMPPManagedConnectionFactory mcf;
 private ConnectionManager connectionManager;
 
 public XMPPConnectionFactoryImpl(XMPPManagedConnectionFactory mcf, ConnectionManager cxManager) {
 this.mcf = mcf;
 this.connectionManager = cxManager;
 }
 
 @Override
 public XMPPConnection getConnection() throws ResourceException {
 log.finest("getConnection()");
 return (XMPPConnection) connectionManager.allocateConnection(mcf, null);
 } }
  • 42. JavaOne @jongallimore @dblevins @tomitribe#Connectors ConnecNon • ManagedConnecLonFactory creates ManagedConnecLon objects • Add methods to the connecLon implementaLon to call the external service public class XMPPManagedConnection implements ManagedConnection {
 
 private XMPPManagedConnectionFactory mcf;
 private List<ConnectionEventListener> listeners;
 private XMPPConnectionImpl connection;
 
 public XMPPManagedConnection(XMPPManagedConnectionFactory mcf) {
 this.mcf = mcf;
 this.logwriter = null;
 this.listeners = Collections.synchronizedList(new ArrayList<ConnectionEventListener>(1));
 this.connection = null;
 }
 
 public Object getConnection(Subject subject,
 ConnectionRequestInfo cxRequestInfo) throws ResourceException {
 log.finest("getConnection()");
 connection = new XMPPConnectionImpl(this, mcf);
 return connection;
 } public void sendMessage(String recipient, String message) throws MessageException {
 log.finest("sendMessage()");
 
 final XMPPResourceAdapter resourceAdapter = (XMPPResourceAdapter) mcf.getResourceAdapter();
 resourceAdapter.sendXMPPMessage(recipient, message);
 } }
  • 43. JavaOne @jongallimore @dblevins @tomitribe#Connectors Using a connecNon • Use @Resource to inject the connecLon factory into a managed component • Obtain a connecLon from the connecLon factory and use it • Do not forget to close the connecLon when you have finished @MessageDriven(name = "Chat")
 public class ChatBean implements XMPPMessageListener {
 
 @Resource
 private XMPPConnectionFactory cf;
 
 @MessageText("echo {message:.*$}")
 public void echo(@SenderParam final String sender, @MessageTextParam("message") final String message) throws Exception {
 final XMPPConnection connection = cf.getConnection();
 connection.sendMessage(sender, message);
 connection.close();
 } }
  • 44. JavaOne @jongallimore @dblevins @tomitribe#Connectors Example: XMPP • Bi-direcLonal connector • Incoming messages call MDBs • ApplicaLon components can use the ConnecLonFactory to send messages • MDB uses the ConnecLonFactory to create an “interacLve bot”
  • 45. JavaOne @jongallimore @dblevins @tomitribe#Connectors Want more? • Examples • h]ps://tomitribe.io/projects/cha]erbox • h]ps://github.com/tomitribe/connector-starter-project • Standardized Extension-Building in Java EE with CDI and JCA [CON2385], Jason Porter, Oct 28th, 4.30pm, Parc 55 Mission
  • 46. JavaOne @jongallimore @dblevins @tomitribe#Connectors Thank You! Jonathan Gallimore Tomitribe David Blevins Tomitribe