Thursday, January 31, 2013

Tomcat with JMX

If you want to add JMX capability to your tomcat, do the following:


in your $tomcat/conf/server.xml, add the following (in bold)


<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener"   miRegistryPortPlatform="10099" rmiServerPortPlatform="9595" />




In addition, add to your $tomcat/lib/ directory the JAR that gives this JMX capability , called catalina-jmx-remote.jar
I can see that you can find it here:





Wednesday, January 30, 2013

Unlocker - file handling detector

Simple copy/paste from this URL http://www.filehippo.com/download_unlocker/


If you've ever been unable to delete a file in Windows, and can't figure out what program's using it, Unlocker is the solution. Have you ever seen these Windows error messages?
  • Cannot delete folder: It is being used by another person or program
  • Cannot delete file: Access is denied
  • There has been a sharing violation.
  • The source or destination file may be in use.
  • The file is in use by another program or user.
  • Make sure the disk is not full or write-protected and that the file is not currently in use.
Unlocker can help! Simply right-click the folder or file and select Unlocker. If the folder or file is locked, a window listing of lockers will appear. Simply click Unlock All and you are done!






Tuesday, January 1, 2013

Problem during access to JMX bean (attribute / operation)


Once again, I've failed at the exact same place ...
I tried to access a JMX bean programatically ... Everything went well (I'm using this wonderful spring infra for accessing my bean).

BUT ... when you try to access a bean that is not well exposed, according to standard, this won't work:

If you expose an operation (and not as attribute) that looks like
public String getServiceStatus()

since it starts by the prefix get , it doesn't receive argument and it returns a value (not a void).
The standard requires that such method should be at least defined as attribute in the JMX server. If it is not, the javax.management.MBeanServerInvocationHandler   won't be able to access the operation.



You can see that in the invoke() method of this MBeanServerInvocationHandler()


      if (methodName.startsWith("get")
                    && methodName.length() > 3
                    && nargs == 0
                    && !returnType.equals(Void.TYPE)) {
                    return connection.getAttribute(objectName,
                        methodName.substring(3));
                }



So the way I've found for overcoming this obstacle was ... to call another bean :(


Here's an example of Spring usage for accessing JMX bean (it's not mine but it's similar):


<bean id="clientConnector"
      class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
  <property name="serviceUrl" value="service:jmx:rmi://remotehost:9875"/>
</bean>

<bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
  <property name="objectName" value="bean:name=testBean"/>
  <property name="proxyInterface" value="org.springframework.jmx.IJmxTestBean"/>
  <property name="server" ref="clientConnector"/>
</bean>