05 November 2008

Checking if FastSwap is enabled

In doing some work with the FastSwap feature of WebLogic Server recently, I wanted to be able to display whether FastSwap was enabled for the application.

I used the small hack below to determine whether FastSwap is enabled or not for the application. This examines the current ClassLoader that is being used and compares it with the FastSwap enabled ClassLoader.

private final String fastSwapLoader = "com.bea.wls.redef.RedefiningClassLoader";
...
private boolean isFastSwapEnabled() {
return Thread.currentThread().getContextClassLoader().getClass().getName().equals(fastSwapLoader);
}
If the classloader name changes in a future release, then of course this would break ... but it serves the purpose currently on WLS 10.3.

Another interesting area was to observe how the class name changed as the underlying class itself changed and FastSwap did its funky thing. I noticed that the second frame on the Thread stack contains the FastSwap modified classname. Grabbing that, you can keep track of the class name changes over time to display.

private String determineClassName() {
return Thread.currentThread().getStackTrace()[1].getClassName();
}

As the class changes over time, the names will look like the below:

  • sab.demo.fastswap.web.TestServlet_beaVersion0_1
  • sab.demo.fastswap.web.TestServlet_beaVersion1_11
  • sab.demo.fastswap.web.TestServlet_beaVersion2_12
  • ...

No comments: