This discussion is archived
0 Replies Latest reply: Sep 28, 2010 12:10 AM by SatendraPare RSS

SOA OC4J Connaction Pool Refresh Using MBean

SatendraPare Newbie
Currently Being Moderated
Hi All

I am using MBean API for refreshing connection pool of oc4j soa. After running the program it is completing with out any exception but while checking on em console i found all the statistics of connection pool as it is.

Please find used code--

package connectionpoolrefresh;

import java.io.IOException;

import java.net.MalformedURLException;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.IntrospectionException;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import oracle.oc4j.admin.jmx.remote.api.JMXConnectorConstant;


public class MBeanClient {

private static final String SOASUITE_OC4J_SOA_URL = "service:jmx:rmi:///opmn://host:6003/home_soa";
private static final String USERNAME = "*******";
private static final String PASSWORD = "**********";
//private static final String MBEAN_OBJECT_NAME = "oc4j:j2eeType=JDBCResource,name=\"CONNECTION_POOL_NAME\",J2EEApplication=default,J2EEServer=standalone";
//private static final String MBEAN_OBJECT_NAME = "oc4j:j2eeType=JDBCResource,name=\"test_CONNECTION_POOL\",J2EEApplication=default,J2EEServer=standalone";
private static final String MBEAN_OBJECT_NAME = "oc4j:j2eeType=JDBCResource,name=\"test_CONNECTION_POOL\",J2EEApplication=default,J2EEServer=standalone";
private static final String MBEAN_METHOD_NAME = "refreshConnectionPool";
//private static final String MBEAN_METHOD_NAME1 = "getMBeanInfo";

public MBeanClient()
{
}

public MBeanServerConnection getMBeanConnection(String URL) throws MalformedURLException, IOException
{       
JMXConnector jmxConnector = null;
JMXServiceURL serviceUrl = new JMXServiceURL(URL);


Hashtable env = new Hashtable();
env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "oracle.oc4j.admin.jmx.remote");

Hashtable credentials = new Hashtable();
credentials.put(JMXConnectorConstant.CREDENTIALS_LOGIN_KEY, USERNAME);
credentials.put(JMXConnectorConstant.CREDENTIALS_PASSWORD_KEY, PASSWORD);
env.put(JMXConnector.CREDENTIALS, credentials);
//env.put(JMXConnectorConstant.PROPRIETARY_MBEANSERVER_DOMAIN_NAME, "myserv");


jmxConnector = JMXConnectorFactory.newJMXConnector(serviceUrl, env);
jmxConnector.connect();

MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();

return mBeanServerConnection;
}

private void refreshConnectionPool(String connectionPoolName) throws MalformedURLException, IOException, MalformedObjectNameException, InstanceNotFoundException, MBeanException, ReflectionException, AttributeNotFoundException, InvalidAttributeValueException,IntrospectionException
          {

MBeanServerConnection mBeanServerConnection = getMBeanConnection(SOASUITE_OC4J_SOA_URL);
String mBeanName = MBEAN_OBJECT_NAME.replace("CONNECTION_POOL_NAME",connectionPoolName);
ObjectName objectName = new ObjectName(mBeanName);
mBeanServerConnection.invoke(objectName, MBEAN_METHOD_NAME, null, null);

MBeanInfo mbeaninfo = mBeanServerConnection.getMBeanInfo(objectName);
System.out.println(" Connection Pool [" + connectionPoolName + "] is refreshed." );
}

public static void main(String[] args) throws MalformedURLException, IOException, MalformedObjectNameException, InstanceNotFoundException, MBeanException, ReflectionException, AttributeNotFoundException, InvalidAttributeValueException,IntrospectionException {

System.out.println("11");
MBeanClient mBeanClient = new MBeanClient();
mBeanClient.refreshConnectionPool("CLRTEST_CONNECTION_POOL");

}

/*public void printAllMBeans(MBeanServerConnection mBeanServerConnection) throws IOException {
System.out.println(" \n\n ------------------------------------ Printing all MBean ------------------------------------ ");
Set mbeans = mBeanServerConnection.queryNames(null, null);
Iterator iter = mbeans.iterator();
while (iter.hasNext()) {
System.out.println(iter.next().toString());
ObjectName objectName = (ObjectName)iter.next();
System.out.println(" domain " + objectName.getDomain() + " " + objectName.getKeyPropertyListString() );
}
System.out.println(" ------------------------------------------------------------------------ \n\n ");
}*/

}


Please let me know if I am doing something wrong.


Thanks
Satendra

Edited by: Satendra Pare on Sep 28, 2010 12:09 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points