Diagrams

The exchange of messages between the JEE container and a JEE Resource Adapter (RA) can seen complex at first glance.

Building on ideas inspired from a blog post written by Rafael Ribeiro I’ll try to gradually distill the JEE Container / RA / Application exchanges in simplified diagrams generated by an excellent open source diagramming tool called PlantUML.

RA State Transitions

Understanding all of the message exchanges with JCA Resource Adapters is complicated by the fact that a resource adapter transitions through several states during its life cycle, and each state can consist of several exchanges between the container and the RA as well as between the application and the RA.

The purpose of some of the APIs in the interfaces will also be easier to explain if we decompose the RA life cycle into discrete states.

The following diagram represents the state transitions a resource adapter makes as it is loaded, used, and unloaded by an active JEE container.

@startuml
scale 3/3

[*] -d-> undeployed

undeployed -r-> deploying
deploying -r-> deployed
deployed -r-> undeploying
undeploying -d-> undeployed

undeployed --> [*]

@enduml

Deploying

When a resource adapter is first started by a JEE container it enters the deploying state.

During the deploying state the JEE container will invoke the resource adapter start( BootstrapContext ) method. The BootstrapContext instance contains a reference to the container managed WorkManager instance which allows the RA to submit threads for execution in a container managed thread executor.

@startuml

scale 3/3
hide footbox
participant "JEE Container" as container
participant "<<ResourceAdapter>>\nEchoResourceAdapter" as ra
participant "<<ManagedConnectionFactory>>\n<<ResourceAdapterAssociation>>\n<<ValidatingManagedConnectionFactory>>\nEchoManagedConnectionFactor" as mcf

activate container

... Container Start up ...

container -> ra: start( **BootstrapContext** )

activate ra
activate mcf

alt implements ResourceAdapterAssociation

container -> mcf: setResourceAdapter( **ResourceAdapter** )

end

activate mcf

... Container Shut down ...

container -> ra: stop

deactivate ra
deactivate mcf

@enduml

Deployment

scale 2/3
hide footbox
participant "JEE Container" as container
participant "<<Interface>>\njavax.resource.spi\nResourceAdapter" as ra

... Container Start up ...

container -> ra: start
activate ra

group If the RA handles inbound connections
... An MDB is deployed to the container ...
container -> ra: endpointActivation
... An MDB is removed from the container ...
container -> ra: endpointDeactivation
end

... Container Shutdown\n or RA re-deployment ...

container -> ra: stop
deactivate ra

Running

scale 2/3
hide footbox
actor Servlet
boundary ConnectonFactory
entity Container
entity ManagedConnectionFactory
entity ManagedConnection

== container start up ==
activate Container
Container -> ManagedConnectionFactory: createConnectionFactory

activate ManagedConnectionFactory

ManagedConnectionFactory -> ConnectonFactory
activate ConnectonFactory

== normal op ==

Servlet -> ConnectonFactory: getConnection
ConnectonFactory -> ManagedConnectionFactory: createManagedConnection
ManagedConnectionFactory -> ManagedConnection
activate ManagedConnection
Container -> ManagedConnection: addConnectionEventListener