aspose file tools*
The moose likes JBoss/WildFly and the fly likes Flush Connections Programatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Flush Connections Programatically" Watch "Flush Connections Programatically" New topic
Author

Flush Connections Programatically

chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
Hi,
i am new bie to Jboss 7.
Earlier i have worked with jboss 4.x/5.x
We use to have connections probelm with our applications.So we use to flush them programaticaly using the following code
MBeanServer server = MBeanServerLocator.locateJBoss();
server.invoke(new ObjectName("jboss.jca:name=DefaultDS,service=ManagedConnectionPool"), "flush", [] as Object[], [] as String[]);

Please some one suggest me in doing the similar kind of job in JBoss 7.1
I am using XA DataSource
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
Can some body please help me in resolving this issue...
Thanks in Advance
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10111
    
165

I haven't looked, but have you connected JConsole to your running WildFly/AS7 instance and checked what MBeans and operations are exposed for the datasource?

[My Blog] [JavaRanch Journal]
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
JConsole doesnt show up the MBeans for the data source.....
Thanks for the reply
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10111
    
165

chicha sonu wrote:JConsole doesnt show up the MBeans for the data source.....


How did you check that?

I decided to check it myself and I can see the MBeans and even the flush operations.



[Thumbnail for mbeans.png]

chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
When i try to run Jconsole it shows the following error

"C:\Program Files\Java\jre7\bin\jconsole.exe"' is not recognized as an internal or external command,
perable program or batch file.

Please let me know the way to access Jconsole
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10111
    
165

chicha sonu wrote:When i try to run Jconsole it shows the following error

"C:\Program Files\Java\jre7\bin\jconsole.exe"' is not recognized as an internal or external command,
perable program or batch file.

Please let me know the way to access Jconsole


If you aren't able to bring up JConsole then I'm surprised by your previous reply where you gave the impression that you have already opened it up and checked.

As for this specific error message, what exact command are you running which gives this error? What happens if you move the Java installation to a folder which doesn't contain the space character in its path? For example: C:\Java\jre7
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
Sorry JaiKiran
I was confused with JMX Console with previous version of jboss with Jconsole.
I am completely new to this JConsole and how to get into this jconsole for catching up MBeans...
Thanks for the reply...
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
The command which is was trying is to execute is jconsole.bat from JBOSS_HOME/bin directory...and there is also no space character....
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
Hi Jaikiran..
Now i Could see the MBeans in JConsole....
Please help me in invoking in Programatically...
Thanks in Advance
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10111
    
165

chicha sonu wrote:Sorry JaiKiran
I was confused with JMX Console with previous version of jboss with Jconsole.



Thanks for clarifying.

Now i Could see the MBeans in JConsole....
Please help me in invoking in Programatically...


All you need to do is the change ObjectName ("jboss.jca:name=DefaultDS,service=ManagedConnectionPool") to the new one that you can find when you traverse the tree in JConsole and also change the operation name and its signature in your calling program. I don't have JConsole open in front of me, so I don't know the exact values. But it should be simple to figure it out when you traverse the tree or perhaps it's even printed in there.
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
Hi Jaikiran,
Thanks for the reply.
I have found the Object Name from JConsole..
So Please let me know if i am wrong
My Programatical Invocation goes as follows
MBeanServer server = MBeanServerLocator.locateJBoss();
server.invoke(new ObjectName("jboss.as:subsystem=datasources,data-source=OracleDS"), "flushAllConnectionInPool", [] as Object[], [] as String[]);

Please Let me know if i am worng
Thanks in Advance



[Thumbnail for Mbeans.jpg]

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10111
    
165

That looks fine although I don't understand:

[] as Object[], [] as String[]


shouldn't that be new Object[], new String[] or even null, null?
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
Hi Jai Kiran
I have Tried the same
I get the following Exception.

default task-13) Method execution failed: : java.lang.IllegalStateException: No 'jboss' MBeanServer found!
at org.jboss.mx.util.MBeanServerLocator.locateJBoss(MBeanServerLocator.java:122) [jbossall-client.jar:4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221
139)]
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
Hi Jaikiran,
I have made small change in Code
MBeanServerConnection server=ManagementFactory.getPlatformMBeanServer();
By Using this i am able to retrieve all the Attributes of my DataSource
Where as i am not able to perform any operations using this.I get following Exception when trying to Perform any Operations


23:08:16,083 INFO [stdout] (default task-17) java.lang.NullPointerException

23:08:16,086 INFO [stdout] (default task-17) at org.jboss.as.jmx.MBeanServerAuditLogger.isOperationReadOnly(MBeanServerAuditLogger.java:494)

23:08:16,087 INFO [stdout] (default task-17) at org.jboss.as.jmx.MBeanServerAuditLogger.invoke(MBeanServerAuditLogger.java:293)

23:08:16,089 INFO [stdout] (default task-17) at org.jboss.as.jmx.PluggableMBeanServerImpl.invoke(PluggableMBeanServerImpl.java:548)

23:08:16,091 INFO [stdout] (default task-17) at com.dao.MyDao.flushConnectionPool(MyDao.java:21)

23:08:16,092 INFO [stdout] (default task-17) at com.service.MyService.CallFlush(MyService.java:14)



Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10111
    
165



That's the correct change.

As for the NullPointerException, which exact version of JBoss AS7 or WildFly is this? I know you mentioned 7.1 in your original post, but I want to be sure. So is this 7.1.1 or something else?
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
hi jaikiran
i have been trying this on wildfly8.0.0.0.Alpha4
thanks for the reply...
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10111
    
165

i have been trying this on wildfly8.0.0.0.Alpha4


We just released WildFly 8.0.0.Beta1 just a couple of days back http://wildfly.org/download/. Can you please try that version? There were some changes in the area you are running into problems with, so see if that's fixed in there.
chicha sonu
Greenhorn

Joined: Sep 15, 2013
Posts: 28
Thanks JaiKiran
The Problem has been resolved
 
Consider Paul's rocket mass heater.
 
subject: Flush Connections Programatically