Example: Accessing MBean connection factory and data sources using wsadmin
Wsadmin commands are used to access connection factory and data source MBeans. MBeans can retrieve or update properties for a connection factory or data source.
To get a list of J2C connection factory or data source Mbean object names, from the wsadmin command line use one of the following administrative control commands:
$AdminControl queryNames *:type=J2CConnectionFactory,* $AdminControl queryNames *:type=DataSource,*Example output from DataSource query:
wsadmin>$AdminControl queryNames *:type=DataSource,* "WebSphere:name=Default Datasource,process=server1,platform=dynamicproxy,node= system1Node01,JDBCProvider=Cloudscape JDBC Provider,j2eeType=JDBCDataSource,J2EESe rver=server1,Server=server1,version=6.0.0.0,type=DataSource,mbeanIdentifier=cell s/system1Node01Cell/nodes/system1Node01/servers/server1/resources.xml#DataSource _1094760149902,JDBCResource=Cloudscape JDBC Provider,cell=system1Node01Cell"By using the J2C connection factory or data source MBean object name, you can access the MBean. The name follows the webSphere:name= expression. In the following example, for the first set, the default data source name is set on variable name. For the second set, the object name is set on variable objectName.
Example using the Default Datasource
- wsadmin>set name [list Default Datasource] Default Datasource - wsadmin>set objectName [$AdminControl queryNames *:name=$name,*] "WebSphere:name=Default Datasource,process=server1,platform=dynamicproxy,node= system1Node01,JDBCProvider=Cloudscape JDBC Provider,j2eeType=JDBCDataSource,J2EESe rver=server1,Server=server1,version=6.0.0.0,type=DataSource,mbeanIdentifier=cell s/system1Node01Cell/nodes/system1Node01/servers/server1/resources.xml#DataSource _1094760149902,JDBCResource=Cloudscape JDBC Provider,cell=system1Node01Cell"Now you can use the objectName for getting help on attributes and operations available for this mbean.
$Help attributes $objectName $Help operations $objectNameTo get or set an attribute or to use an operation, use one of the following commands:
$AdminControl getAttribute $objectName "attribute name" $AdminControl setAttribute $objectName "attribute name" value $AdminControl invoke $objectName "operation"Attribute, operation examples:
Get and set a attribute maxConnections (Note, if you get no value, a null value, or a java.lang.IllegalStateException, the connection factory or data source for this MBean has not been created. The connection factory or data source is created at first JNDI lookup. For this example, the Default Datasource needs to be used before get, set and invoke will work.) wsadmin>$AdminControl getAttribute $objectName maxConnections 10 wsadmin>$AdminControl setAttribute $objectName maxConnections 20 wsadmin>$AdminControl getAttribute $objectName maxConnections 20Use invoke wsadmin>$AdminControl invoke $objectName showPoolContents PoolManager name:DefaultDatasource PoolManager object:746354514 Total number of connections: 3 (max/min 20/1, reap/unused/aged 180/1800/0, connectiontimeout/purge 1800/EntirePool) (testConnection/inteval false/0, stuck timer/time /threshold 0/0/0, surge time/connections 0/-1) Shared Connection information (shared partitions 200) No shared connections Free Connection information (free distribution table/partitions 5/1) (2)(0)MCWrapper id 5c6af75b Managed connection WSRdbManagedConnectionImpl@4b5 a775b State:STATE_ACTIVE_FREE (2)(0)MCWrapper id 3394375a Managed connection WSRdbManagedConnectionImpl@328 5f75a State:STATE_ACTIVE_FREE (2)(0)MCWrapper id 4795b75a Managed connection WSRdbManagedConnectionImpl@46a 4b75a State:STATE_ACTIVE_FREE Total number of connection in free pool: 3 UnShared Connection information No unshared connections
Here is an example Java program using the wsadmin tool to invoke showPoolContents: ShowPoolContents.Java code.
Sub-topics
Example: Invoking showPoolContents using the wsadmin tool
Reference topic