Adapter Development Kit 6.5 | webMethods Adapter Development Kit Documentation | webMethods Adapter Development Kit Installation and User’s Documentation | Run Time Activities | Run Time Connection Allocation for Adapter Services | Implementing Partitioned Connection Pools | Extending WmConnectionRequestInfo
 
Extending WmConnectionRequestInfo
A ConnectionRequestInfo object defines a partition both within the connection pool and in WmManagedConnectionFactory.createManagedConnectionObject() when a new connection is created. The connection pool organized its connections based on the ConnectionRequestInfo object used when the connection was created. In this case, ConnectionRequestInfo objects X and Y are considered the same if (X.hashCode() == Y.hashCode() && X.equals(Y)) The remainder of the ConnectionRequestInfo implementation is defined by the adapter.
In the MegaBank example, a partition is defined by the userId with which the back-end connection is established. In order to ensure that the connection pool properly recognizes objects that refer to the same partition, the example below implements the hashCode() and equals() methods so that they only refer to the userId String.
The final abstract method that must be implemented is getLogableName(). This method is used to provide a partition name that can be recorded in Integration Server logs. In this example, it is also used to correlate the MegaBank user name with the ID used to access the backend. Care should be taken in implementing this method to avoid exposing any sensitive data (such as passwords).
public class MbConnectionRequestInfo extends WmConnectionRequestInfo
{

private final String userId;
private final String mbUserName;
private final Credentials credentials;
private final String logName;

/**
* Sole constructor. verifies all fields populated.
*
* @param mbUserName - common user name used across the integration
* @param userId - name of user as known to the backend system
* @param credentials - credentials required for this user to access
* the backend system
* @throws IllegalArgumentException - if any argument is null
*/
public MbConnectionRequestInfo(String mbUserName, String userId,
Credentials credentials) throws IllegalArgumentException
{
if (mbUserName == null || userId == null || credentials == null)
{
throw new IllegalArgumentException();
}
this.userId = userId;
this.mbUserName = mbUserName;
this.credentials = credentials;
this.logName = mbUserName + "(" + userId + ")";
}

public Credentials getCredentials()
{
return credentials;
}
public String getMbUserName()
{
return mbUserName;
}
public String getUserId()
{
return userId;
}

/**
* Name used by the connection pool when creating log entries relevant
* to the partition identified by this object.
*/
public String getLoggableName()
{
return logName;
}
/**
* In a ConnectionRequestInfo object the hashCode of objects that
* identifythe same partion must be the same, so we use only the
* hashcode of the userId String.
*/
public int hashCode()
{
return this.userId.hashCode();
}
/**
* If two ConnectionRequestInfo objects identify the same partition,
* then the equals method must return true. We compare the userIds of
* the two object rather than allow the default equals implementation
* which only checks if they are the same object instance.
* @param obj - object being compared to this.
*/
public boolean equals(Object obj)
{
boolean isEqual = false;
if(obj instanceof MbConnectionRequestInfo)
{
isEqual = this.userId.equals(((MbConnectionRequestInfo)obj).userId);
}
return isEqual;
}