IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Services and service-related functions > Access external services with adapters > Configure and using adapters > IBM WebSphere Adapters > Adapter Toolkit > Implementing code from the IBM WebSphere Adapter Toolkit > Outbound support > Implementing outbound support
WBIManagedConnection
WBIManagedconnection is an abstract class which implements javax.resource.spi.ManagedConnection. A javax.resource.spi.ManagedConnection instance represents a physical connection to the underlying EIS. The WBIManagedConnection instance implements methods that enable the JCA container to monitor its status and manage its lifecycle.
Subclass methods to implement
- public ManagedConnection(WBIManagedConnectionFactory mcf, Subject subject, WBIConnectionRequestInfo)
This constructor should connect to the EIS instance and maintain a handle to the connection as a property in the ManagedConnection. This method also must call "super" to ensure that the credentials are present for later matching.
- ManagedConnectionMetaData getMetaData()
Create and return a new instance of WBIManagedConnectionMetadata by passing the EIS-specific details such as product name, product version, maximum connections, and user name.
To:public ManagedConnectionMetaData getMetaData() throws ResourceException { return new WBIManagedConnectionMetaData("VTA", "VTA", 1,"VTA"); }- Object getWBIConnection(PasswordCredential, boolean)
If reauthentication is supported, implementation should perform an EIS-specific sign-on based on the credentials passed. Otherwise, it should return a CCI handle to this managed connection.
public Object getWBIConnection(PasswordCredential arg0, boolean arg1) throws ResourceException { if (logUtils.isTraceEnabled(Level.FINE)) logUtils.traceMethodEntrance(EISSAConstants.VTAMANAGEDCONN, "getWBIConnection"); if(rmiSession == null){ String host = factory.getHostname(); String port = factory.getPortnumber(); if (logUtils.isTraceEnabled(Level.FINE)) { logUtils.trace(Level.FINEST, EISSAConstants.VTAEVENTSTOREXID, "EISSAEventStoreWithXid", "The host name is " + host); logUtils.trace(Level.FINEST, EISSAConstants.VTAEVENTSTOREXID, "EISSAEventStoreWithXid", "The port is " + port); } if(host!=null && host.length()>0 && port != null && port.length()>0){ try{ rmiSession = new RMIObjectClient(host, Integer.parseInt(port)); }catch(Exception e){//fail to establish the connection. logUtils.log(LogLevel.FATAL, LogUtilConstants.ADAPTER_RBUNDLE, EISSAConstants.VTAMANAGEDCONN," getWBIConnection", "6011"); throw new CommException("The adapter failed to establish the connection with EIS Mocker.",e); } }else{ } } if (logUtils.isTraceEnabled(Level.FINE)) logUtils.traceMethodExit(EISSAConstants.VTAMANAGEDCONN, "getWBIConnection"); return new EISSAConnection(this); }- destroy()
This method should close this connection to the EIS and release any resources.
Best practices
- Each ManagedConnection instance should encapsulate at most one connection to the EIS.
- Since there may be more than one Connection instance for each ManagedConnection instance, resource adapter developers should implement private contracts between their WBIManagedConnection subclass and their WBIConnection/WBIInteractionsubclasses to ensure that access to the underlying EIS connection or API is performed in a thread-safe manner.
If the EIS API does not support concurrent access by multiple connection handles, concurrent access should not be denied. Instead, the implementation should ensure that one and only one handle can access the EIS at a time (through synchronization blocks, wait/notify patterns, and so on).
- At the start of any EIS-specific method implementation, developers should always invoke super.checkValidity(); this method checks the state of the ManagedConnection instance to ensure that it has not been closed, encountered an error, and so on.
- If possible, always employ eager class initialization of the physical connection to the EIS; do not assume that getConnection is the first method invoked. The JCA container may need to access the XAResource, LocalTransaction, or other features of the managed connection for recovery, and so on, before any client even issues a first request.
Related concepts: