Fusioncube

The online journey of a technophile, by Steve Brownlee

Scope Enhancer

Since the ColdFusion server runs on top of a Java subsystem, I thought it was time for the Server scope to actually contain information about the Java server as well as the CFML processor. The Enhancer adds a new JVM key to the Server scope and adds more keys to the Server.OS structure.

*click image to view full size
Enahncer-781708.jpg

New keys:

  • server.jvm.memory
  • server.jvm.memory.pools
  • server.jvm.threads
  • server.jvm.arguments
  • server.os.CommittedVirtualMemorySize
  • server.os.FreePhysicalMemorySize
  • server.os.FreeSwapSpaceSize
  • server.os.ProcessCpuTime
  • server.os.TotalPhysicalMemorySize
  • server.os.TotalSwapSpaceSize
  • server.os.AvailableProcessors
  • server.os.MBeanInfo

Of course, you can remove any information that you don’t want from the code, but even on my wimpy 500MB RAM/1.33 MHz laptop, execution time for the code was max 67ms and averaged about 32ms.

I created a Java library that you can now include in your ColdFusion web application’s WEB-INF\lib directory.
Scope Enhancer Location

This makes the code much more simple to read and maintain. Here’s an example call to enhance your Server scope.

<cfscript>
runtime = createobject("java", "java.lang.Runtime");
enhancer = createobject("java", "orbwave.ScopeEnhancer");
mgmtFactory = createobject("java", "java.lang.management.ManagementFactory");
sys = createobject("java", "java.lang.System");

memoryPoolBean = mgmtFactory.MemoryPoolMXBeans;

server.jvm = StructNew();
server.jvm.memory = StructNew();
server.jvm.memory.pools = enhancer.memoryPools();
server.jvm.memory.free = runtime.getRuntime().freeMemory();
server.jvm.memory.max = runtime.getRuntime().maxMemory();

server.jvm.arguments = mgmtFactory.RuntimeMXBean.getInputArguments();
server.jvm.threads = enhancer.serverThreads();
server.jvm.properties = enhancer.systemProperties();

server.os.environmentVariables = enhancer.environmentVariables();
</cfscript>

One addition was made in the new library and that is the os.environmentVariables key that holds all of the environment variables of your operating system.
evars.gif

Steps to install

  1. Download enhancer.jar library
  2. Put the enhancer.jar file in your web application’s WEB-INF\lib directory.
  3. Restart your Java application server
  4. Copy the code shown above into application (for example, your onApplicationStart event in Application.cfc)

Now all of the information is available for your use.

About Steve

I am a technologist, and have been ever since 1980 when I got my very first TRS-80 and programmed it to do my math homework. I love to share the gift of technology with others and show them the wonderful things it can do for them, and how they should not fear it, but embrace it.

Latest Tweets

  • Ok... stayed up way too late trying out website designs for my wife's new nonprofit. The kids will be getting me u... — http://t.co/QrKh5iBI
  • Am I the only one who likes Google’s new privacy policy? http://t.co/qwcym5wH
  • All that time wasted learning the .NET framework - Fusioncube - http://t.co/krANoWmg
  • @marcesher libraries like Less only do what you tell them. You can make a mixin to do that, but it doesn't assume anything (which is good)
  • Circus about to start. Girls are so excited they can't stand it!!!! (with Sabrina and Tessa at @BrdgstoneArena) [pic] — http://t.co/PXwi5emj

Subscribe

Entries (RSS)
Comments (RSS)