Labeling Connections in UCP – Adjusting with the API

After decompiling the ucp jar file, I was able to understand the labeling connection callback better and got to know that the implementation didn’t completely match with the jdbc developer guide. This post will detail out on a couple of mismatch’d points from the developer guide.

public boolean configure(Properties reqLabels, Object conn)

From the documentation “This method is called by the connection pool on the selected connection before returning it to the application. The method is used to set the state of the connection and apply or remove any labels to/from the connection.”

a. This method is called only when the cost for configuring the connection (i.e. the integer value returned by the cost() method) is greater then 0 and less then Integer.MAX_VALUE. This method is not called if the cost() method returns 0 (i.e. exact match) or Integer.MAX_VALUE (i.e. indicates that a new connection needs to be created).

b. The connection instance passed to the configure method is the actual physical connection instance. Hence it cannot be casted to LabelableConnection. A workaround to this is detailed my earlier post.

The above two points would be clear after seeing the below ucp code.


for (UniversalPooledConnection conn : availableConnections) {
    ....
    ....

    Properties currentLabels = conn.getConnectionLabels();
    int currentLabelingCost =this.m_cp.getConnectionLabelingCallback().cost       (requestedLabels, currentLabels);

    if (currentLabelingCost == 2147483647) {
      continue;
    }

    if (currentLabelingCost < lowestLabelingCost) {
         lowestLabelingCost = currentLabelingCost;
         pc = conn;

         if (lowestLabelingCost == 0) {
            break;
         }
    }
    ......
    ......
}  //for loop ends

if ((pc != null) && (((isLabeledRequest) && (lowestLabelingCost > 0)) || (isRetryForLabeledRequest)))
 {
       this.m_cp.getConnectionLabelingCallback().configure(requestedLabels, pc.getPhysicalConnection());
 }

......

Advertisement

Posted on December 19, 2011, in oracle-jdbc. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: